Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61c9d4b4 authored by Romain Guy's avatar Romain Guy
Browse files

Let apps change the bottom strip in TabWidget.

Bug #2478088

Also expose a few useful APIs.
parent e0dab5bf
Loading
Loading
Loading
Loading
+109 −0
Original line number Original line Diff line number Diff line
@@ -7819,6 +7819,39 @@
 visibility="public"
 visibility="public"
>
>
</field>
</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"
<field name="suggestActionMsg"
 type="int"
 type="int"
 transient="false"
 transient="false"
@@ -209334,6 +209367,17 @@
 visibility="public"
 visibility="public"
>
>
</method>
</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"
<method name="onFocusChange"
 return="void"
 return="void"
 abstract="false"
 abstract="false"
@@ -209388,6 +209432,71 @@
<parameter name="resId" type="int">
<parameter name="resId" type="int">
</parameter>
</parameter>
</method>
</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>
<class name="TableLayout"
<class name="TableLayout"
 extends="android.widget.LinearLayout"
 extends="android.widget.LinearLayout"
+1 −1
Original line number Original line Diff line number Diff line
@@ -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
        // If this is a custom view, then do not draw the bottom strips for
        // the tab indicators.
        // the tab indicators.
        if (tabSpec.mIndicatorStrategy instanceof ViewIndicatorStrategy) {
        if (tabSpec.mIndicatorStrategy instanceof ViewIndicatorStrategy) {
            mTabWidget.setDrawBottomStrips(false);
            mTabWidget.setStripEnabled(false);
        }
        }
        mTabWidget.addView(tabIndicator);
        mTabWidget.addView(tabIndicator);
        mTabSpecs.add(tabSpec);
        mTabSpecs.add(tabSpec);
+95 −38
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.widget;
package android.widget;


import android.R;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
@@ -28,8 +29,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnFocusChangeListener;




/**
/**
 *
 *
 * Displays a list of tab labels representing each page in the parent's tab
 * 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.
 * called on the containing TabHost object.
 */
 */
public class TabWidget extends LinearLayout implements OnFocusChangeListener {
public class TabWidget extends LinearLayout implements OnFocusChangeListener {


    private OnTabSelectionChanged mSelectionChangedListener;
    private OnTabSelectionChanged mSelectionChangedListener;

    private int mSelectedTab = 0;
    private int mSelectedTab = 0;

    private Drawable mBottomLeftStrip;
    private Drawable mBottomLeftStrip;
    private Drawable mBottomRightStrip;
    private Drawable mBottomRightStrip;

    private boolean mDrawBottomStrips = true;
    private boolean mStripMoved;
    private boolean mStripMoved;

    private Drawable mDividerDrawable;
    private Drawable mDividerDrawable;
    private boolean mDrawBottomStrips = true;

    private final Rect mBounds = new Rect();


    public TabWidget(Context context) {
    public TabWidget(Context context) {
        this(context, null);
        this(context, null);
@@ -63,13 +66,19 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {


    public TabWidget(Context context, AttributeSet attrs, int defStyle) {
    public TabWidget(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs);
        super(context, attrs);
        initTabWidget();


        TypedArray a =
        TypedArray a =
            context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TabWidget,
            context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TabWidget,
                    defStyle, 0);
                    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();
        a.recycle();

        initTabWidget();
    }
    }


    @Override
    @Override
@@ -100,18 +109,25 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        
        
        if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) {
        if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) {
            // Donut apps get old color scheme
            // Donut apps get old color scheme
            if (mBottomLeftStrip == null) {
                mBottomLeftStrip = resources.getDrawable(
                mBottomLeftStrip = resources.getDrawable(
                        com.android.internal.R.drawable.tab_bottom_left_v4);
                        com.android.internal.R.drawable.tab_bottom_left_v4);
            }
            if (mBottomRightStrip == null) {
                mBottomRightStrip = resources.getDrawable(
                mBottomRightStrip = resources.getDrawable(
                        com.android.internal.R.drawable.tab_bottom_right_v4);
                        com.android.internal.R.drawable.tab_bottom_right_v4);
            }
        } else {
        } else {
            // Use modern color scheme for Eclair and beyond
            // Use modern color scheme for Eclair and beyond
            if (mBottomLeftStrip == null) {
                mBottomLeftStrip = resources.getDrawable(
                mBottomLeftStrip = resources.getDrawable(
                        com.android.internal.R.drawable.tab_bottom_left);
                        com.android.internal.R.drawable.tab_bottom_left);
            }
            if (mBottomRightStrip == null) {
                mBottomRightStrip = resources.getDrawable(
                mBottomRightStrip = resources.getDrawable(
                        com.android.internal.R.drawable.tab_bottom_right);
                        com.android.internal.R.drawable.tab_bottom_right);
            }
            }

        }


