diff options
| author | 2010-03-01 14:12:10 -0800 | |
|---|---|---|
| committer | 2010-03-01 14:23:23 -0800 | |
| commit | 61c9d4b4509aeaab1fcad24fb5a63c874d2fd941 (patch) | |
| tree | dfe525c74d45736e5287574c21f517cfa7e17ad5 | |
| parent | e0dab5bf6744812e7059ae63b31ac835479cb321 (diff) | |
Let apps change the bottom strip in TabWidget.
Bug #2478088
Also expose a few useful APIs.
| -rw-r--r-- | api/current.xml | 109 | ||||
| -rw-r--r-- | core/java/android/widget/TabHost.java | 2 | ||||
| -rw-r--r-- | core/java/android/widget/TabWidget.java | 133 | ||||
| -rw-r--r-- | core/res/res/values/attrs.xml | 8 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 3 |
5 files changed, 216 insertions, 39 deletions
diff --git a/api/current.xml b/api/current.xml index 89af2acddc34..6cec09a7feda 100644 --- a/api/current.xml +++ b/api/current.xml @@ -7819,6 +7819,39 @@ visibility="public" > </field> +<field name="stripEnabled" + type="int" + transient="false" + volatile="false" + value="16843454" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="stripLeft" + type="int" + transient="false" + volatile="false" + value="16843452" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="stripRight" + type="int" + transient="false" + volatile="false" + value="16843453" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> <field name="suggestActionMsg" type="int" transient="false" @@ -209334,6 +209367,17 @@ visibility="public" > </method> +<method name="isStripEnabled" + return="boolean" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="onFocusChange" return="void" abstract="false" @@ -209388,6 +209432,71 @@ <parameter name="resId" type="int"> </parameter> </method> +<method name="setLeftStripDrawable" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="drawable" type="android.graphics.drawable.Drawable"> +</parameter> +</method> +<method name="setLeftStripDrawable" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="resId" type="int"> +</parameter> +</method> +<method name="setRightStripDrawable" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="drawable" type="android.graphics.drawable.Drawable"> +</parameter> +</method> +<method name="setRightStripDrawable" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="resId" type="int"> +</parameter> +</method> +<method name="setStripEnabled" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="drawBottomStrips" type="boolean"> +</parameter> +</method> </class> <class name="TableLayout" extends="android.widget.LinearLayout" diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java index d4d90635f49e..02cd6a81ebfd 100644 --- a/core/java/android/widget/TabHost.java +++ b/core/java/android/widget/TabHost.java @@ -204,7 +204,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); // If this is a custom view, then do not draw the bottom strips for // the tab indicators. if (tabSpec.mIndicatorStrategy instanceof ViewIndicatorStrategy) { - mTabWidget.setDrawBottomStrips(false); + mTabWidget.setStripEnabled(false); } mTabWidget.addView(tabIndicator); mTabSpecs.add(tabSpec); diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java index aa47e6daaf4e..658b07bdc176 100644 --- a/core/java/android/widget/TabWidget.java +++ b/core/java/android/widget/TabWidget.java @@ -16,6 +16,7 @@ package android.widget; +import android.R; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; @@ -28,8 +29,6 @@ import android.view.View; import android.view.ViewGroup; import android.view.View.OnFocusChangeListener; - - /** * * Displays a list of tab labels representing each page in the parent's tab @@ -43,15 +42,19 @@ import android.view.View.OnFocusChangeListener; * called on the containing TabHost object. */ public class TabWidget extends LinearLayout implements OnFocusChangeListener { - - private OnTabSelectionChanged mSelectionChangedListener; + private int mSelectedTab = 0; + private Drawable mBottomLeftStrip; private Drawable mBottomRightStrip; + + private boolean mDrawBottomStrips = true; private boolean mStripMoved; + private Drawable mDividerDrawable; - private boolean mDrawBottomStrips = true; + + private final Rect mBounds = new Rect(); public TabWidget(Context context) { this(context, null); @@ -63,13 +66,19 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { public TabWidget(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); - initTabWidget(); TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TabWidget, defStyle, 0); + mDrawBottomStrips = a.getBoolean(R.styleable.TabWidget_stripEnabled, true); + mDividerDrawable = a.getDrawable(R.styleable.TabWidget_divider); + mBottomLeftStrip = a.getDrawable(R.styleable.TabWidget_stripLeft); + mBottomRightStrip = a.getDrawable(R.styleable.TabWidget_stripRight); + a.recycle(); + + initTabWidget(); } @Override @@ -100,19 +109,26 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) { // Donut apps get old color scheme - mBottomLeftStrip = resources.getDrawable( - com.android.internal.R.drawable.tab_bottom_left_v4); - mBottomRightStrip = resources.getDrawable( - com.android.internal.R.drawable.tab_bottom_right_v4); + if (mBottomLeftStrip == null) { + mBottomLeftStrip = resources.getDrawable( + com.android.internal.R.drawable.tab_bottom_left_v4); + } + if (mBottomRightStrip == null) { + mBottomRightStrip = resources.getDrawable( + com.android.internal.R.drawable.tab_bottom_right_v4); + } } else { // Use modern color scheme for Eclair and beyond - mBottomLeftStrip = resources.getDrawable( - com.android.internal.R.drawable.tab_bottom_left); - mBottomRightStrip = resources.getDrawable( - com.android.internal.R.drawable.tab_bottom_right); + if (mBottomLeftStrip == null) { + mBottomLeftStrip = resources.getDrawable( + com.android.internal.R.drawable.tab_bottom_left); + } + if (mBottomRightStrip == null) { + mBottomRightStrip = resources.getDrawable( + com.android.internal.R.drawable.tab_bottom_right); + } } - // Deal with focus, as we don't want the focus to go by default // to a tab other than the current tab setFocusable(true); @@ -166,16 +182,62 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { public void setDividerDrawable(int resId) { mDividerDrawable = mContext.getResources().getDrawable(resId); } + + /** + * Sets the drawable to use as the left part of the strip below the + * tab indicators. + * @param drawable the left strip drawable + */ + public void setLeftStripDrawable(Drawable drawable) { + mBottomLeftStrip = drawable; + } + + /** + * Sets the drawable to use as the left part of the strip below the + * tab indicators. + * @param resId the resource identifier of the drawable to use as the + * left strip drawable + */ + public void setLeftStripDrawable(int resId) { + mBottomLeftStrip = mContext.getResources().getDrawable(resId); + } /** + * Sets the drawable to use as the left part of the strip below the + * tab indicators. + * @param drawable the left strip drawable + */ + public void setRightStripDrawable(Drawable drawable) { + mBottomLeftStrip = drawable; + } + + /** + * Sets the drawable to use as the left part of the strip below the + * tab indicators. + * @param resId the resource identifier of the drawable to use as the + * left strip drawable + */ + public void setRightStripDrawable(int resId) { + mBottomLeftStrip = mContext.getResources().getDrawable(resId); + } + + /** * Controls whether the bottom strips on the tab indicators are drawn or * not. The default is to draw them. If the user specifies a custom * view for the tab indicators, then the TabHost class calls this method * to disable drawing of the bottom strips. - * @param drawBottomStrips true if the bottom strips should be drawn. + * @param stripEnabled true if the bottom strips should be drawn. */ - void setDrawBottomStrips(boolean drawBottomStrips) { - mDrawBottomStrips = drawBottomStrips; + public void setStripEnabled(boolean stripEnabled) { + mDrawBottomStrips = stripEnabled; + } + + /** + * Indicates whether the bottom strips on the tab indicators are drawn + * or not. + */ + public boolean isStripEnabled() { + return mDrawBottomStrips; } @Override @@ -201,33 +263,28 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { return; } - View selectedChild = getChildTabViewAt(mSelectedTab); + final View selectedChild = getChildTabViewAt(mSelectedTab); + + final Drawable leftStrip = mBottomLeftStrip; + final Drawable rightStrip = mBottomRightStrip; - mBottomLeftStrip.setState(selectedChild.getDrawableState()); - mBottomRightStrip.setState(selectedChild.getDrawableState()); + leftStrip.setState(selectedChild.getDrawableState()); + rightStrip.setState(selectedChild.getDrawableState()); if (mStripMoved) { - Rect selBounds = new Rect(); // Bounds of the selected tab indicator - selBounds.left = selectedChild.getLeft(); - selBounds.right = selectedChild.getRight(); + final Rect bounds = mBounds; + bounds.left = selectedChild.getLeft(); + bounds.right = selectedChild.getRight(); final int myHeight = getHeight(); - mBottomLeftStrip.setBounds( - Math.min(0, selBounds.left - - mBottomLeftStrip.getIntrinsicWidth()), - myHeight - mBottomLeftStrip.getIntrinsicHeight(), - selBounds.left, - getHeight()); - mBottomRightStrip.setBounds( - selBounds.right, - myHeight - mBottomRightStrip.getIntrinsicHeight(), - Math.max(getWidth(), - selBounds.right + mBottomRightStrip.getIntrinsicWidth()), - myHeight); + leftStrip.setBounds(Math.min(0, bounds.left - leftStrip.getIntrinsicWidth()), + myHeight - leftStrip.getIntrinsicHeight(), bounds.left, myHeight); + rightStrip.setBounds(bounds.right, myHeight - rightStrip.getIntrinsicHeight(), + Math.max(getWidth(), bounds.right + rightStrip.getIntrinsicWidth()), myHeight); mStripMoved = false; } - mBottomLeftStrip.draw(canvas); - mBottomRightStrip.draw(canvas); + leftStrip.draw(canvas); + rightStrip.draw(canvas); } /** diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 79bd41e892dc..1ced121b300d 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -1867,6 +1867,14 @@ <attr name="layout_span" format="integer" /> </declare-styleable> <declare-styleable name="TabWidget"> + <!-- Drawable used to draw the divider between tabs. --> + <attr name="divider" /> + <!-- Determines whether the strip under the tab indicators is drawn or not. --> + <attr name="stripEnabled" format="boolean" /> + <!-- Drawable used to draw the left part of the strip underneath the tabs. --> + <attr name="stripLeft" format="reference" /> + <!-- Drawable used to draw the right part of the strip underneath the tabs. --> + <attr name="stripRight" format="reference" /> </declare-styleable> <declare-styleable name="TextAppearance"> <!-- Text color. --> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 5da8e8585f10..36a8f5bf3cea 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1232,6 +1232,9 @@ <public type="attr" name="webTextViewStyle" id="0x010102b9" /> <public type="attr" name="overscrollMode" id="0x010102ba" /> <public type="attr" name="restoreAnyVersion" id="0x010102bb" /> + <public type="attr" name="stripLeft" id="0x010102bc" /> + <public type="attr" name="stripRight" id="0x010102bd" /> + <public type="attr" name="stripEnabled" id="0x010102be" /> <public type="anim" name="cycle_interpolator" id="0x010a000c" /> |