Remove drawer code from settings
Change-Id: I3e9920f62745f6ba2236e37689f7603f9a30d6a9
Fix: 35809663
Test: make RunSettingsLibRoboTests
diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java b/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java
index a8cab17..457ce76 100644
--- a/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java
+++ b/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java
@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,7 +18,6 @@
import android.annotation.LayoutRes;
import android.annotation.Nullable;
import android.app.Activity;
-import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -29,20 +28,15 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
-import android.support.v4.widget.DrawerLayout;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
-import android.view.Gravity;
import android.view.LayoutInflater;
-import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
-import android.widget.AdapterView;
import android.widget.FrameLayout;
-import android.widget.ListView;
import android.widget.Toolbar;
import com.android.settingslib.R;
@@ -67,10 +61,7 @@
private final PackageReceiver mPackageReceiver = new PackageReceiver();
private final List<CategoryListener> mCategoryListeners = new ArrayList<>();
- private SettingsDrawerAdapter mDrawerAdapter;
private FrameLayout mContentHeaderContainer;
- private DrawerLayout mDrawerLayout;
- private boolean mShowingMenu;
// Remove below after new IA
@Deprecated
@@ -94,122 +85,50 @@
}
super.setContentView(R.layout.settings_with_drawer);
mContentHeaderContainer = (FrameLayout) findViewById(R.id.content_header_container);
- mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- if (mDrawerLayout == null) {
- return;
- }
+
Toolbar toolbar = (Toolbar) findViewById(R.id.action_bar);
if (theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) {
toolbar.setVisibility(View.GONE);
- mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
- mDrawerLayout = null;
return;
}
- if (!isNavDrawerEnabled()) {
- setIsDrawerPresent(false);
- }
- if (!isDashboardFeatureEnabled()) {
- 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));
- }
- });
- if (DEBUG_TIMING) Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
- + " ms");
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (mShowingMenu && mDrawerLayout != null && item.getItemId() == android.R.id.home
- && mDrawerAdapter.getCount() != 0) {
- openDrawer();
- return true;
+ if (DEBUG_TIMING) {
+ Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
+ + " ms");
}
- return super.onOptionsItemSelected(item);
}
@Override
public boolean onNavigateUp() {
- if (!isNavDrawerEnabled()) {
- finish();
- return true;
- }
- return super.onNavigateUp();
+ finish();
+ return true;
}
@Override
protected void onResume() {
super.onResume();
+ final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+ filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+ filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+ filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+ filter.addDataScheme("package");
+ registerReceiver(mPackageReceiver, filter);
- if (mDrawerLayout != null) {
- final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
- filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
- filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
- filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
- filter.addDataScheme("package");
- registerReceiver(mPackageReceiver, filter);
-
- if (isDashboardFeatureEnabled()) {
- new CategoriesUpdateTask().execute();
- } else {
- new CategoriesUpdater().execute();
- }
- }
+ new CategoriesUpdateTask().execute();
final Intent intent = getIntent();
- if (intent != null) {
- if (intent.hasExtra(EXTRA_SHOW_MENU)) {
- if (intent.getBooleanExtra(EXTRA_SHOW_MENU, false)) {
- // Intent explicitly set to show menu.
- showMenuIcon();
- }
- } else if (isNavDrawerEnabled() && isTopLevelTile(intent)) {
- showMenuIcon();
- }
+ if (intent != null && intent.getBooleanExtra(EXTRA_SHOW_MENU, false)) {
+ // Intent explicitly set to show menu.
+ showMenuIcon();
}
}
@Override
protected void onPause() {
- if (mDrawerLayout != null) {
- unregisterReceiver(mPackageReceiver);
- }
-
+ unregisterReceiver(mPackageReceiver);
super.onPause();
}
- private boolean isTopLevelTile(Intent intent) {
- final ComponentName componentName = intent.getComponent();
- if (componentName == null) {
- return false;
- }
- if (isDashboardFeatureEnabled()) {
- final DashboardCategory homepageCategories = CategoryManager.get(this)
- .getTilesByCategory(this, CategoryKey.CATEGORY_HOMEPAGE, getSettingPkg());
- return homepageCategories ==
- null ? false : homepageCategories.containsComponent(componentName);
- } else {
- // Look for a tile that has the same component as incoming intent
- final List<DashboardCategory> categories = getDashboardCategories();
- for (DashboardCategory category : categories) {
- if (category.containsComponent(componentName)) {
- return true;
- }
- }
- if (DEBUG) {
- Log.d(TAG, "Intent is not for top level settings " + intent);
- }
- return false;
- }
- }
-
/**
* Gets the name of the intent action of the default setting app. Used to launch setting app
* when Settings Home is clicked.
@@ -226,30 +145,6 @@
mCategoryListeners.remove(listener);
}
- public void setIsDrawerPresent(boolean isPresent) {
- if (isPresent) {
- mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- updateDrawer();
- } else {
- if (mDrawerLayout != null) {
- mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
- mDrawerLayout = null;
- }
- }
- }
-
- public void openDrawer() {
- if (mDrawerLayout != null) {
- mDrawerLayout.openDrawer(Gravity.START);
- }
- }
-
- public void closeDrawer() {
- if (mDrawerLayout != null) {
- mDrawerLayout.closeDrawers();
- }
- }
-
public void setContentHeaderView(View headerView) {
mContentHeaderContainer.removeAllViews();
if (headerView != null) {
@@ -276,31 +171,8 @@
((ViewGroup) findViewById(R.id.content_frame)).addView(view, params);
}
- public void updateDrawer() {
- if (mDrawerLayout == null) {
- return;
- }
- // TODO: Do this in the background with some loading.
- if (isDashboardFeatureEnabled()) {
- mDrawerAdapter.updateHomepageCategories(getSettingPkg());
- } else {
- mDrawerAdapter.updateCategories();
- }
- if (mDrawerAdapter.getCount() != 0) {
- mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
- } else {
- mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
- }
- }
-
public void showMenuIcon() {
getActionBar().setDisplayHomeAsUpEnabled(true);
- if (isNavDrawerEnabled()) {
- mShowingMenu = true;
- getActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);
- getActionBar().setHomeActionContentDescription(
- R.string.content_description_menu_button);
- }
}
public List<DashboardCategory> getDashboardCategories() {
@@ -315,51 +187,12 @@
}
protected void onCategoriesChanged() {
- updateDrawer();
final int N = mCategoryListeners.size();
for (int i = 0; i < N; i++) {
mCategoryListeners.get(i).onCategoriesChanged();
}
}
- @Deprecated
- public boolean openTile(Tile tile) {
- closeDrawer();
- if (tile == null) {
- Intent intent = new Intent(getSettingAction()).addFlags(
- Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- return true;
- }
- try {
- ProfileSelectDialog.updateUserHandlesIfNeeded(this /* context */, tile);
- int numUserHandles = tile.userHandle.size();
- if (numUserHandles > 1) {
- ProfileSelectDialog.show(getFragmentManager(), tile);
- return false;
- } else if (numUserHandles == 1) {
- // Show menu on top level items.
- tile.intent.putExtra(EXTRA_SHOW_MENU, true);
- tile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivityAsUser(tile.intent, tile.userHandle.get(0));
- } else {
- // Show menu on top level items.
- tile.intent.putExtra(EXTRA_SHOW_MENU, true);
- tile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(tile.intent);
- }
- } catch (ActivityNotFoundException e) {
- Log.w(TAG, "Couldn't find tile " + tile.intent, e);
- }
- return true;
- }
-
- protected void onTileClicked(Tile tile) {
- if (openTile(tile)) {
- finish();
- }
- }
-
public void onProfileTileOpen() {
finish();
}
@@ -375,8 +208,8 @@
sTileBlacklist.add(component);
}
pm.setComponentEnabledSetting(component, enabled
- ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
- : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+ : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
}
@@ -385,11 +218,7 @@
* Updates dashboard categories. Only necessary to call this after setTileEnabled
*/
public void updateCategories() {
- if (isDashboardFeatureEnabled()) {
- new CategoriesUpdateTask().execute();
- } else {
- new CategoriesUpdater().execute();
- }
+ new CategoriesUpdateTask().execute();
}
public String getSettingPkg() {
@@ -400,42 +229,6 @@
void onCategoriesChanged();
}
- /**
- * @deprecated remove after new IA
- */
- @Deprecated
- private class CategoriesUpdater extends AsyncTask<Void, Void, List<DashboardCategory>> {
- @Override
- protected List<DashboardCategory> doInBackground(Void... params) {
- if (sConfigTracker.applyNewConfig(getResources())) {
- sTileCache.clear();
- }
- return TileUtils.getCategories(SettingsDrawerActivity.this, sTileCache);
- }
-
- @Override
- protected void onPreExecute() {
- if (sConfigTracker == null || sTileCache == null) {
- getDashboardCategories();
- }
- }
-
- @Override
- protected void onPostExecute(List<DashboardCategory> dashboardCategories) {
- for (int i = 0; i < dashboardCategories.size(); i++) {
- DashboardCategory category = dashboardCategories.get(i);
- for (int j = 0; j < category.tiles.size(); j++) {
- Tile tile = category.tiles.get(j);
- if (sTileBlacklist.contains(tile.intent.getComponent())) {
- category.tiles.remove(j--);
- }
- }
- }
- sDashboardCategories = dashboardCategories;
- onCategoriesChanged();
- }
- }
-
private class CategoriesUpdateTask extends AsyncTask<Void, Void, Void> {
private final CategoryManager mCategoryManager;
@@ -457,25 +250,10 @@
}
}
- /**
- * @return {@code true} if IA (Information Architecture) is enabled.
- */
- protected boolean isDashboardFeatureEnabled() {
- return false;
- }
-
- boolean isNavDrawerEnabled() {
- return getResources().getBoolean(R.bool.config_enable_nav_drawer);
- }
-
private class PackageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- if (isDashboardFeatureEnabled()) {
- new CategoriesUpdateTask().execute();
- } else {
- new CategoriesUpdater().execute();
- }
+ new CategoriesUpdateTask().execute();
}
}
}