summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2012-10-12 11:39:22 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-10-12 11:39:23 -0700
commit6ffbe600696396a0444f20f61223923146e9520b (patch)
tree75f57301426896cd2f75f4afc706a5e040a2009a /core
parent732d88e14e4418feba1b80cf1d6010cddb1d5de5 (diff)
parent3cc10f420ff432d7c45d0eefe0b92a0c264b00fa (diff)
downloadframeworks_base-6ffbe600696396a0444f20f61223923146e9520b.zip
frameworks_base-6ffbe600696396a0444f20f61223923146e9520b.tar.gz
frameworks_base-6ffbe600696396a0444f20f61223923146e9520b.tar.bz2
Merge "Fix bug #7325609 FragmentBreadCrumbs should be RTL-aware" into jb-mr1-dev
Diffstat (limited to 'core')
-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 384f1ab..3550df9 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>