blob: 89ed110d3246ae1412b513f4209bc1d18ac9a24e [file] [log] [blame]
Jason Monk744b6362015-11-03 18:24:29 -05001/**
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.settingslib.drawer;
17
18import android.annotation.LayoutRes;
19import android.annotation.Nullable;
20import android.app.Activity;
Jason Monk6bea9502016-02-25 13:07:41 -050021import android.content.ActivityNotFoundException;
Jason Monke79790b2015-12-02 15:39:19 -050022import android.content.BroadcastReceiver;
Jason Monkfcad09a2016-06-07 14:01:32 -040023import android.content.ComponentName;
Jason Monke79790b2015-12-02 15:39:19 -050024import android.content.Context;
25import android.content.Intent;
26import android.content.IntentFilter;
Jason Monkfcad09a2016-06-07 14:01:32 -040027import android.content.pm.PackageManager;
Jason Monkf18a55d2015-11-12 10:52:21 -050028import android.content.res.TypedArray;
Jason Monke79790b2015-12-02 15:39:19 -050029import android.os.AsyncTask;
Jason Monk744b6362015-11-03 18:24:29 -050030import android.os.Bundle;
Jason Monkcafda1f2016-02-05 10:16:22 -050031import android.provider.Settings;
Jason Monk744b6362015-11-03 18:24:29 -050032import android.support.v4.widget.DrawerLayout;
Jason Monkfcad09a2016-06-07 14:01:32 -040033import android.util.ArraySet;
Jason Monke79790b2015-12-02 15:39:19 -050034import android.util.Log;
Jason Monk744b6362015-11-03 18:24:29 -050035import android.util.Pair;
36import android.view.Gravity;
37import android.view.LayoutInflater;
38import android.view.MenuItem;
39import android.view.View;
40import android.view.ViewGroup;
41import android.view.Window;
Jason Monkcafda1f2016-02-05 10:16:22 -050042import android.view.WindowManager.LayoutParams;
Jason Monk744b6362015-11-03 18:24:29 -050043import android.widget.AdapterView;
Fan Zhang7163d772016-03-29 10:30:13 -070044import android.widget.FrameLayout;
Jason Monk744b6362015-11-03 18:24:29 -050045import android.widget.ListView;
46import android.widget.Toolbar;
Fan Zhang7163d772016-03-29 10:30:13 -070047
Jason Monk744b6362015-11-03 18:24:29 -050048import com.android.settingslib.R;
Jason Monkec02e472016-03-28 10:44:43 -040049import com.android.settingslib.applications.InterestingConfigChanges;
Jason Monk744b6362015-11-03 18:24:29 -050050
Jason Monke79790b2015-12-02 15:39:19 -050051import java.util.ArrayList;
Jason Monk744b6362015-11-03 18:24:29 -050052import java.util.HashMap;
53import java.util.List;
54
55public class SettingsDrawerActivity extends Activity {
56
Jason Monke79790b2015-12-02 15:39:19 -050057 protected static final boolean DEBUG_TIMING = false;
58 private static final String TAG = "SettingsDrawerActivity";
Fan Zhang089a2c02016-09-15 14:28:19 -070059 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Jason Monke79790b2015-12-02 15:39:19 -050060
Clara Bayarri962694d2016-04-29 16:56:02 +010061 public static final String EXTRA_SHOW_MENU = "show_drawer_menu";
Jason Monk946483a2016-01-22 15:19:44 -050062
Jason Monkfcad09a2016-06-07 14:01:32 -040063 // Serves as a temporary list of tiles to ignore until we heard back from the PM that they
64 // are disabled.
65 private static ArraySet<ComponentName> sTileBlacklist = new ArraySet<>();
Jason Monke79790b2015-12-02 15:39:19 -050066
67 private final PackageReceiver mPackageReceiver = new PackageReceiver();
68 private final List<CategoryListener> mCategoryListeners = new ArrayList<>();
69
Jason Monk744b6362015-11-03 18:24:29 -050070 private SettingsDrawerAdapter mDrawerAdapter;
Fan Zhang7163d772016-03-29 10:30:13 -070071 private FrameLayout mContentHeaderContainer;
Jason Monk744b6362015-11-03 18:24:29 -050072 private DrawerLayout mDrawerLayout;
Jason Monk946483a2016-01-22 15:19:44 -050073 private boolean mShowingMenu;
Jason Monk744b6362015-11-03 18:24:29 -050074
Fan Zhang22a56d72016-09-27 17:52:00 -070075 // Remove below after new IA
76 @Deprecated
77 private static List<DashboardCategory> sDashboardCategories;
78 @Deprecated
79 private static HashMap<Pair<String, String>, Tile> sTileCache;
80 @Deprecated
81 private static InterestingConfigChanges sConfigTracker;
82 // Remove above after new IA
83
Jason Monk744b6362015-11-03 18:24:29 -050084 @Override
85 protected void onCreate(@Nullable Bundle savedInstanceState) {
86 super.onCreate(savedInstanceState);
87
Jason Monke79790b2015-12-02 15:39:19 -050088 long startTime = System.currentTimeMillis();
89
Udam Saini48987f62016-03-03 13:20:18 -080090 TypedArray theme = getTheme().obtainStyledAttributes(android.R.styleable.Theme);
91 if (!theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) {
92 getWindow().addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
93 getWindow().addFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
94 requestWindowFeature(Window.FEATURE_NO_TITLE);
95 }
Jason Monk744b6362015-11-03 18:24:29 -050096 super.setContentView(R.layout.settings_with_drawer);
Fan Zhang7163d772016-03-29 10:30:13 -070097 mContentHeaderContainer = (FrameLayout) findViewById(R.id.content_header_container);
Jason Monk744b6362015-11-03 18:24:29 -050098 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
Jason Monk51a94232015-11-04 14:57:15 -050099 if (mDrawerLayout == null) {
100 return;
101 }
Jason Monk744b6362015-11-03 18:24:29 -0500102 Toolbar toolbar = (Toolbar) findViewById(R.id.action_bar);
Jason Monkf18a55d2015-11-12 10:52:21 -0500103 if (theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) {
104 toolbar.setVisibility(View.GONE);
105 mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
106 mDrawerLayout = null;
107 return;
108 }
Fan Zhangcf439c02017-01-03 13:06:11 -0800109 if (!isNavDrawerEnabled()) {
110 setIsDrawerPresent(false);
111 }
Fan Zhang22a56d72016-09-27 17:52:00 -0700112 if (!isDashboardFeatureEnabled()) {
113 getDashboardCategories();
114 }
Jason Monk744b6362015-11-03 18:24:29 -0500115 setActionBar(toolbar);
116 mDrawerAdapter = new SettingsDrawerAdapter(this);
117 ListView listView = (ListView) findViewById(R.id.left_drawer);
118 listView.setAdapter(mDrawerAdapter);
119 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
120 public void onItemClick(android.widget.AdapterView<?> parent, View view, int position,
121 long id) {
122 onTileClicked(mDrawerAdapter.getTile(position));
Fan Zhangf311b742016-09-16 08:46:09 -0700123 }
Jason Monk744b6362015-11-03 18:24:29 -0500124 });
jackqdyuleidfc6ce52016-08-24 09:48:54 -0700125
Jason Monke79790b2015-12-02 15:39:19 -0500126 if (DEBUG_TIMING) Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
127 + " ms");
Jason Monk744b6362015-11-03 18:24:29 -0500128 }
129
130 @Override
131 public boolean onOptionsItemSelected(MenuItem item) {
Jason Monk946483a2016-01-22 15:19:44 -0500132 if (mShowingMenu && mDrawerLayout != null && item.getItemId() == android.R.id.home
Jason Monk51a94232015-11-04 14:57:15 -0500133 && mDrawerAdapter.getCount() != 0) {
Jason Monk744b6362015-11-03 18:24:29 -0500134 openDrawer();
135 return true;
136 }
137 return super.onOptionsItemSelected(item);
138 }
139
140 @Override
Fan Zhangcf439c02017-01-03 13:06:11 -0800141 public boolean onNavigateUp() {
142 if (!isNavDrawerEnabled()) {
143 finish();
144 return true;
145 }
146 return super.onNavigateUp();
147 }
148
149 @Override
Jason Monk744b6362015-11-03 18:24:29 -0500150 protected void onResume() {
151 super.onResume();
152
Jason Monk2a5d79a2015-12-03 10:51:58 -0500153 if (mDrawerLayout != null) {
154 final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
155 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
156 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
157 filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
158 filter.addDataScheme("package");
159 registerReceiver(mPackageReceiver, filter);
Jason Monke79790b2015-12-02 15:39:19 -0500160
Fan Zhang22a56d72016-09-27 17:52:00 -0700161 if (isDashboardFeatureEnabled()) {
162 new CategoriesUpdateTask().execute();
163 } else {
164 new CategoriesUpdater().execute();
165 }
Jason Monk2a5d79a2015-12-03 10:51:58 -0500166 }
Fan Zhangf311b742016-09-16 08:46:09 -0700167 final Intent intent = getIntent();
168 if (intent != null) {
169 if (intent.hasExtra(EXTRA_SHOW_MENU)) {
170 if (intent.getBooleanExtra(EXTRA_SHOW_MENU, false)) {
171 // Intent explicitly set to show menu.
172 showMenuIcon();
173 }
174 } else if (isTopLevelTile(intent)) {
175 showMenuIcon();
176 }
Jason Monk946483a2016-01-22 15:19:44 -0500177 }
Jason Monke79790b2015-12-02 15:39:19 -0500178 }
179
180 @Override
181 protected void onPause() {
Jason Monk2a5d79a2015-12-03 10:51:58 -0500182 if (mDrawerLayout != null) {
183 unregisterReceiver(mPackageReceiver);
184 }
Jason Monke79790b2015-12-02 15:39:19 -0500185
186 super.onPause();
187 }
188
Fan Zhangf311b742016-09-16 08:46:09 -0700189 private boolean isTopLevelTile(Intent intent) {
190 final ComponentName componentName = intent.getComponent();
191 if (componentName == null) {
192 return false;
193 }
Fan Zhang22a56d72016-09-27 17:52:00 -0700194 if (isDashboardFeatureEnabled()) {
Fan Zhang5adc2662016-10-04 15:12:58 -0700195 final DashboardCategory homepageCategories = CategoryManager.get(this)
roger xue8f06ab02016-12-08 14:09:50 -0800196 .getTilesByCategory(this, CategoryKey.CATEGORY_HOMEPAGE, getSettingPkg());
197 return homepageCategories ==
198 null ? false : homepageCategories.containsComponent(componentName);
Fan Zhang22a56d72016-09-27 17:52:00 -0700199 } else {
200 // Look for a tile that has the same component as incoming intent
201 final List<DashboardCategory> categories = getDashboardCategories();
202 for (DashboardCategory category : categories) {
203 if (category.containsComponent(componentName)) {
Fan Zhangf311b742016-09-16 08:46:09 -0700204 return true;
205 }
206 }
Fan Zhang22a56d72016-09-27 17:52:00 -0700207 if (DEBUG) {
208 Log.d(TAG, "Intent is not for top level settings " + intent);
209 }
210 return false;
Fan Zhangf311b742016-09-16 08:46:09 -0700211 }
Fan Zhangf311b742016-09-16 08:46:09 -0700212 }
213
roger xue8f06ab02016-12-08 14:09:50 -0800214 /**
215 * Gets the name of the intent action of the default setting app. Used to launch setting app
216 * when Settings Home is clicked.
217 */
218 public String getSettingAction() {
219 return Settings.ACTION_SETTINGS;
220 }
221
Jason Monke79790b2015-12-02 15:39:19 -0500222 public void addCategoryListener(CategoryListener listener) {
223 mCategoryListeners.add(listener);
224 }
225
226 public void remCategoryListener(CategoryListener listener) {
227 mCategoryListeners.remove(listener);
Jason Monk744b6362015-11-03 18:24:29 -0500228 }
229
Anna Galusza1774a272016-02-01 15:44:00 -0800230 public void setIsDrawerPresent(boolean isPresent) {
Anna Galuszafb695c62016-02-02 10:06:05 -0800231 if (isPresent) {
Anna Galusza1774a272016-02-01 15:44:00 -0800232 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
233 updateDrawer();
234 } else {
Udam Saini68dab672016-03-29 10:49:18 -0700235 if (mDrawerLayout != null) {
236 mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
237 mDrawerLayout = null;
238 }
Anna Galusza1774a272016-02-01 15:44:00 -0800239 }
240 }
241
Jason Monk744b6362015-11-03 18:24:29 -0500242 public void openDrawer() {
Jason Monk51a94232015-11-04 14:57:15 -0500243 if (mDrawerLayout != null) {
244 mDrawerLayout.openDrawer(Gravity.START);
245 }
Jason Monk744b6362015-11-03 18:24:29 -0500246 }
247
248 public void closeDrawer() {
Jason Monk51a94232015-11-04 14:57:15 -0500249 if (mDrawerLayout != null) {
250 mDrawerLayout.closeDrawers();
251 }
Jason Monk744b6362015-11-03 18:24:29 -0500252 }
253
Fan Zhang7163d772016-03-29 10:30:13 -0700254 public void setContentHeaderView(View headerView) {
255 mContentHeaderContainer.removeAllViews();
256 if (headerView != null) {
257 mContentHeaderContainer.addView(headerView);
258 }
259 }
260
Jason Monk744b6362015-11-03 18:24:29 -0500261 @Override
262 public void setContentView(@LayoutRes int layoutResID) {
Jason Monk4ea66572016-03-30 11:05:51 -0400263 final ViewGroup parent = (ViewGroup) findViewById(R.id.content_frame);
264 if (parent != null) {
265 parent.removeAllViews();
266 }
267 LayoutInflater.from(this).inflate(layoutResID, parent);
Jason Monk744b6362015-11-03 18:24:29 -0500268 }
269
270 @Override
271 public void setContentView(View view) {
272 ((ViewGroup) findViewById(R.id.content_frame)).addView(view);
273 }
274
275 @Override
276 public void setContentView(View view, ViewGroup.LayoutParams params) {
277 ((ViewGroup) findViewById(R.id.content_frame)).addView(view, params);
278 }
279
280 public void updateDrawer() {
Jason Monk51a94232015-11-04 14:57:15 -0500281 if (mDrawerLayout == null) {
282 return;
283 }
Jason Monk744b6362015-11-03 18:24:29 -0500284 // TODO: Do this in the background with some loading.
Fan Zhang22a56d72016-09-27 17:52:00 -0700285 if (isDashboardFeatureEnabled()) {
roger xue8f06ab02016-12-08 14:09:50 -0800286 mDrawerAdapter.updateHomepageCategories(getSettingPkg());
Fan Zhang22a56d72016-09-27 17:52:00 -0700287 } else {
288 mDrawerAdapter.updateCategories();
289 }
Jason Monk51a94232015-11-04 14:57:15 -0500290 if (mDrawerAdapter.getCount() != 0) {
291 mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
Jason Monk51a94232015-11-04 14:57:15 -0500292 } else {
293 mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
294 }
Jason Monk744b6362015-11-03 18:24:29 -0500295 }
296
Jason Monk946483a2016-01-22 15:19:44 -0500297 public void showMenuIcon() {
Jason Monk946483a2016-01-22 15:19:44 -0500298 getActionBar().setDisplayHomeAsUpEnabled(true);
Fan Zhangcf439c02017-01-03 13:06:11 -0800299 if (isNavDrawerEnabled()) {
300 mShowingMenu = true;
301 getActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);
302 getActionBar().setHomeActionContentDescription(
303 R.string.content_description_menu_button);
304 }
Jason Monk946483a2016-01-22 15:19:44 -0500305 }
306
Jason Monke79790b2015-12-02 15:39:19 -0500307 public List<DashboardCategory> getDashboardCategories() {
Jason Monk2a5d79a2015-12-03 10:51:58 -0500308 if (sDashboardCategories == null) {
309 sTileCache = new HashMap<>();
Jason Monkec02e472016-03-28 10:44:43 -0400310 sConfigTracker = new InterestingConfigChanges();
Jason Monkb0ae8f82016-04-12 10:30:43 -0400311 // Apply initial current config.
312 sConfigTracker.applyNewConfig(getResources());
Jason Monk2a5d79a2015-12-03 10:51:58 -0500313 sDashboardCategories = TileUtils.getCategories(this, sTileCache);
314 }
Jason Monke79790b2015-12-02 15:39:19 -0500315 return sDashboardCategories;
316 }
317
318 protected void onCategoriesChanged() {
319 updateDrawer();
320 final int N = mCategoryListeners.size();
321 for (int i = 0; i < N; i++) {
322 mCategoryListeners.get(i).onCategoriesChanged();
Jason Monk744b6362015-11-03 18:24:29 -0500323 }
Jason Monk744b6362015-11-03 18:24:29 -0500324 }
325
Jason Monkf509d7e2016-01-07 16:22:53 -0500326 public boolean openTile(Tile tile) {
Jason Monk744b6362015-11-03 18:24:29 -0500327 closeDrawer();
Jason Monk3175a6e2015-11-30 15:05:35 -0500328 if (tile == null) {
roger xue8f06ab02016-12-08 14:09:50 -0800329 Intent intent = new Intent(getSettingAction()).addFlags(
330 Intent.FLAG_ACTIVITY_CLEAR_TASK);
331 startActivity(intent);
Jason Monkcafda1f2016-02-05 10:16:22 -0500332 return true;
Jason Monk3175a6e2015-11-30 15:05:35 -0500333 }
Jason Monk6bea9502016-02-25 13:07:41 -0500334 try {
Fan Zhang11b65072016-10-31 16:45:00 -0700335 ProfileSelectDialog.updateUserHandlesIfNeeded(this /* context */, tile);
Jason Monk6bea9502016-02-25 13:07:41 -0500336 int numUserHandles = tile.userHandle.size();
337 if (numUserHandles > 1) {
338 ProfileSelectDialog.show(getFragmentManager(), tile);
339 return false;
340 } else if (numUserHandles == 1) {
341 // Show menu on top level items.
342 tile.intent.putExtra(EXTRA_SHOW_MENU, true);
343 tile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
344 startActivityAsUser(tile.intent, tile.userHandle.get(0));
345 } else {
346 // Show menu on top level items.
347 tile.intent.putExtra(EXTRA_SHOW_MENU, true);
348 tile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
349 startActivity(tile.intent);
350 }
351 } catch (ActivityNotFoundException e) {
352 Log.w(TAG, "Couldn't find tile " + tile.intent, e);
Jason Monk0d72d202015-11-04 13:16:00 -0500353 }
354 return true;
Jason Monk744b6362015-11-03 18:24:29 -0500355 }
356
Jason Monkf509d7e2016-01-07 16:22:53 -0500357 protected void onTileClicked(Tile tile) {
Jason Monk0d72d202015-11-04 13:16:00 -0500358 if (openTile(tile)) {
359 finish();
360 }
361 }
362
363 public void onProfileTileOpen() {
Jason Monk744b6362015-11-03 18:24:29 -0500364 finish();
365 }
Jason Monke79790b2015-12-02 15:39:19 -0500366
Jason Monkfcad09a2016-06-07 14:01:32 -0400367 public void setTileEnabled(ComponentName component, boolean enabled) {
368 PackageManager pm = getPackageManager();
369 int state = pm.getComponentEnabledSetting(component);
370 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
371 if (isEnabled != enabled || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
372 if (enabled) {
373 sTileBlacklist.remove(component);
374 } else {
375 sTileBlacklist.add(component);
376 }
377 pm.setComponentEnabledSetting(component, enabled
378 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
379 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
380 PackageManager.DONT_KILL_APP);
Fan Zhang22a56d72016-09-27 17:52:00 -0700381 if (isDashboardFeatureEnabled()) {
382 new CategoriesUpdateTask().execute();
383 } else {
384 new CategoriesUpdater().execute();
385 }
Jason Monkfcad09a2016-06-07 14:01:32 -0400386 }
387 }
388
roger xue8f06ab02016-12-08 14:09:50 -0800389 public String getSettingPkg() {
390 return TileUtils.SETTING_PKG;
391 }
392
Jason Monke79790b2015-12-02 15:39:19 -0500393 public interface CategoryListener {
394 void onCategoriesChanged();
395 }
396
Fan Zhang22a56d72016-09-27 17:52:00 -0700397 /**
398 * @deprecated remove after new IA
399 */
400 @Deprecated
Jason Monke79790b2015-12-02 15:39:19 -0500401 private class CategoriesUpdater extends AsyncTask<Void, Void, List<DashboardCategory>> {
402 @Override
403 protected List<DashboardCategory> doInBackground(Void... params) {
Jason Monkec02e472016-03-28 10:44:43 -0400404 if (sConfigTracker.applyNewConfig(getResources())) {
405 sTileCache.clear();
406 }
Jason Monke79790b2015-12-02 15:39:19 -0500407 return TileUtils.getCategories(SettingsDrawerActivity.this, sTileCache);
408 }
409
410 @Override
Richard Ho8c4e4b02016-06-13 16:54:04 -0700411 protected void onPreExecute() {
412 if (sConfigTracker == null || sTileCache == null) {
413 getDashboardCategories();
414 }
415 }
416
417 @Override
Jason Monke79790b2015-12-02 15:39:19 -0500418 protected void onPostExecute(List<DashboardCategory> dashboardCategories) {
Jason Monkfcad09a2016-06-07 14:01:32 -0400419 for (int i = 0; i < dashboardCategories.size(); i++) {
420 DashboardCategory category = dashboardCategories.get(i);
421 for (int j = 0; j < category.tiles.size(); j++) {
422 Tile tile = category.tiles.get(j);
423 if (sTileBlacklist.contains(tile.intent.getComponent())) {
424 category.tiles.remove(j--);
425 }
426 }
427 }
Jason Monke79790b2015-12-02 15:39:19 -0500428 sDashboardCategories = dashboardCategories;
429 onCategoriesChanged();
430 }
431 }
432
Fan Zhang22a56d72016-09-27 17:52:00 -0700433 private class CategoriesUpdateTask extends AsyncTask<Void, Void, Void> {
434
435 private final CategoryManager mCategoryManager;
436
437 public CategoriesUpdateTask() {
Fan Zhang5adc2662016-10-04 15:12:58 -0700438 mCategoryManager = CategoryManager.get(SettingsDrawerActivity.this);
Fan Zhang22a56d72016-09-27 17:52:00 -0700439 }
440
441 @Override
442 protected Void doInBackground(Void... params) {
roger xue8f06ab02016-12-08 14:09:50 -0800443 mCategoryManager.reloadAllCategories(SettingsDrawerActivity.this, getSettingPkg());
Fan Zhang22a56d72016-09-27 17:52:00 -0700444 return null;
445 }
446
447 @Override
448 protected void onPostExecute(Void result) {
449 mCategoryManager.updateCategoryFromBlacklist(sTileBlacklist);
450 onCategoriesChanged();
451 }
452 }
453
roger xue8f06ab02016-12-08 14:09:50 -0800454 /**
455 * @return {@code true} if IA (Information Architecture) is enabled.
456 */
Fan Zhang22a56d72016-09-27 17:52:00 -0700457 protected boolean isDashboardFeatureEnabled() {
458 return false;
459 }
460
Fan Zhangcf439c02017-01-03 13:06:11 -0800461 boolean isNavDrawerEnabled() {
462 return !isDashboardFeatureEnabled()
463 || getResources().getBoolean(R.bool.config_enable_nav_drawer);
464 }
465
Jason Monke79790b2015-12-02 15:39:19 -0500466 private class PackageReceiver extends BroadcastReceiver {
467 @Override
468 public void onReceive(Context context, Intent intent) {
Fan Zhang22a56d72016-09-27 17:52:00 -0700469 if (isDashboardFeatureEnabled()) {
470 new CategoriesUpdateTask().execute();
471 } else {
472 new CategoriesUpdater().execute();
473 }
Jason Monke79790b2015-12-02 15:39:19 -0500474 }
475 }
Jason Monk744b6362015-11-03 18:24:29 -0500476}