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

Commit 360abf32 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Adjust holo tabs to match spec."

parents 5fa3e144 11f4a48c
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -566,10 +567,15 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
                    false); // no inflate params

            final TextView tv = (TextView) tabIndicator.findViewById(R.id.title);
            final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon);

            // when icon is gone by default, we're in exclusive mode
            final boolean exclusive = iconView.getVisibility() == View.GONE;
            final boolean bindIcon = !exclusive || TextUtils.isEmpty(mLabel);

            tv.setText(mLabel);

            final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon);
            if (mIcon != null) {
            if (bindIcon && mIcon != null) {
                iconView.setImageDrawable(mIcon);
                iconView.setVisibility(VISIBLE);
            }
+19 −57
Original line number Diff line number Diff line
@@ -62,8 +62,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    private boolean mDrawBottomStrips = true;
    private boolean mStripMoved;

    private Drawable mDividerDrawable;

    private final Rect mBounds = new Rect();

    // When positive, the widths and heights of tabs will be imposed so that they fit in parent
@@ -79,16 +77,14 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    }

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

        TypedArray a =
            context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TabWidget,
                    defStyle, 0);
        final TypedArray a = context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.TabWidget, defStyle, 0);

        mDrawBottomStrips = a.getBoolean(R.styleable.TabWidget_tabStripEnabled, true);
        mDividerDrawable = a.getDrawable(R.styleable.TabWidget_divider);
        mLeftStrip = a.getDrawable(R.styleable.TabWidget_tabStripLeft);
        mRightStrip = a.getDrawable(R.styleable.TabWidget_tabStripRight);
        setStripEnabled(a.getBoolean(R.styleable.TabWidget_tabStripEnabled, true));
        setLeftStripDrawable(a.getDrawable(R.styleable.TabWidget_tabStripLeft));
        setRightStripDrawable(a.getDrawable(R.styleable.TabWidget_tabStripRight));

        a.recycle();

