diff options
Diffstat (limited to 'core/java/android/widget/TabHost.java')
-rw-r--r-- | core/java/android/widget/TabHost.java | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java index 103d44d..31920e7 100644 --- a/core/java/android/widget/TabHost.java +++ b/core/java/android/widget/TabHost.java @@ -20,6 +20,7 @@ import android.app.LocalActivityManager; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; +import android.os.Build; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -28,11 +29,12 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; -import com.android.internal.R; import java.util.ArrayList; import java.util.List; +import com.android.internal.R; + /** * Container for a tabbed window view. This object holds two children: a set of tab labels that the * user clicks to select a specific tab, and a FrameLayout object that displays the contents of that @@ -68,7 +70,7 @@ public class TabHost extends FrameLayout implements ViewTreeObserver.OnTouchMode initTabHost(); } - private final void initTabHost() { + private void initTabHost() { setFocusableInTouchMode(true); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); @@ -101,8 +103,8 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); throw new RuntimeException( "Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'"); } - - // KeyListener to attach to all tabs. Detects non-navigation keys + + // KeyListener to attach to all tabs. Detects non-navigation keys // and relays them to the tab content. mTabKeyListener = new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { @@ -114,14 +116,14 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_ENTER: return false; - + } mTabContent.requestFocus(View.FOCUS_FORWARD); return mTabContent.dispatchKeyEvent(event); } - + }; - + mTabWidget.setTabSelectionListener(new TabWidget.OnTabSelectionChanged() { public void onTabSelectionChanged(int tabIndex, boolean clicked) { setCurrentTab(tabIndex); @@ -134,7 +136,8 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); mTabContent = (FrameLayout) findViewById(com.android.internal.R.id.tabcontent); if (mTabContent == null) { throw new RuntimeException( - "Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'"); + "Your TabHost must have a FrameLayout whose id attribute is " + + "'android.R.id.tabcontent'"); } } @@ -176,7 +179,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); if (!isInTouchMode) { // leaving touch mode.. if nothing has focus, let's give it to // the indicator of the current tab - if (!mCurrentView.hasFocus() || mCurrentView.isFocused()) { + if (mCurrentView != null && (!mCurrentView.hasFocus() || mCurrentView.isFocused())) { mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus(); } } @@ -283,7 +286,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); playSoundEffect(SoundEffectConstants.NAVIGATION_UP); return true; } - return handled; + return handled; } @@ -312,7 +315,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); // Call the tab widget's focusCurrentTab(), instead of just // selecting the tab. mTabWidget.focusCurrentTab(mCurrentTab); - + // tab content mCurrentView = spec.mContentStrategy.getContentView(); @@ -367,7 +370,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); public interface TabContentFactory { /** * Callback to make the tab contents - * + * * @param tag * Which tab was selected. * @return The view to display the contents of the selected tab. @@ -496,8 +499,9 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); } public View createIndicatorView() { + final Context context = getContext(); LayoutInflater inflater = - (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View tabIndicator = inflater.inflate(R.layout.tab_indicator, mTabWidget, // tab widget is the parent false); // no inflate params @@ -505,6 +509,12 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); final TextView tv = (TextView) tabIndicator.findViewById(R.id.title); tv.setText(mLabel); + 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; } } @@ -523,8 +533,9 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); } public View createIndicatorView() { + final Context context = getContext(); LayoutInflater inflater = - (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View tabIndicator = inflater.inflate(R.layout.tab_indicator, mTabWidget, // tab widget is the parent false); // no inflate params @@ -535,6 +546,12 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon); iconView.setImageDrawable(mIcon); + 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; } } @@ -637,7 +654,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); } } mLaunchedView = wd; - + // XXX Set FOCUS_AFTER_DESCENDANTS on embedded activities for now so they can get // focus if none of their children have it. They need focus to be able to // display menu items. |