Merge "Remove drawer code from settings"

This commit is contained in:
TreeHugger Robot
2017-02-28 23:38:42 +00:00
committed by Android (Google) Code Review
9 changed files with 22 additions and 521 deletions

View File

@@ -1,38 +0,0 @@
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />
<TextView
style="@style/TextAppearanceSmall"
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="16dp" />
</LinearLayout>

View File

@@ -1,44 +0,0 @@
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tile_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:orientation="horizontal" >
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/drawer_icon_size"
android:layout_height="@dimen/drawer_icon_size"
android:layout_marginStart="@dimen/drawer_icon_margin"
android:layout_marginEnd="@dimen/drawer_icon_margin"
android:layout_marginTop="@dimen/drawer_item_top_bottom_margin"
android:layout_marginBottom="@dimen/drawer_item_top_bottom_margin"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
android:tint="?android:attr/colorAccent"/>
<TextView
android:textAppearance="@style/TextAppearanceMedium"
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:attr/colorControlNormal" />
</LinearLayout>

View File

@@ -1,20 +0,0 @@
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Space
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spacer"
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_spacer_height" />

View File

@@ -47,13 +47,4 @@
android:layout_height="fill_parent"
android:background="?android:attr/windowBackground" />
</LinearLayout>
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="@dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="?android:attr/colorBackground" />
</android.support.v4.widget.DrawerLayout>

View File

@@ -26,9 +26,6 @@
<!-- Whether to send a custom package name with the PSD.-->
<bool name="config_sendPackageName">false</bool>
<!-- Whether to enable the left nav drawer in all Settings UI.-->
<bool name="config_enable_nav_drawer">false</bool>
<!-- Name for the set of keys associating package names -->
<string name="config_helpPackageNameKey" translatable="false"></string>

View File

@@ -51,12 +51,6 @@
<dimen name="usage_graph_dot_size">.75dp</dimen>
<dimen name="usage_graph_dot_interval">7dp</dimen>
<dimen name="drawer_icon_size">24dp</dimen>
<dimen name="normal_icon_size">24dp</dimen>
<dimen name="drawer_icon_margin">24dp</dimen>
<dimen name="drawer_width">300dp</dimen>
<dimen name="drawer_item_top_bottom_margin">4dp</dimen>
<dimen name="drawer_spacer_height">32dp</dimen>
<dimen name="battery_height">14.5dp</dimen>
<dimen name="battery_width">9.5dp</dimen>

View File

@@ -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 @@ package com.android.settingslib.drawer;
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.content.res.TypedArray;
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 @@ public class SettingsDrawerActivity extends Activity {
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 @@ public class SettingsDrawerActivity extends Activity {
}
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 @@ public class SettingsDrawerActivity extends Activity {
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 @@ public class SettingsDrawerActivity extends Activity {
((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 @@ public class SettingsDrawerActivity extends Activity {
}
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 @@ public class SettingsDrawerActivity extends Activity {
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 @@ public class SettingsDrawerActivity extends Activity {
* 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 @@ public class SettingsDrawerActivity extends Activity {
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 @@ public class SettingsDrawerActivity extends Activity {
}
}
/**
* @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();
}
}
}

View File

@@ -1,147 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settingslib.drawer;
import android.graphics.drawable.Icon;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.settingslib.R;
import java.util.ArrayList;
import java.util.List;
public class SettingsDrawerAdapter extends BaseAdapter {
private final ArrayList<Item> mItems = new ArrayList<>();
private final SettingsDrawerActivity mActivity;
public SettingsDrawerAdapter(SettingsDrawerActivity activity) {
mActivity = activity;
}
/**
* @deprecated Remove after new IA
*/
@Deprecated
void updateCategories() {
List<DashboardCategory> categories = mActivity.getDashboardCategories();
mItems.clear();
// Spacer.
mItems.add(null);
Item tile = new Item();
tile.label = mActivity.getString(R.string.home);
tile.icon = Icon.createWithResource(mActivity, R.drawable.home);
mItems.add(tile);
for (int i = 0; i < categories.size(); i++) {
Item category = new Item();
category.icon = null;
DashboardCategory dashboardCategory = categories.get(i);
category.label = dashboardCategory.title;
mItems.add(category);
for (int j = 0; j < dashboardCategory.tiles.size(); j++) {
tile = new Item();
Tile dashboardTile = dashboardCategory.tiles.get(j);
tile.label = dashboardTile.title;
tile.icon = dashboardTile.icon;
tile.tile = dashboardTile;
mItems.add(tile);
}
}
notifyDataSetChanged();
}
public void updateHomepageCategories(String settingPkg) {
final DashboardCategory category = CategoryManager.get(mActivity)
.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE, settingPkg);
mItems.clear();
// Spacer.
mItems.add(null);
Item tile = new Item();
tile.label = mActivity.getString(R.string.home);
tile.icon = Icon.createWithResource(mActivity, R.drawable.home);
mItems.add(tile);
for (int j = 0; j < category.tiles.size(); j++) {
tile = new Item();
Tile dashboardTile = category.tiles.get(j);
tile.label = dashboardTile.title;
tile.icon = dashboardTile.icon;
tile.tile = dashboardTile;
mItems.add(tile);
}
notifyDataSetChanged();
}
public Tile getTile(int position) {
return mItems.get(position) != null ? mItems.get(position).tile : null;
}
@Override
public int getCount() {
return mItems.size();
}
@Override
public Object getItem(int position) {
return mItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public boolean isEnabled(int position) {
return mItems.get(position) != null && mItems.get(position).icon != null;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Item item = mItems.get(position);
if (item == null) {
if (convertView == null || convertView.getId() != R.id.spacer) {
convertView = LayoutInflater.from(mActivity).inflate(R.layout.drawer_spacer,
parent, false);
}
return convertView;
}
if (convertView != null && convertView.getId() == R.id.spacer) {
convertView = null;
}
boolean isTile = item.icon != null;
if (convertView == null || (isTile != (convertView.getId() == R.id.tile_item))) {
convertView = LayoutInflater.from(mActivity).inflate(isTile ? R.layout.drawer_item
: R.layout.drawer_category,
parent, false);
}
if (isTile) {
((ImageView) convertView.findViewById(android.R.id.icon)).setImageIcon(item.icon);
}
((TextView) convertView.findViewById(android.R.id.title)).setText(item.label);
return convertView;
}
private static class Item {
public Icon icon;
public CharSequence label;
public Tile tile;
}
}

View File

@@ -86,16 +86,6 @@ public class SettingsDrawerActivityTest {
.check(matches(isDisplayed()));
}
@Test
public void startActivity_shouldNotHaveNavDrawer() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
Activity activity = instrumentation.startActivitySync(
new Intent(instrumentation.getTargetContext(), TestActivity.class));
assertThat(((SettingsDrawerActivity) activity).isNavDrawerEnabled())
.isFalse();
}
/**
* Test Activity in this test.
*