Add config to disable app tray preview in display size.

Also move some files

Change-Id: I4636fcd81425991acadede0b703e09513c82543c
Fixes: 113374067
Test: robotests
This commit is contained in:
Fan Zhang
2018-09-07 17:06:07 -07:00
parent 6312aa28e3
commit 9aca4cb48c
17 changed files with 194 additions and 99 deletions

View File

@@ -174,6 +174,9 @@
<!-- Whether wifi_mac_address should be shown or not. -->
<bool name="config_show_wifi_mac_address">true</bool>
<!-- Whether to disable "Uninstall Updates" menu item for System apps or not.. -->
<!-- Whether to disable "Uninstall Updates" menu item for System apps or not. -->
<bool name="config_disable_uninstall_update">false</bool>
<!-- Whether or not extra preview panels should be used for screen zoom setting. -->
<bool name="config_enable_extra_screen_zoom_preview">true</bool>
</resources>

View File

@@ -47,7 +47,7 @@
android:title="@string/display_category_title">
<Preference
android:fragment="com.android.settings.accessibility.ToggleFontSizePreferenceFragment"
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
android:key="font_size_preference_screen"
android:title="@string/title_font_size"
settings:searchable="false"/>

View File

@@ -33,7 +33,7 @@
<Preference
android:fragment=
"com.android.settings.accessibility.FontSizePreferenceFragmentForSetupWizard"
"com.android.settings.display.FontSizePreferenceFragmentForSetupWizard"
android:key="font_size_preference"
android:title="@string/title_font_size"
android:summary="@string/short_summary_font_size" />

View File

@@ -83,7 +83,7 @@
<Preference
android:key="font_size"
android:title="@string/title_font_size"
android:fragment="com.android.settings.accessibility.ToggleFontSizePreferenceFragment"
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
settings:controller="com.android.settings.display.FontSizePreferenceController" />
<com.android.settings.display.ScreenZoomPreference

View File

@@ -55,6 +55,7 @@ import com.android.internal.view.RotationPolicy.RotationPolicyListener;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settings.display.ToggleFontSizePreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;

View File

