Android4.0设置界面改动总结大概介绍了一下设置改tab风格,事实上原理非常easy,理解两个基本的函数就可以:

①.invalidateHeaders(),调用此函数将又一次调用onBuildHeader()来又一次读取xml文件里的header,又一次刷新HeaderAdapter中的数据,因此刷新了ListView的内容,从而更新了界面。

②.onBuildHeaders()中调用loadHeadersFromResource(resId, headers);
就可以又一次载入HeaderAdapter的数据。

可是上次有一个问题,不能横竖屏切换,由于有一些bug未解决,所以我在onCreate中增加了:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);这一句,

另外代码结构略微调整了一下,再和大家分享一下。

主要改动有下面两点:

①.能够横竖屏切换,主要是在HeaderAdapter中增加了一个函数:flushViewCache()。同意横竖屏切换时又一次刷新数据。

②.将每一个tab相应的xml布局当成每一个tab的tag传递给onBuildHeaders,又一次刷新缓存的HeaderAdapter。

好了,废话不多说了,直接上源代码。能够搜索标签 20140601,就可以找到我全部的改动。

Settings.java源代码:

  1. /*
  2. * Copyright (C) 2008 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. package com.android.settings;
  18. import android.app.ActionBar;
  19. import android.app.ActivityManager;
  20. import com.android.internal.util.ArrayUtils;
  21. import com.android.settings.accounts.AccountSyncSettings;
  22. import com.android.settings.accounts.AuthenticatorHelper;
  23. import com.android.settings.accounts.ManageAccountsSettings;
  24. import com.android.settings.applications.ManageApplications;
  25. import com.android.settings.bluetooth.BluetoothEnabler;
  26. import com.android.settings.deviceinfo.Memory;
  27. import com.android.settings.fuelgauge.PowerUsageSummary;
  28. import com.android.settings.inputmethod.UserDictionaryAddWordFragment;
  29. import com.android.settings.wifi.WifiEnabler;
  30. import static com.sprd.android.config.OptConfig.LC_RAM_SUPPORT;
  31. import android.accounts.Account;
  32. import android.accounts.AccountManager;
  33. import android.accounts.OnAccountsUpdateListener;
  34. import android.content.ComponentName;
  35. import android.content.Context;
  36. import android.content.Intent;
  37. import android.content.pm.ActivityInfo;
  38. import android.content.pm.PackageManager;
  39. import android.content.pm.PackageManager.NameNotFoundException;
  40. import android.graphics.drawable.Drawable;
  41. import android.os.Bundle;
  42. import android.os.INetworkManagementService;
  43. import android.os.RemoteException;
  44. import android.os.ServiceManager;
  45. import android.os.UserId;
  46. import android.os.SystemProperties;
  47. import android.os.TopwiseProp;
  48. import android.preference.Preference;
  49. import android.preference.PreferenceActivity;
  50. import android.preference.PreferenceActivity.Header;
  51. import android.preference.PreferenceFragment;
  52. import android.telephony.TelephonyManager;
  53. import android.text.TextUtils;
  54. import android.util.Log;
  55. import android.view.LayoutInflater;
  56. import android.view.View;
  57. import android.view.View.OnClickListener;
  58. import android.view.ViewGroup;
  59. import android.widget.ArrayAdapter;
  60. import android.widget.BaseAdapter;
  61. import android.widget.Button;
  62. import android.widget.ImageView;
  63. import android.widget.ListAdapter;
  64. import android.widget.Switch;
  65. import android.widget.TextView;
  66.  
  67. import java.util.ArrayList;
  68. import java.util.Collections;
  69. import java.util.Comparator;
  70. import java.util.HashMap;
  71. import java.util.List;
  72.  
  73. import android.app.ActionBar;
  74. import android.app.ActionBar.Tab;
  75. import android.app.ActionBar.TabListener;
  76. import android.app.FragmentTransaction;
  77. /**
  78. * Top-level settings activity to handle single pane and double pane UI layout.
  79. */
  80. public class Settings extends PreferenceActivity
  81. implements ButtonBarHandler, OnAccountsUpdateListener {
  82.  
  83. private static final String LOG_TAG = "Settings";
  84.  
  85. private static final String META_DATA_KEY_HEADER_ID =
  86. "com.android.settings.TOP_LEVEL_HEADER_ID";
  87. private static final String META_DATA_KEY_FRAGMENT_CLASS =
  88. "com.android.settings.FRAGMENT_CLASS";
  89. private static final String META_DATA_KEY_PARENT_TITLE =
  90. "com.android.settings.PARENT_FRAGMENT_TITLE";
  91. private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS =
  92. "com.android.settings.PARENT_FRAGMENT_CLASS";
  93.  
  94. private static final String EXTRA_CLEAR_UI_OPTIONS = "settings:remove_ui_options";
  95.  
  96. private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER";
  97. private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER";
  98. //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 start
  99. private static final String GSETTINGS_PROVIDER = "com.google.settings";
  100. //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 send
  101. public static boolean UNIVERSEUI_SUPPORT = SystemProperties.getBoolean("universe_ui_support",false);
  102. public static final boolean CU_SUPPORT = SystemProperties.get("ro.operator").equals("cucc");
  103.  
  104. private String mFragmentClass;
  105. private int mTopLevelHeaderId;
  106. private Header mFirstHeader;
  107. private Header mCurrentHeader;
  108. private Header mParentHeader;
  109. private boolean mInLocalHeaderSwitch;
  110. //start by liweiping 20140601 for tab settings
  111. private ActionBar mActionBar;
  112. private int mCurrentTabIndex = 0;
  113. private View mView;
  114. public static LayoutInflater mInflater;
  115. int mHeadersCategory = R.xml.settings_headers_uui;
  116. private int[] mTabTitle = new int[] {
  117. R.string.header_category_wireless_networks,
  118. R.string.header_category_device,
  119. R.string.header_category_personal,
  120. R.string.header_category_system
  121. };
  122. //end by liweiping 20140601
  123. // Show only these settings for restricted users
  124. private int[] SETTINGS_FOR_RESTRICTED = {
  125. R.id.wifi_settings,
  126. R.id.bluetooth_settings,
  127. R.id.sound_settings,
  128. R.id.display_settings,
  129. R.id.security_settings,
  130. R.id.account_settings,
  131. R.id.about_settings
  132. };
  133.  
  134. private boolean mEnableUserManagement = false;
  135.  
  136. // TODO: Update Call Settings based on airplane mode state.
  137.  
  138. protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
  139.  
  140. private AuthenticatorHelper mAuthenticatorHelper;
  141. private Header mLastHeader;
  142. private boolean mListeningToAccountUpdates;
  143. private boolean mBluetoothEnable;
  144. private boolean mVoiceCapable;
  145.  
  146. @Override
  147. protected void onCreate(Bundle savedInstanceState) {
  148. mBluetoothEnable = (SystemProperties.getInt("ro.tablet.bluetooth.enable", 1) != 0);
  149. mBluetoothEnable = (SystemProperties.getInt("ro.tablet.bluetooth.enable", 1) != 0);
  150. mVoiceCapable = getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
  151. if (getIntent().getBooleanExtra(EXTRA_CLEAR_UI_OPTIONS, false)) {
  152. getWindow().setUiOptions(0);
  153. }
  154.  
  155. if (android.provider.Settings.Secure.getInt(getContentResolver(), "multiuser_enabled", -1)
  156. > 0) {
  157. mEnableUserManagement = true;
  158. }
  159.  
  160. mAuthenticatorHelper = new AuthenticatorHelper();
  161. mAuthenticatorHelper.updateAuthDescriptions(this);
  162. mAuthenticatorHelper.onAccountsUpdated(this, null);
  163.  
  164. getMetaData();
  165. mInLocalHeaderSwitch = true;
  166. super.onCreate(savedInstanceState);
  167. mInLocalHeaderSwitch = false;
  168.  
  169. //For LowCost case, define the list selector by itself
  170. if (LC_RAM_SUPPORT)
  171. getListView().setSelector(R.drawable.list_selector_holo_dark);
  172.  
  173. if (!onIsHidingHeaders() && onIsMultiPane()) {
  174. highlightHeader(mTopLevelHeaderId);
  175. // Force the title so that it doesn't get overridden by a direct launch of
  176. // a specific settings screen.
  177. setTitle(R.string.settings_label);
  178. }
  179.  
  180. // Retrieve any saved state
  181. if (savedInstanceState != null) {
  182. mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER);
  183. mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER);
  184. }
  185.  
  186. // If the current header was saved, switch to it
  187. if (savedInstanceState != null && mCurrentHeader != null) {
  188. //switchToHeaderLocal(mCurrentHeader);
  189. showBreadCrumbs(mCurrentHeader.title, null);
  190. }
  191.  
  192. if (mParentHeader != null) {
  193. setParentTitle(mParentHeader.title, null, new OnClickListener() {
  194. public void onClick(View v) {
  195. switchToParent(mParentHeader.fragment);
  196. }
  197. });
  198. }
  199.  
  200. // Override up navigation for multi-pane, since we handle it in the fragment breadcrumbs
  201. if (onIsMultiPane()) {
  202. getActionBar().setDisplayHomeAsUpEnabled(false);
  203. getActionBar().setHomeButtonEnabled(false);
  204. }
  205. //start by liweiping 20140601 for tab settings
  206. mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  207. if (UNIVERSEUI_SUPPORT) {
  208. if (this.getClass().equals(Settings.class)) {
  209. int index = getIntent().getIntExtra("tab_index", mCurrentTabIndex);
  210. setupTab();
  211. chooseTab(index);
  212. }
  213. }
  214. //end by liweiping 20140601 for tab settings
  215. }
  216.  
  217. @Override
  218. protected void onSaveInstanceState(Bundle outState) {
  219. super.onSaveInstanceState(outState);
  220.  
  221. // Save the current fragment, if it is the same as originally launched
  222. if (mCurrentHeader != null) {
  223. outState.putParcelable(SAVE_KEY_CURRENT_HEADER, mCurrentHeader);
  224. }
  225. if (mParentHeader != null) {
  226. outState.putParcelable(SAVE_KEY_PARENT_HEADER, mParentHeader);
  227. }
  228. }
  229.  
  230. @Override
  231. public void onResume() {
  232. super.onResume();
  233.  
  234. ListAdapter listAdapter = getListAdapter();
  235. if (listAdapter instanceof HeaderAdapter) {
  236. //start by liweiping 20140601 for tab settings
  237. ((HeaderAdapter) listAdapter).flushViewCache();
  238. //end by liweiping 20140601 for tab settings
  239. ((HeaderAdapter) listAdapter).resume();
  240. }
  241. invalidateHeaders();
  242. setActionBarStyle();//add by liweiping 20140210 for bug 173
  243. }
  244.  
  245. //start by liweiping 20140210 for bug 173
  246. /* Set ActionBar with popup function */
  247. protected void setActionBarStyle() {
  248. ActionBar actionBar = getActionBar();
  249. if (actionBar == null){
  250. return;
  251. }
  252. if ( this.toString().contains("SubSettings") ) {
  253. actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
  254. actionBar.setDisplayHomeAsUpEnabled(true);
  255. }
  256. else {
  257. actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP
  258. ^ ActionBar.DISPLAY_HOME_AS_UP
  259. , ActionBar.DISPLAY_HOME_AS_UP);
  260. actionBar.setDisplayHomeAsUpEnabled(false);
  261. }
  262. }
  263. //end by liweiping 20140210
  264.  
  265. @Override
  266. public void onPause() {
  267. super.onPause();
  268.  
  269. ListAdapter listAdapter = getListAdapter();
  270. if (listAdapter instanceof HeaderAdapter) {
  271. ((HeaderAdapter) listAdapter).pause();
  272. }
  273. }
  274.  
  275. private String getRunningActivityName() {
  276. ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  277. return activityManager != null ? activityManager.getRunningTasks(1).get(0).topActivity
  278. .getClassName() : null;
  279. }
  280.  
  281. // fix bug 185285 to avoid jump out of Settings when Locale changed on 20130819 begin
  282. /*@Override
  283. public void onBackPressed() {
  284. if (!moveTaskToBack(false)) {
  285. super.onBackPressed();
  286. }
  287. }*/
  288. // fix bug 185285 to avoid jump out of Settings when Locale changed on 20130819 end
  289.  
  290. @Override
  291. public void onDestroy() {
  292. super.onDestroy();
  293. if (mListeningToAccountUpdates) {
  294. AccountManager.get(this).removeOnAccountsUpdatedListener(this);
  295. }
  296. }
  297.  
  298. private void switchToHeaderLocal(Header header) {
  299. mInLocalHeaderSwitch = true;
  300. switchToHeader(header);
  301. mInLocalHeaderSwitch = false;
  302. }
  303.  
  304. @Override
  305. public void switchToHeader(Header header) {
  306. if (!mInLocalHeaderSwitch) {
  307. mCurrentHeader = null;
  308. mParentHeader = null;
  309. }
  310. super.switchToHeader(header);
  311. }
  312.  
  313. /**
  314. * Switch to parent fragment and store the grand parent's info
  315. * @param className name of the activity wrapper for the parent fragment.
  316. */
  317. private void switchToParent(String className) {
  318. final ComponentName cn = new ComponentName(this, className);
  319. try {
  320. final PackageManager pm = getPackageManager();
  321. final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA);
  322.  
  323. if (parentInfo != null && parentInfo.metaData != null) {
  324. String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
  325. CharSequence fragmentTitle = parentInfo.loadLabel(pm);
  326. Header parentHeader = new Header();
  327. parentHeader.fragment = fragmentClass;
  328. parentHeader.title = fragmentTitle;
  329. mCurrentHeader = parentHeader;
  330.  
  331. switchToHeaderLocal(parentHeader);
  332. highlightHeader(mTopLevelHeaderId);
  333.  
  334. mParentHeader = new Header();
  335. mParentHeader.fragment
  336. = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
  337. mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE);
  338. }
  339. } catch (NameNotFoundException nnfe) {
  340. Log.w(LOG_TAG, "Could not find parent activity : " + className);
  341. }
  342. }
  343.  
  344. @Override
  345. public void onNewIntent(Intent intent) {
  346. super.onNewIntent(intent);
  347.  
  348. // If it is not launched from history, then reset to top-level
  349. if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0
  350. && mFirstHeader != null && !onIsHidingHeaders() && onIsMultiPane()) {
  351. switchToHeaderLocal(mFirstHeader);
  352. }
  353. }
  354.  
  355. private void highlightHeader(int id) {
  356. if (id != 0) {
  357. Integer index = mHeaderIndexMap.get(id);
  358. if (index != null) {
  359. getListView().setItemChecked(index, true);
  360. getListView().smoothScrollToPosition(index);
  361. }
  362. }
  363. }
  364.  
  365. @Override
  366. public Intent getIntent() {
  367. Intent superIntent = super.getIntent();
  368. String startingFragment = getStartingFragmentClass(superIntent);
  369. // This is called from super.onCreate, isMultiPane() is not yet reliable
  370. // Do not use onIsHidingHeaders either, which relies itself on this method
  371. if (startingFragment != null && !onIsMultiPane()) {
  372. Intent modIntent = new Intent(superIntent);
  373. modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
  374. Bundle args = superIntent.getExtras();
  375. if (args != null) {
  376. args = new Bundle(args);
  377. } else {
  378. args = new Bundle();
  379. }
  380. args.putParcelable("intent", superIntent);
  381. modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras());
  382. return modIntent;
  383. }
  384. return superIntent;
  385. }
  386.  
  387. /**
  388. * Checks if the component name in the intent is different from the Settings class and
  389. * returns the class name to load as a fragment.
  390. */
  391. protected String getStartingFragmentClass(Intent intent) {
  392. if (mFragmentClass != null) return mFragmentClass;
  393.  
  394. String intentClass = intent.getComponent().getClassName();
  395. if (intentClass.equals(getClass().getName())) return null;
  396.  
  397. if ("com.android.settings.ManageApplications".equals(intentClass)
  398. || "com.android.settings.RunningServices".equals(intentClass)
  399. || "com.android.settings.applications.StorageUse".equals(intentClass)) {
  400. // Old names of manage apps.
  401. intentClass = com.android.settings.applications.ManageApplications.class.getName();
  402. }
  403.  
  404. return intentClass;
  405. }
  406.  
  407. /**
  408. * Override initial header when an activity-alias is causing Settings to be launched
  409. * for a specific fragment encoded in the android:name parameter.
  410. */
  411. @Override
  412. public Header onGetInitialHeader() {
  413. String fragmentClass = getStartingFragmentClass(super.getIntent());
  414. if (fragmentClass != null) {
  415. Header header = new Header();
  416. header.fragment = fragmentClass;
  417. header.title = getTitle();
  418. header.fragmentArguments = getIntent().getExtras();
  419. mCurrentHeader = header;
  420. return header;
  421. }
  422.  
  423. return mFirstHeader;
  424. }
  425.  
  426. @Override
  427. public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
  428. int titleRes, int shortTitleRes) {
  429. Intent intent = super.onBuildStartFragmentIntent(fragmentName, args,
  430. titleRes, shortTitleRes);
  431.  
  432. // some fragments want to avoid split actionbar
  433. if (DataUsageSummary.class.getName().equals(fragmentName) ||
  434. PowerUsageSummary.class.getName().equals(fragmentName) ||
  435. AccountSyncSettings.class.getName().equals(fragmentName) ||
  436. UserDictionarySettings.class.getName().equals(fragmentName) ||
  437. Memory.class.getName().equals(fragmentName) ||
  438. ManageApplications.class.getName().equals(fragmentName) ||
  439. WirelessSettings.class.getName().equals(fragmentName) ||
  440. SoundSettings.class.getName().equals(fragmentName) ||
  441. PrivacySettings.class.getName().equals(fragmentName) ||
  442. // SPRD: Modify 20130830 Spreadst of Bug 207441 clipboard can not be called
  443. UserDictionaryAddWordFragment.class.getName().equals(fragmentName) ||
  444. ManageAccountsSettings.class.getName().equals(fragmentName)) {
  445. intent.putExtra(EXTRA_CLEAR_UI_OPTIONS, true);
  446. }
  447. //fix bug 226565 select englisg in userdictoryaddwors, rotate, the language change to chinses on 20131012 begin
  448. intent.setClass(this, SubSettings.class);
  449. /*
  450. // fix bug 194403 to make the activity execute onCreate() method when orientation changed on 20130802 begin
  451. Log.i(LOG_TAG,"fragmentName = " + fragmentName);
  452. if (UserDictionaryAddWordFragment.class.getName().equals(fragmentName)) {
  453. intent.setClass(this, LanguageSubSettings.class);
  454. } else {
  455. intent.setClass(this, SubSettings.class);
  456. }
  457. // fix bug 194403 to make the activity execute onCreate() method when orientation changed on 20130802 end
  458. */
  459. // fix bug 226565 select englisg in userdictoryaddwors, rotate, the language change to chinses on 20131012 end
  460. return intent;
  461. }
  462.  
  463. /**
  464. * Populate the activity with the top-level headers.
  465. */
  466. @Override
  467. public void onBuildHeaders(List<Header> headers) {
  468. //start by liweiping 20140601 for tab settings
  469. if(UNIVERSEUI_SUPPORT){
  470. ListAdapter listAdapter = getListAdapter();
  471. loadHeadersFromResource(mHeadersCategory, headers);
  472. if (listAdapter instanceof HeaderAdapter) {
  473. ((HeaderAdapter) listAdapter).flushViewCache();
  474. ((HeaderAdapter) listAdapter).resume();
  475. ((HeaderAdapter) listAdapter).notifyDataSetChanged();
  476. }
  477. //end by liweiping 20140601 for tab settings
  478. }else{
  479. loadHeadersFromResource(R.xml.settings_headers, headers);
  480. }
  481.  
  482. updateHeaderList(headers);
  483. }
  484.  
  485. private void updateHeaderList(List<Header> target) {
  486. int i = 0;
  487. boolean IsSupVoice = Settings.this.getResources().getBoolean(com.android.internal.R.bool.
  488. config_voice_capable);
  489. while (i < target.size()) {
  490. Header header = target.get(i);
  491. // Ids are integers, so downcasting
  492. int id = (int) header.id;
  493. if (id == R.id.dock_settings) {
  494. if (!needsDockSettings())
  495. target.remove(header);
  496. } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
  497. Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
  498. } else if (id == R.id.wifi_settings) {
  499. // Remove WiFi Settings if WiFi service is not available.
  500. // Start by changyan 2014.01.02
  501. //if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
  502. if (!SystemProperties.getBoolean("ro.device.support.wifi", true)) {
  503. //End by changyan
  504. target.remove(header);
  505. }
  506. } else if (id == R.id.bluetooth_settings) {
  507. //Start by changyan 2014.01.03
  508. // Remove Bluetooth Settings if Bluetooth service is not available.
  509. //if ((!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
  510. // || (!mBluetoothEnable)) {
  511. if (!SystemProperties.getBoolean("ro.device.support.bt", true)) {
  512. //End by changyan
  513. target.remove(header);
  514. }
  515. } else if (id == R.id.data_usage_settings) {
  516. // Remove data usage when kernel module not enabled
  517. final INetworkManagementService netManager = INetworkManagementService.Stub
  518. .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
  519. // fix bug 182580 to delete the data usage item of settings on 20130717 begin
  520. boolean support_cmcc = SystemProperties.get("ro.operator").equals("cmcc");
  521. try {
  522. if (!netManager.isBandwidthControlEnabled() || support_cmcc) {
  523. target.remove(header);
  524. }
  525. } catch (RemoteException e) {
  526. // ignored
  527. }
  528. // fix bug 182580 to delete the data usage item of settings on 20130717 end
  529. } else if (id == R.id.account_settings) {
  530. int headerIndex = i + 1;
  531. i = insertAccountsHeaders(target, headerIndex);
  532. } else if (id == R.id.user_settings) {
  533. if (!mEnableUserManagement
  534. || !UserId.MU_ENABLED || UserId.myUserId() != 0
  535. || !getResources().getBoolean(R.bool.enable_user_management)
  536. || Utils.isMonkeyRunning()) {
  537. target.remove(header);
  538. }
  539. } else if (id == R.id.dual_sim_settings) {
  540. if (!TelephonyManager.isMultiSim() || (!mVoiceCapable)) {
  541. target.remove(header);
  542. }
  543. } else if (id == R.id.network_preference_settings) {
  544. if (!CU_SUPPORT) {
  545. target.remove(header);
  546. }
  547. }
  548. else if (id == R.id.sound_settings && IsSupVoice)
  549. {
  550. target.remove(header);
  551. }
  552. else if (id == R.id.audio_profiles && !IsSupVoice)
  553. {
  554. target.remove(header);
  555. }
  556.  
  557. if (UserId.MU_ENABLED && UserId.myUserId() != 0
  558. && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
  559. target.remove(header);
  560. }
  561.  
  562. // Increment if the current one wasn't removed by the Utils code.
  563. if (target.get(i) == header) {
  564. // Hold on to the first header, when we need to reset to the top-level
  565. if (mFirstHeader == null &&
  566. HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
  567. mFirstHeader = header;
  568. }
  569. mHeaderIndexMap.put(id, i);
  570. i++;
  571. }
  572. }
  573. }
  574.  
  575. private int insertAccountsHeaders(List<Header> target, int headerIndex) {
  576. String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes();
  577. List<Header> accountHeaders = new ArrayList<Header>(accountTypes.length);
  578. for (String accountType : accountTypes) {
  579. if (accountType.startsWith("sprd")) {
  580. continue;
  581. }
  582. CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType);
  583. if (label == null) {
  584. continue;
  585. }
  586.  
  587. Account[] accounts = AccountManager.get(this).getAccountsByType(accountType);
  588. boolean skipToAccount = accounts.length == 1
  589. && !mAuthenticatorHelper.hasAccountPreferences(accountType);
  590. Header accHeader = new Header();
  591. accHeader.title = label;
  592. if (accHeader.extras == null) {
  593. accHeader.extras = new Bundle();
  594. }
  595. if (skipToAccount) {
  596. accHeader.breadCrumbTitleRes = R.string.account_sync_settings_title;
  597. accHeader.breadCrumbShortTitleRes = R.string.account_sync_settings_title;
  598. accHeader.fragment = AccountSyncSettings.class.getName();
  599. accHeader.fragmentArguments = new Bundle();
  600. // Need this for the icon
  601. accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
  602. accHeader.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]);
  603. accHeader.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY,
  604. accounts[0]);
  605. } else {
  606. accHeader.breadCrumbTitle = label;
  607. accHeader.breadCrumbShortTitle = label;
  608. accHeader.fragment = ManageAccountsSettings.class.getName();
  609. accHeader.fragmentArguments = new Bundle();
  610. accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
  611. accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE,
  612. accountType);
  613. if (!isMultiPane()) {
  614. accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL,
  615. label.toString());
  616. }
  617. }
  618. accountHeaders.add(accHeader);
  619. }
  620.  
  621. // Sort by label
  622. Collections.sort(accountHeaders, new Comparator<Header>() {
  623. @Override
  624. public int compare(Header h1, Header h2) {
  625. return h1.title.toString().compareTo(h2.title.toString());
  626. }
  627. });
  628.  
  629. for (Header header : accountHeaders) {
  630. target.add(headerIndex++, header);
  631. }
  632. if (!mListeningToAccountUpdates) {
  633. AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);
  634. mListeningToAccountUpdates = true;
  635. }
  636. return headerIndex;
  637. }
  638.  
  639. private boolean needsDockSettings() {
  640. return getResources().getBoolean(R.bool.has_dock_settings);
  641. }
  642.  
  643. private void getMetaData() {
  644. try {
  645. ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
  646. PackageManager.GET_META_DATA);
  647. if (ai == null || ai.metaData == null) return;
  648. mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID);
  649. mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
  650.  
  651. // Check if it has a parent specified and create a Header object
  652. final int parentHeaderTitleRes = ai.metaData.getInt(META_DATA_KEY_PARENT_TITLE);
  653. String parentFragmentClass = ai.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
  654. if (parentFragmentClass != null) {
  655. mParentHeader = new Header();
  656. mParentHeader.fragment = parentFragmentClass;
  657. if (parentHeaderTitleRes != 0) {
  658. mParentHeader.title = getResources().getString(parentHeaderTitleRes);
  659. }
  660. }
  661. } catch (NameNotFoundException nnfe) {
  662. // No recovery
  663. }
  664. }
  665.  
  666. @Override
  667. public boolean hasNextButton() {
  668. return super.hasNextButton();
  669. }
  670.  
  671. @Override
  672. public Button getNextButton() {
  673. return super.getNextButton();
  674. }
  675.  
  676. private static class HeaderAdapter extends ArrayAdapter<Header> {
  677. static final int HEADER_TYPE_CATEGORY = 0;
  678. static final int HEADER_TYPE_NORMAL = 1;
  679. static final int HEADER_TYPE_SWITCH = 2;
  680. private static final int HEADER_TYPE_COUNT = HEADER_TYPE_SWITCH + 1;
  681.  
  682. private final WifiEnabler mWifiEnabler;
  683. private final BluetoothEnabler mBluetoothEnabler;
  684. private AuthenticatorHelper mAuthHelper;
  685.  
  686. //start by liweiping 20140601 for tab settings
  687. private View[] mViewCache;
  688. private int mViewCacheSize = 0;
  689. //end by liweiping 20140601 for tab settings
  690.  
  691. private static class HeaderViewHolder {
  692. ImageView icon;
  693. TextView title;
  694. TextView summary;
  695. Switch switch_;
  696. }
  697.  
  698. private LayoutInflater mInflater;
  699.  
  700. static int getHeaderType(Header header) {
  701. if (header.fragment == null && header.intent == null) {
  702. return HEADER_TYPE_CATEGORY;
  703. } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) {
  704. return HEADER_TYPE_SWITCH;
  705. } else {
  706. return HEADER_TYPE_NORMAL;
  707. }
  708. }
  709.  
  710. @Override
  711. public int getItemViewType(int position) {
  712. Header header = getItem(position);
  713. return getHeaderType(header);
  714. }
  715.  
  716. @Override
  717. public boolean areAllItemsEnabled() {
  718. return false; // because of categories
  719. }
  720.  
  721. @Override
  722. public boolean isEnabled(int position) {
  723. return getItemViewType(position) != HEADER_TYPE_CATEGORY;
  724. }
  725.  
  726. @Override
  727. public int getViewTypeCount() {
  728. return HEADER_TYPE_COUNT;
  729. }
  730.  
  731. @Override
  732. public boolean hasStableIds() {
  733. return true;
  734. }
  735.  
  736. public HeaderAdapter(Context context, List<Header> objects,
  737. AuthenticatorHelper authenticatorHelper) {
  738. super(context, 0, objects);
  739.  
  740. mAuthHelper = authenticatorHelper;
  741. mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  742.  
  743. // Temp Switches provided as placeholder until the adapter replaces these with actual
  744. // Switches inflated from their layouts. Must be done before adapter is set in super
  745. mWifiEnabler = new WifiEnabler(context, new Switch(context));
  746. mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context));
  747. //start by liweiping 20140601 for tab settings
  748. mViewCacheSize = objects.size();
  749. mViewCache = new View[mViewCacheSize];
  750. //end by liweiping 20140601 for tab settings
  751. }
  752.  
  753. //start by liweiping 20140601 for tab settings
  754. public boolean flushViewCache() {
  755. int currentCount = getCount();
  756.  
  757. mViewCacheSize = currentCount;
  758. mViewCache = null;
  759. mViewCache = new View[mViewCacheSize];
  760. return true;
  761. }
  762. //end by liweiping 20140601 for tab settings
  763.  
  764. @Override
  765. public View getView(int position, View convertView, ViewGroup parent) {
  766. //start by liweiping 20140601 for tab settings
  767. if (position >= mViewCacheSize) {
  768. flushViewCache();
  769. }
  770. //end by liweiping 20140601 for tab settings
  771.  
  772. HeaderViewHolder holder;
  773. Header header = getItem(position);
  774. int headerType = getHeaderType(header);
  775. View view = null;
  776.  
  777. convertView = mViewCache[position];//add by liweiping 20140601 for tab settings
  778.  
  779. if (convertView == null) {
  780. holder = new HeaderViewHolder();
  781. switch (headerType) {
  782. case HEADER_TYPE_CATEGORY:
  783. view = new TextView(getContext(), null,
  784. android.R.attr.listSeparatorTextViewStyle);
  785. holder.title = (TextView) view;
  786. break;
  787.  
  788. case HEADER_TYPE_SWITCH:
  789. view = mInflater.inflate(R.layout.preference_header_switch_item, parent,
  790. false);
  791. holder.icon = (ImageView) view.findViewById(R.id.icon);
  792. holder.title = (TextView)
  793. view.findViewById(com.android.internal.R.id.title);
  794. holder.summary = (TextView)
  795. view.findViewById(com.android.internal.R.id.summary);
  796. holder.switch_ = (Switch) view.findViewById(R.id.switchWidget);
  797. break;
  798.  
  799. case HEADER_TYPE_NORMAL:
  800. view = mInflater.inflate(
  801. R.layout.preference_header_item, parent,
  802. false);
  803. holder.icon = (ImageView) view.findViewById(R.id.icon);
  804. holder.title = (TextView)
  805. view.findViewById(com.android.internal.R.id.title);
  806. holder.summary = (TextView)
  807. view.findViewById(com.android.internal.R.id.summary);
  808. break;
  809. }
  810. view.setTag(holder);
  811.  
  812. mViewCache[position] = view;//add by liweiping 20140601 for tab settings
  813. } else {
  814. view = convertView;
  815. //start by liweiping 20140601 for tab settings
  816. // holder = (HeaderViewHolder) view.getTag();
  817. return view;
  818. //end by liweiping 20140601 for tab settings
  819. }
  820.  
  821. // All view fields must be updated every time, because the view may be recycled
  822. switch (headerType) {
  823. case HEADER_TYPE_CATEGORY:
  824. holder.title.setText(header.getTitle(getContext().getResources()));
  825. break;
  826.  
  827. case HEADER_TYPE_SWITCH:
  828. // Would need a different treatment if the main menu had more switches
  829. if (header.id == R.id.wifi_settings) {
  830. mWifiEnabler.setSwitch(holder.switch_);
  831. } else {
  832. mBluetoothEnabler.setSwitch(holder.switch_);
  833. }
  834. // No break, fall through on purpose to update common fields
  835.  
  836. //$FALL-THROUGH$
  837. case HEADER_TYPE_NORMAL:
  838. if (header.extras != null
  839. && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
  840. String accType = header.extras.getString(
  841. ManageAccountsSettings.KEY_ACCOUNT_TYPE);
  842. ViewGroup.LayoutParams lp = holder.icon.getLayoutParams();
  843. lp.width = getContext().getResources().getDimensionPixelSize(
  844. R.dimen.header_icon_width);
  845. lp.height = lp.width;
  846. holder.icon.setLayoutParams(lp);
  847. Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
  848. holder.icon.setImageDrawable(icon);
  849. } else {
  850. holder.icon.setImageResource(header.iconRes);
  851. }
  852. holder.title.setText(header.getTitle(getContext().getResources()));
  853. //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 start
  854. if(header.id == R.id.privacy_settings) {
  855. if (getContext().getPackageManager().resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {
  856. holder.title.setText(getContext().getResources().getText(R.string.master_clear_title));
  857. }
  858. }
  859. //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 end
  860. CharSequence summary = header.getSummary(getContext().getResources());
  861. if (!TextUtils.isEmpty(summary)) {
  862. holder.summary.setVisibility(View.VISIBLE);
  863. holder.summary.setText(summary);
  864. } else {
  865. holder.summary.setVisibility(View.GONE);
  866. }
  867. break;
  868. }
  869. //start by liweiping 20140601 for tab settings
  870. if (header.fragment == null && header.intent == null) {
  871. view.setBackgroundColor(android.R.color.transparent);
  872. }else if(header.id == R.id.dual_sim_settings || header.id == R.id.audio_profiles || header.id == R.id.user_settings ||
  873. header.id == R.id.location_settings || header.id == R.id.date_time_settings){
  874. view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_top);
  875. }else if(header.id == R.id.wireless_settings || header.id == R.id.account_add || header.id == R.id.about_settings ||
  876. header.id == R.id.application_settings){
  877. view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_bottom);
  878. }else {
  879. view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_center);
  880. }
  881. //end by liweiping 20140601 for tab settings
  882. return view;
  883. }
  884.  
  885. public void resume() {
  886. mWifiEnabler.resume();
  887. mBluetoothEnabler.resume();
  888. }
  889.  
  890. public void pause() {
  891. mWifiEnabler.pause();
  892. mBluetoothEnabler.pause();
  893. }
  894. }
  895.  
  896. @Override
  897. public void onHeaderClick(Header header, int position) {
  898. boolean revert = false;
  899. if (header.id == R.id.account_add) {
  900. revert = true;
  901. }
  902. //start,added by topwise hehuadong in 2014.01.16
  903. if (TopwiseProp.getDefaultSettingString("default_customize_about_device")!=null){
  904. if (header != null && header.fragment != null && header.fragment.equals("com.android.settings.DeviceInfoSettings")){
  905. header.fragment="com.android.settings.AboutDeviceSettings";
  906. }
  907. }
  908. //end,added by topwise hehuadong in 2014.01.16
  909. super.onHeaderClick(header, position);
  910.  
  911. if (revert && mLastHeader != null) {
  912. // fix bug 200478 to avoid list scroll when account_add item selected on 20130810 begin
  913. //highlightHeader((int) mLastHeader.id);
  914. // fix bug 200478 to avoid list scroll when account_add item selected on 20130810 end
  915. } else {
  916. mLastHeader = header;
  917. }
  918. }
  919.  
  920. @Override
  921. public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
  922. // Override the fragment title for Wallpaper settings
  923. int titleRes = pref.getTitleRes();
  924. if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
  925. titleRes = R.string.wallpaper_settings_fragment_title;
  926. }
  927. startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
  928. null, 0);
  929. return true;
  930. }
  931.  
  932. public boolean shouldUpRecreateTask(Intent targetIntent) {
  933. return super.shouldUpRecreateTask(new Intent(this, Settings.class));
  934. }
  935.  
  936. @Override
  937. public void setListAdapter(ListAdapter adapter) {
  938. if (adapter == null) {
  939. super.setListAdapter(null);
  940. } else {
  941. super.setListAdapter(new HeaderAdapter(this, getHeaders(), mAuthenticatorHelper));
  942. }
  943. }
  944.  
  945. @Override
  946. public void onAccountsUpdated(Account[] accounts) {
  947. mAuthenticatorHelper.onAccountsUpdated(this, accounts);
  948. invalidateHeaders();
  949. }
  950.  
  951. /*
  952. * Settings subclasses for launching independently.
  953. */
  954. public static class BluetoothSettingsActivity extends Settings { /* empty */ }
  955. public static class WirelessSettingsActivity extends Settings { /* empty */ }
  956. public static class TetherSettingsActivity extends Settings { /* empty */ }
  957. public static class VpnSettingsActivity extends Settings { /* empty */ }
  958. public static class DateTimeSettingsActivity extends Settings { /* empty */ }
  959. public static class StorageSettingsActivity extends Settings { /* empty */ }
  960. public static class WifiSettingsActivity extends Settings { /* empty */ }
  961. public static class WifiP2pSettingsActivity extends Settings { /* empty */ }
  962. public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ }
  963. public static class KeyboardLayoutPickerActivity extends Settings { /* empty */ }
  964. public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ }
  965. public static class SpellCheckersSettingsActivity extends Settings { /* empty */ }
  966. public static class LocalePickerActivity extends Settings { /* empty */ }
  967. public static class UserDictionarySettingsActivity extends Settings { /* empty */ }
  968. public static class SoundSettingsActivity extends Settings { /* empty */ }
  969. public static class DisplaySettingsActivity extends Settings { /* empty */ }
  970. public static class DeviceInfoSettingsActivity extends Settings { /* empty */ }
  971. public static class ApplicationSettingsActivity extends Settings { /* empty */ }
  972. public static class ManageApplicationsActivity extends Settings { /* empty */ }
  973. public static class StorageUseActivity extends Settings { /* empty */ }
  974. public static class DevelopmentSettingsActivity extends Settings { /* empty */ }
  975. public static class AccessibilitySettingsActivity extends Settings { /* empty */ }
  976. public static class SecuritySettingsActivity extends Settings { /* empty */ }
  977. public static class LocationSettingsActivity extends Settings { /* empty */ }
  978. public static class PrivacySettingsActivity extends Settings { /* empty */ }
  979. public static class DockSettingsActivity extends Settings { /* empty */ }
  980. public static class RunningServicesActivity extends Settings { /* empty */ }
  981. public static class ManageAccountsSettingsActivity extends Settings { /* empty */ }
  982. public static class PowerUsageSummaryActivity extends Settings { /* empty */ }
  983. public static class AccountSyncSettingsActivity extends Settings { /* empty */ }
  984. public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ }
  985. public static class CryptKeeperSettingsActivity extends Settings { /* empty */ }
  986. public static class DeviceAdminSettingsActivity extends Settings { /* empty */ }
  987. public static class DataUsageSummaryActivity extends Settings { /* empty */ }
  988. public static class AdvancedWifiSettingsActivity extends Settings { /* empty */ }
  989. public static class TextToSpeechSettingsActivity extends Settings { /* empty */ }
  990. public static class AndroidBeamSettingsActivity extends Settings { /* empty */ }
  991.  
  992. //start by liweiping 20140601 for tab settings
  993. private void setupTab() {
  994. mActionBar = getActionBar();
  995. mActionBar.setAlternativeTabStyle(true);
  996. mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  997. int tabHeight = (int) getResources().getDimensionPixelSize(R.dimen.universe_ui_tab_height);
  998. mActionBar.setTabHeight(tabHeight);
  999.  
  1000. setupNetWork();
  1001. setupDevice();
  1002. setupPersonal();
  1003. setupMore();
  1004. setCurrentTab(mCurrentTabIndex);
  1005. }
  1006.  
  1007. private void setupNetWork() {
  1008. final Tab tab = mActionBar.newTab();
  1009. LayoutInflater inflater = getLayoutInflater();
  1010. View view = inflater.inflate(R.layout.tab_widget_view, null);
  1011. ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);
  1012. if (dialView != null) {
  1013. dialView.setImageResource(R.drawable.ic_tab_wireless);
  1014. }
  1015. TextView dialText = (TextView) view.findViewById(R.id.tab_text);
  1016. if (dialText != null) {
  1017. dialText.setText(R.string.header_category_wireless_networks);
  1018. }
  1019. tab.setCustomView(view);
  1020. tab.setTag(R.xml.settings_headers_wireless_networks);
  1021. tab.setTabListener(mTabListener);
  1022. mActionBar.addTab(tab);
  1023. }
  1024. private void setupDevice() {
  1025. final Tab tab = mActionBar.newTab();
  1026. LayoutInflater inflater = getLayoutInflater();
  1027. View view = inflater.inflate(R.layout.tab_widget_view, null);
  1028. ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);
  1029. if (dialView != null) {
  1030. dialView.setImageResource(R.drawable.ic_tab_device);
  1031. }
  1032. TextView dialText = (TextView) view.findViewById(R.id.tab_text);
  1033. if (dialText != null) {
  1034. dialText.setText(R.string.header_category_device);
  1035. }
  1036. tab.setCustomView(view);
  1037. tab.setTag(R.xml.settings_headers_device);
  1038. tab.setTabListener(mTabListener);
  1039. mActionBar.addTab(tab);
  1040. }
  1041. private void setupPersonal() {
  1042. final Tab tab = mActionBar.newTab();
  1043. LayoutInflater inflater = getLayoutInflater();
  1044. View view = inflater.inflate(R.layout.tab_widget_view, null);
  1045. ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);
  1046. if (dialView != null) {
  1047. dialView.setImageResource(R.drawable.ic_tab_personal);
  1048. }
  1049. TextView dialText = (TextView) view.findViewById(R.id.tab_text);
  1050. if (dialText != null) {
  1051. dialText.setText(R.string.header_category_personal);
  1052. }
  1053. tab.setCustomView(view);
  1054. tab.setTag(R.xml.settings_headers_personal);
  1055. tab.setTabListener(mTabListener);
  1056. mActionBar.addTab(tab);
  1057. }
  1058. private void setupMore() {
  1059. final Tab tab = mActionBar.newTab();
  1060. LayoutInflater inflater = getLayoutInflater();
  1061. View view = inflater.inflate(R.layout.tab_widget_view, null);
  1062. ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);
  1063. if (dialView != null) {
  1064. dialView.setImageResource(R.drawable.ic_tab_system);
  1065. }
  1066. TextView dialText = (TextView) view.findViewById(R.id.tab_text);
  1067. if (dialText != null) {
  1068. dialText.setText(R.string.header_category_system);
  1069. }
  1070. tab.setCustomView(view);
  1071. tab.setTag(R.xml.settings_headers_system);
  1072. tab.setTabListener(mTabListener);
  1073. mActionBar.addTab(tab);
  1074. }
  1075.  
  1076. public void setCurrentTab(int position) {
  1077. mCurrentTabIndex = position;
  1078. if ((mActionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS)
  1079. && (mCurrentTabIndex != mActionBar.getSelectedNavigationIndex())) {
  1080. mActionBar.setSelectedNavigationItem(mCurrentTabIndex);
  1081. }
  1082. }
  1083.  
  1084. private final TabListener mTabListener = new TabListener() {
  1085. @Override
  1086. public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  1087. }
  1088.  
  1089. @Override
  1090. public void onTabSelected(Tab tab, FragmentTransaction ft) {
  1091. int tag = (Integer) tab.getTag();
  1092.  
  1093. if (mHeadersCategory != tag) {
  1094. mCurrentTabIndex = tab.getPosition();
  1095. Log.i("TabSettings", "mCurrentTab = " + mCurrentTabIndex);
  1096. getIntent().putExtra("tab_index", mCurrentTabIndex);
  1097. mHeadersCategory = tag;
  1098.  
  1099. invalidateHeaders();
  1100. }
  1101. }
  1102.  
  1103. @Override
  1104. public void onTabReselected(Tab tab, FragmentTransaction ft) {
  1105. }
  1106. };
  1107.  
  1108. private void chooseTab(int index) {
  1109. getActionBar().setSelectedNavigationItem(index);
  1110. mCurrentTabIndex = index;
  1111. getIntent().putExtra("tab_index", mCurrentTabIndex);
  1112. }
  1113. //end by liweiping 20140601 for tab settings/
  1114. }

