packages/apps/Settings/src/com/android/settings/dashboard/DashboardFragment.java
1、去掉CAST 修改
private boolean isEnableWifiDisplay = false;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mDashboardFeatureProvider =
FeatureFactory.getFactory(context).getDashboardFeatureProvider(context);
mProgressiveDisclosureMixin = mDashboardFeatureProvider
.getProgressiveDisclosureMixin(context, this, getArguments());
getLifecycle().addObserver(mProgressiveDisclosureMixin);
//add zhanghao for invisible CAST
//isEnableWifiDisplay = context.getResources().getBoolean(com.android.internal.R.bool.config_enableWifiDisplay);
//end
List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
if (controllers == null) {
controllers = new ArrayList<>();
}
mPlaceholderPreferenceController =
new DashboardTilePlaceholderPreferenceController(context);
controllers.add(mPlaceholderPreferenceController);
for (AbstractPreferenceController controller : controllers) {
addPreferenceController(controller);
}
}
2、去掉打印模块修改
/**
* Refresh preference items backed by DashboardCategory.
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
void refreshDashboardTiles(final String TAG) {
final PreferenceScreen screen = getPreferenceScreen();
final DashboardCategory category =
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
if (category == null) {
Log.d(TAG, "NO dashboard tiles for " + TAG);
return;
}
List<Tile> tiles = category.tiles;
if (tiles == null) {
Log.d(TAG, "tile list is empty, skipping category " + category.title);
return;
}
// Create a list to track which tiles are to be removed.
final List<String> remove = new ArrayList<>(mDashboardTilePrefKeys);
// There are dashboard tiles, so we need to install SummaryLoader.
if (mSummaryLoader != null) {
mSummaryLoader.release();
}
final Context context = getContext();
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
mSummaryLoader.setSummaryConsumer(this);
final TypedArray a = context.obtainStyledAttributes(new int[]{
android.R.attr.colorControlNormal});
final int tintColor = a.getColor(0, context.getColor(android.R.color.white));
a.recycle();
final boolean isOwner = (UserHandle.myUserId() == UserHandle.USER_OWNER);
// Install dashboard tiles.
for (Tile tile : tiles) {
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
if (!isOwner) {
if (key.endsWith(DevelopmentSettingsActivity.class.getSimpleName())
|| key.endsWith(NotificationAppListActivity.class.getSimpleName())) {
continue;
}
}
if (key.endsWith(SimSettingsActivity.class.getSimpleName()) && !isOwner) {
continue;
}
//add zhanghao for invisible Print
if (key.equals("dashboard_tile_pref_com.android.settings.Settings$PrintSettingsActivity")) {
continue;
}
//end
if (TextUtils.isEmpty(key)) {
Log.d(TAG, "tile does not contain a key, skipping " + tile);
continue;
}
if (!displayTile(tile)) {
continue;
}
Log.d(TAG, "isEnableWifiDisplay = " + isEnableWifiDisplay + "; isContainsWifiDisplay(key) = " + isContainsWifiDisplay(key));
if (!isEnableWifiDisplay || Utils.WCN_DISABLED) {
if (isContainsWifiDisplay(key)) {
continue;
}
}
if (tintTileIcon(tile)) {
tile.icon.setTint(tintColor);
}
if (mDashboardTilePrefKeys.contains(key)) {
// Have the key already, will rebind.
final Preference preference = mProgressiveDisclosureMixin.findPreference(
screen, key);
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
preference, tile, key, mPlaceholderPreferenceController.getOrder());
} else {
// Don't have this key, add it.
final Preference pref = new Preference(getPrefContext());
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
pref, tile, key, mPlaceholderPreferenceController.getOrder());
mProgressiveDisclosureMixin.addPreference(screen, pref);
mDashboardTilePrefKeys.add(key);
}
remove.remove(key);
}
// Finally remove tiles that are gone.
for (String key : remove) {
mDashboardTilePrefKeys.remove(key);
mProgressiveDisclosureMixin.removePreference(screen, key);
}
mSummaryLoader.setListening(true);
}

本文介绍了一个关于Android系统设置模块中DashboardFragment的优化案例,重点展示了如何移除不必要的CAST功能及打印模块,通过代码示例详细解释了具体实现过程。
813

被折叠的 条评论
为什么被折叠?



