diff options
author | Gilles Debunne <debunne@google.com> | 2010-10-19 11:56:59 -0700 |
---|---|---|
committer | Gilles Debunne <debunne@google.com> | 2010-10-26 11:08:05 -0700 |
commit | 44c1473c03a0021224fa94af9b1e3579ec244b12 (patch) | |
tree | 24839d8b7800eb6f0d90b042e6736b6e52b06bb5 /core/java/android/widget | |
parent | 48c9daac20dcae18bf45e528fd073612bc0122e1 (diff) | |
download | frameworks_base-44c1473c03a0021224fa94af9b1e3579ec244b12.zip frameworks_base-44c1473c03a0021224fa94af9b1e3579ec244b12.tar.gz frameworks_base-44c1473c03a0021224fa94af9b1e3579ec244b12.tar.bz2 |
New Holo style for Tabs.
Holo theme with new assets and style for TabWidgets.
Legacy Themes still use GB style.
Assets added in a previous bluk update were removed.
Change-Id: Ia4a612678561fa5047bbd2a72488086c0f3d61a1
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/TabHost.java | 29 | ||||
-rw-r--r-- | core/java/android/widget/TabWidget.java | 14 | ||||
-rw-r--r-- | core/java/android/widget/TextView.java | 1 |
3 files changed, 28 insertions, 16 deletions
diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java index ff31dec..2949208 100644 --- a/core/java/android/widget/TabHost.java +++ b/core/java/android/widget/TabHost.java @@ -21,6 +21,7 @@ import com.android.internal.R; import android.app.LocalActivityManager; import android.content.Context; import android.content.Intent; +import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Build; import android.util.AttributeSet; @@ -63,6 +64,8 @@ public class TabHost extends FrameLayout implements ViewTreeObserver.OnTouchMode private OnTabChangeListener mOnTabChangeListener; private OnKeyListener mTabKeyListener; + private int mTabLayoutId; + public TabHost(Context context) { super(context); initTabHost(); @@ -70,6 +73,18 @@ public class TabHost extends FrameLayout implements ViewTreeObserver.OnTouchMode public TabHost(Context context, AttributeSet attrs) { super(context, attrs); + + TypedArray a = context.obtainStyledAttributes(attrs, + com.android.internal.R.styleable.TabWidget, + com.android.internal.R.attr.tabWidgetStyle, 0); + + mTabLayoutId = a.getResourceId(R.styleable.TabWidget_tabLayout, 0); + if (mTabLayoutId == 0) { + throw new IllegalArgumentException("Invalid TabWidget tabLayout id"); + } + + a.recycle(); + initTabHost(); } @@ -214,6 +229,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); if (tabSpec.mIndicatorStrategy instanceof ViewIndicatorStrategy) { mTabWidget.setStripEnabled(false); } + mTabWidget.addView(tabIndicator); mTabSpecs.add(tabSpec); @@ -513,7 +529,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); final Context context = getContext(); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View tabIndicator = inflater.inflate(R.layout.tab_indicator, + View tabIndicator = inflater.inflate(mTabLayoutId, mTabWidget, // tab widget is the parent false); // no inflate params @@ -525,7 +541,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); tabIndicator.setBackgroundResource(R.drawable.tab_indicator_v4); tv.setTextColor(context.getResources().getColorStateList(R.color.tab_indicator_text_v4)); } - + return tabIndicator; } } @@ -547,7 +563,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); final Context context = getContext(); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View tabIndicator = inflater.inflate(R.layout.tab_indicator, + View tabIndicator = inflater.inflate(mTabLayoutId, mTabWidget, // tab widget is the parent false); // no inflate params @@ -555,14 +571,17 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); tv.setText(mLabel); final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon); - iconView.setImageDrawable(mIcon); + if (mIcon != null) { + iconView.setImageDrawable(mIcon); + iconView.setVisibility(VISIBLE); + } if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) { // Donut apps get old color scheme tabIndicator.setBackgroundResource(R.drawable.tab_indicator_v4); tv.setTextColor(context.getResources().getColorStateList(R.color.tab_indicator_text_v4)); } - + return tabIndicator; } } diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java index 0469e7b..36adacd 100644 --- a/core/java/android/widget/TabWidget.java +++ b/core/java/android/widget/TabWidget.java @@ -120,7 +120,9 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { final Context context = mContext; final Resources resources = context.getResources(); - + + // Tests the target Sdk version, as set in the Manifest. Could not be set using styles.xml + // in a values-v? directory which targets the current platform Sdk version instead. if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) { // Donut apps get old color scheme if (mLeftStrip == null) { @@ -131,16 +133,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { mRightStrip = resources.getDrawable( com.android.internal.R.drawable.tab_bottom_right_v4); } - } else { - // Use modern color scheme for Eclair and beyond - if (mLeftStrip == null) { - mLeftStrip = resources.getDrawable( - com.android.internal.R.drawable.tab_bottom_left); - } - if (mRightStrip == null) { - mRightStrip = resources.getDrawable( - com.android.internal.R.drawable.tab_bottom_right); - } } // Deal with focus, as we don't want the focus to go by default diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 09563fc..6897537 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -7142,6 +7142,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case Gravity.RIGHT: return 0.0f; case Gravity.CENTER_HORIZONTAL: + case Gravity.FILL_HORIZONTAL: return (mLayout.getLineWidth(0) - ((mRight - mLeft) - getCompoundPaddingLeft() - getCompoundPaddingRight())) / getHorizontalFadingEdgeLength(); |