Android 7.1原生设置项删除

从源码中看到Settings继承SettingsActivity,而SettingsActivity继承SettingsDrawerActivity,在SettingsDrawerActivity的onCreate方法中,我们看到调用了getDashboardCategories方法,代码:

getDashboardCategories();//获取设置项列表
        setActionBar(toolbar);
        mDrawerAdapter = new SettingsDrawerAdapter(this);
        ListView listView = (ListView) findViewById(R.id.left_drawer);
        listView.setAdapter(mDrawerAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(Android.widget.AdapterView<?> parent, View view, int position,
                    long id) {
                onTileClicked(mDrawerAdapter.getTile(position));
            }
        });

跟进到该方法的具体实现:

public List<DashboardCategory> getDashboardCategories() {
        if (sDashboardCategories == null) {
            sTileCache = new HashMap<>();
            sConfigTracker = new InterestingConfigChanges();
            // Apply initial current config.
            boolean newC =sConfigTracker.applyNewConfig(getResources());
            Log.d(TAG, "newC = " + newC);
            sDashboardCategories = TileUtils.getCategories(this, sTileCache);//重点在这里
        }
        return sDashboardCategories;
    }


跟进到getCategories方法:


    private static final String EXTRA_SETTINGS_ACTION =
            "com.android.settings.action.EXTRA_SETTINGS";

/**
    * Same as #EXTRA_SETTINGS_ACTION but used for the platform Settings activities.
    */
    private static final String SETTINGS_ACTION =
            "com.android.settings.action.SETTINGS";

private static final String OPERATOR_SETTINGS =
            "com.android.settings.OPERATOR_APPLICATION_SETTING";

private static final String OPERATOR_DEFAULT_CATEGORY =
            "com.android.settings.category.wireless";

private static final String MANUFACTURER_SETTINGS =
            "com.android.settings.MANUFACTURER_APPLICATION_SETTING";

private static final String MANUFACTURER_DEFAULT_CATEGORY =
            "com.android.settings.category.device";

//以上是TileUtils.java定义的常量

public static List<DashboardCategory> getCategories(Context context,
            HashMap<Pair<String, String>, Tile> cache) {
        //......省略
        for (UserHandle user : userManager.getUserProfiles()) {
            // TODO: Needs much optimization, too many PM queries going on here.
            if (user.getIdentifier() == ActivityManager.getCurrentUser()) {
                // Only add Settings for this user.
                getTilesForAction(context, user, SETTINGS_ACTION, cache, null, tiles, true);
                getTilesForAction(context, user, OPERATOR_SETTINGS, cache,
                        OPERATOR_DEFAULT_CATEGORY, tiles, false);
                getTilesForAction(context, user, MANUFACTURER_SETTINGS, cache,
                        MANUFACTURER_DEFAULT_CATEGORY, tiles, false);
            }
            if (setup) {
                getTilesForAction(context, user, EXTRA_SETTINGS_ACTION, cache, null, tiles, false);
            }
        }
        //......省略
        return categories;
    }

到这里我们就可以看得到,这是根据AndroidManifest.xml对activity及fragement的定义来划分设置项分类的。我们再看一下AndroidManifest.xml对各个activity及fragment的定义,拿个简单的来看看:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/46d064960db028e1f565a10855fc594f.html