mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Simplify ClipboardManager
No longer API dependent.
This commit is contained in:
parent
028f6f9055
commit
786511ed88
@ -1,38 +1,21 @@
|
|||||||
package com.fsck.k9.helper;
|
package com.fsck.k9.helper;
|
||||||
|
|
||||||
|
import android.content.ClipData;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to access the system clipboard
|
* Access the system clipboard using the new {@link ClipboardManager} introduced with API 11
|
||||||
*
|
|
||||||
* @see ClipboardManagerApi1
|
|
||||||
* @see ClipboardManagerApi11
|
|
||||||
*/
|
*/
|
||||||
public abstract class ClipboardManager {
|
public class ClipboardManager {
|
||||||
/**
|
|
||||||
* Instance of the API-specific class that interfaces with the clipboard API.
|
|
||||||
*/
|
|
||||||
private static ClipboardManager sInstance = null;
|
private static ClipboardManager sInstance = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get API-specific instance of the {@code ClipboardManager} class
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* A {@link Context} instance.
|
|
||||||
*
|
|
||||||
* @return Appropriate {@link ClipboardManager} instance for this device.
|
|
||||||
*/
|
|
||||||
public static ClipboardManager getInstance(Context context) {
|
public static ClipboardManager getInstance(Context context) {
|
||||||
Context appContext = context.getApplicationContext();
|
Context appContext = context.getApplicationContext();
|
||||||
|
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
sInstance = new ClipboardManager(appContext);
|
||||||
sInstance = new ClipboardManagerApi1(appContext);
|
|
||||||
} else {
|
|
||||||
sInstance = new ClipboardManagerApi11(appContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sInstance;
|
return sInstance;
|
||||||
@ -59,5 +42,10 @@ public abstract class ClipboardManager {
|
|||||||
* @param text
|
* @param text
|
||||||
* The actual text to be copied to the clipboard.
|
* The actual text to be copied to the clipboard.
|
||||||
*/
|
*/
|
||||||
public abstract void setText(String label, String text);
|
public void setText(String label, String text) {
|
||||||
|
android.content.ClipboardManager clipboardManager =
|
||||||
|
(android.content.ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = ClipData.newPlainText(label, text);
|
||||||
|
clipboardManager.setPrimaryClip(clip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package com.fsck.k9.helper;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.ClipboardManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access the system clipboard using the now deprecated {@link ClipboardManager}
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class ClipboardManagerApi1 extends com.fsck.k9.helper.ClipboardManager {
|
|
||||||
|
|
||||||
public ClipboardManagerApi1(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setText(String label, String text) {
|
|
||||||
ClipboardManager clipboardManager =
|
|
||||||
(ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
clipboardManager.setText(text);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package com.fsck.k9.helper;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.ClipData;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.ClipboardManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access the system clipboard using the new {@link ClipboardManager} introduced with API 11
|
|
||||||
*/
|
|
||||||
@TargetApi(11)
|
|
||||||
public class ClipboardManagerApi11 extends com.fsck.k9.helper.ClipboardManager {
|
|
||||||
|
|
||||||
public ClipboardManagerApi11(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setText(String label, String text) {
|
|
||||||
ClipboardManager clipboardManager =
|
|
||||||
(ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
ClipData clip = ClipData.newPlainText(label, text);
|
|
||||||
clipboardManager.setPrimaryClip(clip);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user