Skip to content

Commit b003e28

Browse files
author
Fabrice Di Meglio
committed
Fix bug #7367429 Popup window should get its direction from it Anchor View if it can
- set the popup layout direction depending on the anchor view's layout direction (if not defined before) - make first pass of ViewRootImpl.performTraversals() and configuration update not override any layout direction that could have been set before Change-Id: I8e86ca805f0caf52c058d06aa7861df56fb862e6
1 parent fc2652e commit b003e28

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ public final class ViewRootImpl implements ViewParent,
317317
private final int mDensity;
318318
private final int mNoncompatDensity;
319319

320+
private int mViewLayoutDirectionInitial;
321+
320322
/**
321323
* Consistency verifier for debugging purposes.
322324
*/
@@ -465,6 +467,7 @@ public void setView(View view, WindowManager.LayoutParams attrs, View panelParen
465467
synchronized (this) {
466468
if (mView == null) {
467469
mView = view;
470+
mViewLayoutDirectionInitial = mView.getRawLayoutDirection();
468471
mFallbackEventHandler.setView(view);
469472
mWindowAttributes.copyFrom(attrs);
470473
attrs = mWindowAttributes;
@@ -1184,7 +1187,10 @@ private void performTraversals() {
11841187
viewVisibilityChanged = false;
11851188
mLastConfiguration.setTo(host.getResources().getConfiguration());
11861189
mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility;
1187-
host.setLayoutDirection(mLastConfiguration.getLayoutDirection());
1190+
// Set the layout direction if it has not been set before (inherit is the default)
1191+
if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) {
1192+
host.setLayoutDirection(mLastConfiguration.getLayoutDirection());
1193+
}
11881194
host.dispatchAttachedToWindow(attachInfo, 0);
11891195
mFitSystemWindowsInsets.set(mAttachInfo.mContentInsets);
11901196
host.fitSystemWindows(mFitSystemWindowsInsets);
@@ -2680,7 +2686,8 @@ void updateConfiguration(Configuration config, boolean force) {
26802686
final int lastLayoutDirection = mLastConfiguration.getLayoutDirection();
26812687
final int currentLayoutDirection = config.getLayoutDirection();
26822688
mLastConfiguration.setTo(config);
2683-
if (lastLayoutDirection != currentLayoutDirection) {
2689+
if (lastLayoutDirection != currentLayoutDirection &&
2690+
mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) {
26842691
mView.setLayoutDirection(currentLayoutDirection);
26852692
}
26862693
mView.dispatchConfigurationChanged(config);

core/java/android/widget/PopupWindow.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public void onScrollChanged() {
142142
};
143143
private int mAnchorXoff, mAnchorYoff;
144144

145+
private boolean mPopupViewInitialLayoutDirectionInherited;
146+
145147
/**
146148
* <p>Create a new empty, non focusable popup window of dimension (0,0).</p>
147149
*
@@ -968,6 +970,8 @@ private void preparePopup(WindowManager.LayoutParams p) {
968970
} else {
969971
mPopupView = mContentView;
970972
}
973+
mPopupViewInitialLayoutDirectionInherited =
974+
(mPopupView.getRawLayoutDirection() == View.LAYOUT_DIRECTION_INHERIT);
971975
mPopupWidth = p.width;
972976
mPopupHeight = p.height;
973977
}
@@ -985,9 +989,19 @@ private void invokePopup(WindowManager.LayoutParams p) {
985989
p.packageName = mContext.getPackageName();
986990
}
987991
mPopupView.setFitsSystemWindows(mLayoutInsetDecor);
992+
setLayoutDirectionFromAnchor();
988993
mWindowManager.addView(mPopupView, p);
989994
}
990995

996+
private void setLayoutDirectionFromAnchor() {
997+
if (mAnchor != null) {
998+
View anchor = mAnchor.get();
999+
if (anchor != null && mPopupViewInitialLayoutDirectionInherited) {
1000+
mPopupView.setLayoutDirection(anchor.getLayoutDirection());
1001+
}
1002+
}
1003+
}
1004+
9911005
/**
9921006
* <p>Generate the layout parameters for the popup window.</p>
9931007
*
@@ -1304,8 +1318,9 @@ public void update() {
13041318
p.flags = newFlags;
13051319
update = true;
13061320
}
1307-
1321+
13081322
if (update) {
1323+
setLayoutDirectionFromAnchor();
13091324
mWindowManager.updateViewLayout(mPopupView, p);
13101325
}
13111326
}
@@ -1406,6 +1421,7 @@ public void update(int x, int y, int width, int height, boolean force) {
14061421
}
14071422

14081423
if (update) {
1424+
setLayoutDirectionFromAnchor();
14091425
mWindowManager.updateViewLayout(mPopupView, p);
14101426
}
14111427
}
@@ -1482,7 +1498,7 @@ private void update(View anchor, boolean updateLocation, int xoff, int yoff,
14821498
} else {
14831499
updateAboveAnchor(findDropDownPosition(anchor, p, mAnchorXoff, mAnchorYoff));
14841500
}
1485-
1501+
14861502
update(p.x, p.y, width, height, x != p.x || y != p.y);
14871503
}
14881504

0 commit comments

Comments
 (0)