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



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

之前有跟大家分享设置Tab风格和Item圆角的实现,希望能给有需要的朋友一点点帮助,今天再和大家分享一下用ViewPager实现设置分页,小米和OPPO就是这样的设置,先来看看效果图:

 

为了帮助大家更清晰的理解,单独拿出一个小例子,有需要的朋友可以下载下来看看:

http://git.oschina.net/way/SettingTab/tree/master


其实要实现这样的风格并不难只要能比较深入的理解PreferenceActivity.java就可以了。我们都知道Settings.java是继承自PreferenceActivity.java,所用的布局文件layout也是父类的,而且他的二级界面都是Fragment,都是依赖他这个Activity,如果在onCreate函数中通过setContentView()改变Settings.java的布局,岂不是也会影响他的二级界面?相信很多遇到困难的朋友就是这个原因。


答案是否定的!很明显,我们只需要在显示Settings的第一个界面的时候才setContentView(),也就是说在onCreate里面判断一下 if (this.getClass().equals(Settings.class)),为什么是这样呢?我们可以滚动到Settings.java文件末尾,会发现,其实二级菜单都是一些Fragment,但是它们也有虚拟的类名的,都是Settings的内部类,所以,进到二级菜单就不满足这个条件了。

如下所示:

  1. if (this.getClass().equals(Settings.class)) {  
  2.     setContentView(R.layout.tab_settings);  
  3.     mTabCursor = (ImageView) findViewById(R.id.tab_cursor);  
  4.     ViewPager viewPager = (ViewPager) findViewById(R.id.pager);  
  5.     viewPager.setAdapter(new ViewPagerAdapter(getFragmentManager()));  
  6.     viewPager.setOnPageChangeListener(mPageChangeListener);  
  7.     mViewPager = viewPager;  
  8.   
  9.     mTabGeneral = (TextView) findViewById(R.id.tab_general);  
  10.     mTabDisplay = (TextView) findViewById(R.id.tab_display);  
  11.     mTabGeneral.setOnClickListener(mTabOnClickListener);  
  12.     mTabDisplay.setOnClickListener(mTabOnClickListener);  
  13.     mTabGeneral.setTextColor(COLOR_SELECTED);  
  14.     mTabGeneral.setTextSize(TEXT_SIZE_SELECTED);  
  15. }  
		if (this.getClass().equals(Settings.class)) {
			setContentView(R.layout.tab_settings);
			mTabCursor = (ImageView) findViewById(R.id.tab_cursor);
			ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
			viewPager.setAdapter(new ViewPagerAdapter(getFragmentManager()));
			viewPager.setOnPageChangeListener(mPageChangeListener);
			mViewPager = viewPager;

			mTabGeneral = (TextView) findViewById(R.id.tab_general);
			mTabDisplay = (TextView) findViewById(R.id.tab_display);
			mTabGeneral.setOnClickListener(mTabOnClickListener);
			mTabDisplay.setOnClickListener(mTabOnClickListener);
			mTabGeneral.setTextColor(COLOR_SELECTED);
			mTabGeneral.setTextSize(TEXT_SIZE_SELECTED);
		}


相信,看完上面这段代码,遇到困难的朋友应该会豁然开朗。下面都可以不用继续看下去了。

不过为了善始善终,我继续贴下去。

接下来,我们看看tab_settings.xml的布局,由于PreferenceActivity的特性,布局中必须要有一个id为android:id/list的ListView,因为所有的xml目录下的preference解析出来都是显示在上面,虽然我们改变了布局,但是不能改变他的代码嘛!就弄一个高度宽度为0的ListView骗一下它就可以了,呵呵

  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="match_parent"  
  3.     android:layout_height="match_parent"  
  4.     >  
  5.     <ListView  
  6.         android:id="@android:id/list"  
  7.         android:layout_width="0dp"  
  8.         android:layout_height="0dp"  
  9.         android:visibility="gone"/>  
  10.     <LinearLayout  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="wrap_content"  
  13.         android:orientation="vertical" >  
  14.         <FrameLayout   
  15.            android:layout_width="match_parent"  
  16.            android:layout_height="@dimen/tab_height"  
  17.            android:background="@drawable/tab_background" >  
  18.     <ImageView   
  19.                 android:id="@+id/tab_cursor"  
  20.                 android:layout_width="@dimen/tab_width"  
  21.                 android:layout_height="@dimen/tab_height"  
  22.                 android:background="@drawable/tab_cursor"/>  
  23.             <LinearLayout  
  24.                 android:layout_width="match_parent"  
  25.                 android:layout_height="@dimen/tab_height">  
  26.                 <TextView  
  27.                     android:id="@+id/tab_general"  
  28.                     android:layout_width="0dp"  
  29.                     android:layout_height="wrap_content"  
  30.                     android:layout_weight="1"  
  31.                     android:layout_gravity="center_vertical"  
  32.                     android:gravity="center"  
  33.                     android:text="@string/tab_general"  
  34.                     android:singleLine="true"  
  35.                     android:textSize="@dimen/tab_text_size" />  
  36.                 <TextView  
  37.                     android:id="@+id/tab_display"  
  38.                     android:layout_width="0dp"  
  39.                     android:layout_height="wrap_content"  
  40.                     android:layout_weight="1"  
  41.                     android:gravity="center"  
  42.                     android:layout_gravity="center_vertical"  
  43.                     android:text="@string/tab_display"  
  44.                     android:singleLine="true"  
  45.                     android:textSize="@dimen/tab_text_size" />  
  46.             </LinearLayout>    
  47.         </FrameLayout>  
  48.   
  49.         <android.support.v4.view.ViewPager  
  50.             android:id="@+id/pager"  
  51.             android:layout_width="match_parent"  
  52.             android:layout_height="match_parent" />  
  53.     </LinearLayout>  
  54.   
  55. </FrameLayout>  
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ListView
        android:id="@android:id/list"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:visibility="gone"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <FrameLayout 
           android:layout_width="match_parent"
           android:layout_height="@dimen/tab_height"
           android:background="@drawable/tab_background" >
    <ImageView 
                android:id="@+id/tab_cursor"
                android:layout_width="@dimen/tab_width"
                android:layout_height="@dimen/tab_height"
                android:background="@drawable/tab_cursor"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/tab_height">
                <TextView
                    android:id="@+id/tab_general"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_gravity="center_vertical"
                    android:gravity="center"
                    android:text="@string/tab_general"
                    android:singleLine="true"
                    android:textSize="@dimen/tab_text_size" />
                <TextView
                    android:id="@+id/tab_display"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:layout_gravity="center_vertical"
                    android:text="@string/tab_display"
                    android:singleLine="true"
                    android:textSize="@dimen/tab_text_size" />
            </LinearLayout>  
        </FrameLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

</FrameLayout>


接下来便是普通ViewPager的使用了,我这里就不多说了。

下面把整个Settings.java的源代码分享一下:

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


















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值