From 775a4b11bf8d95b8f4dd00477808fbd8b871e62e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 19 Jun 2016 13:22:15 +0200 Subject: [PATCH] do not allow copying empty value to clipboard --- .../calculator/activities/MainActivity.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/calculator/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/calculator/activities/MainActivity.java index 71d52a7..ff98d83 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/calculator/activities/MainActivity.java @@ -132,26 +132,28 @@ public class MainActivity extends AppCompatActivity implements Calculator { @OnLongClick(R.id.formula) public boolean formulaLongPressed() { - copyToClipboard(false); - return true; + return copyToClipboard(false); } @OnLongClick(R.id.result) public boolean resultLongPressed() { - copyToClipboard(true); - return true; + return copyToClipboard(true); } - private void copyToClipboard(boolean copyResult) { - String value = mFormula.getText().toString(); + private boolean copyToClipboard(boolean copyResult) { + String value = mFormula.getText().toString().trim(); if (copyResult) { - value = mResult.getText().toString(); + value = mResult.getText().toString().trim(); } + if (value.isEmpty()) + return false; + final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); final ClipData clip = ClipData.newPlainText(getResources().getString(R.string.app_name), value); clipboard.setPrimaryClip(clip); Utils.showToast(getApplicationContext(), R.string.copied_to_clipboard); + return true; } @Override