Adding the ability to customize the subtitle on an unavailable slice
When a slice is depending on some setting and the setting is off, it shows "depends on another setting". Add an new attribute for Preference to customize the subtitle when a slice is unavailable. Bug: 118399193 Test: Robo test on com.android.settings.slices, com.android.settings.core Change-Id: I84a8400295b36abb357e5baf98e9be3a8d6ea897
This commit is contained in:
@@ -425,7 +425,10 @@ public class SliceBuilderUtils {
|
||||
final String title = data.getTitle();
|
||||
final Set<String> keywords = buildSliceKeywords(data);
|
||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(context);
|
||||
final CharSequence summary = context.getText(R.string.disabled_dependent_setting_summary);
|
||||
|
||||
final String customSubtitle = data.getUnavailableSliceSubtitle();
|
||||
final CharSequence subtitle = !TextUtils.isEmpty(customSubtitle) ? customSubtitle
|
||||
: context.getText(R.string.disabled_dependent_setting_summary);
|
||||
final IconCompat icon = getSafeIcon(context, data);
|
||||
final SliceAction primaryAction = SliceAction.createDeeplink(
|
||||
getContentPendingIntent(context, data),
|
||||
@@ -436,7 +439,7 @@ public class SliceBuilderUtils {
|
||||
.addRow(new RowBuilder()
|
||||
.setTitle(title)
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setSubtitle(summary)
|
||||
.setSubtitle(subtitle)
|
||||
.setPrimaryAction(primaryAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* Note that {@link #mKey} is treated as a primary key for this class and determines equality.
|
||||
*/
|
||||
public class SliceData {
|
||||
|
||||
/**
|
||||
* Flags indicating the UI type of the Slice.
|
||||
*/
|
||||
@@ -76,6 +75,8 @@ public class SliceData {
|
||||
|
||||
private final boolean mIsDynamicSummaryAllowed;
|
||||
|
||||
private final String mUnavailableSliceSubtitle;
|
||||
|
||||
public String getKey() {
|
||||
return mKey;
|
||||
}
|
||||
@@ -124,6 +125,10 @@ public class SliceData {
|
||||
return mIsDynamicSummaryAllowed;
|
||||
}
|
||||
|
||||
public String getUnavailableSliceSubtitle() {
|
||||
return mUnavailableSliceSubtitle;
|
||||
}
|
||||
|
||||
private SliceData(Builder builder) {
|
||||
mKey = builder.mKey;
|
||||
mTitle = builder.mTitle;
|
||||
@@ -137,6 +142,7 @@ public class SliceData {
|
||||
mSliceType = builder.mSliceType;
|
||||
mIsPlatformDefined = builder.mIsPlatformDefined;
|
||||
mIsDynamicSummaryAllowed = builder.mIsDynamicSummaryAllowed;
|
||||
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,6 +184,8 @@ public class SliceData {
|
||||
|
||||
private boolean mIsDynamicSummaryAllowed;
|
||||
|
||||
private String mUnavailableSliceSubtitle;
|
||||
|
||||
public Builder setKey(String key) {
|
||||
mKey = key;
|
||||
return this;
|
||||
@@ -238,6 +246,12 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUnavailableSliceSubtitle(
|
||||
String unavailableSliceSubtitle) {
|
||||
mUnavailableSliceSubtitle = unavailableSliceSubtitle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SliceData build() {
|
||||
if (TextUtils.isEmpty(mKey)) {
|
||||
throw new InvalidSliceDataException("Key cannot be empty");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils
|
||||
.METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_CONTROLLER;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_PLATFORM_SLICE_FLAG;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_UNAVAILABLE_SLICE_SUBTITLE;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
||||
|
||||
@@ -189,7 +189,8 @@ class SliceDataConverter {
|
||||
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
||||
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG
|
||||
| MetadataFlag.FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE);
|
||||
| MetadataFlag.FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE
|
||||
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
|
||||
@@ -208,6 +209,8 @@ class SliceDataConverter {
|
||||
final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
|
||||
final boolean isDynamicSummaryAllowed = bundle.getBoolean(
|
||||
METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE);
|
||||
final String unavailableSliceSubtitle = bundle.getString(
|
||||
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
final SliceData xmlSlice = new SliceData.Builder()
|
||||
.setKey(key)
|
||||
@@ -220,6 +223,7 @@ class SliceDataConverter {
|
||||
.setSliceType(sliceType)
|
||||
.setPlatformDefined(isPlatformSlice)
|
||||
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.build();
|
||||
|
||||
final BasePreferenceController controller =
|
||||
|
||||
@@ -50,6 +50,7 @@ public class SlicesDatabaseAccessor {
|
||||
IndexColumns.PLATFORM_SLICE,
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
};
|
||||
|
||||
// Cursor value for boolean true
|
||||
@@ -167,6 +168,8 @@ public class SlicesDatabaseAccessor {
|
||||
cursor.getColumnIndex(IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE)) == TRUE;
|
||||
int sliceType = cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.SLICE_TYPE));
|
||||
final String unavailableSliceSubtitle = cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE));
|
||||
|
||||
if (isIntentOnly) {
|
||||
sliceType = SliceData.SliceType.INTENT;
|
||||
@@ -185,6 +188,7 @@ public class SlicesDatabaseAccessor {
|
||||
.setPlatformDefined(isPlatformDefined)
|
||||
.setSliceType(sliceType)
|
||||
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "slices_index.db";
|
||||
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
|
||||
|
||||
private static final int DATABASE_VERSION = 3;
|
||||
private static final int DATABASE_VERSION = 4;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -99,6 +99,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
* preference controller.
|
||||
*/
|
||||
String ALLOW_DYNAMIC_SUMMARY_IN_SLICE = "allow_dynamic_summary_in_slice";
|
||||
|
||||
/**
|
||||
* Customized subtitle if it's a unavailable slice
|
||||
*/
|
||||
String UNAVAILABLE_SLICE_SUBTITLE = "unavailable_slice_subtitle";
|
||||
}
|
||||
|
||||
private static final String CREATE_SLICES_TABLE =
|
||||
@@ -125,6 +130,8 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
IndexColumns.SLICE_TYPE +
|
||||
", " +
|
||||
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE +
|
||||
", " +
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
||||
");";
|
||||
|
||||
private final Context mContext;
|
||||
@@ -151,7 +158,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (oldVersion < DATABASE_VERSION) {
|
||||
Log.d(TAG, "Reconstructing DB from " + oldVersion + "to " + newVersion);
|
||||
Log.d(TAG, "Reconstructing DB from " + oldVersion + " to " + newVersion);
|
||||
reconstruct(db);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ class SlicesIndexer implements Runnable {
|
||||
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
||||
values.put(IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
|
||||
dataRow.isDynamicSummaryAllowed());
|
||||
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
dataRow.getUnavailableSliceSubtitle());
|
||||
|
||||
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
|
||||
values);
|
||||
|
||||
Reference in New Issue
Block a user