Rework the key insertion logic

Bug: 21495243

This changes the behavior to be much more compatible with L.

We generally do not allow consecutive binary operators to be inserted.
In the case of a minus operator however, the logic is more complicated.
We do allow a minus after multiplication, division and power.
When the minus is explicitly entered, so the user sees our corrections,
we do not allow a minus after additive operators.  In pasted text,
we do.

We no longer reject additions that would result in implicit
multiplications.  We do immediately reject binary operators in leading
contexts, e.g. after a left parenthesis, in which they must result in
a syntax error.

Change-Id: I1d35d74335371f6f113808d68a4f293b699d9bd0
diff --git a/src/com/android/calculator2/KeyMaps.java b/src/com/android/calculator2/KeyMaps.java
index 5385424..c28e80d 100644
--- a/src/com/android/calculator2/KeyMaps.java
+++ b/src/com/android/calculator2/KeyMaps.java
@@ -132,6 +132,41 @@
     }
 
     /**
+     * Does a button id correspond to a function that introduces an implicit lparen?
+     * Pure function.
+     */
+    public static boolean isFunc(int id) {
+        switch(id) {
+            case R.id.fun_sin:
+            case R.id.fun_cos:
+            case R.id.fun_tan:
+            case R.id.fun_arcsin:
+            case R.id.fun_arccos:
+            case R.id.fun_arctan:
+            case R.id.fun_ln:
+            case R.id.fun_log:
+            case R.id.fun_exp:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    /**
+     * Does a button id correspond to a prefix operator?
+     * Pure function.
+     */
+    public static boolean isPrefix(int id) {
+        switch(id) {
+            case R.id.op_sqrt:
+            case R.id.op_sub:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    /**
      * Does a button id correspond to a suffix operator?
      */
     public static boolean isSuffix(int id) {