Merge "Fix bug #8051633 Recent Apps thumbnails in RTL mode (Arabic / Hebrew / Farsi) should be aligned"

This commit is contained in:
Fabrice Di Meglio
2013-01-28 20:32:48 +00:00
committed by Android (Google) Code Review

View File

@@ -37,6 +37,7 @@ import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewDebug; import android.view.ViewDebug;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.RemoteViews.RemoteView; import android.widget.RemoteViews.RemoteView;
@@ -220,10 +221,13 @@ public class RelativeLayout extends ViewGroup {
// Some apps came to rely on them. :( // Some apps came to rely on them. :(
private boolean mAllowBrokenMeasureSpecs = false; private boolean mAllowBrokenMeasureSpecs = false;
private int mDisplayWidth;
public RelativeLayout(Context context) { public RelativeLayout(Context context) {
super(context); super(context);
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <= mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
Build.VERSION_CODES.JELLY_BEAN_MR1; Build.VERSION_CODES.JELLY_BEAN_MR1;
getDisplayWidth();
} }
public RelativeLayout(Context context, AttributeSet attrs) { public RelativeLayout(Context context, AttributeSet attrs) {
@@ -231,6 +235,7 @@ public class RelativeLayout extends ViewGroup {
initFromAttributes(context, attrs); initFromAttributes(context, attrs);
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <= mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
Build.VERSION_CODES.JELLY_BEAN_MR1; Build.VERSION_CODES.JELLY_BEAN_MR1;
getDisplayWidth();
} }
public RelativeLayout(Context context, AttributeSet attrs, int defStyle) { public RelativeLayout(Context context, AttributeSet attrs, int defStyle) {
@@ -238,6 +243,7 @@ public class RelativeLayout extends ViewGroup {
initFromAttributes(context, attrs); initFromAttributes(context, attrs);
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <= mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
Build.VERSION_CODES.JELLY_BEAN_MR1; Build.VERSION_CODES.JELLY_BEAN_MR1;
getDisplayWidth();
} }
private void initFromAttributes(Context context, AttributeSet attrs) { private void initFromAttributes(Context context, AttributeSet attrs) {
@@ -247,6 +253,11 @@ public class RelativeLayout extends ViewGroup {
a.recycle(); a.recycle();
} }
private void getDisplayWidth() {
WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
mDisplayWidth = wm.getDefaultDisplay().getWidth();
}
@Override @Override
public boolean shouldDelayChildPressedState() { public boolean shouldDelayChildPressedState() {
return false; return false;
@@ -438,38 +449,19 @@ public class RelativeLayout extends ViewGroup {
final boolean isWrapContentWidth = widthMode != MeasureSpec.EXACTLY; final boolean isWrapContentWidth = widthMode != MeasureSpec.EXACTLY;
final boolean isWrapContentHeight = heightMode != MeasureSpec.EXACTLY; final boolean isWrapContentHeight = heightMode != MeasureSpec.EXACTLY;
// We need to know our size for doing the correct computation of children positioning in RTL
// mode but there is no practical way to get it instead of running the code below.
// So, instead of running the code twice, we just set the width to the "display width"
// before the computation and then, as a last pass, we will update their real position with
// an offset equals to "displayWidth - width".
final int layoutDirection = getLayoutDirection();
if (isLayoutRtl() && myWidth == -1) {
myWidth = mDisplayWidth;
}
View[] views = mSortedHorizontalChildren; View[] views = mSortedHorizontalChildren;
int count = views.length; int count = views.length;
// We need to know our size for doing the correct computation of positioning in RTL mode
if (isLayoutRtl() && (myWidth == -1 || isWrapContentWidth)) {
int w = getPaddingStart() + getPaddingEnd();
for (int i = 0; i < count; i++) {
View child = views[i];
if (child.getVisibility() != GONE) {
LayoutParams params = (LayoutParams) child.getLayoutParams();
int[] rules = params.getRules(View.LAYOUT_DIRECTION_LTR);
applyHorizontalSizeRules(params, myWidth, rules);
measureChildHorizontal(child, params, -1, myHeight);
w += child.getMeasuredWidth();
w += params.leftMargin + params.rightMargin;
}
}
if (myWidth == -1) {
// Easy case: "myWidth" was undefined before so use the width we have just computed
myWidth = w;
} else {
// "myWidth" was defined before, so take the min of it and the computed width if it
// is a non null one
if (w > 0) {
myWidth = Math.min(myWidth, w);
}
}
}
final int layoutDirection = getLayoutDirection();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
View child = views[i]; View child = views[i];
if (child.getVisibility() != GONE) { if (child.getVisibility() != GONE) {
@@ -500,7 +492,11 @@ public class RelativeLayout extends ViewGroup {
} }
if (isWrapContentWidth) { if (isWrapContentWidth) {
width = Math.max(width, params.mRight); if (isLayoutRtl()) {
width = Math.max(width, myWidth - params.mLeft);
} else {
width = Math.max(width, params.mRight);
}
} }
if (isWrapContentHeight) { if (isWrapContentHeight) {
@@ -628,6 +624,19 @@ public class RelativeLayout extends ViewGroup {
} }
} }
if (isLayoutRtl()) {
final int offsetWidth = myWidth - width;
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
LayoutParams params = (LayoutParams) child.getLayoutParams();
params.mLeft -= offsetWidth;
params.mRight -= offsetWidth;
}
}
}
setMeasuredDimension(width, height); setMeasuredDimension(width, height);
} }