am a9df3402: am 68bb7221: am 6f0490fb: am c0aa9744: Merge "PopupWindow position must be specified in window coordinates." into mnc-dev
* commit 'a9df340233de9cf30680c981620d11e5f7e1394e': PopupWindow position must be specified in window coordinates.
This commit is contained in:
@@ -285,7 +285,6 @@ public final class FloatingToolbar {
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final View mParent;
|
private final View mParent;
|
||||||
private final int[] mParentPositionOnScreen = new int[2];
|
|
||||||
private final PopupWindow mPopupWindow;
|
private final PopupWindow mPopupWindow;
|
||||||
private final ViewGroup mContentContainer;
|
private final ViewGroup mContentContainer;
|
||||||
private final int mMarginHorizontal;
|
private final int mMarginHorizontal;
|
||||||
@@ -339,7 +338,8 @@ public final class FloatingToolbar {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private final Rect mViewPortOnScreen = new Rect();
|
private final Rect mViewPortOnScreen = new Rect();
|
||||||
private final Point mCoordsOnScreen = new Point();
|
private final Point mCoordsOnWindow = new Point();
|
||||||
|
private final int[] mTmpCoords = new int[2];
|
||||||
private final Rect mTmpRect = new Rect();
|
private final Rect mTmpRect = new Rect();
|
||||||
|
|
||||||
private final Region mTouchableRegion = new Region();
|
private final Region mTouchableRegion = new Region();
|
||||||
@@ -450,16 +450,11 @@ public final class FloatingToolbar {
|
|||||||
}
|
}
|
||||||
refreshCoordinatesAndOverflowDirection(contentRectOnScreen);
|
refreshCoordinatesAndOverflowDirection(contentRectOnScreen);
|
||||||
preparePopupContent();
|
preparePopupContent();
|
||||||
// PopupWindow#showAtLocation() receives the location relative to the attached window
|
// We need to specify the position in window coordinates.
|
||||||
// hence the following code is correct when and only when mParent is aligned to the
|
|
||||||
// top-left of the attached window.
|
|
||||||
// TODO: Fix the following logic so that mParent can be placed at anywhere.
|
|
||||||
// TODO: Consider to use PopupWindow.setLayoutInScreenEnabled(true) so that we can
|
// TODO: Consider to use PopupWindow.setLayoutInScreenEnabled(true) so that we can
|
||||||
// specify the popup poision in screen coordinates.
|
// specify the popup poision in screen coordinates.
|
||||||
mParent.getLocationOnScreen(mParentPositionOnScreen);
|
mPopupWindow.showAtLocation(mParent, Gravity.NO_GRAVITY, mCoordsOnWindow.x,
|
||||||
final int relativeX = mCoordsOnScreen.x - mParentPositionOnScreen[0];
|
mCoordsOnWindow.y);
|
||||||
final int relativeY = mCoordsOnScreen.y - mParentPositionOnScreen[1];
|
|
||||||
mPopupWindow.showAtLocation(mParent, Gravity.NO_GRAVITY, relativeX, relativeY);
|
|
||||||
setTouchableSurfaceInsetsComputer();
|
setTouchableSurfaceInsetsComputer();
|
||||||
runShowAnimation();
|
runShowAnimation();
|
||||||
}
|
}
|
||||||
@@ -522,17 +517,10 @@ public final class FloatingToolbar {
|
|||||||
cancelOverflowAnimations();
|
cancelOverflowAnimations();
|
||||||
refreshCoordinatesAndOverflowDirection(contentRectOnScreen);
|
refreshCoordinatesAndOverflowDirection(contentRectOnScreen);
|
||||||
preparePopupContent();
|
preparePopupContent();
|
||||||
// PopupWindow#update() receives the location relative to the attached window hence
|
// We need to specify the position in window coordinates.
|
||||||
// the following code is correct when and only when mParent is aligned to the top-left
|
|
||||||
// of the attached window.
|
|
||||||
// TODO: Fix the following logic so that mParent can be placed at anywhere.
|
|
||||||
// We need to specify the offset relative to mParent.
|
|
||||||
// TODO: Consider to use PopupWindow.setLayoutInScreenEnabled(true) so that we can
|
// TODO: Consider to use PopupWindow.setLayoutInScreenEnabled(true) so that we can
|
||||||
// specify the popup poision in screen coordinates.
|
// specify the popup poision in screen coordinates.
|
||||||
mParent.getLocationOnScreen(mParentPositionOnScreen);
|
mPopupWindow.update(mCoordsOnWindow.x, mCoordsOnWindow.y, getWidth(), getHeight());
|
||||||
final int relativeX = mCoordsOnScreen.x - mParentPositionOnScreen[0];
|
|
||||||
final int relativeY = mCoordsOnScreen.y - mParentPositionOnScreen[1];
|
|
||||||
mPopupWindow.update(relativeX, relativeY, getWidth(), getHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -631,7 +619,22 @@ public final class FloatingToolbar {
|
|||||||
mOverflowPanel.setOverflowDirection(mOverflowDirection);
|
mOverflowPanel.setOverflowDirection(mOverflowDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
mCoordsOnScreen.set(x, y);
|
// We later specify the location of PopupWindow relative to the attached window.
|
||||||
|
// The idea here is that 1) we can get the location of a View in both window coordinates
|
||||||
|
// and screen coordiantes, where the offset between them should be equal to the window
|
||||||
|
// origin, and 2) we can use an arbitrary for this calculation while calculating the
|
||||||
|
// location of the rootview is supposed to be least expensive.
|
||||||
|
// TODO: Consider to use PopupWindow.setLayoutInScreenEnabled(true) so that we can avoid
|
||||||
|
// the following calculation.
|
||||||
|
mParent.getRootView().getLocationOnScreen(mTmpCoords);
|
||||||
|
int rootViewLeftOnScreen = mTmpCoords[0];
|
||||||
|
int rootViewTopOnScreen = mTmpCoords[1];
|
||||||
|
mParent.getRootView().getLocationInWindow(mTmpCoords);
|
||||||
|
int rootViewLeftOnWindow = mTmpCoords[0];
|
||||||
|
int rootViewTopOnWindow = mTmpCoords[1];
|
||||||
|
int windowLeftOnScreen = rootViewLeftOnScreen - rootViewLeftOnWindow;
|
||||||
|
int windowTopOnScreen = rootViewTopOnScreen - rootViewTopOnWindow;
|
||||||
|
mCoordsOnWindow.set(x - windowLeftOnScreen, y - windowTopOnScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getToolbarHeightWithVerticalMargin() {
|
private int getToolbarHeightWithVerticalMargin() {
|
||||||
|
|||||||
Reference in New Issue
Block a user