Merge "Add keywords to Slices" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2f911e2e9e
@@ -77,6 +77,7 @@ public class PreferenceXmlParserUtils {
|
||||
int FLAG_NEED_PREF_SUMMARY = 1 << 5;
|
||||
int FLAG_NEED_PREF_ICON = 1 << 6;
|
||||
int FLAG_NEED_PLATFORM_SLICE_FLAG = 1 << 7;
|
||||
int FLAG_NEED_KEYWORDS = 1 << 8;
|
||||
}
|
||||
|
||||
public static final String METADATA_PREF_TYPE = "type";
|
||||
@@ -86,6 +87,7 @@ public class PreferenceXmlParserUtils {
|
||||
public static final String METADATA_SUMMARY = "summary";
|
||||
public static final String METADATA_ICON = "icon";
|
||||
public static final String METADATA_PLATFORM_SLICE_FLAG = "platform_slice";
|
||||
public static final String METADATA_KEYWORDS = "keywords";
|
||||
|
||||
private static final String ENTRIES_SEPARATOR = "|";
|
||||
|
||||
@@ -226,6 +228,9 @@ public class PreferenceXmlParserUtils {
|
||||
preferenceMetadata.putBoolean(METADATA_PLATFORM_SLICE_FLAG,
|
||||
getPlatformSlice(preferenceAttributes));
|
||||
}
|
||||
if (hasFlag(flags, MetadataFlag.FLAG_NEED_KEYWORDS)) {
|
||||
preferenceMetadata.putString(METADATA_KEYWORDS, getKeywords(preferenceAttributes));
|
||||
}
|
||||
metadata.add(preferenceMetadata);
|
||||
|
||||
preferenceAttributes.recycle();
|
||||
@@ -305,4 +310,8 @@ public class PreferenceXmlParserUtils {
|
||||
private static boolean getPlatformSlice(TypedArray styledAttributes) {
|
||||
return styledAttributes.getBoolean(R.styleable.Preference_platform_slice, false /* def */);
|
||||
}
|
||||
|
||||
private static String getKeywords(TypedArray styleAttributes) {
|
||||
return styleAttributes.getString(R.styleable.Preference_keywords);
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,10 @@ import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import android.support.v4.graphics.drawable.IconCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.builders.ListBuilder;
|
||||
import androidx.slice.builders.SliceAction;
|
||||
@@ -231,6 +235,7 @@ public class SliceBuilderUtils {
|
||||
(TogglePreferenceController) controller;
|
||||
final SliceAction sliceAction = getToggleAction(context, sliceData,
|
||||
toggleController.isChecked());
|
||||
final List<String> keywords = buildSliceKeywords(sliceData.getKeywords());
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), SLICE_TTL_MILLIS)
|
||||
.addRow(rowBuilder -> rowBuilder
|
||||
@@ -239,6 +244,7 @@ public class SliceBuilderUtils {
|
||||
.setPrimaryAction(
|
||||
new SliceAction(contentIntent, icon, sliceData.getTitle()))
|
||||
.addEndItem(sliceAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -247,6 +253,7 @@ public class SliceBuilderUtils {
|
||||
final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
|
||||
final IconCompat icon = IconCompat.createWithResource(context, sliceData.getIconResource());
|
||||
final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
|
||||
final List<String> keywords = buildSliceKeywords(sliceData.getKeywords());
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), SLICE_TTL_MILLIS)
|
||||
.addRow(rowBuilder -> rowBuilder
|
||||
@@ -254,6 +261,7 @@ public class SliceBuilderUtils {
|
||||
.setSubtitle(subtitleText)
|
||||
.setPrimaryAction(
|
||||
new SliceAction(contentIntent, icon, sliceData.getTitle())))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -265,6 +273,7 @@ public class SliceBuilderUtils {
|
||||
final IconCompat icon = IconCompat.createWithResource(context, sliceData.getIconResource());
|
||||
final SliceAction primaryAction = new SliceAction(contentIntent, icon,
|
||||
sliceData.getTitle());
|
||||
final List<String> keywords = buildSliceKeywords(sliceData.getKeywords());
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), SLICE_TTL_MILLIS)
|
||||
.addInputRange(builder -> builder
|
||||
@@ -273,6 +282,7 @@ public class SliceBuilderUtils {
|
||||
.setValue(sliderController.getSliderPosition())
|
||||
.setInputAction(actionIntent)
|
||||
.setPrimaryAction(primaryAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -311,9 +321,19 @@ public class SliceBuilderUtils {
|
||||
|| TextUtils.equals(summary, doublePlaceHolder));
|
||||
}
|
||||
|
||||
private static List<String> buildSliceKeywords(String keywordString) {
|
||||
if (keywordString == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
final String[] keywords = keywordString.split(",");
|
||||
return Arrays.asList(keywords);
|
||||
}
|
||||
|
||||
private static Slice buildUnavailableSlice(Context context, SliceData data,
|
||||
BasePreferenceController controller) {
|
||||
final String title = data.getTitle();
|
||||
final List<String> keywords = buildSliceKeywords(data.getKeywords());
|
||||
final String summary;
|
||||
final SliceAction primaryAction;
|
||||
final IconCompat icon = IconCompat.createWithResource(context, data.getIconResource());
|
||||
@@ -344,6 +364,7 @@ public class SliceBuilderUtils {
|
||||
.setTitle(title)
|
||||
.setSubtitle(summary)
|
||||
.setPrimaryAction(primaryAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import android.text.TextUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Data class representing a slice stored by {@link SlicesIndexer}.
|
||||
@@ -59,6 +60,8 @@ public class SliceData {
|
||||
|
||||
private final CharSequence mScreenTitle;
|
||||
|
||||
private final String mKeywords;
|
||||
|
||||
private final int mIconResource;
|
||||
|
||||
private final String mFragmentClassName;
|
||||
@@ -88,6 +91,10 @@ public class SliceData {
|
||||
return mScreenTitle;
|
||||
}
|
||||
|
||||
public String getKeywords() {
|
||||
return mKeywords;
|
||||
}
|
||||
|
||||
public int getIconResource() {
|
||||
return mIconResource;
|
||||
}
|
||||
@@ -117,6 +124,7 @@ public class SliceData {
|
||||
mTitle = builder.mTitle;
|
||||
mSummary = builder.mSummary;
|
||||
mScreenTitle = builder.mScreenTitle;
|
||||
mKeywords = builder.mKeywords;
|
||||
mIconResource = builder.mIconResource;
|
||||
mFragmentClassName = builder.mFragmentClassName;
|
||||
mUri = builder.mUri;
|
||||
@@ -148,6 +156,8 @@ public class SliceData {
|
||||
|
||||
private CharSequence mScreenTitle;
|
||||
|
||||
private String mKeywords;
|
||||
|
||||
private int mIconResource;
|
||||
|
||||
private String mFragmentClassName;
|
||||
@@ -180,6 +190,11 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setKeywords(String keywords) {
|
||||
mKeywords = keywords;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIcon(int iconResource) {
|
||||
mIconResource = iconResource;
|
||||
return this;
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.slices;
|
||||
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_KEYWORDS;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_PLATFORM_SLICE_FLAG;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
||||
@@ -184,6 +185,7 @@ class SliceDataConverter {
|
||||
| MetadataFlag.FLAG_NEED_PREF_TITLE
|
||||
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
||||
| MetadataFlag.FLAG_NEED_KEYWORDS
|
||||
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
@@ -196,6 +198,7 @@ class SliceDataConverter {
|
||||
final String key = bundle.getString(METADATA_KEY);
|
||||
final String title = bundle.getString(METADATA_TITLE);
|
||||
final String summary = bundle.getString(METADATA_SUMMARY);
|
||||
final String keywords = bundle.getString(METADATA_KEYWORDS);
|
||||
final int iconResId = bundle.getInt(METADATA_ICON);
|
||||
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
|
||||
key);
|
||||
@@ -207,6 +210,7 @@ class SliceDataConverter {
|
||||
.setSummary(summary)
|
||||
.setIcon(iconResId)
|
||||
.setScreenTitle(screenTitle)
|
||||
.setKeywords(keywords)
|
||||
.setPreferenceControllerClassName(controllerClassName)
|
||||
.setFragmentName(fragmentName)
|
||||
.setSliceType(sliceType)
|
||||
|
@@ -44,6 +44,7 @@ public class SlicesDatabaseAccessor {
|
||||
IndexColumns.TITLE,
|
||||
IndexColumns.SUMMARY,
|
||||
IndexColumns.SCREENTITLE,
|
||||
IndexColumns.KEYWORDS,
|
||||
IndexColumns.ICON_RESOURCE,
|
||||
IndexColumns.FRAGMENT,
|
||||
IndexColumns.CONTROLLER,
|
||||
@@ -150,6 +151,7 @@ public class SlicesDatabaseAccessor {
|
||||
final String summary = cursor.getString(cursor.getColumnIndex(IndexColumns.SUMMARY));
|
||||
final String screenTitle = cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.SCREENTITLE));
|
||||
final String keywords = cursor.getString(cursor.getColumnIndex(IndexColumns.KEYWORDS));
|
||||
final int iconResource = cursor.getInt(cursor.getColumnIndex(IndexColumns.ICON_RESOURCE));
|
||||
final String fragmentClassName = cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.FRAGMENT));
|
||||
@@ -169,6 +171,7 @@ public class SlicesDatabaseAccessor {
|
||||
.setTitle(title)
|
||||
.setSummary(summary)
|
||||
.setScreenTitle(screenTitle)
|
||||
.setKeywords(keywords)
|
||||
.setIcon(iconResource)
|
||||
.setFragmentName(fragmentClassName)
|
||||
.setPreferenceControllerClassName(controllerClassName)
|
||||
|
@@ -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 = 1;
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -63,6 +63,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
String SCREENTITLE = "screentitle";
|
||||
|
||||
/**
|
||||
* String with a comma separated list of keywords relating to the Slice.
|
||||
*/
|
||||
String KEYWORDS = "keywords";
|
||||
|
||||
/**
|
||||
* Resource ID for the icon of the setting. Should be 0 for no icon.
|
||||
*/
|
||||
@@ -101,6 +106,8 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
", " +
|
||||
IndexColumns.SCREENTITLE +
|
||||
", " +
|
||||
IndexColumns.KEYWORDS +
|
||||
", " +
|
||||
IndexColumns.ICON_RESOURCE +
|
||||
", " +
|
||||
IndexColumns.FRAGMENT +
|
||||
@@ -109,7 +116,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
", " +
|
||||
IndexColumns.PLATFORM_SLICE +
|
||||
", " +
|
||||
IndexColumns.SLICE_TYPE+
|
||||
IndexColumns.SLICE_TYPE +
|
||||
");";
|
||||
|
||||
private final Context mContext;
|
||||
|
@@ -105,6 +105,7 @@ class SlicesIndexer implements Runnable {
|
||||
values.put(IndexColumns.TITLE, dataRow.getTitle());
|
||||
values.put(IndexColumns.SUMMARY, dataRow.getSummary());
|
||||
values.put(IndexColumns.SCREENTITLE, dataRow.getScreenTitle().toString());
|
||||
values.put(IndexColumns.KEYWORDS, dataRow.getKeywords());
|
||||
values.put(IndexColumns.ICON_RESOURCE, dataRow.getIconResource());
|
||||
values.put(IndexColumns.FRAGMENT, dataRow.getFragmentClassName());
|
||||
values.put(IndexColumns.CONTROLLER, dataRow.getPreferenceController());
|
||||
|
Reference in New Issue
Block a user