am bfc4e4d8: Improve hardware keyboard support

* commit 'bfc4e4d88011b33b4cf142a89b9125bd07393ab5':
  Improve hardware keyboard support
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 @@
                     }
                     // 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.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 @@
 
 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 @@
 
         a.recycle();
 
-        setCustomSelectionActionModeCallback(mNoSelectionActionModeCallback);
-
+        setCustomSelectionActionModeCallback(NO_SELECTION_ACTION_MODE_CALLBACK);
         if (isFocusable()) {
             setMovementMethod(ScrollingMovementMethod.getInstance());
         }
@@ -117,8 +118,23 @@
     }
 
     @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()));
     }