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:
@@ -42,7 +42,6 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.slices.Copyable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -50,7 +49,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
|
||||
public class BuildNumberPreferenceController extends BasePreferenceController implements Copyable,
|
||||
public class BuildNumberPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart {
|
||||
|
||||
static final int TAPS_TO_BE_A_DEVELOPER = 7;
|
||||
@@ -108,6 +107,11 @@ public class BuildNumberPreferenceController extends BasePreferenceController im
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyableSlice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
|
||||
|
@@ -35,14 +35,12 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Copyable;
|
||||
import com.android.settingslib.DeviceInfoUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PhoneNumberPreferenceController extends BasePreferenceController implements
|
||||
Copyable {
|
||||
public class PhoneNumberPreferenceController extends BasePreferenceController {
|
||||
|
||||
private final static String KEY_PHONE_NUMBER = "phone_number";
|
||||
|
||||
@@ -98,6 +96,11 @@ public class PhoneNumberPreferenceController extends BasePreferenceController im
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyableSlice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
|
||||
|
@@ -31,12 +31,11 @@ import androidx.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Copyable;
|
||||
import com.android.settings.slices.Sliceable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
|
||||
public class FirmwareVersionDetailPreferenceController extends BasePreferenceController implements
|
||||
Copyable {
|
||||
public class FirmwareVersionDetailPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "firmwareDialogCtrl";
|
||||
private static final int DELAY_TIMER_MILLIS = 500;
|
||||
@@ -119,7 +118,7 @@ public class FirmwareVersionDetailPreferenceController extends BasePreferenceCon
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Copyable.setCopyContent(mContext, getSummary(),
|
||||
Sliceable.setCopyContent(mContext, getSummary(),
|
||||
mContext.getText(R.string.firmware_version));
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Copyable;
|
||||
import com.android.settings.slices.Sliceable;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -38,7 +38,7 @@ import java.util.List;
|
||||
/**
|
||||
* Controller that manages preference for single and multi sim devices.
|
||||
*/
|
||||
public class ImeiInfoPreferenceController extends BasePreferenceController implements Copyable {
|
||||
public class ImeiInfoPreferenceController extends BasePreferenceController {
|
||||
|
||||
private final boolean mIsMultiSim;
|
||||
private final TelephonyManager mTelephonyManager;
|
||||
@@ -105,9 +105,14 @@ public class ImeiInfoPreferenceController extends BasePreferenceController imple
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyableSlice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Copyable.setCopyContent(mContext, getSummary(), mContext.getText(R.string.status_imei));
|
||||
Sliceable.setCopyContent(mContext, getSummary(), mContext.getText(R.string.status_imei));
|
||||
}
|
||||
|
||||
private void updatePreference(Preference preference, int simSlot) {
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -19,9 +19,8 @@ package com.android.settings.testutils;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Copyable;
|
||||
|
||||
public class FakeCopyableController extends BasePreferenceController implements Copyable {
|
||||
public class FakeCopyableController extends BasePreferenceController {
|
||||
|
||||
public FakeCopyableController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
@@ -38,6 +37,7 @@ public class FakeCopyableController extends BasePreferenceController implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
public boolean isCopyableSlice() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user