Android4.0设置界面修改总结(三)

转载自:http://blog.csdn.net/way_ping_li/article/details/29855869

=============================================================================================================================

Android4.0设置界面修改总结大概介绍了一下设置改tab风格,其实原理很简单,理解两个主要的函数即可:

①.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源码:

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  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(thisnull);  
  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, nullnew 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 != nullreturn 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(thisnulltrue);  
  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 == nullreturn;  
  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.   
  780.             if (convertView == null) {  
  781.                 holder = new HeaderViewHolder();  
  782.                 switch (headerType) {  
  783.                     case HEADER_TYPE_CATEGORY:  
  784.                         view = new TextView(getContext(), null,  
  785.                                 android.R.attr.listSeparatorTextViewStyle);  
  786.                         holder.title = (TextView) view;  
  787.                         break;  
  788.   
  789.                     case HEADER_TYPE_SWITCH:  
  790.                         view = mInflater.inflate(R.layout.preference_header_switch_item, parent,  
  791.                                 false);  
  792.                         holder.icon = (ImageView) view.findViewById(R.id.icon);  
  793.                         holder.title = (TextView)  
  794.                                 view.findViewById(com.android.internal.R.id.title);  
  795.                         holder.summary = (TextView)  
  796.                                 view.findViewById(com.android.internal.R.id.summary);  
  797.                         holder.switch_ = (Switch) view.findViewById(R.id.switchWidget);  
  798.                         break;  
  799.   
  800.                     case HEADER_TYPE_NORMAL:  
  801.                         view = mInflater.inflate(  
  802.                                 R.layout.preference_header_item, parent,  
  803.                                 false);  
  804.                         holder.icon = (ImageView) view.findViewById(R.id.icon);  
  805.                         holder.title = (TextView)  
  806.                                 view.findViewById(com.android.internal.R.id.title);  
  807.                         holder.summary = (TextView)  
  808.                                 view.findViewById(com.android.internal.R.id.summary);  
  809.                         break;  
  810.                 }  
  811.                 view.setTag(holder);  
  812.                   
  813.                 mViewCache[position] = view;//add by liweiping 20140601 for tab settings  
  814.             } else {  
  815.                 view = convertView;  
  816.                 //start by liweiping 20140601 for tab settings  
  817.                 // holder = (HeaderViewHolder) view.getTag();  
  818.                 return view;  
  819.                 //end by liweiping 20140601 for tab settings  
  820.             }  
  821.   
  822.             // All view fields must be updated every time, because the view may be recycled  
  823.             switch (headerType) {  
  824.                 case HEADER_TYPE_CATEGORY:  
  825.                     holder.title.setText(header.getTitle(getContext().getResources()));  
  826.                     break;  
  827.   
  828.                 case HEADER_TYPE_SWITCH:  
  829.                     // Would need a different treatment if the main menu had more switches  
  830.                     if (header.id == R.id.wifi_settings) {  
  831.                         mWifiEnabler.setSwitch(holder.switch_);  
  832.                     } else {  
  833.                         mBluetoothEnabler.setSwitch(holder.switch_);  
  834.                     }  
  835.                     // No break, fall through on purpose to update common fields  
  836.   
  837.                     //$FALL-THROUGH$  
  838.                 case HEADER_TYPE_NORMAL:  
  839.                     if (header.extras != null  
  840.                             && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {  
  841.                         String accType = header.extras.getString(  
  842.                                 ManageAccountsSettings.KEY_ACCOUNT_TYPE);  
  843.                         ViewGroup.LayoutParams lp = holder.icon.getLayoutParams();  
  844.                         lp.width = getContext().getResources().getDimensionPixelSize(  
  845.                                 R.dimen.header_icon_width);  
  846.                         lp.height = lp.width;  
  847.                         holder.icon.setLayoutParams(lp);  
  848.                         Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);  
  849.                         holder.icon.setImageDrawable(icon);  
  850.                     } else {  
  851.                         holder.icon.setImageResource(header.iconRes);  
  852.                     }  
  853.                     holder.title.setText(header.getTitle(getContext().getResources()));  
  854.                     //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 start  
  855.                     if(header.id == R.id.privacy_settings) {  
  856.                         if (getContext().getPackageManager().resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {  
  857.                             holder.title.setText(getContext().getResources().getText(R.string.master_clear_title));  
  858.                         }  
  859.                     }  
  860.                     //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 end  
  861.                     CharSequence summary = header.getSummary(getContext().getResources());  
  862.                     if (!TextUtils.isEmpty(summary)) {  
  863.                         holder.summary.setVisibility(View.VISIBLE);  
  864.                         holder.summary.setText(summary);  
  865.                     } else {  
  866.                         holder.summary.setVisibility(View.GONE);  
  867.                     }  
  868.                     break;  
  869.             }  
  870.             //start by liweiping 20140601 for tab settings  
  871.             if (header.fragment == null && header.intent == null) {  
  872.                 view.setBackgroundColor(android.R.color.transparent);   
  873.             }else if(header.id == R.id.dual_sim_settings || header.id == R.id.audio_profiles || header.id == R.id.user_settings ||   
  874.                     header.id == R.id.location_settings || header.id == R.id.date_time_settings){  
  875.                 view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_top);  
  876.             }else if(header.id == R.id.wireless_settings || header.id == R.id.account_add || header.id == R.id.about_settings ||   
  877.                     header.id == R.id.application_settings){  
  878.                 view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_bottom);  
  879.             }else {  
  880.                 view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_center);  
  881.             }  
  882.             //end by liweiping 20140601 for tab settings  
  883.             return view;  
  884.         }  
  885.   
  886.         public void resume() {  
  887.             mWifiEnabler.resume();  
  888.             mBluetoothEnabler.resume();  
  889.         }  
  890.   
  891.         public void pause() {  
  892.             mWifiEnabler.pause();  
  893.             mBluetoothEnabler.pause();  
  894.         }  
  895.     }  
  896.   
  897.     @Override  
  898.     public void onHeaderClick(Header header, int position) {  
  899.         boolean revert = false;  
  900.         if (header.id == R.id.account_add) {  
  901.             revert = true;  
  902.         }  
  903. //start,added by topwise hehuadong in 2014.01.16  
  904.         if (TopwiseProp.getDefaultSettingString("default_customize_about_device")!=null){  
  905.             if (header != null && header.fragment != null && header.fragment.equals("com.android.settings.DeviceInfoSettings")){  
  906.                 header.fragment="com.android.settings.AboutDeviceSettings";  
  907.             }  
  908.         }  
  909. //end,added by topwise hehuadong in 2014.01.16  
  910.         super.onHeaderClick(header, position);  
  911.   
  912.         if (revert && mLastHeader != null) {  
  913.             // fix bug 200478 to avoid list scroll when account_add item selected on 20130810 begin  
  914.             //highlightHeader((int) mLastHeader.id);  
  915.             // fix bug 200478 to avoid list scroll when account_add item selected on 20130810 end  
  916.         } else {  
  917.             mLastHeader = header;  
  918.         }  
  919.     }  
  920.   
  921.     @Override  
  922.     public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {  
  923.         // Override the fragment title for Wallpaper settings  
  924.         int titleRes = pref.getTitleRes();  
  925.         if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {  
  926.             titleRes = R.string.wallpaper_settings_fragment_title;  
  927.         }  
  928.         startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),  
  929.                 null0);  
  930.         return true;  
  931.     }  
  932.   
  933.     public boolean shouldUpRecreateTask(Intent targetIntent) {  
  934.         return super.shouldUpRecreateTask(new Intent(this, Settings.class));  
  935.     }  
  936.   
  937.     @Override  
  938.     public void setListAdapter(ListAdapter adapter) {  
  939.         if (adapter == null) {  
  940.             super.setListAdapter(null);  
  941.         } else {  
  942.             super.setListAdapter(new HeaderAdapter(this, getHeaders(), mAuthenticatorHelper));  
  943.         }  
  944.     }  
  945.   
  946.     @Override  
  947.     public void onAccountsUpdated(Account[] accounts) {  
  948.         mAuthenticatorHelper.onAccountsUpdated(this, accounts);  
  949.         invalidateHeaders();  
  950.     }  
  951.   
  952.     /* 
  953.      * Settings subclasses for launching independently. 
  954.      */  
  955.     public static class BluetoothSettingsActivity extends Settings { /* empty */ }  
  956.     public static class WirelessSettingsActivity extends Settings { /* empty */ }  
  957.     public static class TetherSettingsActivity extends Settings { /* empty */ }  
  958.     public static class VpnSettingsActivity extends Settings { /* empty */ }  
  959.     public static class DateTimeSettingsActivity extends Settings { /* empty */ }  
  960.     public static class StorageSettingsActivity extends Settings { /* empty */ }  
  961.     public static class WifiSettingsActivity extends Settings { /* empty */ }  
  962.     public static class WifiP2pSettingsActivity extends Settings { /* empty */ }  
  963.     public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ }  
  964.     public static class KeyboardLayoutPickerActivity extends Settings { /* empty */ }  
  965.     public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ }  
  966.     public static class SpellCheckersSettingsActivity extends Settings { /* empty */ }  
  967.     public static class LocalePickerActivity extends Settings { /* empty */ }  
  968.     public static class UserDictionarySettingsActivity extends Settings { /* empty */ }  
  969.     public static class SoundSettingsActivity extends Settings { /* empty */ }  
  970.     public static class DisplaySettingsActivity extends Settings { /* empty */ }  
  971.     public static class DeviceInfoSettingsActivity extends Settings { /* empty */ }  
  972.     public static class ApplicationSettingsActivity extends Settings { /* empty */ }  
  973.     public static class ManageApplicationsActivity extends Settings { /* empty */ }  
  974.     public static class StorageUseActivity extends Settings { /* empty */ }  
  975.     public static class DevelopmentSettingsActivity extends Settings { /* empty */ }  
  976.     public static class AccessibilitySettingsActivity extends Settings { /* empty */ }  
  977.     public static class SecuritySettingsActivity extends Settings { /* empty */ }  
  978.     public static class LocationSettingsActivity extends Settings { /* empty */ }  
  979.     public static class PrivacySettingsActivity extends Settings { /* empty */ }  
  980.     public static class DockSettingsActivity extends Settings { /* empty */ }  
  981.     public static class RunningServicesActivity extends Settings { /* empty */ }  
  982.     public static class ManageAccountsSettingsActivity extends Settings { /* empty */ }  
  983.     public static class PowerUsageSummaryActivity extends Settings { /* empty */ }  
  984.     public static class AccountSyncSettingsActivity extends Settings { /* empty */ }  
  985.     public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ }  
  986.     public static class CryptKeeperSettingsActivity extends Settings { /* empty */ }  
  987.     public static class DeviceAdminSettingsActivity extends Settings { /* empty */ }  
  988.     public static class DataUsageSummaryActivity extends Settings { /* empty */ }  
  989.     public static class AdvancedWifiSettingsActivity extends Settings { /* empty */ }  
  990.     public static class TextToSpeechSettingsActivity extends Settings { /* empty */ }  
  991.     public static class AndroidBeamSettingsActivity extends Settings { /* empty */ }  
  992.           
  993.     //start by liweiping 20140601 for tab settings  
  994.     private void setupTab() {  
  995.         mActionBar = getActionBar();  
  996.         mActionBar.setAlternativeTabStyle(true);  
  997.         mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);  
  998.         int tabHeight = (int) getResources().getDimensionPixelSize(R.dimen.universe_ui_tab_height);  
  999.         mActionBar.setTabHeight(tabHeight);  
  1000.   
  1001.         setupNetWork();  
  1002.         setupDevice();  
  1003.         setupPersonal();  
  1004.         setupMore();  
  1005.         setCurrentTab(mCurrentTabIndex);  
  1006.     }  
  1007.   
  1008.     private void setupNetWork() {  
  1009.         final Tab tab = mActionBar.newTab();  
  1010.         LayoutInflater inflater = getLayoutInflater();  
  1011.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1012.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1013.         if (dialView != null) {  
  1014.             dialView.setImageResource(R.drawable.ic_tab_wireless);  
  1015.         }  
  1016.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1017.         if (dialText != null) {  
  1018.             dialText.setText(R.string.header_category_wireless_networks);  
  1019.         }  
  1020.         tab.setCustomView(view);  
  1021.         tab.setTag(R.xml.settings_headers_wireless_networks);  
  1022.         tab.setTabListener(mTabListener);  
  1023.         mActionBar.addTab(tab);  
  1024.     }  
  1025.     private void setupDevice() {  
  1026.         final Tab tab = mActionBar.newTab();  
  1027.         LayoutInflater inflater = getLayoutInflater();  
  1028.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1029.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1030.         if (dialView != null) {  
  1031.             dialView.setImageResource(R.drawable.ic_tab_device);  
  1032.         }  
  1033.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1034.         if (dialText != null) {  
  1035.             dialText.setText(R.string.header_category_device);  
  1036.         }  
  1037.         tab.setCustomView(view);  
  1038.         tab.setTag(R.xml.settings_headers_device);  
  1039.         tab.setTabListener(mTabListener);  
  1040.         mActionBar.addTab(tab);  
  1041.     }  
  1042.     private void setupPersonal() {  
  1043.         final Tab tab = mActionBar.newTab();  
  1044.         LayoutInflater inflater = getLayoutInflater();  
  1045.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1046.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1047.         if (dialView != null) {  
  1048.             dialView.setImageResource(R.drawable.ic_tab_personal);  
  1049.         }  
  1050.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1051.         if (dialText != null) {  
  1052.             dialText.setText(R.string.header_category_personal);  
  1053.         }  
  1054.         tab.setCustomView(view);  
  1055.         tab.setTag(R.xml.settings_headers_personal);  
  1056.         tab.setTabListener(mTabListener);  
  1057.         mActionBar.addTab(tab);  
  1058.     }  
  1059.     private void setupMore() {  
  1060.         final Tab tab = mActionBar.newTab();  
  1061.         LayoutInflater inflater = getLayoutInflater();  
  1062.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1063.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1064.         if (dialView != null) {  
  1065.             dialView.setImageResource(R.drawable.ic_tab_system);  
  1066.         }  
  1067.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1068.         if (dialText != null) {  
  1069.             dialText.setText(R.string.header_category_system);  
  1070.         }  
  1071.         tab.setCustomView(view);  
  1072.         tab.setTag(R.xml.settings_headers_system);  
  1073.         tab.setTabListener(mTabListener);  
  1074.         mActionBar.addTab(tab);  
  1075.     }  
  1076.   
  1077.      
  1078.     public void setCurrentTab(int position) {  
  1079.         mCurrentTabIndex = position;  
  1080.         if ((mActionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS)  
  1081.                 && (mCurrentTabIndex != mActionBar.getSelectedNavigationIndex())) {  
  1082.             mActionBar.setSelectedNavigationItem(mCurrentTabIndex);  
  1083.         }  
  1084.     }  
  1085.   
  1086.     private final TabListener mTabListener = new TabListener() {  
  1087.         @Override  
  1088.         public void onTabUnselected(Tab tab, FragmentTransaction ft) {  
  1089.         }  
  1090.   
  1091.         @Override  
  1092.         public void onTabSelected(Tab tab, FragmentTransaction ft) {  
  1093.             int tag = (Integer) tab.getTag();  
  1094.   
  1095.             if (mHeadersCategory != tag) {  
  1096.                 mCurrentTabIndex = tab.getPosition();  
  1097.                 Log.i("TabSettings""mCurrentTab = " + mCurrentTabIndex);  
  1098.                 getIntent().putExtra("tab_index", mCurrentTabIndex);  
  1099.                 mHeadersCategory = tag;  
  1100.   
  1101.                 invalidateHeaders();  
  1102.             }  
  1103.         }  
  1104.   
  1105.         @Override  
  1106.         public void onTabReselected(Tab tab, FragmentTransaction ft) {  
  1107.         }  
  1108.     };  
  1109.   
  1110.     private void chooseTab(int index) {  
  1111.         getActionBar().setSelectedNavigationItem(index);  
  1112.         mCurrentTabIndex = index;  
  1113.         getIntent().putExtra("tab_index", mCurrentTabIndex);  
  1114.     }  
  1115.     //end by liweiping 20140601 for tab settings/  
  1116. }  