@@ -18,7 +18,6 @@ import android.content.res.Resources;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.accessibility.ToggleFontSizePreferenceFragment;
import com.android.settings.core.BasePreferenceController;
public class FontSizePreferenceController extends BasePreferenceController {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 The Android Open Source Project
* Copyright (C) 2018 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.accessibility;
package com.android.settings.display;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 The Android Open Source Project
* Copyright (C) 2018 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
package com.android.settings.display;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
@@ -32,6 +32,8 @@ import android.widget.LinearLayout;
import androidx.viewpager.widget.PagerAdapter;
import com.android.settings.support.actionbar.HelpResourceProvider;
/**
* A PagerAdapter used by PreviewSeekBarPreferenceFragment that for showing multiple preview screen
* regarding a single setting and allowing the user to swipe across them.
@@ -76,16 +78,12 @@ public class PreviewPagerAdapter extends PagerAdapter {
final Context configContext = context.createConfigurationContext(configurations[j]);
configContext.getTheme().setTo(context.getTheme());
final LayoutInflater configInflater = LayoutInflater.from(configContext);
final ViewStub sampleViewStub = new ViewStub(configContext);
sampleViewStub.setLayoutResource(previewSampleResIds[i]);
final int fi = i, fj = j;
sampleViewStub.setOnInflateListener(new OnInflateListener() {
@Override
public void onInflate(ViewStub stub, View inflated) {
sampleViewStub.setOnInflateListener((stub, inflated) -> {
inflated.setVisibility(stub.getVisibility());
mViewStubInflated[fi][fj] = true;
}
});
mPreviewFrames[p].addView(sampleViewStub);
@@ -94,7 +92,7 @@ public class PreviewPagerAdapter extends PagerAdapter {
}
@Override
public void destroyItem (ViewGroup container, int position, Object object) {
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2018 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.
@@ -14,14 +14,13 @@
* limitations under the License.
*/
package com.android.settings;
package com.android.settings.display;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.widget.SeekBar;
@@ -31,6 +30,8 @@ import android.widget.TextView;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.widget.DotsPageIndicator;
import com.android.settings.widget.LabeledSeekBar;
@@ -48,12 +49,6 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
/** Index of the entry corresponding to current value of the settings. */
protected int mCurrentIndex;
/** Resource id of the layout for this preference fragment. */
protected int mActivityLayoutResId;
/** Resource id of the layout that defines the contents inside preview screen. */
protected int[] mPreviewSampleResIds;
private ViewPager mPreviewPager;
private PreviewPagerAdapter mPreviewPagerAdapter;
private DotsPageIndicator mPageIndicator;
@@ -82,12 +77,7 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (mPreviewPagerAdapter.isAnimating()) {
mPreviewPagerAdapter.setAnimationEndAction(new Runnable() {
@Override
public void run() {
commit();
}
});
mPreviewPagerAdapter.setAnimationEndAction(() -> commit());
} else {
commit();
}
@@ -102,40 +92,34 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
final ViewGroup listContainer = root.findViewById(android.R.id.list_container);
listContainer.removeAllViews();
final View content = inflater.inflate(mActivityLayoutResId, listContainer, false);
final View content = inflater.inflate(getActivityLayoutResId(), listContainer, false);
listContainer.addView(content);
mLabel = (TextView) content.findViewById(R.id.current_label);
mLabel = content.findViewById(R.id.current_label);
// The maximum SeekBar value always needs to be non-zero. If there's
// only one available value, we'll handle this by disabling the
// seek bar.
final int max = Math.max(1, mEntries.length - 1);
mSeekBar = (LabeledSeekBar) content.findViewById(R.id.seek_bar);
mSeekBar = content.findViewById(R.id.seek_bar);
mSeekBar.setLabels(mEntries);
mSeekBar.setMax(max);
mSmaller = content.findViewById(R.id.smaller);
mSmaller.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSmaller.setOnClickListener(v -> {
final int progress = mSeekBar.getProgress();
if (progress > 0) {
mSeekBar.setProgress(progress - 1, true);
}
}
});
mLarger = content.findViewById(R.id.larger);
mLarger.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mLarger.setOnClickListener(v -> {
final int progress = mSeekBar.getProgress();
if (progress < mSeekBar.getMax()) {
mSeekBar.setProgress(progress + 1, true);
}
}
});
if (mEntries.length == 1) {
@@ -152,15 +136,16 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
configurations[i] = createConfig(origConfig, i);
}
mPreviewPager = (ViewPager) content.findViewById(R.id.preview_pager);
final int[] previews = getPreviewSampleResIds();
mPreviewPager = content.findViewById(R.id.preview_pager);
mPreviewPagerAdapter = new PreviewPagerAdapter(context, isLayoutRtl,
mPreviewSampleResIds, configurations);
previews, configurations);
mPreviewPager.setAdapter(mPreviewPagerAdapter);
mPreviewPager.setCurrentItem(isLayoutRtl ? mPreviewSampleResIds.length - 1 : 0);
mPreviewPager.setCurrentItem(isLayoutRtl ? previews.length - 1 : 0);
mPreviewPager.addOnPageChangeListener(mPreviewPageChangeListener);
mPageIndicator = (DotsPageIndicator) content.findViewById(R.id.page_indicator);
if (mPreviewSampleResIds.length > 1) {
mPageIndicator = content.findViewById(R.id.page_indicator);
if (previews.length > 1) {
mPageIndicator.setViewPager(mPreviewPager);
mPageIndicator.setVisibility(View.VISIBLE);
mPageIndicator.setOnPageChangeListener(mPageIndicatorPageChangeListener);
@@ -187,6 +172,12 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
mSeekBar.setOnSeekBarChangeListener(null);
}
/** Resource id of the layout for this preference fragment. */
protected abstract int getActivityLayoutResId();
/** Resource id of the layout that defines the contents inside preview screen. */
protected abstract int[] getPreviewSampleResIds();
/**
* Creates new configuration based on the current position of the SeekBar.
*/
@@ -210,8 +201,8 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
private void setPagerIndicatorContentDescription(int position) {
mPageIndicator.setContentDescription(
getPrefContext().getString(R.string.preview_page_indicator_content_description,
position + 1, mPreviewSampleResIds.length));
getString(R.string.preview_page_indicator_content_description,
position + 1, getPreviewSampleResIds().length));
}
private OnPageChangeListener mPreviewPageChangeListener = new OnPageChangeListener() {

View File

@@ -18,8 +18,7 @@ package com.android.settings.display;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
public class ScreenZoomPreferenceFragmentForSetupWizard
extends ScreenZoomSettings {
public class ScreenZoomPreferenceFragmentForSetupWizard extends ScreenZoomSettings {
@Override
public int getMetricsCategory() {

View File

@@ -24,9 +24,9 @@ import android.os.Bundle;
import android.view.Display;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.PreviewSeekBarPreferenceFragment;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settingslib.display.DisplayDensityUtils;
import com.android.settingslib.search.SearchIndexable;
@@ -43,17 +43,26 @@ public class ScreenZoomSettings extends PreviewSeekBarPreferenceFragment {
private int mDefaultDensity;
private int[] mValues;
@Override
protected int getActivityLayoutResId() {
return R.layout.screen_zoom_activity;
}
@Override
protected int[] getPreviewSampleResIds() {
return getContext().getResources().getBoolean(
R.bool.config_enable_extra_screen_zoom_preview)
? new int[]{
R.layout.screen_zoom_preview_1,
R.layout.screen_zoom_preview_2,
R.layout.screen_zoom_preview_settings}
: new int[]{R.layout.screen_zoom_preview_1};
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivityLayoutResId = R.layout.screen_zoom_activity;
// This should be replaced once the final preview sample screen is in place.
mPreviewSampleResIds = new int[] {R.layout.screen_zoom_preview_1,
R.layout.screen_zoom_preview_2,
R.layout.screen_zoom_preview_settings};
final DisplayDensityUtils density = new DisplayDensityUtils(getContext());
final int initialIndex = density.getCurrentIndex();
@@ -62,8 +71,8 @@ public class ScreenZoomSettings extends PreviewSeekBarPreferenceFragment {
// connect to the window manager service. Just use the current
// density and don't let the user change anything.
final int densityDpi = getResources().getDisplayMetrics().densityDpi;
mValues = new int[] {densityDpi};
mEntries = new String[] {getString(DisplayDensityUtils.SUMMARY_DEFAULT)};
mValues = new int[]{densityDpi};
mEntries = new String[]{getString(DisplayDensityUtils.SUMMARY_DEFAULT)};
mInitialIndex = 0;
mDefaultDensity = densityDpi;
} else {
@@ -108,7 +117,7 @@ public class ScreenZoomSettings extends PreviewSeekBarPreferenceFragment {
}
/** Index provider used to expose this fragment in search. */
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context,

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2018 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.accessibility;
package com.android.settings.display;
import android.annotation.Nullable;
import android.content.ContentResolver;
@@ -25,7 +25,6 @@ import android.os.Bundle;
import android.provider.Settings;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.PreviewSeekBarPreferenceFragment;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -43,14 +42,21 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
private float[] mValues;
@Override
protected int getActivityLayoutResId() {
return R.layout.font_size_activity;
}
@Override
protected int[] getPreviewSampleResIds() {
return new int[]{R.layout.font_size_preview};
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivityLayoutResId = R.layout.font_size_activity;
mPreviewSampleResIds = new int[] {R.layout.font_size_preview};
Resources res = getContext().getResources();
final Resources res = getContext().getResources();
final ContentResolver resolver = getContext().getContentResolver();
// Mark the appropriate item in the preferences list.
mEntries = res.getStringArray(R.array.entries_font_size);

View File

@@ -1,3 +1,3 @@
com.android.settings.accessibility.FontSizePreferenceFragmentForSetupWizard
com.android.settings.display.FontSizePreferenceFragmentForSetupWizard
com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard
com.android.settings.search.FakeSettingsFragment

View File

@@ -1,3 +1,5 @@
manifest=packages/apps/Settings/AndroidManifest.xml
sdk=NEWEST_SDK
shadows=com.android.settings.testutils.shadow.ShadowThreadUtils
shadows=\
com.android.settings.testutils.shadow.ShadowThreadUtils,\
com.android.settings.testutils.shadow.ShadowXmlUtils

View File

@@ -63,6 +63,9 @@
<bool name="config_disable_uninstall_update">true</bool>
<bool name="config_show_device_name">false</bool>
<!-- Whether or not extra preview panels should be used for screen zoom setting. -->
<bool name="config_enable_extra_screen_zoom_preview">false</bool>
<!-- List of a11y components on the device allowed to be enabled by Settings Slices -->
<string-array name="config_settings_slices_accessibility_components" translatable="false">
<item>fake_package/fake_service</item>
@@ -72,5 +75,4 @@
<string-array name="slice_whitelist_package_names" translatable="false">
<item>com.android.settings.slice_whitelist_package</item>
</string-array>
</resources>

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2018 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.display;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.Context;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
public class ScreenZoomSettingsTest {
private ScreenZoomSettings mSettings;
private Context mContext;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSettings = spy(new ScreenZoomSettings());
doReturn(mContext).when(mSettings).getContext();
}
@Test
public void getPreviewSampleResIds_default_return3Previews() {
assertThat(mSettings.getPreviewSampleResIds()).hasLength(3);
}
@Test
@Config(qualifiers = "mcc999")
public void getPreviewSampleResIds_extraPreviewDisabled_return1Preview() {
assertThat(mSettings.getPreviewSampleResIds()).hasLength(1);
}
}

View File

@@ -0,0 +1,28 @@
package com.android.settings.testutils.shadow;
import static org.robolectric.shadow.api.Shadow.directlyOn;
import com.android.internal.util.XmlUtils;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;
@Implements(XmlUtils.class)
public class ShadowXmlUtils {
@Implementation
public static final int convertValueToInt(CharSequence charSeq, int defaultValue) {
final Class<?> xmlUtilsClass = ReflectionHelpers.loadClass(
Robolectric.class.getClassLoader(), "com.android.internal.util.XmlUtils");
try {
return directlyOn(xmlUtilsClass, "convertValueToInt",
ClassParameter.from(CharSequence.class, charSeq),
ClassParameter.from(int.class, new Integer(defaultValue)));
} catch (NumberFormatException e) {
return defaultValue;
}
}
}