Merge "A new attribute which can show the dynamic summary"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5f9d178360
@@ -69,7 +69,8 @@ public class PreferenceXmlParserUtils {
|
||||
MetadataFlag.FLAG_NEED_PREF_TITLE,
|
||||
MetadataFlag.FLAG_NEED_PREF_SUMMARY,
|
||||
MetadataFlag.FLAG_NEED_PREF_ICON,
|
||||
MetadataFlag.FLAG_NEED_SEARCHABLE})
|
||||
MetadataFlag.FLAG_NEED_SEARCHABLE,
|
||||
MetadataFlag.FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface MetadataFlag {
|
||||
int FLAG_INCLUDE_PREF_SCREEN = 1;
|
||||
@@ -82,6 +83,7 @@ public class PreferenceXmlParserUtils {
|
||||
int FLAG_NEED_PLATFORM_SLICE_FLAG = 1 << 7;
|
||||
int FLAG_NEED_KEYWORDS = 1 << 8;
|
||||
int FLAG_NEED_SEARCHABLE = 1 << 9;
|
||||
int FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE = 1 << 10;
|
||||
}
|
||||
|
||||
public static final String METADATA_PREF_TYPE = "type";
|
||||
@@ -93,6 +95,8 @@ public class PreferenceXmlParserUtils {
|
||||
public static final String METADATA_PLATFORM_SLICE_FLAG = "platform_slice";
|
||||
public static final String METADATA_KEYWORDS = "keywords";
|
||||
public static final String METADATA_SEARCHABLE = "searchable";
|
||||
public static final String METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE =
|
||||
"allow_dynamic_summary_in_slice";
|
||||
|
||||
private static final String ENTRIES_SEPARATOR = "|";
|
||||
|
||||
@@ -228,6 +232,10 @@ public class PreferenceXmlParserUtils {
|
||||
preferenceMetadata.putBoolean(METADATA_SEARCHABLE,
|
||||
isSearchable(preferenceAttributes));
|
||||
}
|
||||
if (hasFlag(flags, MetadataFlag.FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE)) {
|
||||
preferenceMetadata.putBoolean(METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
|
||||
isDynamicSummaryAllowed(preferenceAttributes));
|
||||
}
|
||||
metadata.add(preferenceMetadata);
|
||||
|
||||
preferenceAttributes.recycle();
|
||||
@@ -312,6 +320,11 @@ public class PreferenceXmlParserUtils {
|
||||
return styledAttributes.getBoolean(R.styleable.Preference_searchable, true /* default */);
|
||||
}
|
||||
|
||||
private static boolean isDynamicSummaryAllowed(TypedArray styledAttributes) {
|
||||
return styledAttributes.getBoolean(R.styleable.Preference_allowDynamicSummaryInSlice,
|
||||
false /* default */);
|
||||
}
|
||||
|
||||
private static String getKeywords(TypedArray styleAttributes) {
|
||||
return styleAttributes.getString(R.styleable.Preference_keywords);
|
||||
}
|
||||
|
||||
@@ -184,12 +184,23 @@ public class SliceBuilderUtils {
|
||||
*/
|
||||
public static CharSequence getSubtitleText(Context context,
|
||||
AbstractPreferenceController controller, SliceData sliceData) {
|
||||
CharSequence summaryText = sliceData.getScreenTitle();
|
||||
final boolean isDynamicSummaryAllowed = sliceData.isDynamicSummaryAllowed();
|
||||
CharSequence summaryText = controller.getSummary();
|
||||
|
||||
// Priority 1 : User prefers showing the dynamic summary in slice view rather than static
|
||||
// summary.
|
||||
if (isDynamicSummaryAllowed && isValidSummary(context, summaryText)) {
|
||||
return summaryText;
|
||||
}
|
||||
|
||||
// Priority 2 : Show screen title.
|
||||
summaryText = sliceData.getScreenTitle();
|
||||
if (isValidSummary(context, summaryText) && !TextUtils.equals(summaryText,
|
||||
sliceData.getTitle())) {
|
||||
return summaryText;
|
||||
}
|
||||
|
||||
// Priority 3 : Show dynamic summary from preference controller.
|
||||
if (controller != null) {
|
||||
summaryText = controller.getSummary();
|
||||
|
||||
@@ -198,11 +209,13 @@ public class SliceBuilderUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 4 : Show summary from slice data.
|
||||
summaryText = sliceData.getSummary();
|
||||
if (isValidSummary(context, summaryText)) {
|
||||
return summaryText;
|
||||
}
|
||||
|
||||
// Priority 5 : Show empty text.
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -217,7 +230,7 @@ public class SliceBuilderUtils {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Intent buildSearchResultPageIntent(Context context, String className, String key,
|
||||
public static Intent buildSearchResultPageIntent(Context context, String className, String key,
|
||||
String screenTitle, int sourceMetricsCategory) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||
|
||||
@@ -74,6 +74,8 @@ public class SliceData {
|
||||
|
||||
private final boolean mIsPlatformDefined;
|
||||
|
||||
private final boolean mIsDynamicSummaryAllowed;
|
||||
|
||||
public String getKey() {
|
||||
return mKey;
|
||||
}
|
||||
@@ -118,6 +120,10 @@ public class SliceData {
|
||||
return mIsPlatformDefined;
|
||||
}
|
||||
|
||||
public boolean isDynamicSummaryAllowed() {
|
||||
return mIsDynamicSummaryAllowed;
|
||||
}
|
||||
|
||||
private SliceData(Builder builder) {
|
||||
mKey = builder.mKey;
|
||||
mTitle = builder.mTitle;
|
||||
@@ -130,6 +136,7 @@ public class SliceData {
|
||||
mPreferenceController = builder.mPrefControllerClassName;
|
||||
mSliceType = builder.mSliceType;
|
||||
mIsPlatformDefined = builder.mIsPlatformDefined;
|
||||
mIsDynamicSummaryAllowed = builder.mIsDynamicSummaryAllowed;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -169,6 +176,8 @@ public class SliceData {
|
||||
|
||||
private boolean mIsPlatformDefined;
|
||||
|
||||
private boolean mIsDynamicSummaryAllowed;
|
||||
|
||||
public Builder setKey(String key) {
|
||||
mKey = key;
|
||||
return this;
|
||||
@@ -224,6 +233,11 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDynamicSummaryAllowed(boolean isDynamicSummaryAllowed) {
|
||||
mIsDynamicSummaryAllowed = isDynamicSummaryAllowed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SliceData build() {
|
||||
if (TextUtils.isEmpty(mKey)) {
|
||||
throw new InvalidSliceDataException("Key cannot be empty");
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
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_CONTROLLER;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
|
||||
@@ -186,7 +188,8 @@ class SliceDataConverter {
|
||||
| MetadataFlag.FLAG_NEED_PREF_TITLE
|
||||
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
||||
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG);
|
||||
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG
|
||||
| MetadataFlag.FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
|
||||
@@ -203,6 +206,8 @@ class SliceDataConverter {
|
||||
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
|
||||
key);
|
||||
final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
|
||||
final boolean isDynamicSummaryAllowed = bundle.getBoolean(
|
||||
METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE);
|
||||
|
||||
final SliceData xmlSlice = new SliceData.Builder()
|
||||
.setKey(key)
|
||||
@@ -214,6 +219,7 @@ class SliceDataConverter {
|
||||
.setFragmentName(fragmentName)
|
||||
.setSliceType(sliceType)
|
||||
.setPlatformDefined(isPlatformSlice)
|
||||
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
|
||||
.build();
|
||||
|
||||
final BasePreferenceController controller =
|
||||
|
||||
@@ -49,6 +49,7 @@ public class SlicesDatabaseAccessor {
|
||||
IndexColumns.CONTROLLER,
|
||||
IndexColumns.PLATFORM_SLICE,
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
|
||||
};
|
||||
|
||||
// Cursor value for boolean true
|
||||
@@ -159,6 +160,8 @@ public class SlicesDatabaseAccessor {
|
||||
cursor.getColumnIndex(IndexColumns.CONTROLLER));
|
||||
final boolean isPlatformDefined = cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PLATFORM_SLICE)) == TRUE;
|
||||
final boolean isDynamicSummaryAllowed = cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE)) == TRUE;
|
||||
int sliceType = cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.SLICE_TYPE));
|
||||
|
||||
@@ -178,6 +181,7 @@ public class SlicesDatabaseAccessor {
|
||||
.setUri(uri)
|
||||
.setPlatformDefined(isPlatformDefined)
|
||||
.setSliceType(sliceType)
|
||||
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
|
||||
.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 = 2;
|
||||
private static final int DATABASE_VERSION = 3;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -93,6 +93,12 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
* {@link SliceData.SliceType} representing the inline type of the result.
|
||||
*/
|
||||
String SLICE_TYPE = "slice_type";
|
||||
|
||||
/**
|
||||
* Boolean flag, {@code true} when the slice object prefers using the dynamic summary from
|
||||
* preference controller.
|
||||
*/
|
||||
String ALLOW_DYNAMIC_SUMMARY_IN_SLICE = "allow_dynamic_summary_in_slice";
|
||||
}
|
||||
|
||||
private static final String CREATE_SLICES_TABLE =
|
||||
@@ -117,6 +123,8 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
IndexColumns.PLATFORM_SLICE +
|
||||
", " +
|
||||
IndexColumns.SLICE_TYPE +
|
||||
", " +
|
||||
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE +
|
||||
");";
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
@@ -111,6 +111,8 @@ class SlicesIndexer implements Runnable {
|
||||
values.put(IndexColumns.CONTROLLER, dataRow.getPreferenceController());
|
||||
values.put(IndexColumns.PLATFORM_SLICE, dataRow.isPlatformDefined());
|
||||
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
||||
values.put(IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
|
||||
dataRow.isDynamicSummaryAllowed());
|
||||
|
||||
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
|
||||
values);
|
||||
|
||||
Reference in New Issue
Block a user