Remove drawer from settings

Change-Id: Ib11376206cf8366c86c427104c47740c3ca8b0d0
Fix: 35809663
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-02-27 16:10:05 -08:00
parent bf96583086
commit 78ab9f98de
9 changed files with 3 additions and 398 deletions

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<com.android.settings.widget.RtlCompatibleViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<com.android.settings.widget.SlidingTabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dashboard_header_margin_start"
android:layout_marginEnd="@dimen/dashboard_header_margin_end"/>

View File

@@ -21,10 +21,6 @@
<dimen name="dashboard_padding_start">160dp</dimen>
<dimen name="dashboard_padding_end">160dp</dimen>
<!-- Dashboard Header margin in its container -->
<dimen name="dashboard_header_margin_start">304dp</dimen>
<dimen name="dashboard_header_margin_end">304dp</dimen>
<!-- ActionBar contentInsetStart -->
<dimen name="actionbar_contentInsetStart">128dp</dimen>
<dimen name="actionbar_subsettings_contentInsetStart">128dp</dimen>

View File

@@ -42,10 +42,6 @@
<dimen name="dashboard_padding_start">80dp</dimen>
<dimen name="dashboard_padding_end">80dp</dimen>
<!-- Dashboard Header margin in its container -->
<dimen name="dashboard_header_margin_start">176dp</dimen>
<dimen name="dashboard_header_margin_end">176dp</dimen>
<!-- Dashboard category padding start / end -->
<dimen name="dashboard_category_padding_start">24dp</dimen>
<dimen name="dashboard_category_padding_end">24dp</dimen>

View File

@@ -88,10 +88,6 @@
<dimen name="dashboard_padding_top">0dp</dimen>
<dimen name="dashboard_padding_bottom">0dp</dimen>
<!-- Dashboard Header margin in its container -->
<dimen name="dashboard_header_margin_start">0dp</dimen>
<dimen name="dashboard_header_margin_end">0dp</dimen>
<!-- Dashboard category padding start / end -->
<dimen name="dashboard_category_padding_start">0dp</dimen>
<dimen name="dashboard_category_padding_end">0dp</dimen>

View File

