Add fallback summary text if there is no matching screen timeout value
Screen timeout summary string can be null if there is no matching candidate, so we need a fallback summary here to avoid showing unexpected summary text. Bug: 252340891 Test: manual Change-Id: I939ae97a50063b2ffe84029135c3f340aeedf4c7
This commit is contained in:
@@ -3196,6 +3196,8 @@
|
|||||||
<string name="screen_timeout_title">Screen turns off</string>
|
<string name="screen_timeout_title">Screen turns off</string>
|
||||||
<!-- Sound & display settings screen, setting option summary to change screen timeout -->
|
<!-- Sound & display settings screen, setting option summary to change screen timeout -->
|
||||||
<string name="screen_timeout_summary">After <xliff:g id="timeout_description">%1$s</xliff:g> of inactivity</string>
|
<string name="screen_timeout_summary">After <xliff:g id="timeout_description">%1$s</xliff:g> of inactivity</string>
|
||||||
|
<!-- Sound & display settings screen, setting option summary if there is no matching candidate -->
|
||||||
|
<string name="screen_timeout_summary_not_set">Not set</string>
|
||||||
<!-- Wallpaper settings title [CHAR LIMIT=30] -->
|
<!-- Wallpaper settings title [CHAR LIMIT=30] -->
|
||||||
<string name="wallpaper_settings_title">Wallpaper</string>
|
<string name="wallpaper_settings_title">Wallpaper</string>
|
||||||
<!-- Styles & Wallpapers settings title [CHAR LIMIT=30] -->
|
<!-- Styles & Wallpapers settings title [CHAR LIMIT=30] -->
|
||||||
|
@@ -27,6 +27,7 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -74,7 +75,9 @@ public class ScreenTimeoutPreferenceController extends BasePreferenceController
|
|||||||
private CharSequence getTimeoutSummary(long maxTimeout) {
|
private CharSequence getTimeoutSummary(long maxTimeout) {
|
||||||
final long currentTimeout = getCurrentScreenTimeout();
|
final long currentTimeout = getCurrentScreenTimeout();
|
||||||
final CharSequence description = getTimeoutDescription(currentTimeout, maxTimeout);
|
final CharSequence description = getTimeoutDescription(currentTimeout, maxTimeout);
|
||||||
return mContext.getString(R.string.screen_timeout_summary, description);
|
return description == null ? mContext.getString(
|
||||||
|
R.string.screen_timeout_summary_not_set) : mContext.getString(
|
||||||
|
R.string.screen_timeout_summary, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long getMaxScreenTimeout() {
|
private Long getMaxScreenTimeout() {
|
||||||
@@ -112,6 +115,7 @@ public class ScreenTimeoutPreferenceController extends BasePreferenceController
|
|||||||
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private CharSequence getTimeoutDescription(long currentTimeout, long maxTimeout) {
|
private CharSequence getTimeoutDescription(long currentTimeout, long maxTimeout) {
|
||||||
if (currentTimeout < 0 || mTimeoutEntries == null || mTimeoutValues == null
|
if (currentTimeout < 0 || mTimeoutEntries == null || mTimeoutValues == null
|
||||||
|| mTimeoutValues.length != mTimeoutEntries.length) {
|
|| mTimeoutValues.length != mTimeoutEntries.length) {
|
||||||
@@ -127,6 +131,7 @@ public class ScreenTimeoutPreferenceController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private CharSequence getCurrentTimeout(long currentTimeout) {
|
private CharSequence getCurrentTimeout(long currentTimeout) {
|
||||||
for (int i = 0; i < mTimeoutValues.length; i++) {
|
for (int i = 0; i < mTimeoutValues.length; i++) {
|
||||||
if (currentTimeout == Long.parseLong(mTimeoutValues[i].toString())) {
|
if (currentTimeout == Long.parseLong(mTimeoutValues[i].toString())) {
|
||||||
@@ -136,6 +141,7 @@ public class ScreenTimeoutPreferenceController extends BasePreferenceController
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private CharSequence getLargestTimeout(long maxTimeout) {
|
private CharSequence getLargestTimeout(long maxTimeout) {
|
||||||
CharSequence largestTimeout = null;
|
CharSequence largestTimeout = null;
|
||||||
// The list of timeouts is sorted
|
// The list of timeouts is sorted
|
||||||
|
Reference in New Issue
Block a user