android Settings 解析

1、Settings的主界面的实现:

Settings采用了PreferenceActivity和PreferenceFragment结合的实现方式。

Settings.java继承自PreferenceActivity,是Settings的主界面,它通过loadHeadersFromResource函数(api level 11)加载res/xml/settings_headers.xml来构造界面。在settings_headers.xml中声明了要在Settings主界面显示的各个header(如Sound、Display等)Settings.HeaderAdapter将其中的header分为三类。在Settings.HeaderAdapter中的getView方法中根据header的类型使用不同的布局文件。

为header划分类型的函数

       static int getHeaderType(Header header) {

           if (header.fragment == null && header.intent == null) {

               return HEADER_TYPE_CATEGORY; // 因为没有指明fragment和intent

           } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings || header.id == R.id.mobiledata_settings) {

               return HEADER_TYPE_SWITCH; // 针对特定的三个header,分别为Wi-Fi、Bluetooth和Mobile data

           } else {

               return HEADER_TYPE_NORMAL;

           }

       }

当我们点击主界面的header后会显示与该header相关的设置界面。大部分(如Display的详细设置界面)都是通过继承PreferenceFragment来实现的;有一部分是在settings_headers.xml中声明<intent>,当被点击时(触发PreferenceActivity的onHeaderClick())将会通过startActivity来启动在<intent>节点中声明的targetClass(如设置中的Add account)。

2、通过res/xml/settings_headers.xml分析android4.3里设置的构成

无线和网络

Wifi:com.android.settings.wifi.WifiSettings

MobileData:com.android.phone.MSimMobileNetworkSubSettings   phone里的写的

Bluetooth:com.android.settings.bluetooth.BluetoothSettings

Data Usage(流量使用情况):com.android.settings.DataUsageSummary

Operator hook(运营商):com.android.settings.WirelessSettings(NFC    nfc  beam 具体不清楚)

Other wireless and network controls(更多):com.android.settings.WirelessSettings

设备

Multi Sim Settings(多SIM卡设置):com.android.settings.MultiSimSettings被注释掉了

Multi Sim Settings(双卡设置):com.android.settings.multisimsettings.MultiSimSettings

Global roaming settings(国际漫游设置)if RoamingSettings installed(如果安装了漫游设置):android:action="com.android.action.roamingsettings"

Sound:com.android.settings.SoundSettings

Display:com.android.settings.DisplaySettings

Storage:com.android.settings.deviceinfo.Memory

Battery:com.android.settings.fuelgauge.PowerUsageSummary

Application Settings(应用):com.android.settings.ApplicationSettings

Manage users(用户):com.android.settings.users.UserSettings

Manufacturer hook(制造商):com.android.settings.WirelessSettings

PERSONAL(个人)

Location(位置信息使用权限):com.android.settings.LocationSettings

Security(安全):com.android.settings.SecuritySettings

Language:com.android.settings.inputmethod.InputMethodAndLanguageSettings

Backup and reset(备份和重置):com.android.settings.PrivacySettings

ACCOUNTS section(账户)

add account(添加账户):android.settings.ADD_ACCOUNT_SETTINGS

SYSTEM(系统)

Date & Time:com.android.settings.DateTimeSettings

Accessibility feedback(辅助功能):com.android.settings.AccessibilitySettings

Development(开发者选项):com.android.settings.DevelopmentSettings

About Device(关于手机):com.android.settings.DeviceInfoSettings

 

posted @ 2014-01-22 10:22  阳光穿透泛白的记忆  阅读(4525)  评论(0编辑  收藏  举报