Merge "Add a preview image to the color mode preference."

This commit is contained in:
Sean Callanan
2018-03-01 22:39:23 +00:00
committed by Android (Google) Code Review
5 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/color_mode_preview_height"
android:paddingBottom="@dimen/color_mode_preview_padding_bottom"
android:scaleType="centerCrop"
android:cropToPadding="true"
android:src="@drawable/caption_background"
android:contentDescription="@null" />
</FrameLayout>

View File

@@ -60,6 +60,9 @@
<dimen name="captioning_preview_height">200dp</dimen> <dimen name="captioning_preview_height">200dp</dimen>
<dimen name="color_mode_preview_height">320dp</dimen>
<dimen name="color_mode_preview_padding_bottom">40dp</dimen>
<dimen name="ring_progress_bar_thickness">4dp</dimen> <dimen name="ring_progress_bar_thickness">4dp</dimen>
<dimen name="settings_side_margin">0dip</dimen> <dimen name="settings_side_margin">0dip</dimen>

View File

@@ -16,10 +16,12 @@ package com.android.settings.display;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.VisibleForTesting; import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.app.ColorDisplayController; import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.widget.RadioButtonPickerFragment; import com.android.settings.widget.RadioButtonPickerFragment;
import com.android.settingslib.widget.CandidateInfo; import com.android.settingslib.widget.CandidateInfo;
@@ -50,6 +52,19 @@ public class ColorModePreferenceFragment extends RadioButtonPickerFragment {
return R.xml.color_mode_settings; return R.xml.color_mode_settings;
} }
@VisibleForTesting
void configureAndInstallPreview(LayoutPreference preview, PreferenceScreen screen) {
preview.setSelectable(false);
screen.addPreference(preview);
}
@Override
protected void addStaticPreferences(PreferenceScreen screen) {
final LayoutPreference preview = new LayoutPreference(screen.getContext(),
R.layout.color_mode_preview);
configureAndInstallPreview(preview, screen);
}
@Override @Override
protected List<? extends CandidateInfo> getCandidates() { protected List<? extends CandidateInfo> getCandidates() {
Context c = getContext(); Context c = getContext();

View File

@@ -101,6 +101,13 @@ public abstract class RadioButtonPickerFragment extends InstrumentedPreferenceFr
return false; return false;
} }
/**
* Populate any static preferences, independent of the radio buttons.
* These might be used to provide extra information about the choices.
**/
protected void addStaticPreferences(PreferenceScreen screen) {
}
protected CandidateInfo getCandidate(String key) { protected CandidateInfo getCandidate(String key) {
return mCandidates.get(key); return mCandidates.get(key);
} }
@@ -134,6 +141,7 @@ public abstract class RadioButtonPickerFragment extends InstrumentedPreferenceFr
final String systemDefaultKey = getSystemDefaultKey(); final String systemDefaultKey = getSystemDefaultKey();
final PreferenceScreen screen = getPreferenceScreen(); final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll(); screen.removeAll();
addStaticPreferences(screen);
final int customLayoutResId = getRadioButtonPreferenceCustomLayoutResId(); final int customLayoutResId = getRadioButtonPreferenceCustomLayoutResId();
if (shouldShowItemNone()) { if (shouldShowItemNone()) {

View File

@@ -20,13 +20,17 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.app.ColorDisplayController; import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.TestConfig; import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -37,6 +41,7 @@ import com.android.settingslib.widget.CandidateInfo;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -145,4 +150,17 @@ public class ColorModePreferenceFragmentTest {
verify(mFragment).addPreferencesFromResource(R.xml.color_mode_settings); verify(mFragment).addPreferencesFromResource(R.xml.color_mode_settings);
} }
@Test
public void addStaticPreferences_shouldAddPreviewImage() {
PreferenceScreen mockPreferenceScreen = Mockito.mock(PreferenceScreen.class);
LayoutPreference mockPreview = Mockito.mock(LayoutPreference.class);
ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
mFragment.configureAndInstallPreview(mockPreview, mockPreferenceScreen);
Mockito.verify(mockPreview, times(1)).setSelectable(false);
Mockito.verify(mockPreferenceScreen, times(1)).addPreference(preferenceCaptor.capture());
assertThat(preferenceCaptor.getValue()).isEqualTo(mockPreview);
}
} }