Convert xml based API allowDynamicSummaryInSlice to java
- Add boolean useDynamicSliceSummary() in Sliceable interface. This is the switch equivalent to android:allowDynamicSummaryInSlice in xml. It moves the setter closer to regular Sliceable APIs, thus less easily to miss. - Coverted all android:allowDynamicSummaryInSlice to use the java API. - Except 2 prefs in my_device_info. They incorrectly set this to true previously (controller is not sliceable, no point setting dynamicSliceSummary to true. They just won't do anything) Fixes: 128446156 Test: robolectric Change-Id: Ic57acd590dec3e87dcf4592df137321d14b854d9
This commit is contained in:
@@ -72,7 +72,6 @@ public class PreferenceXmlParserUtils {
|
||||
MetadataFlag.FLAG_NEED_PREF_SUMMARY,
|
||||
MetadataFlag.FLAG_NEED_PREF_ICON,
|
||||
MetadataFlag.FLAG_NEED_SEARCHABLE,
|
||||
MetadataFlag.FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
|
||||
MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface MetadataFlag {
|
||||
@@ -87,9 +86,8 @@ 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;
|
||||
int FLAG_NEED_PREF_APPEND = 1 << 11;
|
||||
int FLAG_UNAVAILABLE_SLICE_SUBTITLE = 1 << 12;
|
||||
int FLAG_NEED_PREF_APPEND = 1 << 10;
|
||||
int FLAG_UNAVAILABLE_SLICE_SUBTITLE = 1 << 11;
|
||||
}
|
||||
|
||||
public static final String METADATA_PREF_TYPE = "type";
|
||||
@@ -101,8 +99,6 @@ 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";
|
||||
public static final String METADATA_APPEND = "staticPreferenceLocation";
|
||||
public static final String METADATA_UNAVAILABLE_SLICE_SUBTITLE =
|
||||
"unavailable_slice_subtitle";
|
||||
@@ -246,10 +242,6 @@ 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));
|
||||
}
|
||||
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_APPEND) && hasPrefScreenFlag) {
|
||||
preferenceMetadata.putBoolean(METADATA_APPEND,
|
||||
isAppended(preferenceScreenAttributes));
|
||||
@@ -267,14 +259,6 @@ public class PreferenceXmlParserUtils {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fragment name if this preference launches a child fragment.
|
||||
*/
|
||||
public static String getDataChildFragment(Context context, AttributeSet attrs) {
|
||||
return getStringData(context, attrs, R.styleable.Preference,
|
||||
R.styleable.Preference_android_fragment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call {@link #extractMetadata(Context, int, int)} with a {@link MetadataFlag} instead.
|
||||
*/
|
||||
@@ -342,11 +326,6 @@ 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 styledAttributes) {
|
||||
return styledAttributes.getString(R.styleable.Preference_keywords);
|
||||
}
|
||||
|
@@ -101,6 +101,11 @@ public class PhoneNumberPreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
|
||||
|
@@ -58,6 +58,11 @@ public class FirmwareVersionDetailPreferenceController extends BasePreferenceCon
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
|
@@ -55,6 +55,11 @@ public class SimpleBuildNumberPreferenceController extends BasePreferenceControl
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
|
||||
|
@@ -44,4 +44,9 @@ public class DeviceModelPreferenceController extends HardwareInfoPreferenceContr
|
||||
public CharSequence getSummary() {
|
||||
return HardwareInfoPreferenceController.getDeviceModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -34,6 +34,11 @@ public class HardwareRevisionPreferenceController extends BasePreferenceControll
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
|
@@ -45,6 +45,11 @@ public class SerialNumberPreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Sliceable.setCopyContent(mContext, getSummary(),
|
||||
|
@@ -110,6 +110,11 @@ public class ImeiInfoPreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Sliceable.setCopyContent(mContext, getSummary(), mContext.getText(R.string.status_imei));
|
||||
|
@@ -26,7 +26,6 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.accounts.AccountRestrictionHelper;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SliderPreferenceController;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
@@ -35,7 +34,7 @@ import com.android.settingslib.RestrictedPreference;
|
||||
* restriction
|
||||
*/
|
||||
public abstract class AdjustVolumeRestrictedPreferenceController extends
|
||||
SliderPreferenceController implements PreferenceControllerMixin {
|
||||
SliderPreferenceController {
|
||||
|
||||
private AccountRestrictionHelper mHelper;
|
||||
|
||||
|
@@ -22,8 +22,7 @@ import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class AlarmVolumePreferenceController extends
|
||||
VolumeSeekBarPreferenceController {
|
||||
public class AlarmVolumePreferenceController extends VolumeSeekBarPreferenceController {
|
||||
|
||||
private static final String KEY_ALARM_VOLUME = "alarm_volume";
|
||||
|
||||
@@ -42,6 +41,11 @@ public class AlarmVolumePreferenceController extends
|
||||
return TextUtils.equals(getPreferenceKey(), "alarm_volume");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_ALARM_VOLUME;
|
||||
|
@@ -43,6 +43,11 @@ public class CallVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
return TextUtils.equals(getPreferenceKey(), "call_volume");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioStream() {
|
||||
if (mAudioManager.isBluetoothScoOn()) {
|
||||
|
@@ -22,8 +22,7 @@ import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class MediaVolumePreferenceController extends
|
||||
VolumeSeekBarPreferenceController {
|
||||
public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceController {
|
||||
|
||||
private static final String KEY_MEDIA_VOLUME = "media_volume";
|
||||
|
||||
@@ -43,6 +42,11 @@ public class MediaVolumePreferenceController extends
|
||||
return TextUtils.equals(getPreferenceKey(), KEY_MEDIA_VOLUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_MEDIA_VOLUME;
|
||||
|
@@ -37,8 +37,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RemoteVolumePreferenceController extends
|
||||
VolumeSeekBarPreferenceController {
|
||||
public class RemoteVolumePreferenceController extends VolumeSeekBarPreferenceController {
|
||||
|
||||
private static final String KEY_REMOTE_VOLUME = "remote_volume";
|
||||
@VisibleForTesting
|
||||
@@ -167,6 +166,11 @@ public class RemoteVolumePreferenceController extends
|
||||
return TextUtils.equals(getPreferenceKey(), KEY_REMOTE_VOLUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_REMOTE_VOLUME;
|
||||
|
@@ -95,6 +95,11 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
return TextUtils.equals(getPreferenceKey(), KEY_RING_VOLUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioStream() {
|
||||
return AudioManager.STREAM_RING;
|
||||
|
@@ -207,7 +207,7 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
if (System.getProperty(SYSPROP_CRASH_ON_ERROR) != null) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Log.e(TAG, "Error trying to get non-indexable keys from: " + clazz.getName() , e);
|
||||
Log.e(TAG, "Error trying to get non-indexable keys from: " + clazz.getName(), e);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -188,8 +188,8 @@ public class SliceBuilderUtils {
|
||||
* @return the summary text for a {@link Slice} built for {@param sliceData}.
|
||||
*/
|
||||
public static CharSequence getSubtitleText(Context context,
|
||||
AbstractPreferenceController controller, SliceData sliceData) {
|
||||
final boolean isDynamicSummaryAllowed = sliceData.isDynamicSummaryAllowed();
|
||||
BasePreferenceController controller, SliceData sliceData) {
|
||||
final boolean isDynamicSummaryAllowed = controller.useDynamicSliceSummary();
|
||||
CharSequence summaryText = controller.getSummary();
|
||||
|
||||
// Priority 1 : User prefers showing the dynamic summary in slice view rather than static
|
||||
|
@@ -73,8 +73,6 @@ public class SliceData {
|
||||
|
||||
private final boolean mIsPlatformDefined;
|
||||
|
||||
private final boolean mIsDynamicSummaryAllowed;
|
||||
|
||||
private final String mUnavailableSliceSubtitle;
|
||||
|
||||
public String getKey() {
|
||||
@@ -121,10 +119,6 @@ public class SliceData {
|
||||
return mIsPlatformDefined;
|
||||
}
|
||||
|
||||
public boolean isDynamicSummaryAllowed() {
|
||||
return mIsDynamicSummaryAllowed;
|
||||
}
|
||||
|
||||
public String getUnavailableSliceSubtitle() {
|
||||
return mUnavailableSliceSubtitle;
|
||||
}
|
||||
@@ -141,7 +135,6 @@ public class SliceData {
|
||||
mPreferenceController = builder.mPrefControllerClassName;
|
||||
mSliceType = builder.mSliceType;
|
||||
mIsPlatformDefined = builder.mIsPlatformDefined;
|
||||
mIsDynamicSummaryAllowed = builder.mIsDynamicSummaryAllowed;
|
||||
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
||||
}
|
||||
|
||||
@@ -182,8 +175,6 @@ public class SliceData {
|
||||
|
||||
private boolean mIsPlatformDefined;
|
||||
|
||||
private boolean mIsDynamicSummaryAllowed;
|
||||
|
||||
private String mUnavailableSliceSubtitle;
|
||||
|
||||
public Builder setKey(String key) {
|
||||
@@ -241,11 +232,6 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDynamicSummaryAllowed(boolean isDynamicSummaryAllowed) {
|
||||
mIsDynamicSummaryAllowed = isDynamicSummaryAllowed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUnavailableSliceSubtitle(
|
||||
String unavailableSliceSubtitle) {
|
||||
mUnavailableSliceSubtitle = unavailableSliceSubtitle;
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
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;
|
||||
@@ -189,7 +188,6 @@ 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_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
@@ -207,8 +205,6 @@ 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 String unavailableSliceSubtitle = bundle.getString(
|
||||
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
@@ -222,7 +218,6 @@ class SliceDataConverter {
|
||||
.setFragmentName(fragmentName)
|
||||
.setSliceType(sliceType)
|
||||
.setPlatformDefined(isPlatformSlice)
|
||||
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.build();
|
||||
|
||||
|
@@ -78,6 +78,13 @@ public interface Sliceable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not summary comes from something dynamic (ie, not hardcoded in xml)
|
||||
*/
|
||||
default boolean useDynamicSliceSummary() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the copy content to the clipboard and show the toast.
|
||||
*/
|
||||
|
@@ -49,7 +49,6 @@ public class SlicesDatabaseAccessor {
|
||||
IndexColumns.CONTROLLER,
|
||||
IndexColumns.PLATFORM_SLICE,
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
};
|
||||
|
||||
@@ -166,8 +165,6 @@ 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));
|
||||
final String unavailableSliceSubtitle = cursor.getString(
|
||||
@@ -189,7 +186,6 @@ public class SlicesDatabaseAccessor {
|
||||
.setUri(uri)
|
||||
.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 = 4;
|
||||
private static final int DATABASE_VERSION = 5;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -94,12 +94,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
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";
|
||||
|
||||
/**
|
||||
* Customized subtitle if it's a unavailable slice
|
||||
*/
|
||||
@@ -129,8 +123,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
", " +
|
||||
IndexColumns.SLICE_TYPE +
|
||||
", " +
|
||||
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE +
|
||||
", " +
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
||||
");";
|
||||
|
||||
|
@@ -110,8 +110,6 @@ 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());
|
||||
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
dataRow.getUnavailableSliceSubtitle());
|
||||
|
||||
|
Reference in New Issue
Block a user