Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

disable keys in bin/dec

  • Loading branch information...
commit b1dc0f656e3ab0e6026df413e9f0392e811f53b4 1 parent bf170bb
Will authored
4 AndroidManifest.xml
View
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android2.calculator3"
- android:versionCode="24"
- android:versionName="2.0"
+ android:versionCode="25"
+ android:versionName="2.1"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="16"/>
20 res/layout-port/advanced_pad.xml
View
@@ -69,8 +69,8 @@
style="@style/button_small_style"
/>
<com.android2.calculator3.ColorButton
- android:id="@+id/factorial"
- android:text="@string/factorial"
+ android:id="@+id/power"
+ android:text="@string/power"
style="@style/button_style"
/>
<com.android2.calculator3.ColorButton
@@ -96,14 +96,14 @@
style="@style/button_style"
/>
<com.android2.calculator3.ColorButton
- android:id="@+id/power"
- android:text="@string/power"
+ android:id="@+id/factorial"
+ android:text="@string/factorial"
style="@style/button_style"
/>
<com.android2.calculator3.ColorButton
- android:id="@+id/X"
- android:text="@string/X"
- style="@style/digit_button_style"
+ android:id="@+id/sqrt"
+ android:text="@string/sqrt"
+ style="@style/button_style"
/>
</LinearLayout>
@@ -123,9 +123,9 @@
style="@style/button_style"
/>
<com.android2.calculator3.ColorButton
- android:id="@+id/sqrt"
- android:text="@string/sqrt"
- style="@style/button_style"
+ android:id="@+id/X"
+ android:text="@string/X"
+ style="@style/digit_button_style"
/>
<com.android2.calculator3.ColorButton
android:id="@+id/Y"
42 src/com/android2/calculator3/EventListener.java
View
@@ -16,6 +16,9 @@
package com.android2.calculator3;
+import java.util.Arrays;
+import java.util.List;
+
import com.android2.calculator3.Calculator.Panel;
import com.android2.calculator3.Logic.Mode;
@@ -45,6 +48,8 @@
private String mDY;
private String solveForX;
private String solveForY;
+ private List<String> bannedInDecimal;
+ private List<String> bannedInBinary;
void setHandler(Context context, Logic handler, ViewPager pager) {
mContext = context;
@@ -60,6 +65,23 @@ void setHandler(Context context, Logic handler, ViewPager pager) {
mDY = mContext.getResources().getString(R.string.dy);
solveForX = mContext.getResources().getString(R.string.solveForX);
solveForY = mContext.getResources().getString(R.string.solveForY);
+
+ String digit2 = context.getResources().getString(R.string.digit2);
+ String digit3 = context.getResources().getString(R.string.digit3);
+ String digit4 = context.getResources().getString(R.string.digit4);
+ String digit5 = context.getResources().getString(R.string.digit5);
+ String digit6 = context.getResources().getString(R.string.digit6);
+ String digit7 = context.getResources().getString(R.string.digit7);
+ String digit8 = context.getResources().getString(R.string.digit8);
+ String digit9 = context.getResources().getString(R.string.digit9);
+ String A = context.getResources().getString(R.string.A);
+ String B = context.getResources().getString(R.string.B);
+ String C = context.getResources().getString(R.string.C);
+ String D = context.getResources().getString(R.string.D);
+ String E = context.getResources().getString(R.string.E);
+ String F = context.getResources().getString(R.string.F);
+ bannedInDecimal = Arrays.asList(A,B,C,D,E,F);
+ bannedInBinary = Arrays.asList(A,B,C,D,E,F,digit2,digit3,digit4,digit5,digit6,digit7,digit8,digit9);
}
@Override
@@ -198,6 +220,9 @@ public void run() {
if (view instanceof Button) {
if(mHandler.getText().equals(mErrorString)) mHandler.setText("");
String text = ((Button) view).getText().toString();
+ if (!acceptableKey(text)) {
+ break;
+ }
if (text.equals(mDX) || text.equals(mDY)) {
// Do nothing
}
@@ -292,4 +317,21 @@ public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
}
return true;
}
+
+ private boolean acceptableKey(String text) {
+ if (text.length() == 1) {
+ // Disable ABCDEF in DEC/BIN and 23456789 in BIN
+ if (mHandler.getMode().equals(Mode.DECIMAL)) {
+ for (String s : bannedInDecimal) {
+ if(s.equals(text)) return false;
+ }
+ }
+ if (mHandler.getMode().equals(Mode.BINARY)) {
+ for (String s : bannedInBinary) {
+ if(s.equals(text)) return false;
+ }
+ }
+ }
+ return true;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.