[java]  view plain copy print ?
  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(thisnull);  
  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, nullnew 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 != nullreturn 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(thisnulltrue);  
  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 == nullreturn;  
  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.   
  780.             if (convertView == null) {  
  781.                 holder = new HeaderViewHolder();  
  782.                 switch (headerType) {  
  783.                     case HEADER_TYPE_CATEGORY:  
  784.                         view = new TextView(getContext(), null,  
  785.                                 android.R.attr.listSeparatorTextViewStyle);  
  786.                         holder.title = (TextView) view;  
  787.                         break;  
  788.   
  789.                     case HEADER_TYPE_SWITCH:  
  790.                         view = mInflater.inflate(R.layout.preference_header_switch_item, parent,  
  791.                                 false);  
  792.                         holder.icon = (ImageView) view.findViewById(R.id.icon);  
  793.                         holder.title = (TextView)  
  794.                                 view.findViewById(com.android.internal.R.id.title);  
  795.                         holder.summary = (TextView)  
  796.                                 view.findViewById(com.android.internal.R.id.summary);  
  797.                         holder.switch_ = (Switch) view.findViewById(R.id.switchWidget);  
  798.                         break;  
  799.   
  800.                     case HEADER_TYPE_NORMAL:  
  801.                         view = mInflater.inflate(  
  802.                                 R.layout.preference_header_item, parent,  
  803.                                 false);  
  804.                         holder.icon = (ImageView) view.findViewById(R.id.icon);  
  805.                         holder.title = (TextView)  
  806.                                 view.findViewById(com.android.internal.R.id.title);  
  807.                         holder.summary = (TextView)  
  808.                                 view.findViewById(com.android.internal.R.id.summary);  
  809.                         break;  
  810.                 }  
  811.                 view.setTag(holder);  
  812.                   
  813.                 mViewCache[position] = view;//add by liweiping 20140601 for tab settings  
  814.             } else {  
  815.                 view = convertView;  
  816.                 //start by liweiping 20140601 for tab settings  
  817.                 // holder = (HeaderViewHolder) view.getTag();  
  818.                 return view;  
  819.                 //end by liweiping 20140601 for tab settings  
  820.             }  
  821.   
  822.             // All view fields must be updated every time, because the view may be recycled  
  823.             switch (headerType) {  
  824.                 case HEADER_TYPE_CATEGORY:  
  825.                     holder.title.setText(header.getTitle(getContext().getResources()));  
  826.                     break;  
  827.   
  828.                 case HEADER_TYPE_SWITCH:  
  829.                     // Would need a different treatment if the main menu had more switches  
  830.                     if (header.id == R.id.wifi_settings) {  
  831.                         mWifiEnabler.setSwitch(holder.switch_);  
  832.                     } else {  
  833.                         mBluetoothEnabler.setSwitch(holder.switch_);  
  834.                     }  
  835.                     // No break, fall through on purpose to update common fields  
  836.   
  837.                     //$FALL-THROUGH$  
  838.                 case HEADER_TYPE_NORMAL:  
  839.                     if (header.extras != null  
  840.                             && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {  
  841.                         String accType = header.extras.getString(  
  842.                                 ManageAccountsSettings.KEY_ACCOUNT_TYPE);  
  843.                         ViewGroup.LayoutParams lp = holder.icon.getLayoutParams();  
  844.                         lp.width = getContext().getResources().getDimensionPixelSize(  
  845.                                 R.dimen.header_icon_width);  
  846.                         lp.height = lp.width;  
  847.                         holder.icon.setLayoutParams(lp);  
  848.                         Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);  
  849.                         holder.icon.setImageDrawable(icon);  
  850.                     } else {  
  851.                         holder.icon.setImageResource(header.iconRes);  
  852.                     }  
  853.                     holder.title.setText(header.getTitle(getContext().getResources()));  
  854.                     //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 start  
  855.                     if(header.id == R.id.privacy_settings) {  
  856.                         if (getContext().getPackageManager().resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {  
  857.                             holder.title.setText(getContext().getResources().getText(R.string.master_clear_title));  
  858.                         }  
  859.                     }  
  860.                     //fix bug 210641 the text of "backup and reset" not appropriate ,when os did not support backup on 2013.9.4 end  
  861.                     CharSequence summary = header.getSummary(getContext().getResources());  
  862.                     if (!TextUtils.isEmpty(summary)) {  
  863.                         holder.summary.setVisibility(View.VISIBLE);  
  864.                         holder.summary.setText(summary);  
  865.                     } else {  
  866.                         holder.summary.setVisibility(View.GONE);  
  867.                     }  
  868.                     break;  
  869.             }  
  870.             //start by liweiping 20140601 for tab settings  
  871.             if (header.fragment == null && header.intent == null) {  
  872.                 view.setBackgroundColor(android.R.color.transparent);   
  873.             }else if(header.id == R.id.dual_sim_settings || header.id == R.id.audio_profiles || header.id == R.id.user_settings ||   
  874.                     header.id == R.id.location_settings || header.id == R.id.date_time_settings){  
  875.                 view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_top);  
  876.             }else if(header.id == R.id.wireless_settings || header.id == R.id.account_add || header.id == R.id.about_settings ||   
  877.                     header.id == R.id.application_settings){  
  878.                 view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_bottom);  
  879.             }else {  
  880.                 view.setBackgroundResource(com.android.internal.R.drawable.easy_pref_item_center);  
  881.             }  
  882.             //end by liweiping 20140601 for tab settings  
  883.             return view;  
  884.         }  
  885.   
  886.         public void resume() {  
  887.             mWifiEnabler.resume();  
  888.             mBluetoothEnabler.resume();  
  889.         }  
  890.   
  891.         public void pause() {  
  892.             mWifiEnabler.pause();  
  893.             mBluetoothEnabler.pause();  
  894.         }  
  895.     }  
  896.   
  897.     @Override  
  898.     public void onHeaderClick(Header header, int position) {  
  899.         boolean revert = false;  
  900.         if (header.id == R.id.account_add) {  
  901.             revert = true;  
  902.         }  
  903. //start,added by topwise hehuadong in 2014.01.16  
  904.         if (TopwiseProp.getDefaultSettingString("default_customize_about_device")!=null){  
  905.             if (header != null && header.fragment != null && header.fragment.equals("com.android.settings.DeviceInfoSettings")){  
  906.                 header.fragment="com.android.settings.AboutDeviceSettings";  
  907.             }  
  908.         }  
  909. //end,added by topwise hehuadong in 2014.01.16  
  910.         super.onHeaderClick(header, position);  
  911.   
  912.         if (revert && mLastHeader != null) {  
  913.             // fix bug 200478 to avoid list scroll when account_add item selected on 20130810 begin  
  914.             //highlightHeader((int) mLastHeader.id);  
  915.             // fix bug 200478 to avoid list scroll when account_add item selected on 20130810 end  
  916.         } else {  
  917.             mLastHeader = header;  
  918.         }  
  919.     }  
  920.   
  921.     @Override  
  922.     public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {  
  923.         // Override the fragment title for Wallpaper settings  
  924.         int titleRes = pref.getTitleRes();  
  925.         if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {  
  926.             titleRes = R.string.wallpaper_settings_fragment_title;  
  927.         }  
  928.         startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),  
  929.                 null0);  
  930.         return true;  
  931.     }  
  932.   
  933.     public boolean shouldUpRecreateTask(Intent targetIntent) {  
  934.         return super.shouldUpRecreateTask(new Intent(this, Settings.class));  
  935.     }  
  936.   
  937.     @Override  
  938.     public void setListAdapter(ListAdapter adapter) {  
  939.         if (adapter == null) {  
  940.             super.setListAdapter(null);  
  941.         } else {  
  942.             super.setListAdapter(new HeaderAdapter(this, getHeaders(), mAuthenticatorHelper));  
  943.         }  
  944.     }  
  945.   
  946.     @Override  
  947.     public void onAccountsUpdated(Account[] accounts) {  
  948.         mAuthenticatorHelper.onAccountsUpdated(this, accounts);  
  949.         invalidateHeaders();  
  950.     }  
  951.   
  952.     /* 
  953.      * Settings subclasses for launching independently. 
  954.      */  
  955.     public static class BluetoothSettingsActivity extends Settings { /* empty */ }  
  956.     public static class WirelessSettingsActivity extends Settings { /* empty */ }  
  957.     public static class TetherSettingsActivity extends Settings { /* empty */ }  
  958.     public static class VpnSettingsActivity extends Settings { /* empty */ }  
  959.     public static class DateTimeSettingsActivity extends Settings { /* empty */ }  
  960.     public static class StorageSettingsActivity extends Settings { /* empty */ }  
  961.     public static class WifiSettingsActivity extends Settings { /* empty */ }  
  962.     public static class WifiP2pSettingsActivity extends Settings { /* empty */ }  
  963.     public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ }  
  964.     public static class KeyboardLayoutPickerActivity extends Settings { /* empty */ }  
  965.     public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ }  
  966.     public static class SpellCheckersSettingsActivity extends Settings { /* empty */ }  
  967.     public static class LocalePickerActivity extends Settings { /* empty */ }  
  968.     public static class UserDictionarySettingsActivity extends Settings { /* empty */ }  
  969.     public static class SoundSettingsActivity extends Settings { /* empty */ }  
  970.     public static class DisplaySettingsActivity extends Settings { /* empty */ }  
  971.     public static class DeviceInfoSettingsActivity extends Settings { /* empty */ }  
  972.     public static class ApplicationSettingsActivity extends Settings { /* empty */ }  
  973.     public static class ManageApplicationsActivity extends Settings { /* empty */ }  
  974.     public static class StorageUseActivity extends Settings { /* empty */ }  
  975.     public static class DevelopmentSettingsActivity extends Settings { /* empty */ }  
  976.     public static class AccessibilitySettingsActivity extends Settings { /* empty */ }  
  977.     public static class SecuritySettingsActivity extends Settings { /* empty */ }  
  978.     public static class LocationSettingsActivity extends Settings { /* empty */ }  
  979.     public static class PrivacySettingsActivity extends Settings { /* empty */ }  
  980.     public static class DockSettingsActivity extends Settings { /* empty */ }  
  981.     public static class RunningServicesActivity extends Settings { /* empty */ }  
  982.     public static class ManageAccountsSettingsActivity extends Settings { /* empty */ }  
  983.     public static class PowerUsageSummaryActivity extends Settings { /* empty */ }  
  984.     public static class AccountSyncSettingsActivity extends Settings { /* empty */ }  
  985.     public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ }  
  986.     public static class CryptKeeperSettingsActivity extends Settings { /* empty */ }  
  987.     public static class DeviceAdminSettingsActivity extends Settings { /* empty */ }  
  988.     public static class DataUsageSummaryActivity extends Settings { /* empty */ }  
  989.     public static class AdvancedWifiSettingsActivity extends Settings { /* empty */ }  
  990.     public static class TextToSpeechSettingsActivity extends Settings { /* empty */ }  
  991.     public static class AndroidBeamSettingsActivity extends Settings { /* empty */ }  
  992.           
  993.     //start by liweiping 20140601 for tab settings  
  994.     private void setupTab() {  
  995.         mActionBar = getActionBar();  
  996.         mActionBar.setAlternativeTabStyle(true);  
  997.         mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);  
  998.         int tabHeight = (int) getResources().getDimensionPixelSize(R.dimen.universe_ui_tab_height);  
  999.         mActionBar.setTabHeight(tabHeight);  
  1000.   
  1001.         setupNetWork();  
  1002.         setupDevice();  
  1003.         setupPersonal();  
  1004.         setupMore();  
  1005.         setCurrentTab(mCurrentTabIndex);  
  1006.     }  
  1007.   
  1008.     private void setupNetWork() {  
  1009.         final Tab tab = mActionBar.newTab();  
  1010.         LayoutInflater inflater = getLayoutInflater();  
  1011.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1012.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1013.         if (dialView != null) {  
  1014.             dialView.setImageResource(R.drawable.ic_tab_wireless);  
  1015.         }  
  1016.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1017.         if (dialText != null) {  
  1018.             dialText.setText(R.string.header_category_wireless_networks);  
  1019.         }  
  1020.         tab.setCustomView(view);  
  1021.         tab.setTag(R.xml.settings_headers_wireless_networks);  
  1022.         tab.setTabListener(mTabListener);  
  1023.         mActionBar.addTab(tab);  
  1024.     }  
  1025.     private void setupDevice() {  
  1026.         final Tab tab = mActionBar.newTab();  
  1027.         LayoutInflater inflater = getLayoutInflater();  
  1028.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1029.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1030.         if (dialView != null) {  
  1031.             dialView.setImageResource(R.drawable.ic_tab_device);  
  1032.         }  
  1033.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1034.         if (dialText != null) {  
  1035.             dialText.setText(R.string.header_category_device);  
  1036.         }  
  1037.         tab.setCustomView(view);  
  1038.         tab.setTag(R.xml.settings_headers_device);  
  1039.         tab.setTabListener(mTabListener);  
  1040.         mActionBar.addTab(tab);  
  1041.     }  
  1042.     private void setupPersonal() {  
  1043.         final Tab tab = mActionBar.newTab();  
  1044.         LayoutInflater inflater = getLayoutInflater();  
  1045.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1046.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1047.         if (dialView != null) {  
  1048.             dialView.setImageResource(R.drawable.ic_tab_personal);  
  1049.         }  
  1050.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1051.         if (dialText != null) {  
  1052.             dialText.setText(R.string.header_category_personal);  
  1053.         }  
  1054.         tab.setCustomView(view);  
  1055.         tab.setTag(R.xml.settings_headers_personal);  
  1056.         tab.setTabListener(mTabListener);  
  1057.         mActionBar.addTab(tab);  
  1058.     }  
  1059.     private void setupMore() {  
  1060.         final Tab tab = mActionBar.newTab();  
  1061.         LayoutInflater inflater = getLayoutInflater();  
  1062.         View view = inflater.inflate(R.layout.tab_widget_view, null);  
  1063.         ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon);  
  1064.         if (dialView != null) {  
  1065.             dialView.setImageResource(R.drawable.ic_tab_system);  
  1066.         }  
  1067.         TextView dialText = (TextView) view.findViewById(R.id.tab_text);  
  1068.         if (dialText != null) {  
  1069.             dialText.setText(R.string.header_category_system);  
  1070.         }  
  1071.         tab.setCustomView(view);  
  1072.         tab.setTag(R.xml.settings_headers_system);  
  1073.         tab.setTabListener(mTabListener);  
  1074.         mActionBar.addTab(tab);  
  1075.     }  
  1076.   
  1077.      
  1078.     public void setCurrentTab(int position) {  
  1079.         mCurrentTabIndex = position;  
  1080.         if ((mActionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS)  
  1081.                 && (mCurrentTabIndex != mActionBar.getSelectedNavigationIndex())) {  
  1082.             mActionBar.setSelectedNavigationItem(mCurrentTabIndex);  
  1083.         }  
  1084.     }  
  1085.   
  1086.     private final TabListener mTabListener = new TabListener() {  
  1087.         @Override  
  1088.         public void onTabUnselected(Tab tab, FragmentTransaction ft) {  
  1089.         }  
  1090.   
  1091.         @Override  
  1092.         public void onTabSelected(Tab tab, FragmentTransaction ft) {  
  1093.             int tag = (Integer) tab.getTag();  
  1094.   
  1095.             if (mHeadersCategory != tag) {  
  1096.                 mCurrentTabIndex = tab.getPosition();  
  1097.                 Log.i("TabSettings""mCurrentTab = " + mCurrentTabIndex);  
  1098.                 getIntent().putExtra("tab_index", mCurrentTabIndex);  
  1099.                 mHeadersCategory = tag;  
  1100.   
  1101.                 invalidateHeaders();  
  1102.             }  
  1103.         }  
  1104.   
  1105.         @Override  
  1106.         public void onTabReselected(Tab tab, FragmentTransaction ft) {  
  1107.         }  
  1108.     };  
  1109.   
  1110.     private void chooseTab(int index) {  
  1111.         getActionBar().setSelectedNavigationItem(index);  
  1112.         mCurrentTabIndex = index;  
  1113.         getIntent().putExtra("tab_index", mCurrentTabIndex);  
  1114.     }  
  1115.     //end by liweiping 20140601 for tab settings/  
  1116. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值