Settings某些菜单项的定义
在Settings里面,正常的二级菜单或者三级菜单是直接在当前界面的布局文件里面定义的,所以可以找到。但是某个二级或者三级菜单里面的preference,在本菜单的布局文件里面没有定义,被定义在Androidmanifest.xml中,它又是如何匹配到二级,或三级菜单里面去的呢。
比如,在Connected devices–>Connection preferences–>Cast,它就是定义到 Androidmanifest里面。
<activity
android:name="Settings$WifiDisplaySettingsActivity"
android:label="@string/wifi_display_settings_title"
android:icon="@drawable/ic_cast_24dp"
android:parentActivityName="Settings">
<intent-filter android:priority="1">
<action android:name="android.settings.CAST_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
<meta-data android:name="com.android.settings.order" android:value="-6"/>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.device" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.wfd.WifiDisplaySettings" />
</activity>
在它的activity定义里有这样一条属性,
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.device" />
它就是指定这个activity显示在那一层菜单中。下面来看这个的属性的定义流程
/frameworks/base/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryKey.java
public final class CategoryKey {
// Activities in this category shows up in Settings homepage.
public static final String CATEGORY_HOMEPAGE = "com.android.settings.category.ia.homepage";
// Top level category.
public static final String CATEGORY_NETWORK = "com.android.settings.category.ia.wireless";
public static final String CATEGORY_CONNECT = "com.android.settings.category.ia.connect";
public static final String CATEGORY_DEVICE = "com.android.settings.category.ia.device";
public static final String CATEGORY_APPS = "com.android.settings.category.ia.apps";
public static final String CATEGORY_APPS_DEFAULT =
"com.android.settings.category.ia.apps.default";
public static final String CATEGORY_BATTERY = "com.android.settings.category.ia.battery";
public static final String CATEGORY_DISPLAY = "com.android.settings.category.ia.display";
public static final String CATEGORY_SOUND = "com.android.settings.category.ia.sound";
public static final String CATEGORY_STORAGE = "com.android.settings.category.ia.storage";
public static final String CATEGORY_SECURITY = "com.android.settings.category.ia.security";
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
在CategoryKey.java定义了com.android.settings.category.ia.device
这些值的静态字符串,
public static final String CATEGORY_DEVICE = "com.android.settings.category.ia.device
然后在:
vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/dashboard
/DashboardFragmentRegistry.java
这里面定义了一个ArrayMap
static {
PARENT_TO_CATEGORY_KEY_MAP = new ArrayMap<>();
PARENT_TO_CATEGORY_KEY_MAP.put(TopLevelSettings.class.getName(),
CategoryKey.CATEGORY_HOMEPAGE);
PARENT_TO_CATEGORY_KEY_MAP.put(
NetworkDashboardFragment.class.getName(), CategoryKey.CATEGORY_NETWORK);
PARENT_TO_CATEGORY_KEY_MAP.put(ConnectedDeviceDashboardFragment.class.getName(),
CategoryKey.CATEGORY_CONNECT);
PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedConnectedDeviceDashboardFragment.class.getName(),
CategoryKey.CATEGORY_DEVICE);
PARENT_TO_CATEGORY_KEY_MAP.put(AppAndNotificationDashboardFragment.class.getName(),
CategoryKey.CATEGORY_APPS);
PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),
CategoryKey.CATEGORY_BATTERY);
然后将这些指定的字符串和指定的Java类对应起来,例如:
PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedConnectedDeviceDashboardFragment.class.getName(),
CategoryKey.CATEGORY_DEVICE);
AdvancedConnectedDeviceDashboardFragment 这个就是Connection preferences,它又对应CategoryKey.CATEGORY_DEVICE,即com.android.settings.category.ia.device,所以cast放在了Connection preferences下