summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2012-10-10 19:11:47 -0700
committerFabrice Di Meglio <fdimeglio@google.com>2012-10-11 19:17:39 -0700
commit3cc10f420ff432d7c45d0eefe0b92a0c264b00fa (patch)
treebf8d8ec7a0b6798a122197c361b74438b739214f
parentf6215e55df1ab4f6cda33dd081c0a91062a1be63 (diff)
downloadframeworks_base-3cc10f420ff432d7c45d0eefe0b92a0c264b00fa.zip
frameworks_base-3cc10f420ff432d7c45d0eefe0b92a0c264b00fa.tar.gz
frameworks_base-3cc10f420ff432d7c45d0eefe0b92a0c264b00fa.tar.bz2
Fix bug #7325609 FragmentBreadCrumbs should be RTL-aware
- add horizontal gravity support - use gravity for doing layout depending on layout direction Change-Id: I562e824d15da9b00e1392f125b293aee21f8ee16
-rw-r--r--core/java/android/app/FragmentBreadCrumbs.java64
-rwxr-xr-xcore/res/res/values/attrs.xml6
2 files changed, 62 insertions, 8 deletions
diff --git a/core/java/android/app/FragmentBreadCrumbs.java b/core/java/android/app/FragmentBreadCrumbs.java
index df64035..b810b89 100644
--- a/core/java/android/app/FragmentBreadCrumbs.java
+++ b/core/java/android/app/FragmentBreadCrumbs.java
@@ -19,7 +19,9 @@ package android.app;
import android.animation.LayoutTransition;
import android.app.FragmentManager.BackStackEntry;
import android.content.Context;
+import android.content.res.TypedArray;
import android.util.AttributeSet;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -51,7 +53,11 @@ public class FragmentBreadCrumbs extends ViewGroup
private OnClickListener mParentClickListener;
private OnBreadCrumbClickListener mOnBreadCrumbClickListener;
-
+
+ private int mGravity;
+
+ private static final int DEFAULT_GRAVITY = Gravity.START | Gravity.CENTER_VERTICAL;
+
/**
* Interface to intercept clicks on the bread crumbs.
*/
@@ -80,6 +86,14 @@ public class FragmentBreadCrumbs extends ViewGroup
public FragmentBreadCrumbs(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+
+ TypedArray a = context.obtainStyledAttributes(attrs,
+ com.android.internal.R.styleable.FragmentBreadCrumbs, defStyle, 0);
+
+ mGravity = a.getInt(com.android.internal.R.styleable.FragmentBreadCrumbs_gravity,
+ DEFAULT_GRAVITY);
+
+ a.recycle();
}
/**
@@ -159,16 +173,50 @@ public class FragmentBreadCrumbs extends ViewGroup
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
- // Eventually we should implement our own layout of the views,
- // rather than relying on a linear layout.
+ // Eventually we should implement our own layout of the views, rather than relying on
+ // a single linear layout.
final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- final View child = getChildAt(i);
+ if (childCount == 0) {
+ return;
+ }
+
+ final View child = getChildAt(0);
- int childRight = mPaddingLeft + child.getMeasuredWidth() - mPaddingRight;
- int childBottom = mPaddingTop + child.getMeasuredHeight() - mPaddingBottom;
- child.layout(mPaddingLeft, mPaddingTop, childRight, childBottom);
+ final int childTop = mPaddingTop;
+ final int childBottom = mPaddingTop + child.getMeasuredHeight() - mPaddingBottom;
+
+ int childLeft;
+ int childRight;
+
+ final int layoutDirection = getLayoutDirection();
+ final int horizontalGravity = mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK;
+ switch (Gravity.getAbsoluteGravity(horizontalGravity, layoutDirection)) {
+ case Gravity.RIGHT:
+ childRight = mRight - mLeft - mPaddingRight;
+ childLeft = childRight - child.getMeasuredWidth();
+ break;
+
+ case Gravity.CENTER_HORIZONTAL:
+ childLeft = mPaddingLeft + (mRight - mLeft - child.getMeasuredWidth()) / 2;
+ childRight = childLeft + child.getMeasuredWidth();
+ break;
+
+ case Gravity.LEFT:
+ default:
+ childLeft = mPaddingLeft;
+ childRight = childLeft + child.getMeasuredWidth();
+ break;
}
+
+ if (childLeft < mPaddingLeft) {
+ childLeft = mPaddingLeft;
+ }
+
+ if (childRight > mRight - mLeft - mPaddingRight) {
+ childRight = mRight - mLeft - mPaddingRight;
+ }
+
+ child.layout(childLeft, childTop, childRight, childBottom);
}
@Override
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 9ce7f8a..b5ca752 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -5781,4 +5781,10 @@
<attr name="leftToRight" format="boolean" />
</declare-styleable>
+ <!-- Attributes that can be used with <code>&lt;FragmentBreadCrumbs&gt;</code>
+ tags. -->
+ <declare-styleable name="FragmentBreadCrumbs">
+ <attr name="gravity" />
+ </declare-styleable>
+
</resources>