diff --git a/res/values/bools.xml b/res/values/bools.xml index f1abe9dd6fa..8bd11c78d53 100644 --- a/res/values/bools.xml +++ b/res/values/bools.xml @@ -174,6 +174,9 @@ true - + false + + + true diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml index 95dba41710b..a76bef7f185 100644 --- a/res/xml/accessibility_settings.xml +++ b/res/xml/accessibility_settings.xml @@ -47,7 +47,7 @@ android:title="@string/display_category_title"> diff --git a/res/xml/accessibility_settings_for_setup_wizard.xml b/res/xml/accessibility_settings_for_setup_wizard.xml index c1141abc4a9..738bb8e3cc2 100644 --- a/res/xml/accessibility_settings_for_setup_wizard.xml +++ b/res/xml/accessibility_settings_for_setup_wizard.xml @@ -33,7 +33,7 @@ diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index 54769cfac59..db4e7d87838 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -83,7 +83,7 @@ { + 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); } @@ -164,29 +162,29 @@ public class PreviewPagerAdapter extends PagerAdapter { if (visibility == View.VISIBLE) { // Fade in animation. view.animate() - .alpha(alpha) - .setInterpolator(FADE_IN_INTERPOLATOR) - .setDuration(CROSS_FADE_DURATION_MS) - .setListener(new PreviewFrameAnimatorListener()) - .withStartAction(new Runnable() { - @Override - public void run() { - view.setVisibility(visibility); - } - }); + .alpha(alpha) + .setInterpolator(FADE_IN_INTERPOLATOR) + .setDuration(CROSS_FADE_DURATION_MS) + .setListener(new PreviewFrameAnimatorListener()) + .withStartAction(new Runnable() { + @Override + public void run() { + view.setVisibility(visibility); + } + }); } else { // Fade out animation. view.animate() - .alpha(alpha) - .setInterpolator(FADE_OUT_INTERPOLATOR) - .setDuration(CROSS_FADE_DURATION_MS) - .setListener(new PreviewFrameAnimatorListener()) - .withEndAction(new Runnable() { - @Override - public void run() { - view.setVisibility(visibility); - } - }); + .alpha(alpha) + .setInterpolator(FADE_OUT_INTERPOLATOR) + .setDuration(CROSS_FADE_DURATION_MS) + .setListener(new PreviewFrameAnimatorListener()) + .withEndAction(new Runnable() { + @Override + public void run() { + view.setVisibility(visibility); + } + }); } } } diff --git a/src/com/android/settings/PreviewSeekBarPreferenceFragment.java b/src/com/android/settings/display/PreviewSeekBarPreferenceFragment.java similarity index 80% rename from src/com/android/settings/PreviewSeekBarPreferenceFragment.java rename to src/com/android/settings/display/PreviewSeekBarPreferenceFragment.java index 164648fdde1..bb9e3d71024 100644 --- a/src/com/android/settings/PreviewSeekBarPreferenceFragment.java +++ b/src/com/android/settings/display/PreviewSeekBarPreferenceFragment.java @@ -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,39 +92,33 @@ 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) { - final int progress = mSeekBar.getProgress(); - if (progress > 0) { - mSeekBar.setProgress(progress - 1, true); - } + 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) { - final int progress = mSeekBar.getProgress(); - if (progress < mSeekBar.getMax()) { - mSeekBar.setProgress(progress + 1, true); - } + mLarger.setOnClickListener(v -> { + final int progress = mSeekBar.getProgress(); + if (progress < mSeekBar.getMax()) { + mSeekBar.setProgress(progress + 1, true); } }); @@ -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() { diff --git a/src/com/android/settings/display/ScreenZoomPreferenceFragmentForSetupWizard.java b/src/com/android/settings/display/ScreenZoomPreferenceFragmentForSetupWizard.java index 82cb58d3cd0..e02579f7dfb 100644 --- a/src/com/android/settings/display/ScreenZoomPreferenceFragmentForSetupWizard.java +++ b/src/com/android/settings/display/ScreenZoomPreferenceFragmentForSetupWizard.java @@ -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() { diff --git a/src/com/android/settings/display/ScreenZoomSettings.java b/src/com/android/settings/display/ScreenZoomSettings.java index dbb63530f1f..37ac0469433 100644 --- a/src/com/android/settings/display/ScreenZoomSettings.java +++ b/src/com/android/settings/display/ScreenZoomSettings.java @@ -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 getRawDataToIndex(Context context, diff --git a/src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java b/src/com/android/settings/display/ToggleFontSizePreferenceFragment.java similarity index 92% rename from src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java rename to src/com/android/settings/display/ToggleFontSizePreferenceFragment.java index c3100eeeadb..4f118d5facf 100644 --- a/src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java +++ b/src/com/android/settings/display/ToggleFontSizePreferenceFragment.java @@ -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); diff --git a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry index af663f44a46..64e0a014353 100644 --- a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry +++ b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry @@ -1,3 +1,3 @@ -com.android.settings.accessibility.FontSizePreferenceFragmentForSetupWizard +com.android.settings.display.FontSizePreferenceFragmentForSetupWizard com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard com.android.settings.search.FakeSettingsFragment diff --git a/tests/robotests/config/robolectric.properties b/tests/robotests/config/robolectric.properties index d213eec90d9..717f20d8fb6 100644 --- a/tests/robotests/config/robolectric.properties +++ b/tests/robotests/config/robolectric.properties @@ -1,3 +1,5 @@ manifest=packages/apps/Settings/AndroidManifest.xml sdk=NEWEST_SDK -shadows=com.android.settings.testutils.shadow.ShadowThreadUtils \ No newline at end of file +shadows=\ + com.android.settings.testutils.shadow.ShadowThreadUtils,\ + com.android.settings.testutils.shadow.ShadowXmlUtils \ No newline at end of file diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml index 2488882f2b5..6347d7935c2 100644 --- a/tests/robotests/res/values-mcc999/config.xml +++ b/tests/robotests/res/values-mcc999/config.xml @@ -63,6 +63,9 @@ true false + + false + fake_package/fake_service @@ -72,5 +75,4 @@ com.android.settings.slice_whitelist_package - diff --git a/tests/robotests/src/com/android/settings/display/ScreenZoomSettingsTest.java b/tests/robotests/src/com/android/settings/display/ScreenZoomSettingsTest.java new file mode 100644 index 00000000000..082207629ea --- /dev/null +++ b/tests/robotests/src/com/android/settings/display/ScreenZoomSettingsTest.java @@ -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); + } +} diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowXmlUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowXmlUtils.java new file mode 100644 index 00000000000..c2864e5f984 --- /dev/null +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowXmlUtils.java @@ -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; + } + } +}