Permalink
Browse files

windows mode on samsung devices

matrices work in hexdecimal and binary now
  • Loading branch information...
1 parent d660468 commit d46ee659d4e723efa78f375b4ec8485b2be81c84 @Xlythe committed Feb 9, 2013
View
7 AndroidManifest.xml
@@ -8,6 +8,12 @@
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17"/>
<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher_calculator" android:allowBackup="true">
+ <uses-library android:required="false" android:name="com.sec.android.app.multiwindow" />
+ <meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
+ <meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:resource="@dimen/app_defaultsize_w" />
+ <meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:resource="@dimen/app_defaultsize_h" />
+ <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:resource="@dimen/app_minimumsize_w" />
+ <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:resource="@dimen/app_minimumsize_h" />
<activity android:name=".Calculator"
android:theme="@android:style/Theme.Holo.NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden"
@@ -17,6 +23,7 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_CALCULATOR" />
+ <category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Preferences" android:label="@string/settings" />
View
4 res/values/styles.xml
@@ -25,6 +25,10 @@
<dimen name="max_display_height">200dp</dimen>
<dimen name="barHeight">25dp</dimen>
<integer name="barHeight">25</integer>
+ <dimen name="app_defaultsize_w">632.0dip</dimen>
+ <dimen name="app_defaultsize_h">598.0dip</dimen>
+ <dimen name="app_minimumsize_w">632.0dip</dimen>
+ <dimen name="app_minimumsize_h">598.0dip</dimen>
<!-- Cling -->
<dimen name="clingPunchThroughGraphicCenterRadius">94dp</dimen>
View
2 src/com/android2/calculator3/EventListener.java
@@ -175,7 +175,7 @@ public void onClick(View view) {
case R.id.sign:
active = mHandler.mDisplay.getActiveEditText();
int selection = active.getSelectionStart();
- if(active.getText().toString().matches(Logic.DECIMAL_NUMBER)) {
+ if(active.getText().toString().matches(Logic.NUMBER)) {
if(active.getText().toString().startsWith(String.valueOf(Logic.MINUS))) {
active.setText(active.getText().toString().substring(1));
selection--;
View
79 src/com/android2/calculator3/Logic.java
@@ -41,9 +41,9 @@
import com.android2.calculator3.view.MatrixView;
public class Logic {
- private static final String REGEX_NUMBER = "[A-F0-9\\.,]";
- private static final String REGEX_NOT_NUMBER = "[^A-F0-9\\.,]";
- public static final String DECIMAL_NUMBER = "[" + Logic.MINUS + "-]?\\d+(\\.\\d*)?";
+ private static final String REGEX_NUMBER = "[A-F0-9\\.]";
+ private static final String REGEX_NOT_NUMBER = "[^A-F0-9\\.]";
+ public static final String NUMBER = "[" + Logic.MINUS + "-]?[A-F0-9]+(\\.[A-F0-9]*)?";
public static final String INFINITY_UNICODE = "\u221e";
// Double.toString() for Infinity
public static final String INFINITY = "Infinity";
@@ -306,7 +306,7 @@ String evaluate(String input) throws SyntaxException {
input = localize(input);
// Convert to decimal
- String decimalInput = updateTextToNewMode(input, mode, Mode.DECIMAL);
+ String decimalInput = convertToDecimal(input);
Complex value = mSymbols.evalComplex(decimalInput);
@@ -335,6 +335,10 @@ String evaluate(String input) throws SyntaxException {
return updateTextToNewMode(result, Mode.DECIMAL, mode).replace('-', MINUS).replace(INFINITY, INFINITY_UNICODE);
}
+ public String convertToDecimal(String input) {
+ return updateTextToNewMode(input, mode, Mode.DECIMAL);
+ }
+
String localize(String input) {
// Delocalize functions (e.g. Spanish localizes "sin" as "sen"). Order
// matters for arc functions
@@ -446,7 +450,7 @@ else if(child instanceof MatrixInverseView) {
else throw new SyntaxException();
}
}
- return MatrixView.matrixToString(matrix);
+ return updateTextToNewMode(MatrixView.matrixToString(matrix), Mode.DECIMAL, mode);
}
catch(Exception e) {
throw new SyntaxException();
@@ -498,8 +502,8 @@ void updateGraph(final Graph g) {
if(equation.length != 2) return;
// Translate into decimal
- equation[0] = updateTextToNewMode(localize(equation[0]), mode, Mode.DECIMAL);
- equation[1] = updateTextToNewMode(localize(equation[1]), mode, Mode.DECIMAL);
+ equation[0] = convertToDecimal(localize(equation[0]));
+ equation[1] = convertToDecimal(localize(equation[1]));
final double minY = g.getRenderer().getYAxisMin();
final double maxY = g.getRenderer().getYAxisMax();
final double minX = g.getRenderer().getXAxisMin();
@@ -655,14 +659,21 @@ public String setMode(Mode mode) {
}
private String updateTextToNewMode(final String originalText, final Mode mode1, final Mode mode2) {
- if(mode1.equals(mode2)) return originalText;
- String text = originalText;
- if(!text.equals(mErrorString) && !text.isEmpty() && !mode1.equals(mode2)) {
- String[] operations = text.split(REGEX_NUMBER);
- String[] numbers = text.split(REGEX_NOT_NUMBER);
- String[] translatedNumbers = new String[numbers.length];
- for(int i = 0; i < numbers.length; i++) {
- if(!numbers[i].isEmpty()) switch(mode1) {
+ if(mode1.equals(mode2) || originalText.equals(mErrorString) || originalText.isEmpty()) return originalText;
+
+ System.out.println(originalText);
+ String[] operations = originalText.split(REGEX_NUMBER);
+ for(String s : operations) {
+ System.out.println("Ops: " + s);
+ }
+ String[] numbers = originalText.split(REGEX_NOT_NUMBER);
+ for(String s : numbers) {
+ System.out.println("Nums: " + s);
+ }
+ String[] translatedNumbers = new String[numbers.length];
+ for(int i = 0; i < numbers.length; i++) {
+ if(!numbers[i].isEmpty()) {
+ switch(mode1) {
case BINARY:
switch(mode2) {
case BINARY:
@@ -751,28 +762,28 @@ private String updateTextToNewMode(final String originalText, final Mode mode1,
break;
}
}
- text = "";
- Object[] o = removeWhitespace(operations);
- Object[] n = removeWhitespace(translatedNumbers);
- if(originalText.substring(0, 1).matches(REGEX_NUMBER)) {
- for(int i = 0; i < o.length && i < n.length; i++) {
- text += n[i];
- text += o[i];
- }
- }
- else {
- for(int i = 0; i < o.length && i < n.length; i++) {
- text += o[i];
- text += n[i];
- }
- }
- if(o.length > n.length) {
- text += o[o.length - 1];
+ }
+ String text = "";
+ Object[] o = removeWhitespace(operations);
+ Object[] n = removeWhitespace(translatedNumbers);
+ if(originalText.substring(0, 1).matches(REGEX_NUMBER)) {
+ for(int i = 0; i < o.length && i < n.length; i++) {
+ text += n[i];
+ text += o[i];
}
- else if(n.length > o.length) {
- text += n[n.length - 1];
+ }
+ else {
+ for(int i = 0; i < o.length && i < n.length; i++) {
+ text += o[i];
+ text += n[i];
}
}
+ if(o.length > n.length) {
+ text += o[o.length - 1];
+ }
+ else if(n.length > o.length) {
+ text += n[n.length - 1];
+ }
return text;
}
View
6 src/com/android2/calculator3/view/AdvancedDisplay.java
@@ -16,6 +16,7 @@
import android.widget.LinearLayout;
import android.widget.Toast;
+import com.android2.calculator3.Logic;
import com.android2.calculator3.MutableString;
import com.android2.calculator3.R;
@@ -28,6 +29,7 @@
EditText mActiveEditText;
KeyListener mKeyListener;
Factory mFactory;
+ Logic mLogic;
public AdvancedDisplay(Context context) {
this(context, null);
@@ -163,6 +165,10 @@ public void setEditableFactory(Factory factory) {
mFactory = factory;
}
+ public void setLogic(Logic logic) {
+ mLogic = logic;
+ }
+
public EditText getActiveEditText() {
return mActiveEditText;
}
View
3 src/com/android2/calculator3/view/CalculatorDisplay.java
@@ -49,7 +49,7 @@
// only these chars are accepted from keyboard
private static final char[] ACCEPTED_CHARS = "0123456789.+-*/\u2212\u00d7\u00f7()!%^".toCharArray();
- private static final int ANIM_DURATION = 500;
+ private static final int ANIM_DURATION = 400;
public enum Scroll {
UP, DOWN, NONE
@@ -143,6 +143,7 @@ public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent even
Editable.Factory factory = new CalculatorEditable.Factory(logic);
for(int i = 0; i < 2; ++i) {
AdvancedDisplay text = ((ScrollableDisplay) getChildAt(i)).getView();
+ text.setLogic(logic);
text.setEditableFactory(factory);
text.setKeyListener(calculatorKeyListener);
text.setLayoutParams(new ScrollableDisplay.LayoutParams(ScrollableDisplay.LayoutParams.WRAP_CONTENT, ScrollableDisplay.LayoutParams.WRAP_CONTENT,
View
2 src/com/android2/calculator3/view/MatrixEditText.java
@@ -73,7 +73,7 @@ public int getInputType() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for(int i = start; i < end; i++) {
String text = dest.toString().substring(0, dstart) + source.toString() + dest.toString().substring(dend);
- if(!text.matches(Logic.DECIMAL_NUMBER)) {
+ if(!text.matches(Logic.NUMBER)) {
return "";
}
}
View
18 src/com/android2/calculator3/view/MatrixView.java
@@ -19,10 +19,11 @@
public class MatrixView extends TableLayout {
private static String FORMAT = "#.######";
private static DecimalFormat FORMATTER = new DecimalFormat(FORMAT);
- private static final String VALID_MATRIX = "\\[(\\[[\u2212-]?(\\d+(\\.\\d*)?)*(,[\u2212-]?(\\d+(\\.\\d*)?)*)*\\])+\\].*";
+ private static final String VALID_MATRIX = "\\[(\\[[\u2212-]?[A-F0-9]*(\\.[A-F0-9]*)?(,[\u2212-]?[A-F0-9]*(\\.[A-F0-9]*)?)*\\])+\\].*";
private int rows, columns = 0;
private AdvancedDisplay parent;
+ private Logic logic;
public MatrixView(Context context) {
super(context);
@@ -37,6 +38,7 @@ public MatrixView(AdvancedDisplay parent) {
private void setup() {
setBackgroundResource(R.drawable.matrix_background);
setFocusable(true);
+ logic = parent.mLogic;
}
public void addRow() {
@@ -90,7 +92,6 @@ public SimpleMatrix getSimpleMatrix() throws SyntaxException {
String input = ((EditText) tr.getChildAt(column)).getText().toString();
input = stringify(input);
if(input.isEmpty()) throw new SyntaxException();
- input = input.replaceAll(Logic.INFINITY_UNICODE, Logic.INFINITY);
try {
data[row][column] = Double.valueOf(input);
}
@@ -108,7 +109,7 @@ public SimpleMatrix getSimpleMatrix() throws SyntaxException {
TableRow tr = (TableRow) getChildAt(row);
for(int column = 0; column < columns; column++) {
String input = ((EditText) tr.getChildAt(column)).getText().toString();
- data[row][column] = stringify(input);
+ data[row][column] = input;
}
}
return data;
@@ -117,6 +118,7 @@ public SimpleMatrix getSimpleMatrix() throws SyntaxException {
private String stringify(String input) {
if(input.isEmpty()) return "";
else {
+ input = logic.convertToDecimal(input);
if(input.charAt(0) == '\u2212') {
if(input.length() == 1) input = "";
else input = "-" + input.substring(1);
@@ -127,12 +129,7 @@ private String stringify(String input) {
else if(input.startsWith("-.")) {
input = "-0" + input.substring(1);
}
- try {
- return FORMATTER.format(Double.valueOf(input));
- }
- catch(Exception e) {
- return "";
- }
+ return input;
}
}
@@ -195,14 +192,13 @@ public String toString() {
}
public static String matrixToString(SimpleMatrix matrix) {
- DecimalFormat formatter = new DecimalFormat(FORMAT);
int rows = matrix.numRows();
int columns = matrix.numCols();
String input = "[";
for(int i = 0; i < rows; i++) {
input += "[";
for(int j = 0; j < columns; j++) {
- input += formatter.format(matrix.get(i, j)) + ",";
+ input += FORMATTER.format(matrix.get(i, j)) + ",";
}
// Remove trailing ,
input = input.substring(0, input.length() - 1);

0 comments on commit d46ee65

Please sign in to comment.