Add night display pref controllers and change UX

- Convert NightDisplaySettings to a DashboardFragment
- Add preference controllers for all Night Display settings
- Change UX for activation from a toggle to a button

Bug: 73739388
Bug: 69912911
Test: make -j100 and make RunSettingsRoboTests -j100
Change-Id: Ia173f16207ba59bf57eb7546cbb1e2dbca67b063
Merged-In: Ia173f16207ba59bf57eb7546cbb1e2dbca67b063
This commit is contained in:
Christine Franks
2018-03-16 16:33:18 -07:00
parent 9b29aeba5a
commit 77df09244e
21 changed files with 1124 additions and 192 deletions

View File

@@ -0,0 +1,98 @@
/*
* 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.Matchers.anyString;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings.Secure;
import android.support.v7.preference.PreferenceScreen;
import android.view.View;
import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class NightDisplayActivationPreferenceControllerTest {
@Mock
private PreferenceScreen mScreen;
private LayoutPreference mPreference;
private Context mContext;
private NightDisplayActivationPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mPreference = new LayoutPreference(mContext, R.layout.night_display_activation_button);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mController = new NightDisplayActivationPreferenceController(mContext,
"night_display_activation");
mController.displayPreference(mScreen);
}
@Test
public void isAvailable_configuredAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredUnavailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void onClick_activates() {
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
view.performClick();
assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, -1))
.isEqualTo(1);
}
@Test
public void onClick_deactivates() {
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
view.performClick();
assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, -1))
.isEqualTo(0);
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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 android.content.Context;
import android.provider.Settings.Secure;
import com.android.internal.app.ColorDisplayController;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
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)
@Config(shadows = SettingsShadowResources.class)
public class NightDisplayAutoModePreferenceControllerTest {
private Context mContext;
private NightDisplayAutoModePreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new NightDisplayAutoModePreferenceController(mContext,
"night_display_auto_mode");
}
@Test
public void isAvailable_configuredAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredUnavailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void onPreferenceChange_changesAutoMode() {
mController.onPreferenceChange(null,
String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT));
assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, -1))
.isEqualTo(ColorDisplayController.AUTO_MODE_TWILIGHT);
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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 com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
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)
@Config(shadows = SettingsShadowResources.class)
public class NightDisplayCustomEndTimePreferenceControllerTest {
private NightDisplayCustomEndTimePreferenceController mController;
@Before
public void setUp() {
mController = new NightDisplayCustomEndTimePreferenceController(
RuntimeEnvironment.application, "night_display_end_time");
}
@Test
public void isAvailable_configuredAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredUnavailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, false);
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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 com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
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)
@Config(shadows = SettingsShadowResources.class)
public class NightDisplayCustomStartTimePreferenceControllerTest {
private NightDisplayCustomStartTimePreferenceController mController;
@Before
public void setUp() {
mController = new NightDisplayCustomStartTimePreferenceController(
RuntimeEnvironment.application, "night_display_start_time");
}
@Test
public void isAvailable_configuredAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredUnavailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, false);
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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 com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
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)
@Config(shadows = SettingsShadowResources.class)
public class NightDisplayFooterPreferenceControllerTest {
private NightDisplayFooterPreferenceController mController;
@Before
public void setUp() {
mController = new NightDisplayFooterPreferenceController(RuntimeEnvironment.application);
}
@Test
public void isAvailable_configuredAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredUnavailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, false);
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -0,0 +1,79 @@
/*
* 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 android.content.Context;
import android.provider.Settings.Secure;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
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)
@Config(shadows = SettingsShadowResources.class)
public class NightDisplayIntensityPreferenceControllerTest {
private Context mContext;
private NightDisplayIntensityPreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new NightDisplayIntensityPreferenceController(mContext,
"night_display_temperature");
}
@Test
public void isAvailable_configuredAvailable_isActivated_available() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredAvailable_isNotActivated_available() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredUnavailable_unavailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void onPreferenceChange_changesTemperature() {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_nightDisplayColorTemperatureMin, 2950);
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_nightDisplayColorTemperatureMax, 3050);
// A slider-adjusted "20" here would be 1/5 from the left / least-intense, i.e. 3030.
mController.onPreferenceChange(null, 20);
assertThat(Secure.getInt(mContext.getContentResolver(),
Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, -1))
.isEqualTo(3030);
}
}