        // Deal with focus, as we don't want the focus to go by default
        // Deal with focus, as we don't want the focus to go by default
        // to a tab other than the current tab
        // to a tab other than the current tab
@@ -167,15 +183,61 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        mDividerDrawable = mContext.getResources().getDrawable(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
     * 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
     * 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
     * view for the tab indicators, then the TabHost class calls this method
     * to disable drawing of the bottom strips.
     * 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) {
    public void setStripEnabled(boolean stripEnabled) {
        mDrawBottomStrips = drawBottomStrips;
        mDrawBottomStrips = stripEnabled;
    }

    /**
     * Indicates whether the bottom strips on the tab indicators are drawn
     * or not.
     */
    public boolean isStripEnabled() {
        return mDrawBottomStrips;
    }
    }


    @Override
    @Override
@@ -201,33 +263,28 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
            return;
            return;
        }
        }


        View selectedChild = getChildTabViewAt(mSelectedTab);
        final View selectedChild = getChildTabViewAt(mSelectedTab);

        final Drawable leftStrip = mBottomLeftStrip;
        final Drawable rightStrip = mBottomRightStrip;


        mBottomLeftStrip.setState(selectedChild.getDrawableState());
        leftStrip.setState(selectedChild.getDrawableState());
        mBottomRightStrip.setState(selectedChild.getDrawableState());
        rightStrip.setState(selectedChild.getDrawableState());


        if (mStripMoved) {
        if (mStripMoved) {
            Rect selBounds = new Rect(); // Bounds of the selected tab indicator
            final Rect bounds = mBounds;
            selBounds.left = selectedChild.getLeft();
            bounds.left = selectedChild.getLeft();
            selBounds.right = selectedChild.getRight();
            bounds.right = selectedChild.getRight();
            final int myHeight = getHeight();
            final int myHeight = getHeight();
            mBottomLeftStrip.setBounds(
            leftStrip.setBounds(Math.min(0, bounds.left - leftStrip.getIntrinsicWidth()),
                    Math.min(0, selBounds.left
                    myHeight - leftStrip.getIntrinsicHeight(), bounds.left, myHeight);
                                 - mBottomLeftStrip.getIntrinsicWidth()),
            rightStrip.setBounds(bounds.right, myHeight - rightStrip.getIntrinsicHeight(),
                    myHeight - mBottomLeftStrip.getIntrinsicHeight(),
                    Math.max(getWidth(), bounds.right + rightStrip.getIntrinsicWidth()), myHeight);
                    selBounds.left,
                    getHeight());
            mBottomRightStrip.setBounds(
                    selBounds.right,
                    myHeight - mBottomRightStrip.getIntrinsicHeight(),
                    Math.max(getWidth(),
                            selBounds.right + mBottomRightStrip.getIntrinsicWidth()),
                    myHeight);
            mStripMoved = false;
            mStripMoved = false;
        }
        }


        mBottomLeftStrip.draw(canvas);
        leftStrip.draw(canvas);
        mBottomRightStrip.draw(canvas);
        rightStrip.draw(canvas);
    }
    }


    /**
    /**
+8 −0
Original line number Original line Diff line number Diff line
@@ -1867,6 +1867,14 @@
        <attr name="layout_span" format="integer" />
        <attr name="layout_span" format="integer" />
    </declare-styleable>
    </declare-styleable>
    <declare-styleable name="TabWidget">
    <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>
    <declare-styleable name="TextAppearance">
    <declare-styleable name="TextAppearance">
        <!-- Text color. -->
        <!-- Text color. -->
+3 −0
Original line number Original line Diff line number Diff line
@@ -1232,6 +1232,9 @@
  <public type="attr" name="webTextViewStyle" id="0x010102b9" />
  <public type="attr" name="webTextViewStyle" id="0x010102b9" />
  <public type="attr" name="overscrollMode" id="0x010102ba" />
  <public type="attr" name="overscrollMode" id="0x010102ba" />
  <public type="attr" name="restoreAnyVersion" id="0x010102bb" />
  <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" />
  <public type="anim" name="cycle_interpolator" id="0x010a000c" />