Loading res/drawable/ic_content_copy_grey600_24dp.xml 0 → 100644 +9 −0 Original line number Diff line number Diff line <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> <path android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z" android:fillColor="#757575"/> </vector> src/com/android/settings/slices/CopyableSlice.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * 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(); } src/com/android/settings/slices/SettingsSliceProvider.java +6 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading src/com/android/settings/slices/SliceBroadcastReceiver.java +27 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } } Loading Loading @@ -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. Loading src/com/android/settings/slices/SliceBuilderUtils.java +34 −0 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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 { Loading @@ -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; Loading Loading
res/drawable/ic_content_copy_grey600_24dp.xml 0 → 100644 +9 −0 Original line number Diff line number Diff line <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> <path android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z" android:fillColor="#757575"/> </vector>
src/com/android/settings/slices/CopyableSlice.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * 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(); }
src/com/android/settings/slices/SettingsSliceProvider.java +6 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading
src/com/android/settings/slices/SliceBroadcastReceiver.java +27 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } } Loading Loading @@ -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. Loading
src/com/android/settings/slices/SliceBuilderUtils.java +34 −0 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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 { Loading @@ -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; Loading