From 1176f23dae4d3740782e46463003e9f36a381c9d Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Mon, 11 May 2015 16:26:03 -0700 Subject: Improve copy/paste handling, minor instant result fixes Bug: 20764417 Bug: 20838790 Finish the action mode when we do almost anything else. We should probably be even more aggressive about terminating it, and we may eventually want to use a different approach. But this avoids the crashes, and greatly improves the behavior. Display copy menu only when there is something to copy. Fix a couple of bugs introduced by recent instant display overhaul (one line each): - Instant display disappeared on rotation. - It was sometimes still possible to scroll the previous result after CLR. Change-Id: I1a91d312358898add1e281aaba116d709b4c92a7 --- src/com/android/calculator2/Calculator.java | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/com/android/calculator2/Calculator.java') diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java index dd6c541..d5242fa 100644 --- a/src/com/android/calculator2/Calculator.java +++ b/src/com/android/calculator2/Calculator.java @@ -122,6 +122,7 @@ public class Calculator extends Activity @Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if (keyEvent.getAction() != KeyEvent.ACTION_UP) return true; + stopActionMode(); switch (keyCode) { case KeyEvent.KEYCODE_NUMPAD_ENTER: case KeyEvent.KEYCODE_ENTER: @@ -311,15 +312,28 @@ public class Calculator extends Activity } } + // Stop any active ActionMode. Return true if there was one. + private boolean stopActionMode() { + if (mResult.stopActionMode()) { + return true; + } + if (mFormulaText.stopActionMode()) { + return true; + } + return false; + } + @Override public void onBackPressed() { - if (mPadViewPager == null || mPadViewPager.getCurrentItem() == 0) { - // If the user is currently looking at the first pad (or the pad is not paged), - // allow the system to handle the Back button. - super.onBackPressed(); - } else { - // Otherwise, select the previous pad. - mPadViewPager.setCurrentItem(mPadViewPager.getCurrentItem() - 1); + if (!stopActionMode()) { + if (mPadViewPager != null && mPadViewPager.getCurrentItem() != 0) { + // Select the previous pad. + mPadViewPager.setCurrentItem(mPadViewPager.getCurrentItem() - 1); + } else { + // If the user is currently looking at the first pad (or the pad is not paged), + // allow the system to handle the Back button. + super.onBackPressed(); + } } } @@ -380,6 +394,7 @@ public class Calculator extends Activity public void onButtonClick(View view) { mCurrentButton = view; + stopActionMode(); // Always cancel in-progress evaluation. // If we were waiting for the result, do nothing else. -- cgit v1.2.3