Loading packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java +20 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.util.ArrayMap; import android.util.Log; import android.util.Pair; import com.android.settingslib.applications.InterestingConfigChanges; import java.util.List; import java.util.Map; import java.util.Set; Loading @@ -30,6 +32,7 @@ public class CategoryManager { private static final String TAG = "CategoryManager"; private static CategoryManager sInstance; private final InterestingConfigChanges mInterestingConfigChanges; // Tile cache (key: <packageName, activityName>, value: tile) private final Map<Pair<String, String>, Tile> mTileByComponentCache; Loading @@ -39,16 +42,18 @@ public class CategoryManager { private List<DashboardCategory> mCategories; public static CategoryManager get() { public static CategoryManager get(Context context) { if (sInstance == null) { sInstance = new CategoryManager(); sInstance = new CategoryManager(context); } return sInstance; } CategoryManager() { CategoryManager(Context context) { mTileByComponentCache = new ArrayMap<>(); mCategoryByKeyMap = new ArrayMap<>(); mInterestingConfigChanges = new InterestingConfigChanges(); mInterestingConfigChanges.applyNewConfig(context.getResources()); } public synchronized DashboardCategory getTilesByCategory(Context context, String categoryKey) { Loading @@ -67,8 +72,10 @@ public class CategoryManager { } public synchronized void reloadAllCategories(Context context) { final boolean forceClearCache = mInterestingConfigChanges.applyNewConfig( context.getResources()); mCategories = null; tryInitCategories(context); tryInitCategories(context, forceClearCache); } public synchronized void updateCategoryFromBlacklist(Set<ComponentName> tileBlacklist) { Loading @@ -87,8 +94,16 @@ public class CategoryManager { } private synchronized void tryInitCategories(Context context) { // Keep cached tiles by default. The cache is only invalidated when InterestingConfigChange // happens. tryInitCategories(context, false /* forceClearCache */); } private synchronized void tryInitCategories(Context context, boolean forceClearCache) { if (mCategories == null) { if (forceClearCache) { mTileByComponentCache.clear(); } mCategoryByKeyMap.clear(); mCategories = TileUtils.getCategories(context, mTileByComponentCache, false /* categoryDefinedInManifest */); Loading packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java +2 −2 Original line number Diff line number Diff line Loading @@ -185,7 +185,7 @@ public class SettingsDrawerActivity extends Activity { return false; } if (isDashboardFeatureEnabled()) { final DashboardCategory homepageCategories = CategoryManager.get() final DashboardCategory homepageCategories = CategoryManager.get(this) .getTilesByCategory(this, CategoryKey.CATEGORY_HOMEPAGE); return homepageCategories.containsComponent(componentName); } else { Loading Loading @@ -429,7 +429,7 @@ public class SettingsDrawerActivity extends Activity { private final CategoryManager mCategoryManager; public CategoriesUpdateTask() { mCategoryManager = CategoryManager.get(); mCategoryManager = CategoryManager.get(SettingsDrawerActivity.this); } @Override Loading packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerAdapter.java +2 −2 Original line number Diff line number Diff line Loading @@ -69,8 +69,8 @@ public class SettingsDrawerAdapter extends BaseAdapter { } public void updateHomepageCategories() { DashboardCategory category = CategoryManager.get().getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE); final DashboardCategory category = CategoryManager.get(mActivity) .getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE); mItems.clear(); // Spacer. mItems.add(null); Loading Loading
packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java +20 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.util.ArrayMap; import android.util.Log; import android.util.Pair; import com.android.settingslib.applications.InterestingConfigChanges; import java.util.List; import java.util.Map; import java.util.Set; Loading @@ -30,6 +32,7 @@ public class CategoryManager { private static final String TAG = "CategoryManager"; private static CategoryManager sInstance; private final InterestingConfigChanges mInterestingConfigChanges; // Tile cache (key: <packageName, activityName>, value: tile) private final Map<Pair<String, String>, Tile> mTileByComponentCache; Loading @@ -39,16 +42,18 @@ public class CategoryManager { private List<DashboardCategory> mCategories; public static CategoryManager get() { public static CategoryManager get(Context context) { if (sInstance == null) { sInstance = new CategoryManager(); sInstance = new CategoryManager(context); } return sInstance; } CategoryManager() { CategoryManager(Context context) { mTileByComponentCache = new ArrayMap<>(); mCategoryByKeyMap = new ArrayMap<>(); mInterestingConfigChanges = new InterestingConfigChanges(); mInterestingConfigChanges.applyNewConfig(context.getResources()); } public synchronized DashboardCategory getTilesByCategory(Context context, String categoryKey) { Loading @@ -67,8 +72,10 @@ public class CategoryManager { } public synchronized void reloadAllCategories(Context context) { final boolean forceClearCache = mInterestingConfigChanges.applyNewConfig( context.getResources()); mCategories = null; tryInitCategories(context); tryInitCategories(context, forceClearCache); } public synchronized void updateCategoryFromBlacklist(Set<ComponentName> tileBlacklist) { Loading @@ -87,8 +94,16 @@ public class CategoryManager { } private synchronized void tryInitCategories(Context context) { // Keep cached tiles by default. The cache is only invalidated when InterestingConfigChange // happens. tryInitCategories(context, false /* forceClearCache */); } private synchronized void tryInitCategories(Context context, boolean forceClearCache) { if (mCategories == null) { if (forceClearCache) { mTileByComponentCache.clear(); } mCategoryByKeyMap.clear(); mCategories = TileUtils.getCategories(context, mTileByComponentCache, false /* categoryDefinedInManifest */); Loading
packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java +2 −2 Original line number Diff line number Diff line Loading @@ -185,7 +185,7 @@ public class SettingsDrawerActivity extends Activity { return false; } if (isDashboardFeatureEnabled()) { final DashboardCategory homepageCategories = CategoryManager.get() final DashboardCategory homepageCategories = CategoryManager.get(this) .getTilesByCategory(this, CategoryKey.CATEGORY_HOMEPAGE); return homepageCategories.containsComponent(componentName); } else { Loading Loading @@ -429,7 +429,7 @@ public class SettingsDrawerActivity extends Activity { private final CategoryManager mCategoryManager; public CategoriesUpdateTask() { mCategoryManager = CategoryManager.get(); mCategoryManager = CategoryManager.get(SettingsDrawerActivity.this); } @Override Loading
packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerAdapter.java +2 −2 Original line number Diff line number Diff line Loading @@ -69,8 +69,8 @@ public class SettingsDrawerAdapter extends BaseAdapter { } public void updateHomepageCategories() { DashboardCategory category = CategoryManager.get().getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE); final DashboardCategory category = CategoryManager.get(mActivity) .getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE); mItems.clear(); // Spacer. mItems.add(null); Loading