@@ -119,7 +115,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    }

    private void initTabWidget() {
        mGroupFlags |= FLAG_USE_CHILD_DRAWING_ORDER;
        setChildrenDrawingOrderEnabled(true);

        final Context context = mContext;
        final Resources resources = context.getResources();
@@ -158,8 +154,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    void measureChildBeforeLayout(View child, int childIndex,
            int widthMeasureSpec, int totalWidth,
            int heightMeasureSpec, int totalHeight) {

        if (mImposedTabsHeight >= 0) {
        if (!isMeasureWithLargestChildEnabled() && mImposedTabsHeight >= 0) {
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(
                    totalWidth + mImposedTabWidths[childIndex], MeasureSpec.EXACTLY);
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(mImposedTabsHeight,
@@ -223,11 +218,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
     * @return the tab indicator view at the given index
     */
    public View getChildTabViewAt(int index) {
        // If we are using dividers, then instead of tab views at 0, 1, 2, ...
        // we have tab views at 0, 2, 4, ...
        if (mDividerDrawable != null) {
            index *= 2;
        }
        return getChildAt(index);
    }

@@ -236,15 +226,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
     * @return the number of tab indicator views.
     */
    public int getTabCount() {
        int children = getChildCount();

        // If we have dividers, then we will always have an odd number of
        // children: 1, 3, 5, ... and we want to convert that sequence to
        // this: 1, 2, 3, ...
        if (mDividerDrawable != null) {
            children = (children + 1) / 2;
        }
        return children;
        return getChildCount();
    }

    /**
@@ -253,9 +235,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
     */
    @Override
    public void setDividerDrawable(Drawable drawable) {
        mDividerDrawable = drawable;
        requestLayout();
        invalidate();
        super.setDividerDrawable(drawable);
    }

    /**
@@ -264,9 +244,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
     * divider.
     */
    public void setDividerDrawable(int resId) {
        mDividerDrawable = mContext.getResources().getDrawable(resId);
        requestLayout();
        invalidate();
        setDividerDrawable(getResources().getDrawable(resId));
    }
    
    /**
@@ -287,9 +265,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
     * left strip drawable
     */
    public void setLeftStripDrawable(int resId) {
        mLeftStrip = mContext.getResources().getDrawable(resId);
        requestLayout();
        invalidate();
        setLeftStripDrawable(getResources().getDrawable(resId));
    }

    /**
@@ -300,7 +276,8 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    public void setRightStripDrawable(Drawable drawable) {
        mRightStrip = drawable;
        requestLayout();
        invalidate();    }
        invalidate();
    }

    /**
     * Sets the drawable to use as the right part of the strip below the
@@ -309,9 +286,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
     * right strip drawable
     */
    public void setRightStripDrawable(int resId) {
        mRightStrip = mContext.getResources().getDrawable(resId);
        requestLayout();
        invalidate();
        setRightStripDrawable(getResources().getDrawable(resId));
    }

    /**
@@ -471,8 +446,8 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        int count = getTabCount();

        final int count = getTabCount();
        for (int i = 0; i < count; i++) {
            View child = getChildTabViewAt(i);
            child.setEnabled(enabled);
@@ -493,18 +468,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        child.setFocusable(true);
        child.setClickable(true);

        // If we have dividers between the tabs and we already have at least one
        // tab, then add a divider before adding the next tab.
        if (mDividerDrawable != null && getTabCount() > 0) {
            ImageView divider = new ImageView(mContext);
            final LinearLayout.LayoutParams lp = new LayoutParams(
                    mDividerDrawable.getIntrinsicWidth(),
                    LayoutParams.MATCH_PARENT);
            lp.setMargins(0, 0, 0, 0);
            divider.setLayoutParams(lp);
            divider.setBackgroundDrawable(mDividerDrawable);
            super.addView(divider);
        }
        super.addView(child);

        // TODO: detect this via geometry with a tabwidget listener rather
@@ -535,6 +498,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        mSelectionChangedListener = listener;
    }

    /** {@inheritDoc} */
    public void onFocusChange(View v, boolean hasFocus) {
        if (v == this && hasFocus && getTabCount() > 0) {
            getChildTabViewAt(mSelectedTab).requestFocus();
@@ -588,6 +552,4 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
         */
        void onTabSelectionChanged(int tabIndex, boolean clicked);
    }

}
+15 −19
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
<!-- Copyright (C) 2011 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -14,27 +14,23 @@
     limitations under the License.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="58dp"
    android:layout_weight="0"
    android:paddingBottom="8dp"
    android:background="@android:drawable/tab_indicator_holo">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="?android:attr/actionBarSize"
    android:orientation="horizontal"
    style="@android:style/Widget.Holo.Tab">

    <ImageView android:id="@+id/icon"
    <ImageView
        android:id="@android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="3dp"
        android:paddingRight="3dp"
        android:layout_centerHorizontal="true" />
        android:layout_gravity="center_vertical"
        android:visibility="gone" />

    <TextView android:id="@+id/title"
    <TextView
        android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:paddingLeft="3dp"
        android:paddingRight="3dp"
        style="?android:attr/tabWidgetStyle" />
        android:layout_gravity="center_vertical"
        style="@android:style/Widget.Holo.TabText" />

</RelativeLayout>
</LinearLayout>
+0 −46
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="56dip"
    android:layout_weight="0"
    android:layout_marginLeft="0dip"
    android:layout_marginRight="0dip"
    android:background="@android:drawable/tab_indicator_holo">

    <View android:id="@+id/tab_indicator_left_spacer"
        android:layout_width="16dip"
        android:layout_height="0dip" />

    <ImageView android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:visibility="gone"
        android:layout_toRightOf="@id/tab_indicator_left_spacer"
        android:paddingRight="8dip" />

    <TextView android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/icon"
        android:paddingLeft="0dip"
        android:paddingRight="16dip"
        style="?android:attr/tabWidgetStyle" />

</RelativeLayout>
+5 −11
Original line number Diff line number Diff line
@@ -15,20 +15,14 @@
-->

<resources>
    <style name="TextAppearance.Holo.Widget.TabWidget">
        <item name="android:textSize">18sp</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textColor">@android:color/tab_indicator_text</item>
    </style>
    
    <style name="Widget.Holo.TabWidget" parent="Widget.TabWidget">
        <item name="android:textAppearance">@style/TextAppearance.Holo.Widget.TabWidget</item>
        <item name="android:tabStripLeft">@null</item>
        <item name="android:tabStripRight">@null</item>
        <item name="android:tabStripEnabled">false</item>
        <item name="android:divider">@null</item>
        <item name="android:gravity">left|center_vertical</item>
        <item name="android:tabLayout">@android:layout/tab_indicator_holo_large</item>
        <item name="android:divider">?android:attr/dividerVertical</item>
        <item name="android:showDividers">middle</item>
        <item name="android:dividerPadding">8dip</item>
        <item name="android:measureWithLargestChild">true</item>
        <item name="android:tabLayout">@android:layout/tab_indicator_holo</item>
    </style>
</resources>
Loading