mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Added helper class to use the most recent ClipboardManager
This commit is contained in:
parent
240f7ea9ac
commit
1d25d2ff40
63
src/com/fsck/k9/helper/ClipboardManager.java
Normal file
63
src/com/fsck/k9/helper/ClipboardManager.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.fsck.k9.helper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
|
||||
/**
|
||||
* Helper class to access the system clipboard
|
||||
*
|
||||
* @see ClipboardManagerApi1
|
||||
* @see ClipboardManagerApi11
|
||||
*/
|
||||
public abstract class ClipboardManager {
|
||||
/**
|
||||
* Instance of the API-specific class that interfaces with the clipboard API.
|
||||
*/
|
||||
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) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
|
||||
if (sInstance == null) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
sInstance = new ClipboardManagerApi1(appContext);
|
||||
} else {
|
||||
sInstance = new ClipboardManagerApi11(appContext);
|
||||
}
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
protected Context mContext;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* A {@link Context} instance.
|
||||
*/
|
||||
protected ClipboardManager(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a text string to the system clipboard
|
||||
*
|
||||
* @param label
|
||||
* User-visible label for the content.
|
||||
* @param text
|
||||
* The actual text to be copied to the clipboard.
|
||||
*/
|
||||
public abstract void setText(String label, String text);
|
||||
}
|
22
src/com/fsck/k9/helper/ClipboardManagerApi1.java
Normal file
22
src/com/fsck/k9/helper/ClipboardManagerApi1.java
Normal file
@ -0,0 +1,22 @@
|
||||
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);
|
||||
}
|
||||
}
|
23
src/com/fsck/k9/helper/ClipboardManagerApi11.java
Normal file
23
src/com/fsck/k9/helper/ClipboardManagerApi11.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.fsck.k9.helper;
|
||||
|
||||
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
|
||||
*/
|
||||
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