Merge "A new attribute which can show the dynamic summary"

This commit is contained in:
TreeHugger Robot
2018-09-28 02:38:12 +00:00
committed by Android (Google) Code Review
17 changed files with 210 additions and 16 deletions

View File

@@ -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);

View File

@@ -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");

View File

@@ -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 =

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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);