Merge Copyable into Sliceable.
It's only a slice concept. Regular preference copyability is handled in xml. Bug: 112427717 Test: rebuild Change-Id: Iaba7077c320cd03a5963797916a60e0dc80fdbbe
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Provide the copy ability for preference controller to copy the data to the clipboard.
|
||||
*/
|
||||
public interface Copyable {
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Set the copy content to the clipboard and show the toast.
|
||||
*/
|
||||
static void setCopyContent(Context context, CharSequence copyContent,
|
||||
CharSequence messageTitle) {
|
||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(
|
||||
CLIPBOARD_SERVICE);
|
||||
final ClipData clip = ClipData.newPlainText("text", copyContent);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
|
||||
final String toast = context.getString(R.string.copyable_slice_toast, messageTitle);
|
||||
Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
final BasePreferenceController controller = getPreferenceController(context, key);
|
||||
|
||||
if (!(controller instanceof Copyable)) {
|
||||
if (!(controller instanceof Sliceable)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Copyable action passed for a non-copyable key:" + key);
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
((Copyable) controller).copy();
|
||||
((Sliceable) controller).copy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,7 +93,7 @@ public class SliceBuilderUtils {
|
||||
return buildUnavailableSlice(context, sliceData);
|
||||
}
|
||||
|
||||
if (controller instanceof Copyable) {
|
||||
if (controller.isCopyableSlice()) {
|
||||
return buildCopyableSlice(context, sliceData, controller);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,15 @@
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* A collection of API making a PreferenceController "sliceable"
|
||||
@@ -55,4 +63,32 @@ public interface Sliceable {
|
||||
default boolean hasAsyncUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the key slice information to the clipboard.
|
||||
* It is highly recommended to show the toast to notify users when implemented this function.
|
||||
*/
|
||||
default void copy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not it's a copyable slice.
|
||||
*/
|
||||
default boolean isCopyableSlice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the copy content to the clipboard and show the toast.
|
||||
*/
|
||||
static void setCopyContent(Context context, CharSequence copyContent,
|
||||
CharSequence messageTitle) {
|
||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(
|
||||
CLIPBOARD_SERVICE);
|
||||
final ClipData clip = ClipData.newPlainText("text", copyContent);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
|
||||
final String toast = context.getString(R.string.copyable_slice_toast, messageTitle);
|
||||
Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user