Loading res/values/strings.xml +3 −3 Original line number Diff line number Diff line Loading @@ -2568,9 +2568,9 @@ <string name="brightness_summary">Adjust the brightness of the screen</string> <!-- Sound & display settings screen, setting option name to enable adaptive brightness [CHAR LIMIT=30] --> <string name="auto_brightness_title">Adaptive brightness</string> <!-- Sound & display settings screen, setting option summary to enable adaptive brightness [CHAR LIMIT=100] --> <string name="auto_brightness_summary">Optimize brightness level for available light</string> <!-- Sound & display settings screen, setting option summary when adaptive brightness is off [CHAR LIMIT=100] --> <!-- Setting option summary when adaptive brightness is on [CHAR LIMIT=NONE] --> <string name="auto_brightness_summary_on">On</string> <!-- Setting option summary when adaptive brightness is off [CHAR LIMIT=NONE] --> <string name="auto_brightness_summary_off">Off</string> <!-- Sound & display settings screen, setting option summary when preferred adaptive brightness is very low [CHAR LIMIT=100] --> <string name="auto_brightness_summary_very_low">Preferred brightness is very low</string> Loading res/xml/display_settings.xml +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ <Preference android:key="auto_brightness_entry" android:title="@string/auto_brightness_title" android:summary="@string/auto_brightness_summary" android:summary="@string/summary_placeholder" android:fragment="com.android.settings.display.AutoBrightnessSettings" settings:controller="com.android.settings.display.AutoBrightnessPreferenceController" /> Loading src/com/android/settings/display/AutoBrightnessPreferenceController.java +8 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.provider.Settings; import android.text.TextUtils; import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; Loading Loading @@ -59,4 +60,11 @@ public class AutoBrightnessPreferenceController extends TogglePreferenceControll public boolean isSliceable() { return TextUtils.equals(getPreferenceKey(), "auto_brightness"); } @Override public CharSequence getSummary() { return mContext.getText(isChecked() ? R.string.auto_brightness_summary_on : R.string.auto_brightness_summary_off); } } No newline at end of file tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java +39 −20 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.content.ContentResolver; import android.content.Context; import android.provider.Settings; import com.android.settings.R; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; Loading Loading @@ -52,7 +53,7 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void testOnPreferenceChange_TurnOnAuto_ReturnAuto() { public void onPreferenceChange_TurnOnAuto_ReturnAuto() { mController.onPreferenceChange(null, true); final int mode = Settings.System.getInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, Loading @@ -61,7 +62,7 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void testOnPreferenceChange_TurnOffAuto_ReturnManual() { public void onPreferenceChange_TurnOffAuto_ReturnManual() { mController.onPreferenceChange(null, false); final int mode = Settings.System.getInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, Loading @@ -70,32 +71,50 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void testSetValue_updatesCorrectly() { boolean newValue = true; public void setChecked_updatesCorrectly() { mController.setChecked(true); assertThat(mController.isChecked()).isTrue(); mController.setChecked(false); assertThat(mController.isChecked()).isFalse(); } @Test public void isChecked_no() { Settings.System.putInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL); mController.setChecked(newValue); boolean updatedValue = Settings.System.getInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, -1) != SCREEN_BRIGHTNESS_MODE_MANUAL; assertThat(updatedValue).isEqualTo(newValue); assertThat(mController.isChecked()).isFalse(); } @Test public void testGetValue_correctValueReturned() { public void isChecked_yes() { Settings.System.putInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_AUTOMATIC); int newValue = mController.isChecked() ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL; assertThat(mController.isChecked()).isTrue(); } @Test public void getSummary_settingOn_shouldReturnOnSummary() { mController.setChecked(true); assertThat(mController.getSummary()) .isEqualTo(mContext.getText(R.string.auto_brightness_summary_on)); } @Test public void getSummary_settingOff_shouldReturnOffSummary() { mController.setChecked(false); assertThat(newValue).isEqualTo(SCREEN_BRIGHTNESS_MODE_AUTOMATIC); assertThat(mController.getSummary()) .isEqualTo(mContext.getText(R.string.auto_brightness_summary_off)); } @Test public void isSliceableCorrectKey_returnsTrue() { public void isSliceable_correctKey_returnsTrue() { final AutoBrightnessPreferenceController controller = new AutoBrightnessPreferenceController(mContext, "auto_brightness"); Loading @@ -103,7 +122,7 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void isSliceableIncorrectKey_returnsFalse() { public void isSliceable_incorrectKey_returnsFalse() { final AutoBrightnessPreferenceController controller = new AutoBrightnessPreferenceController(mContext, "bad_key"); assertThat(controller.isSliceable()).isFalse(); Loading Loading
res/values/strings.xml +3 −3 Original line number Diff line number Diff line Loading @@ -2568,9 +2568,9 @@ <string name="brightness_summary">Adjust the brightness of the screen</string> <!-- Sound & display settings screen, setting option name to enable adaptive brightness [CHAR LIMIT=30] --> <string name="auto_brightness_title">Adaptive brightness</string> <!-- Sound & display settings screen, setting option summary to enable adaptive brightness [CHAR LIMIT=100] --> <string name="auto_brightness_summary">Optimize brightness level for available light</string> <!-- Sound & display settings screen, setting option summary when adaptive brightness is off [CHAR LIMIT=100] --> <!-- Setting option summary when adaptive brightness is on [CHAR LIMIT=NONE] --> <string name="auto_brightness_summary_on">On</string> <!-- Setting option summary when adaptive brightness is off [CHAR LIMIT=NONE] --> <string name="auto_brightness_summary_off">Off</string> <!-- Sound & display settings screen, setting option summary when preferred adaptive brightness is very low [CHAR LIMIT=100] --> <string name="auto_brightness_summary_very_low">Preferred brightness is very low</string> Loading
res/xml/display_settings.xml +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ <Preference android:key="auto_brightness_entry" android:title="@string/auto_brightness_title" android:summary="@string/auto_brightness_summary" android:summary="@string/summary_placeholder" android:fragment="com.android.settings.display.AutoBrightnessSettings" settings:controller="com.android.settings.display.AutoBrightnessPreferenceController" /> Loading
src/com/android/settings/display/AutoBrightnessPreferenceController.java +8 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.provider.Settings; import android.text.TextUtils; import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; Loading Loading @@ -59,4 +60,11 @@ public class AutoBrightnessPreferenceController extends TogglePreferenceControll public boolean isSliceable() { return TextUtils.equals(getPreferenceKey(), "auto_brightness"); } @Override public CharSequence getSummary() { return mContext.getText(isChecked() ? R.string.auto_brightness_summary_on : R.string.auto_brightness_summary_off); } } No newline at end of file
tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java +39 −20 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.content.ContentResolver; import android.content.Context; import android.provider.Settings; import com.android.settings.R; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; Loading Loading @@ -52,7 +53,7 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void testOnPreferenceChange_TurnOnAuto_ReturnAuto() { public void onPreferenceChange_TurnOnAuto_ReturnAuto() { mController.onPreferenceChange(null, true); final int mode = Settings.System.getInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, Loading @@ -61,7 +62,7 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void testOnPreferenceChange_TurnOffAuto_ReturnManual() { public void onPreferenceChange_TurnOffAuto_ReturnManual() { mController.onPreferenceChange(null, false); final int mode = Settings.System.getInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, Loading @@ -70,32 +71,50 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void testSetValue_updatesCorrectly() { boolean newValue = true; public void setChecked_updatesCorrectly() { mController.setChecked(true); assertThat(mController.isChecked()).isTrue(); mController.setChecked(false); assertThat(mController.isChecked()).isFalse(); } @Test public void isChecked_no() { Settings.System.putInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL); mController.setChecked(newValue); boolean updatedValue = Settings.System.getInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, -1) != SCREEN_BRIGHTNESS_MODE_MANUAL; assertThat(updatedValue).isEqualTo(newValue); assertThat(mController.isChecked()).isFalse(); } @Test public void testGetValue_correctValueReturned() { public void isChecked_yes() { Settings.System.putInt(mContentResolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_AUTOMATIC); int newValue = mController.isChecked() ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL; assertThat(mController.isChecked()).isTrue(); } @Test public void getSummary_settingOn_shouldReturnOnSummary() { mController.setChecked(true); assertThat(mController.getSummary()) .isEqualTo(mContext.getText(R.string.auto_brightness_summary_on)); } @Test public void getSummary_settingOff_shouldReturnOffSummary() { mController.setChecked(false); assertThat(newValue).isEqualTo(SCREEN_BRIGHTNESS_MODE_AUTOMATIC); assertThat(mController.getSummary()) .isEqualTo(mContext.getText(R.string.auto_brightness_summary_off)); } @Test public void isSliceableCorrectKey_returnsTrue() { public void isSliceable_correctKey_returnsTrue() { final AutoBrightnessPreferenceController controller = new AutoBrightnessPreferenceController(mContext, "auto_brightness"); Loading @@ -103,7 +122,7 @@ public class AutoBrightnessPreferenceControllerTest { } @Test public void isSliceableIncorrectKey_returnsFalse() { public void isSliceable_incorrectKey_returnsFalse() { final AutoBrightnessPreferenceController controller = new AutoBrightnessPreferenceController(mContext, "bad_key"); assertThat(controller.isSliceable()).isFalse(); Loading