@@ -58,7 +58,6 @@ import com.android.settings.backup.BackupSettingsActivity;
import com.android.settings.core.gateway.SettingsGateway;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.core.instrumentation.SharedPreferencesLogger;
import com.android.settings.dashboard.DashboardContainerFragment;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.DashboardSummary;
import com.android.settings.dashboard.SearchResultsSummary;
@@ -154,6 +153,7 @@ public class SettingsActivity extends SettingsDrawerActivity
public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
":settings:show_fragment_as_subsetting";
@Deprecated
public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
public static final String META_DATA_KEY_FRAGMENT_CLASS =
@@ -367,9 +367,6 @@ public class SettingsActivity extends SettingsDrawerActivity
if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
}
if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
setIsDrawerPresent(false);
}
mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
Context.MODE_PRIVATE);
@@ -461,17 +458,8 @@ public class SettingsActivity extends SettingsDrawerActivity
mDisplaySearch = true;
mInitialTitleResId = R.string.dashboard_title;
// add argument to indicate which settings tab should be initially selected
final Bundle args = new Bundle();
final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
args.putString(extraName, intent.getStringExtra(extraName));
if (isDashboardFeatureEnabled()) {
switchToFragment(DashboardSummary.class.getName(), args, false, false,
switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
mInitialTitleResId, mInitialTitle, false);
} else {
switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
mInitialTitleResId, mInitialTitle, false);
}
}
}
@@ -957,12 +945,7 @@ public class SettingsActivity extends SettingsDrawerActivity
if (UserHandle.MU_ENABLED && !isAdmin) {
// When on restricted users, disable all extra categories (but only the settings ones).
List<DashboardCategory> categories;
if (isDashboardFeatureEnabled()) {
categories = mDashboardFeatureProvider.getAllCategories();
} else {
categories = getDashboardCategories();
}
final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
for (DashboardCategory category : categories) {
for (Tile tile : category.tiles) {
@@ -1017,15 +1000,6 @@ public class SettingsActivity extends SettingsDrawerActivity
}
}
@Override
protected boolean isDashboardFeatureEnabled() {
if (mDashboardFeatureProvider == null) {
mDashboardFeatureProvider =
FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
}
return mDashboardFeatureProvider.isEnabled();
}
// give subclasses access to the Next button
public boolean hasNextButton() {
return mNextButton != null;
@@ -1084,16 +1058,6 @@ public class SettingsActivity extends SettingsDrawerActivity
return true;
}
@Override
protected void onTileClicked(Tile tile) {
if (mIsShowingDashboard) {
// If on dashboard, don't finish so the back comes back to here.
openTile(tile);
} else {
super.onTileClicked(tile);
}
}
@Override
public void onProfileTileOpen() {
if (!mIsShowingDashboard) {

View File

@@ -46,7 +46,6 @@ public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivit
// Finish configuring the content view.
getActionBar().setDisplayHomeAsUpEnabled(true);
setIsDrawerPresent(false);
}
@Override

View File

@@ -1,194 +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.
*/
package com.android.settings.dashboard;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.widget.RtlCompatibleViewPager;
import com.android.settings.widget.SlidingTabLayout;
import com.android.settingslib.drawer.SettingsDrawerActivity;
/**
* Container for Dashboard fragments.
*/
public final class DashboardContainerFragment extends InstrumentedFragment {
public static final String EXTRA_SELECT_SETTINGS_TAB = ":settings:select_settings_tab";
private static final String ARG_SUPPORT_TAB = "SUPPORT";
private static final String ARG_SUMMARY_TAB = "SUMMARY";
private static final int INDEX_SUMMARY_FRAGMENT = 0;
private static final int INDEX_SUPPORT_FRAGMENT = 1;
private RtlCompatibleViewPager mViewPager;
private View mHeaderView;
private DashboardViewPagerAdapter mPagerAdapter;
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DASHBOARD_CONTAINER;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
final View content = inflater.inflate(R.layout.dashboard_container, parent, false);
mViewPager = (RtlCompatibleViewPager) content.findViewById(R.id.pager);
mPagerAdapter = new DashboardViewPagerAdapter(getContext(),
getChildFragmentManager(), mViewPager);
mViewPager.setAdapter(mPagerAdapter);
mViewPager.addOnPageChangeListener(
new TabChangeListener((SettingsActivity) getActivity(), mMetricsFeatureProvider));
// check if support tab needs to be selected
final String selectedTab = getArguments().
getString(EXTRA_SELECT_SETTINGS_TAB, ARG_SUMMARY_TAB);
if (TextUtils.equals(selectedTab, ARG_SUPPORT_TAB)) {
mViewPager.setCurrentItem(INDEX_SUPPORT_FRAGMENT);
} else {
mViewPager.setCurrentItem(INDEX_SUMMARY_FRAGMENT);
}
mHeaderView = inflater.inflate(R.layout.dashboard_container_header, parent, false);
((SlidingTabLayout) mHeaderView).setViewPager(mViewPager);
return content;
}
@Override
public void onResume() {
super.onResume();
if (mPagerAdapter.getCount() > 1) {
final Activity activity = getActivity();
if (activity instanceof SettingsDrawerActivity) {
((SettingsDrawerActivity) getActivity()).setContentHeaderView(mHeaderView);
}
}
}
private static final class DashboardViewPagerAdapter extends FragmentPagerAdapter {
private final Context mContext;
private final SupportFeatureProvider mSupportFeatureProvider;
private final RtlCompatibleViewPager mViewPager;
public DashboardViewPagerAdapter(Context context, FragmentManager fragmentManager,
RtlCompatibleViewPager viewPager) {
super(fragmentManager);
mContext = context;
mSupportFeatureProvider =
FeatureFactory.getFactory(context).getSupportFeatureProvider(context);
mViewPager = viewPager;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case INDEX_SUMMARY_FRAGMENT:
return mContext.getString(R.string.page_tab_title_summary);
case INDEX_SUPPORT_FRAGMENT:
return mContext.getString(R.string.page_tab_title_support);
}
return super.getPageTitle(position);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case INDEX_SUMMARY_FRAGMENT:
return new DashboardSummary();
case INDEX_SUPPORT_FRAGMENT:
return new SupportFragment();
default:
throw new IllegalArgumentException(
String.format(
"Position %d does not map to a valid dashboard fragment",
position));
}
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
return super.instantiateItem(container,
mViewPager.getRtlAwareIndex(position));
}
@Override
public int getCount() {
return mSupportFeatureProvider == null ? 1 : 2;
}
}
private static final class TabChangeListener
implements RtlCompatibleViewPager.OnPageChangeListener {
private final SettingsActivity mActivity;
private final MetricsFeatureProvider mMetricsFeatureProvider;
public TabChangeListener(SettingsActivity activity,
MetricsFeatureProvider metricsFeatureProvider) {
mActivity = activity;
mMetricsFeatureProvider = metricsFeatureProvider;
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// Do nothing.
}
@Override
public void onPageScrollStateChanged(int state) {
// Do nothing
}
@Override
public void onPageSelected(int position) {
switch (position) {
case INDEX_SUMMARY_FRAGMENT:
mMetricsFeatureProvider.action(
mActivity, MetricsProto.MetricsEvent.ACTION_SELECT_SUMMARY);
mActivity.setDisplaySearchMenu(true);
break;
case INDEX_SUPPORT_FRAGMENT:
mMetricsFeatureProvider.action(
mActivity, MetricsProto.MetricsEvent.ACTION_SELECT_SUPPORT_FRAGMENT);
mActivity.setDisplaySearchMenu(false);
break;
}
}
}
}

