From 4a8d97041a08c5a6a639caf821388c39546a7d1b Mon Sep 17 00:00:00 2001 From: Majid Valipour Date: Sat, 31 Jan 2015 16:33:52 -0500 Subject: [PATCH] Minor cleanup --- .../ca/zgrs/clipper/ClipboardService.java | 27 +++++++++---------- .../java/ca/zgrs/clipper/ClipperReceiver.java | 22 +++++---------- src/main/java/ca/zgrs/clipper/Main.java | 2 +- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/main/java/ca/zgrs/clipper/ClipboardService.java b/src/main/java/ca/zgrs/clipper/ClipboardService.java index 5dad6e1..b6a2f0f 100644 --- a/src/main/java/ca/zgrs/clipper/ClipboardService.java +++ b/src/main/java/ca/zgrs/clipper/ClipboardService.java @@ -1,18 +1,16 @@ package ca.zgrs.clipper; -import android.text.ClipboardManager; import android.app.IntentService; import android.content.Intent; import android.util.Log; public class ClipboardService extends IntentService { - private static String TAG = "ClipboardService"; + private static String TAG = "ClipboardService"; - - public ClipboardService() { - super("ClipboardService"); - } + public ClipboardService() { + super("ClipboardService"); + } /* Define service as sticky so that it stays in background */ @Override @@ -24,16 +22,17 @@ public int onStartCommand(Intent intent, int flags, int startId) { @Override public void onCreate() { super.onCreate(); - //start itself to ensure our broadcast receiver is active + // start itself to ensure our broadcast receiver is active Log.d(TAG, "Start clipboard service."); - startService(new Intent(getApplicationContext(),ClipboardService.class)); + startService(new Intent(getApplicationContext(), ClipboardService.class)); } /** - * The IntentService calls this method from the default worker thread with - * the intent that started the service. When this method returns, IntentService - * stops the service, as appropriate. - */ - @Override - protected void onHandleIntent(Intent intent) {} + * The IntentService calls this method from the default worker thread with + * the intent that started the service. When this method returns, IntentService + * stops the service, as appropriate. + */ + @Override + protected void onHandleIntent(Intent intent) { + } } \ No newline at end of file diff --git a/src/main/java/ca/zgrs/clipper/ClipperReceiver.java b/src/main/java/ca/zgrs/clipper/ClipperReceiver.java index 2ca99af..d833cf8 100644 --- a/src/main/java/ca/zgrs/clipper/ClipperReceiver.java +++ b/src/main/java/ca/zgrs/clipper/ClipperReceiver.java @@ -13,13 +13,12 @@ * The broadcast receiver is active only as long as the application, or its service is active. */ public class ClipperReceiver extends BroadcastReceiver { - private static String TAG = "ClipboardReceiver"; + private static String TAG = "ClipboardReceiver"; public static String ACTION_GET = "clipper.get"; public static String ACTION_GET_SHORT = "get"; public static String ACTION_SET = "clipper.set"; public static String ACTION_SET_SHORT = "set"; - public static String EXTRA_TEXT = "text"; public static boolean isActionGet(final String action) { @@ -30,13 +29,8 @@ public static boolean isActionSet(final String action) { return ACTION_SET.equals(action) || ACTION_SET_SHORT.equals(action); } - @Override public void onReceive(Context context, Intent intent) { - Log.d(TAG, "Inside broadcast handler!"); - - Log.d(TAG, String.format("Action: %s", intent.getAction())); - ClipboardManager cb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (isActionSet(intent.getAction())) { Log.d(TAG, "Setting text into clipboard"); @@ -44,24 +38,22 @@ public void onReceive(Context context, Intent intent) { if (text != null) { cb.setText(text); setResultCode(Activity.RESULT_OK); - setResultData("Text is copied in clipboard."); + setResultData("Text is copied into clipboard."); } else { setResultCode(Activity.RESULT_CANCELED); - setResultData("No text was provided. Use -e text \"text to be pasted\""); + setResultData("No text is provided. Use -e text \"text to be pasted\""); } } else if (isActionGet(intent.getAction())) { Log.d(TAG, "Getting text from clipboard"); - CharSequence clip = cb.getText(); + CharSequence clip = cb.getText(); if (clip != null) { - Log.d(TAG, String.format(" dd Clipboard text: %s", clip)); + Log.d(TAG, String.format("Clipboard text: %s", clip)); setResultCode(Activity.RESULT_OK); setResultData(clip.toString()); } else { setResultCode(Activity.RESULT_CANCELED); - setResultData("Clipboard is empty."); + setResultData(""); } - } + } } - //android.intent.action.PACKAGE_ADDED - } \ No newline at end of file diff --git a/src/main/java/ca/zgrs/clipper/Main.java b/src/main/java/ca/zgrs/clipper/Main.java index fe81a8c..cb7aef6 100644 --- a/src/main/java/ca/zgrs/clipper/Main.java +++ b/src/main/java/ca/zgrs/clipper/Main.java @@ -12,7 +12,7 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.main); - //start clipboard service + // start clipboard service Intent serviceIntent = new Intent(this, ClipboardService.class); startService(serviceIntent); }