Android4.0设置界面改动总结(三)的更多相关文章

  1. Android4.0设置界面改动总结(二)

    今年1月份的时候.有和大家分享给予Android4.0+系统设置的改动:Android4.0设置界面改动总结 时隔半年.回头看看那个时候的改动.事实上是有非常多问题的,比方说: ①.圆角Item会影响 ...

  2. Android常用控件之Fragment仿Android4.0设置界面

    Fragment是Android3.0新增的概念,是碎片的意思,它和Activity很相像,用来在一个Activity中描述一些行为或部分用户界面:使用多个Fragment可以在一个单独的Activi ...

  3. android4.0默认界面旋转180

    不巧新拿的android4.0默认启动画面和正常显示旋转了180度,即为倒立的.原来是屏输出为倒的,查找得知可以做旋转: 步骤: 一:先把这个加上 然后加上属性ro.sf.hwrotation = 1 ...

  4. Android4.0设置接口变更摘要(四)

    为了与你之前,你已经设置了共享Tab风格和Item实现圆角.希望能给有须要的朋友一点点帮助,今天再和大家分享一下用ViewPager实现设置分页,小米和OPPO就是这种设置,先来看看效果图: wate ...

  5. Android4.0图库Gallery2代码分析(二) 数据管理和数据加载

    Android4.0图库Gallery2代码分析(二) 数据管理和数据加载 2012-09-07 11:19 8152人阅读 评论(12) 收藏 举报 代码分析android相册优化工作 Androi ...

  6. Android4.0+锁屏程序开发——设置锁屏页面篇

    [如何开发一个锁屏应用] 想要开发一个锁屏应用,似乎很难,其实并没有想象中那么难. 从本质上来说,锁屏界面也只是一个Activity而已,只是这个界面比较特殊,在我们点亮屏幕的时候,这个界面就会出现. ...

  7. iOS开发——开发必备OC篇&UITableView设置界面完整封装(三)

    UITableView设置界面完整封装(三) 简单MVC实现UITableView设置界面之界面跳转 创建一个需要调整的对应的控制器 在需要调整的类型模型中创建对应的属性用来实现调整类型控制器的设置 ...

  8. Android4.0的Alertdialog对话框,设置点击其他位置不消失

    Android4.0以上AlertDialog,包括其他自定义的dialog,在触摸对话框边缘外部,对话框消失. 可以设置这么一条属性,当然必须先AlertDialog.Builder.create( ...

  9. 深入浅出 - Android系统移植与平台开发(三)- 编译并运行Android4.0模拟器

    作者:唐老师,华清远见嵌入式学院讲师. 1.   编译Android模拟器 在Ubuntu下,我们可以在源码里编译出自己的模拟器及SDK等编译工具,当然这个和在windows里下载的看起来没有什么区别 ...

随机推荐

  1. [Backbone.js]如何用backbone写一个仿网页版微信的webapp?

    var Chat = Backbone.Model.extend({ idAttribute:'id', initialize:function(options){ var users = this. ...

  2. mysql_config_editor程序的用法

    1.mysql_config_editor程序的作用: 它只是用来在用户的家目录下生成一个.mylogin.cnf 里面保存有用于登录mysql-server端的password,host,user信 ...

  3. USB2.0的基本学习

    SB2.0是在1.0的基础上于2000年提出来的,在1.0的基础上曾加了480Mbps的数据传输率.USB2.0具有以下的优点: 1.每个USB系统中有一个主机,通过级联的方式连接多个外部设备,最多可 ...

  4. 8.2.5: Spring3.0新增的@DependsOn和@Lazy

    @DependsOn用于强制初始化其他Bean.可以修饰Bean类或方法,使用该Annotation时可以指定一个字符串数组作为参数,每个数组元素对应于一个强制初始化的Bean. @DependsOn ...

  5. VC实现将对话框最小化到系统托盘

    1.minisysDlg.h头文件设置: 1)public: void setTray();//设置托盘    NOTIFYICONDATA nid;//NOTIFYICONDATA结构包含了系统用来 ...

  6. 开源语音识别系统 Simon

    http://www.lupaworld.com/proj.php?mod=view&cid=&id=824 语音识别系统 Simon:Simon 是一个开源的语音识别系统,它不仅可以 ...

  7. libcurl提交表单上传文件

    不多说了,curl的http上传文件代码示例,有需要的可以参考. int http_post_file(const char *url, const char *user, const char *p ...

  8. 【思路解析】discuz 帖子设置封面 setthreadcover 表pre_forum_threadimage

    在Discuz 中有一项就是给帖子设置封面,很多情况下只能通过手动的方式去设置或者用提交POST请求的式去设置: 但是这都是调用DISCUZ的功能设置的: 有的时候并非万能的,也有用不到的时候:下面就 ...

  9. C++ STL 一般总结

    以下内容来源网上 经过整合而成(转载) 一.一般介绍 STL(Standard Template Library),即标准模板库,是一个具有工业强度的,高效的C++程序库.它被容纳于C++标准程序库( ...

  10. 基于php常用正则表达整理(下)

    61        \n 匹配一个换行符.等价于 \x0a 和 \cJ.62        \r 匹配一个回车符.等价于 \x0d 和 \cM.63        \s 匹配任何空白字符,包括空格.制 ...