| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.os.Bundle; |
| 20 |
import android.view.View; |
| 21 |
import android.widget.TabHost; |
| 22 |
import android.widget.TabWidget; |
| 23 |
import android.widget.TextView; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
@Deprecated |
| 37 |
public class TabActivity extends ActivityGroup { |
| 38 |
private TabHost mTabHost; |
| 39 |
private String mDefaultTab = null; |
| 40 |
private int mDefaultTabIndex = -1; |
| 41 |
|
| 42 |
public TabActivity() { |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public void setDefaultTab(String tag) { |
| 51 |
mDefaultTab = tag; |
| 52 |
mDefaultTabIndex = -1; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public void setDefaultTab(int index) { |
| 61 |
mDefaultTab = null; |
| 62 |
mDefaultTabIndex = index; |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
protected void onRestoreInstanceState(Bundle state) { |
| 67 |
super.onRestoreInstanceState(state); |
| 68 |
ensureTabHost(); |
| 69 |
String cur = state.getString("currentTab"); |
| 70 |
if (cur != null) { |
| 71 |
mTabHost.setCurrentTabByTag(cur); |
| 72 |
} |
| 73 |
if (mTabHost.getCurrentTab() < 0) { |
| 74 |
if (mDefaultTab != null) { |
| 75 |
mTabHost.setCurrentTabByTag(mDefaultTab); |
| 76 |
} else if (mDefaultTabIndex >= 0) { |
| 77 |
mTabHost.setCurrentTab(mDefaultTabIndex); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
@Override |
| 83 |
protected void onPostCreate(Bundle icicle) { |
| 84 |
super.onPostCreate(icicle); |
| 85 |
|
| 86 |
ensureTabHost(); |
| 87 |
|
| 88 |
if (mTabHost.getCurrentTab() == -1) { |
| 89 |
mTabHost.setCurrentTab(0); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
protected void onSaveInstanceState(Bundle outState) { |
| 95 |
super.onSaveInstanceState(outState); |
| 96 |
String currentTabTag = mTabHost.getCurrentTabTag(); |
| 97 |
if (currentTabTag != null) { |
| 98 |
outState.putString("currentTab", currentTabTag); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
@Override |
| 109 |
public void onContentChanged() { |
| 110 |
super.onContentChanged(); |
| 111 |
mTabHost = findViewById(com.android.internal.R.id.tabhost); |
| 112 |
|
| 113 |
if (mTabHost == null) { |
| 114 |
throw new RuntimeException( |
| 115 |
"Your content must have a TabHost whose id attribute is " + |
| 116 |
"'android.R.id.tabhost'"); |
| 117 |
} |
| 118 |
mTabHost.setup(getLocalActivityManager()); |
| 119 |
} |
| 120 |
|
| 121 |
private void ensureTabHost() { |
| 122 |
if (mTabHost == null) { |
| 123 |
this.setContentView(com.android.internal.R.layout.tab_content); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
@Override |
| 128 |
protected void |
| 129 |
onChildTitleChanged(Activity childActivity, CharSequence title) { |
| 130 |
|
| 131 |
if (getLocalActivityManager().getCurrentActivity() == childActivity) { |
| 132 |
View tabView = mTabHost.getCurrentTabView(); |
| 133 |
if (tabView != null && tabView instanceof TextView) { |
| 134 |
((TextView) tabView).setText(title); |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public TabHost getTabHost() { |
| 145 |
ensureTabHost(); |
| 146 |
return mTabHost; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public TabWidget getTabWidget() { |
| 155 |
return mTabHost.getTabWidget(); |
| 156 |
} |
| 157 |
} |