Merge "Add display white balance setting"

This commit is contained in:
Christine Franks
2019-01-03 16:25:28 +00:00
committed by Android (Google) Code Review
4 changed files with 132 additions and 0 deletions

View File

@@ -2646,6 +2646,9 @@
<!-- Description about the feature adaptive brightness -->
<string name="auto_brightness_description">Your screen brightness will automatically adjust to your environment and activities. You can move the slider manually to help adaptive brightness learn your preferences.</string>
<!-- Display settings screen, display white balance settings title [CHAR LIMIT=30] -->
<string name="display_white_balance_title">Display white balance</string>
<!-- Night display screen, setting option name to enable night display (renamed "Night Light" with title caps). [CHAR LIMIT=30] -->
<string name="night_display_title">Night Light</string>
<!-- Night display screen, description of night display feature (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->

View File

@@ -79,6 +79,11 @@
settings:controller="com.android.settings.display.ColorModePreferenceController"
settings:keywords="@string/keywords_color_mode" />
<SwitchPreference
android:key="display_white_balance"
android:title="@string/display_white_balance_title"
settings:controller="com.android.settings.display.DisplayWhiteBalancePreferenceController" />
<Preference
android:key="font_size"
android:title="@string/title_font_size"

View File

@@ -0,0 +1,46 @@
/*
* 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 android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.os.UserHandle;
import android.provider.Settings.Secure;
import com.android.settings.core.TogglePreferenceController;
public class DisplayWhiteBalancePreferenceController extends TogglePreferenceController {
public DisplayWhiteBalancePreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return ColorDisplayManager.isDisplayWhiteBalanceAvailable(mContext) ?
AVAILABLE : DISABLED_FOR_USER;
}
@Override
public boolean isChecked() {
return Secure.getIntForUser(mContext.getContentResolver(),
Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
}
@Override
public boolean setChecked(boolean isChecked) {
Secure.putIntForUser(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED,
isChecked ? 1 : 0, UserHandle.USER_CURRENT);
return true;
}
}

View File

@@ -0,0 +1,78 @@
package com.android.settings.display;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import android.provider.Settings.Secure;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
SettingsShadowResources.class
})
public class DisplayWhiteBalancePreferenceControllerTest {
private Context mContext;
private DisplayWhiteBalancePreferenceController mController;
@After
public void tearDown() {
SettingsShadowResources.reset();
}
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new DisplayWhiteBalancePreferenceController(mContext, "display_white_balance");
}
@Test
public void isAvailable_configuredAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_displayWhiteBalanceAvailable, true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredUnavailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_displayWhiteBalanceAvailable, false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void setChecked_true() {
mController.setChecked(true);
assertThat(Settings.Secure
.getInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0) == 1)
.isTrue();
}
@Test
public void setChecked_false() {
mController.setChecked(false);
assertThat(Settings.Secure
.getInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0) == 1)
.isFalse();
}
@Test
public void isChecked_true() {
Settings.Secure.putInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 1);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_false() {
Settings.Secure.putInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0);
assertThat(mController.isChecked()).isFalse();
}
}