diff options
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/app/FragmentBreadCrumbs.java | 33 | ||||
-rw-r--r-- | core/java/android/preference/PreferenceActivity.java | 21 | ||||
-rw-r--r-- | core/java/android/preference/PreferenceFrameLayout.java | 6 |
3 files changed, 42 insertions, 18 deletions
diff --git a/core/java/android/app/FragmentBreadCrumbs.java b/core/java/android/app/FragmentBreadCrumbs.java index 139095f..8d76ffe 100644 --- a/core/java/android/app/FragmentBreadCrumbs.java +++ b/core/java/android/app/FragmentBreadCrumbs.java @@ -41,6 +41,7 @@ public class FragmentBreadCrumbs extends ViewGroup Activity mActivity; LayoutInflater mInflater; LinearLayout mContainer; + int mMaxVisible = -1; // Hahah BackStackRecord mTopEntry; @@ -74,6 +75,14 @@ public class FragmentBreadCrumbs extends ViewGroup } /** + * The maximum number of crumbs to show. + * @hide + */ + public void setMaxVisible(int visibleCrumbs) { + mMaxVisible = visibleCrumbs; + } + + /** * Set a custom title for the bread crumbs. This will be the first entry * shown at the left, representing the root of the bread crumbs. If the * title is null, it will not be shown. @@ -160,17 +169,17 @@ public class FragmentBreadCrumbs extends ViewGroup } } if (viewI >= numViews) { - View item = mInflater.inflate( + final View item = mInflater.inflate( com.android.internal.R.layout.fragment_bread_crumb_item, this, false); - TextView text = (TextView)item.findViewById(com.android.internal.R.id.title); + final TextView text = (TextView) item.findViewById(com.android.internal.R.id.title); text.setText(bse.getBreadCrumbTitle()); - item.setTag(bse); + text.setTag(bse); if (viewI == 0) { - text.setCompoundDrawables(null, null, null, null); + item.findViewById(com.android.internal.R.id.left_icon).setVisibility(View.GONE); } mContainer.addView(item); - item.setOnClickListener(mOnClickListener); + text.setOnClickListener(mOnClickListener); } } int viewI = mTopEntry != null ? numEntries + 1 : numEntries; @@ -179,6 +188,20 @@ public class FragmentBreadCrumbs extends ViewGroup mContainer.removeViewAt(numViews-1); numViews--; } + // Adjust the visibility and availability of the bread crumbs and divider + for (int i = 0; i < numViews; i++) { + final View child = mContainer.getChildAt(i); + // Disable the last one + child.findViewById(com.android.internal.R.id.title).setEnabled(i < numViews - 1); + if (mMaxVisible > 0) { + // Make only the last mMaxVisible crumbs visible + child.setVisibility(i < numViews - mMaxVisible ? View.GONE : View.VISIBLE); + final View leftIcon = child.findViewById(com.android.internal.R.id.left_icon); + // Remove the divider for all but the last mMaxVisible - 1 + leftIcon.setVisibility(i > numViews - mMaxVisible && i != 0 ? View.VISIBLE + : View.GONE); + } + } } private OnClickListener mOnClickListener = new OnClickListener() { diff --git a/core/java/android/preference/PreferenceActivity.java b/core/java/android/preference/PreferenceActivity.java index aedbfca..6172ce9 100644 --- a/core/java/android/preference/PreferenceActivity.java +++ b/core/java/android/preference/PreferenceActivity.java @@ -171,7 +171,7 @@ public abstract class PreferenceActivity extends ListActivity implements private FrameLayout mListFooter; - private View mPrefsContainer; + private ViewGroup mPrefsContainer; private FragmentBreadCrumbs mFragmentBreadCrumbs; @@ -491,7 +491,7 @@ public abstract class PreferenceActivity extends ListActivity implements setContentView(com.android.internal.R.layout.preference_list_content); mListFooter = (FrameLayout)findViewById(com.android.internal.R.id.list_footer); - mPrefsContainer = findViewById(com.android.internal.R.id.prefs); + mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs_frame); boolean hidingHeaders = onIsHidingHeaders(); mSinglePane = hidingHeaders || !onIsMultiPane(); String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); @@ -559,7 +559,7 @@ public abstract class PreferenceActivity extends ListActivity implements // of preferences" mode. setContentView(com.android.internal.R.layout.preference_list_content_single); mListFooter = (FrameLayout) findViewById(com.android.internal.R.id.list_footer); - mPrefsContainer = findViewById(com.android.internal.R.id.prefs); + mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs); mPreferenceManager = new PreferenceManager(this, FIRST_REQUEST_CODE); mPreferenceManager.setOnPreferenceTreeClickListener(this); } @@ -990,13 +990,16 @@ public abstract class PreferenceActivity extends ListActivity implements */ public void showBreadCrumbs(CharSequence title, CharSequence shortTitle) { if (mFragmentBreadCrumbs == null) { - mFragmentBreadCrumbs = new FragmentBreadCrumbs(this); - mFragmentBreadCrumbs.setActivity(this); - - ActionBar actionBar = getActionBar(); - if (actionBar != null) { - actionBar.setCustomNavigationMode(mFragmentBreadCrumbs); + mFragmentBreadCrumbs = (FragmentBreadCrumbs) findViewById(android.R.id.title); + if (mFragmentBreadCrumbs == null) { + mFragmentBreadCrumbs = new FragmentBreadCrumbs(this); + ActionBar actionBar = getActionBar(); + if (actionBar != null) { + actionBar.setCustomNavigationMode(mFragmentBreadCrumbs); + } } + mFragmentBreadCrumbs.setMaxVisible(2); + mFragmentBreadCrumbs.setActivity(this); } mFragmentBreadCrumbs.setTitle(title, shortTitle); } diff --git a/core/java/android/preference/PreferenceFrameLayout.java b/core/java/android/preference/PreferenceFrameLayout.java index 4c737b5..75372aa 100644 --- a/core/java/android/preference/PreferenceFrameLayout.java +++ b/core/java/android/preference/PreferenceFrameLayout.java @@ -16,13 +16,12 @@ package android.preference; +import android.app.FragmentBreadCrumbs; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.View; -import android.view.ViewGroup.MarginLayoutParams; import android.widget.FrameLayout; -import android.widget.FrameLayout.LayoutParams; /** * @hide @@ -36,7 +35,7 @@ public class PreferenceFrameLayout extends FrameLayout { private final int mBorderBottom; private final int mBorderLeft; private final int mBorderRight; - private boolean mPaddingApplied = false; + private boolean mPaddingApplied; public PreferenceFrameLayout(Context context) { this(context, null); @@ -70,7 +69,6 @@ public class PreferenceFrameLayout extends FrameLayout { com.android.internal.R.styleable.PreferenceFrameLayout_borderRight, defaultRightPadding); - a.recycle(); } |