Architecture review of Copyable Slice
Design doc: https://drive.google.com/open?id=1NJPd_282H4195HUGJH5cGJO_Jrcz1Vl6AAw_VQOtGq0 Fixes: 118398321 Test: manual Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.slice Change-Id: Ic6762e58698a994d16a5de1778b4035ae430a256
This commit is contained in:
28
src/com/android/settings/slices/CopyableSlice.java
Normal file
28
src/com/android/settings/slices/CopyableSlice.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
/**
|
||||
* Provide the copy ability for preference controller to copy the data to the clipboard.
|
||||
*/
|
||||
public interface CopyableSlice {
|
||||
/**
|
||||
* Copy the key slice information to the clipboard.
|
||||
* It is highly recommended to show the toast to notify users when implemented this function.
|
||||
*/
|
||||
void copy();
|
||||
}
|
@@ -106,6 +106,12 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
public static final String ACTION_SLIDER_CHANGED =
|
||||
"com.android.settings.slice.action.SLIDER_CHANGED";
|
||||
|
||||
/**
|
||||
* Action passed for copy data for the Copyable Slices.
|
||||
*/
|
||||
public static final String ACTION_COPY =
|
||||
"com.android.settings.slice.action.COPY";
|
||||
|
||||
/**
|
||||
* Intent Extra passed for the key identifying the Setting Slice.
|
||||
*/
|
||||
@@ -509,4 +515,4 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import static com.android.settings.network.telephony.Enhanced4gLteSliceHelper
|
||||
import static com.android.settings.notification.ZenModeSliceBuilder.ACTION_ZEN_MODE_SLICE_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_SLIDER_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_TOGGLE_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_COPY;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_PLATFORM_DEFINED;
|
||||
import static com.android.settings.wifi.calling.WifiCallingSliceHelper.ACTION_WIFI_CALLING_CHANGED;
|
||||
@@ -115,6 +116,9 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
case ACTION_FLASHLIGHT_SLICE_CHANGED:
|
||||
FlashlightSliceBuilder.handleUriChange(context, intent);
|
||||
break;
|
||||
case ACTION_COPY:
|
||||
handleCopyAction(context, key, isPlatformSlice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +188,29 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
}
|
||||
|
||||
private void handleCopyAction(Context context, String key, boolean isPlatformSlice) {
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalArgumentException("No key passed to Intent for controller");
|
||||
}
|
||||
|
||||
final BasePreferenceController controller = getPreferenceController(context, key);
|
||||
|
||||
if (!(controller instanceof CopyableSlice)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Copyable action passed for a non-copyable key:" + key);
|
||||
}
|
||||
|
||||
if (!controller.isAvailable()) {
|
||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||
if (!controller.hasAsyncUpdate()) {
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
((CopyableSlice) controller).copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log Slice value update events into MetricsFeatureProvider. The logging schema generally
|
||||
* follows the pattern in SharedPreferenceLogger.
|
||||
|
@@ -93,6 +93,10 @@ public class SliceBuilderUtils {
|
||||
return buildUnavailableSlice(context, sliceData);
|
||||
}
|
||||
|
||||
if (controller instanceof CopyableSlice) {
|
||||
return buildCopyableSlice(context, sliceData, controller);
|
||||
}
|
||||
|
||||
switch (sliceData.getSliceType()) {
|
||||
case SliceData.SliceType.INTENT:
|
||||
return buildIntentSlice(context, sliceData, controller);
|
||||
@@ -324,6 +328,28 @@ public class SliceBuilderUtils {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Slice buildCopyableSlice(Context context, SliceData sliceData,
|
||||
BasePreferenceController controller) {
|
||||
final SliceAction copyableAction = getCopyableAction(context, sliceData);
|
||||
final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
|
||||
final IconCompat icon = getSafeIcon(context, sliceData);
|
||||
final SliceAction primaryAction = new SliceAction(contentIntent, icon,
|
||||
sliceData.getTitle());
|
||||
final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
|
||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(context);
|
||||
final Set<String> keywords = buildSliceKeywords(sliceData);
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(color)
|
||||
.addRow(new RowBuilder()
|
||||
.setTitle(sliceData.getTitle())
|
||||
.setSubtitle(subtitleText)
|
||||
.setPrimaryAction(primaryAction)
|
||||
.addEndItem(copyableAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static BasePreferenceController getPreferenceController(Context context,
|
||||
String controllerClassName, String controllerKey) {
|
||||
try {
|
||||
@@ -346,6 +372,14 @@ public class SliceBuilderUtils {
|
||||
return getActionIntent(context, SettingsSliceProvider.ACTION_SLIDER_CHANGED, sliceData);
|
||||
}
|
||||
|
||||
private static SliceAction getCopyableAction(Context context, SliceData sliceData) {
|
||||
final PendingIntent intent = getActionIntent(context,
|
||||
SettingsSliceProvider.ACTION_COPY, sliceData);
|
||||
final IconCompat icon = IconCompat.createWithResource(context,
|
||||
R.drawable.ic_content_copy_grey600_24dp);
|
||||
return new SliceAction(intent, icon, sliceData.getTitle());
|
||||
}
|
||||
|
||||
private static boolean isValidSummary(Context context, CharSequence summary) {
|
||||
if (summary == null || TextUtils.isEmpty(summary.toString().trim())) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user