summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorJustin Klaassen <justinklaassen@google.com>2014-08-27 10:56:49 -0700
committerJustin Klaassen <justinklaassen@google.com>2014-08-27 12:33:20 -0700
commitbfc4e4d88011b33b4cf142a89b9125bd07393ab5 (patch)
tree4c680b0750f8d7ca8b9c1b9be13cedff41847510 /src/com/android
parentf79d6f699b04a735e1627b47a059760ff40c26b9 (diff)
downloadandroid_packages_apps_ExactCalculator-bfc4e4d88011b33b4cf142a89b9125bd07393ab5.tar.gz
android_packages_apps_ExactCalculator-bfc4e4d88011b33b4cf142a89b9125bd07393ab5.tar.bz2
android_packages_apps_ExactCalculator-bfc4e4d88011b33b4cf142a89b9125bd07393ab5.zip
Improve hardware keyboard support
Bug: 17188394 - Ensure cursor is always at end of the current expression. - Allow the delete key to be handled by the EditText fixing an issue where delete would occur twice on keyUp and keyDown. - Prevent text freezing in onSaveInstanceState so that text can be restored at the Activity level. Change-Id: Ie20a7f88b9c43223ae840a1191361de7f1e35127
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/calculator2/Calculator.java3
-rw-r--r--src/com/android/calculator2/CalculatorEditText.java22
2 files changed, 19 insertions, 6 deletions
diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java
index 83a9bb9..dc606c9 100644
--- a/src/com/android/calculator2/Calculator.java
+++ b/src/com/android/calculator2/Calculator.java
@@ -91,9 +91,6 @@ public class Calculator extends Activity
}
// ignore all other actions
return true;
- case KeyEvent.KEYCODE_DEL:
- onDelete();
- return true;
}
return false;
}
diff --git a/src/com/android/calculator2/CalculatorEditText.java b/src/com/android/calculator2/CalculatorEditText.java
index 746b6f5..5a0d8ba 100644
--- a/src/com/android/calculator2/CalculatorEditText.java
+++ b/src/com/android/calculator2/CalculatorEditText.java
@@ -21,6 +21,7 @@ import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.Rect;
+import android.os.Parcelable;
import android.text.method.ScrollingMovementMethod;
import android.text.TextPaint;
import android.util.AttributeSet;
@@ -34,7 +35,8 @@ import android.widget.TextView;
public class CalculatorEditText extends EditText {
- private final ActionMode.Callback mNoSelectionActionModeCallback = new ActionMode.Callback() {
+ private final static ActionMode.Callback NO_SELECTION_ACTION_MODE_CALLBACK =
+ new ActionMode.Callback() {
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
@@ -89,8 +91,7 @@ public class CalculatorEditText extends EditText {
a.recycle();
- setCustomSelectionActionModeCallback(mNoSelectionActionModeCallback);
-
+ setCustomSelectionActionModeCallback(NO_SELECTION_ACTION_MODE_CALLBACK);
if (isFocusable()) {
setMovementMethod(ScrollingMovementMethod.getInstance());
}
@@ -117,8 +118,23 @@ public class CalculatorEditText extends EditText {
}
@Override
+ public Parcelable onSaveInstanceState() {
+ super.onSaveInstanceState();
+
+ // EditText will freeze any text with a selection regardless of getFreezesText() ->
+ // return null to prevent any state from being preserved at the instance level.
+ return null;
+ }
+
+ @Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
+
+ final int textLength = text.length();
+ if (getSelectionStart() != textLength || getSelectionEnd() != textLength) {
+ // Pin the selection to the end of the current text.
+ setSelection(textLength);
+ }
setTextSize(TypedValue.COMPLEX_UNIT_PX, getVariableTextSize(text.toString()));
}