Change Display summary to sleep timeout description.
Bug: 29579542 Fixes: 29579542 Change-Id: I4e122bd6972fde933229768cba86302eb4d3f7c6 Test: Added Robo test, manually tested
This commit is contained in:
@@ -7271,11 +7271,8 @@
|
|||||||
<!-- Summary of storage usage [CHAR LIMIT=NONE] -->
|
<!-- Summary of storage usage [CHAR LIMIT=NONE] -->
|
||||||
<string name="storage_summary"><xliff:g id="size1" example="8GB">%1$s</xliff:g> of <xliff:g id="size2" example="32GB">%2$s</xliff:g> used</string>
|
<string name="storage_summary"><xliff:g id="size1" example="8GB">%1$s</xliff:g> of <xliff:g id="size2" example="32GB">%2$s</xliff:g> used</string>
|
||||||
|
|
||||||
<!-- Summary of display with adaptive brightness on [CHAR LIMIT=NONE] -->
|
<!-- Summary of display with screen sleep timeout [CHAR LIMIT=NONE] -->
|
||||||
<string name="display_summary_on">Adaptive brightness is ON</string>
|
<string name="display_summary">Sleep after <xliff:g id="timeout_description" example="10 minutes">%1$s</xliff:g> of inactivity</string>
|
||||||
|
|
||||||
<!-- Summary of display with adaptive brightness off [CHAR LIMIT=NONE] -->
|
|
||||||
<string name="display_summary_off">Adaptive brightness is OFF</string>
|
|
||||||
|
|
||||||
<!-- Summary of memory screen [CHAR LIMIT=NONE] -->
|
<!-- Summary of memory screen [CHAR LIMIT=NONE] -->
|
||||||
<string name="memory_summary">Avg <xliff:g id="used_memory" example="1.7GB">%1$s</xliff:g> of <xliff:g id="total_memory" example="2GB">%2$s</xliff:g> memory used</string>
|
<string name="memory_summary">Avg <xliff:g id="used_memory" example="1.7GB">%1$s</xliff:g> of <xliff:g id="total_memory" example="2GB">%2$s</xliff:g> memory used</string>
|
||||||
|
@@ -289,31 +289,36 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private void updateTimeoutPreferenceDescription(long currentTimeout) {
|
private void updateTimeoutPreferenceDescription(long currentTimeout) {
|
||||||
TimeoutListPreference preference = mScreenTimeoutPreference;
|
TimeoutListPreference preference = mScreenTimeoutPreference;
|
||||||
|
final CharSequence[] entries = preference.getEntries();
|
||||||
|
final CharSequence[] values = preference.getEntryValues();
|
||||||
String summary;
|
String summary;
|
||||||
if (preference.isDisabledByAdmin()) {
|
if (preference.isDisabledByAdmin()) {
|
||||||
summary = getString(R.string.disabled_by_policy_title);
|
summary = getString(R.string.disabled_by_policy_title);
|
||||||
} else if (currentTimeout < 0) {
|
|
||||||
// Unsupported value
|
|
||||||
summary = "";
|
|
||||||
} else {
|
} else {
|
||||||
final CharSequence[] entries = preference.getEntries();
|
CharSequence timeoutDescription = getTimeoutDescription(
|
||||||
final CharSequence[] values = preference.getEntryValues();
|
currentTimeout, entries, values);
|
||||||
if (entries == null || entries.length == 0) {
|
summary = timeoutDescription == null ? ""
|
||||||
summary = "";
|
: getString(R.string.screen_timeout_summary, timeoutDescription);
|
||||||
} else {
|
|
||||||
int best = 0;
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
long timeout = Long.parseLong(values[i].toString());
|
|
||||||
if (currentTimeout >= timeout) {
|
|
||||||
best = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
summary = getString(R.string.screen_timeout_summary, entries[best]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
preference.setSummary(summary);
|
preference.setSummary(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static CharSequence getTimeoutDescription(
|
||||||
|
long currentTimeout, CharSequence[] entries, CharSequence[] values) {
|
||||||
|
if (currentTimeout < 0 || entries == null || values == null
|
||||||
|
|| values.length != entries.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
long timeout = Long.parseLong(values[i].toString());
|
||||||
|
if (currentTimeout == timeout) {
|
||||||
|
return entries[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -472,11 +477,17 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateSummary() {
|
private void updateSummary() {
|
||||||
boolean auto = Settings.System.getInt(mContext.getContentResolver(),
|
final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
|
||||||
SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_AUTOMATIC)
|
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
||||||
== SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
|
final CharSequence[] entries =
|
||||||
mLoader.setSummary(this, mContext.getString(auto ? R.string.display_summary_on
|
mContext.getResources().getTextArray(R.array.screen_timeout_entries);
|
||||||
: R.string.display_summary_off));
|
final CharSequence[] values =
|
||||||
|
mContext.getResources().getTextArray(R.array.screen_timeout_values);
|
||||||
|
final CharSequence timeoutDescription = getTimeoutDescription(
|
||||||
|
currentTimeout, entries, values);
|
||||||
|
final String summary = timeoutDescription == null ? ""
|
||||||
|
: mContext.getString(R.string.display_summary, timeoutDescription);
|
||||||
|
mLoader.setSummary(this, summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.provider.Settings.System;
|
||||||
|
|
||||||
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class DisplaySettingsTest {
|
||||||
|
|
||||||
|
private Activity mActivity;
|
||||||
|
@Mock private SummaryLoader mSummaryLoader;
|
||||||
|
private SummaryLoader.SummaryProvider mSummaryProvider;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mActivity = Robolectric.buildActivity(Activity.class).get();
|
||||||
|
mSummaryProvider = DisplaySettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(
|
||||||
|
mActivity, mSummaryLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidTimeouts_summaryShouldBeEmpty() {
|
||||||
|
System.putLong(mActivity.getContentResolver(), SCREEN_OFF_TIMEOUT, -1);
|
||||||
|
assertEquals(System.getLong(mActivity.getContentResolver(), SCREEN_OFF_TIMEOUT, 0), -1);
|
||||||
|
mSummaryProvider.setListening(true);
|
||||||
|
|
||||||
|
System.putLong(mActivity.getContentResolver(), SCREEN_OFF_TIMEOUT, 1234);
|
||||||
|
mSummaryProvider.setListening(true);
|
||||||
|
|
||||||
|
verify(mSummaryLoader, times(2)).setSummary(mSummaryProvider, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidTimeouts_summaryShouldNotBeEmpty() {
|
||||||
|
final CharSequence[] values =
|
||||||
|
mActivity.getResources().getTextArray(R.array.screen_timeout_values);
|
||||||
|
|
||||||
|
for (CharSequence value : values) {
|
||||||
|
long timeout = Long.parseLong(value.toString());
|
||||||
|
System.putLong(mActivity.getContentResolver(), SCREEN_OFF_TIMEOUT, timeout);
|
||||||
|
assertEquals(System.getLong(mActivity.getContentResolver(), SCREEN_OFF_TIMEOUT, 0), timeout);
|
||||||
|
mSummaryProvider.setListening(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(mSummaryLoader, never()).setSummary(mSummaryProvider, "");
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user