summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-08-08 21:05:40 -0700
committerJeff Sharkey <jsharkey@android.com>2011-08-15 15:49:48 -0700
commit11f4a48c54f3006778c874662ff04a4d9d157f25 (patch)
treeea1c87a38a861b9e4c44339ab62a478a80e53e96
parentdd7bc9f457204e60feeea53b0b12ba706d6964df (diff)
downloadframeworks_base-11f4a48c54f3006778c874662ff04a4d9d157f25.zip
frameworks_base-11f4a48c54f3006778c874662ff04a4d9d157f25.tar.gz
frameworks_base-11f4a48c54f3006778c874662ff04a4d9d157f25.tar.bz2
Adjust holo tabs to match spec.
Change-Id: I8653ab10cd45bed3c38b15362e80af6c3319f763
-rw-r--r--core/java/android/widget/TabHost.java10
-rw-r--r--core/java/android/widget/TabWidget.java76
-rw-r--r--core/res/res/layout/tab_indicator_holo.xml34
-rw-r--r--core/res/res/layout/tab_indicator_holo_large.xml46
-rw-r--r--core/res/res/values-sw600dp/styles.xml16
-rw-r--r--core/res/res/values/styles.xml25
6 files changed, 63 insertions, 144 deletions
diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java
index 57a8531..88d7230 100644
--- a/core/java/android/widget/TabHost.java
+++ b/core/java/android/widget/TabHost.java
@@ -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);
}
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java
index 3d1dedc..9afb625 100644
--- a/core/java/android/widget/TabWidget.java
+++ b/core/java/android/widget/TabWidget.java
@@ -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();
@@ -146,7 +142,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
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
// to a tab other than the current tab
@@ -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,11 +286,9 @@ 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));
}
-
+
/**
* 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
@@ -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);
}
-
}
-
diff --git a/core/res/res/layout/tab_indicator_holo.xml b/core/res/res/layout/tab_indicator_holo.xml
index d5fc3f4..4410b20 100644
--- a/core/res/res/layout/tab_indicator_holo.xml
+++ b/core/res/res/layout/tab_indicator_holo.xml
@@ -1,5 +1,5 @@
<?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" />
-
-</RelativeLayout>
+ android:layout_gravity="center_vertical"
+ style="@android:style/Widget.Holo.TabText" />
+
+</LinearLayout>
diff --git a/core/res/res/layout/tab_indicator_holo_large.xml b/core/res/res/layout/tab_indicator_holo_large.xml
deleted file mode 100644
index bdd8d11..0000000
--- a/core/res/res/layout/tab_indicator_holo_large.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?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>
diff --git a/core/res/res/values-sw600dp/styles.xml b/core/res/res/values-sw600dp/styles.xml
index 645db13..7dea9b8 100644
--- a/core/res/res/values-sw600dp/styles.xml
+++ b/core/res/res/values-sw600dp/styles.xml
@@ -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>
-
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index d20d16c..8e74457 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -1751,19 +1751,27 @@ please see styles_device_defaults.xml.
<item name="android:button">@android:drawable/btn_star_holo_dark</item>
</style>
- <!-- The holo style for smaller screens actually uses the non-holo layout,
- which is more compact. values-xlarge defines an alternative version
- for the real holo look on a large screen. -->
<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: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>
+ <style name="Widget.Holo.Tab" parent="Widget.Holo.ActionBar.TabView">
+ <item name="android:layout_width">0dip</item>
+ <item name="android:layout_weight">1</item>
+ <item name="android:minWidth">80dip</item>
+ </style>
+
+ <style name="Widget.Holo.TabText" parent="Widget.Holo.ActionBar.TabText">
+ <item name="android:maxWidth">180dip</item>
+ </style>
+
<style name="Widget.Holo.WebTextView" parent="Widget.WebTextView">
</style>
@@ -1843,9 +1851,6 @@ please see styles_device_defaults.xml.
<item name="android:paddingRight">16dip</item>
</style>
- <style name="Widget.Holo.Tab" parent="Widget.Holo.ActionBar.TabView">
- </style>
-
<style name="Widget.Holo.ActionBar.TabBar" parent="Widget.ActionBar.TabBar">
<item name="android:divider">?android:attr/actionBarDivider</item>
<item name="android:showDividers">middle</item>
@@ -1858,6 +1863,8 @@ please see styles_device_defaults.xml.
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textAllCaps">true</item>
+ <item name="android:ellipsize">marquee</item>
+ <item name="android:maxLines">2</item>
</style>
<style name="Widget.Holo.ActionMode" parent="Widget.ActionMode">