View File

@@ -1,108 +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.
*/
package com.android.settings.dashboard;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.android.settings.Settings;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isSelected;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.IsNot.not;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class TabSelectionOnLaunchTest {
@Rule
public ActivityTestRule<Settings> mActivityRule =
new ActivityTestRule<>(Settings.class, true, false);
private final int FLAG_RESTART = Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK;
private final String ARG_SELECT_SUPPORT_TAB = "SUPPORT";
private final String ARG_SELECT_FAKE_TAB = "NOT_SUPPORT";
@Test
/* cold start for settings app with correct flags and extra always selects support tab */
public void test_ColdStartWithCorrectArgsCorrectFlags_SupportSelected() {
launchSettingsWithFlags(ARG_SELECT_SUPPORT_TAB, FLAG_RESTART);
verifySupportSelected();
}
@Test
/* cold start with correct flags and wrong extra defaults to all tab */
public void test_ColdStartWithWrongExtra_DoesNotSelectSupport() {
launchSettingsWithFlags(ARG_SELECT_FAKE_TAB, FLAG_RESTART);
verifySupportNotSelected();
}
@Test
/* warm start from elsewhere in settings with wrong flags does not select support */
public void test_WarmStartSummarySelectedCorrectExtraWrongFlags_DoesNotSelectSupport() {
InstrumentationRegistry.getContext().
startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
launchSettingsNoFlags(ARG_SELECT_SUPPORT_TAB);
verifySupportNotSelected();
}
@Test
/* warm start from elsewhere in settings with with wrong flags & extra does not select support*/
public void test_WarmStartSummarySelectedWrongExtraWrongFlags_DoesNotSelectSupport() {
InstrumentationRegistry.getContext().
startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
launchSettingsNoFlags(ARG_SELECT_FAKE_TAB);
verifySupportNotSelected();
}
@Test
/* settings does not crash on null string */
public void test_DoesNotCrashOnNullExtra_DoesNotSelectSupport() {
launchSettingsWithFlags(null, FLAG_RESTART);
verifySupportNotSelected();
}
private void verifySupportNotSelected() {
onView(withText(mActivityRule.getActivity().getApplicationContext().
getString(com.android.settings.R.string.page_tab_title_support))).
check(matches(not(isSelected())));
}
private void verifySupportSelected() {
onView(withText(mActivityRule.getActivity().getApplicationContext().
getString(com.android.settings.R.string.page_tab_title_support))).
check(matches(isSelected()));
}
private void launchSettingsWithFlags(String extra, int flags) {
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(flags);
intent.putExtra(DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB, extra);
mActivityRule.launchActivity(intent);
}
private void launchSettingsNoFlags(String extra) {
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.putExtra(DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB, extra);
mActivityRule.launchActivity(intent);
}
}