Implement the Copyable interface to FirmwareVersionPreferenceController
Copy the device version number to clipboard for Copyable. Change-Id: Ibb687be442dd702c1197c7e8295fac5b914a7047 Fixes: 121463656 Test: manual and robotests
This commit is contained in:
@@ -23,9 +23,12 @@ import android.text.TextUtils;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.slices.Copyable;
|
||||||
|
|
||||||
public class FirmwareVersionPreferenceController extends BasePreferenceController {
|
public class FirmwareVersionPreferenceController extends BasePreferenceController implements
|
||||||
|
Copyable {
|
||||||
|
|
||||||
private Fragment mFragment;
|
private Fragment mFragment;
|
||||||
|
|
||||||
@@ -61,4 +64,10 @@ public class FirmwareVersionPreferenceController extends BasePreferenceControlle
|
|||||||
public boolean isSliceable() {
|
public boolean isSliceable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy() {
|
||||||
|
Copyable.setCopyContent(mContext, getSummary(),
|
||||||
|
mContext.getText(R.string.firmware_version));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.slices;
|
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.
|
* Provide the copy ability for preference controller to copy the data to the clipboard.
|
||||||
*/
|
*/
|
||||||
@@ -25,4 +34,18 @@ public interface Copyable {
|
|||||||
* It is highly recommended to show the toast to notify users when implemented this function.
|
* It is highly recommended to show the toast to notify users when implemented this function.
|
||||||
*/
|
*/
|
||||||
void copy();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.deviceinfo.firmwareversion;
|
package com.android.settings.deviceinfo.firmwareversion;
|
||||||
|
|
||||||
|
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
@@ -108,6 +111,17 @@ public class FirmwareVersionPreferenceControllerTest {
|
|||||||
assertThat(mController.isSliceable()).isTrue();
|
assertThat(mController.isSliceable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void copy_shouldCopyVersionNumberToClipboard() {
|
||||||
|
mController.copy();
|
||||||
|
|
||||||
|
final Context context = RuntimeEnvironment.application;
|
||||||
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(
|
||||||
|
CLIPBOARD_SERVICE);
|
||||||
|
final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText();
|
||||||
|
assertThat(data.toString()).isEqualTo(Build.VERSION.RELEASE);
|
||||||
|
}
|
||||||
|
|
||||||
@Implements(FirmwareVersionDialogFragment.class)
|
@Implements(FirmwareVersionDialogFragment.class)
|
||||||
public static class ShadowFirmwareVersionDialogFragment {
|
public static class ShadowFirmwareVersionDialogFragment {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user