From 786511ed88dbbd52b6f151a84a7e2f70219a9464 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Sat, 16 Aug 2014 20:24:54 -0400 Subject: [PATCH] Simplify ClipboardManager No longer API dependent. --- src/com/fsck/k9/helper/ClipboardManager.java | 34 ++++++------------- .../fsck/k9/helper/ClipboardManagerApi1.java | 22 ------------ .../fsck/k9/helper/ClipboardManagerApi11.java | 25 -------------- 3 files changed, 11 insertions(+), 70 deletions(-) delete mode 100644 src/com/fsck/k9/helper/ClipboardManagerApi1.java delete mode 100644 src/com/fsck/k9/helper/ClipboardManagerApi11.java diff --git a/src/com/fsck/k9/helper/ClipboardManager.java b/src/com/fsck/k9/helper/ClipboardManager.java index 7751b3b89..c60b6f62a 100644 --- a/src/com/fsck/k9/helper/ClipboardManager.java +++ b/src/com/fsck/k9/helper/ClipboardManager.java @@ -1,38 +1,21 @@ package com.fsck.k9.helper; +import android.content.ClipData; import android.content.Context; -import android.os.Build; /** - * Helper class to access the system clipboard - * - * @see ClipboardManagerApi1 - * @see ClipboardManagerApi11 + * Access the system clipboard using the new {@link ClipboardManager} introduced with API 11 */ -public abstract class ClipboardManager { - /** - * Instance of the API-specific class that interfaces with the clipboard API. - */ +public class ClipboardManager { + 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); - } + sInstance = new ClipboardManager(appContext); } return sInstance; @@ -59,5 +42,10 @@ public abstract class ClipboardManager { * @param text * 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); + } } diff --git a/src/com/fsck/k9/helper/ClipboardManagerApi1.java b/src/com/fsck/k9/helper/ClipboardManagerApi1.java deleted file mode 100644 index 80bfe714c..000000000 --- a/src/com/fsck/k9/helper/ClipboardManagerApi1.java +++ /dev/null @@ -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); - } -} diff --git a/src/com/fsck/k9/helper/ClipboardManagerApi11.java b/src/com/fsck/k9/helper/ClipboardManagerApi11.java deleted file mode 100644 index 5c142b9b4..000000000 --- a/src/com/fsck/k9/helper/ClipboardManagerApi11.java +++ /dev/null @@ -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); - } -}