Permalink
Browse files

center matrices, rearrange matrix page

sign button, easter egg
  • Loading branch information...
1 parent a1d769a commit 65cbad5c48620cce431251ea02f1e2938c3ff94e @Xlythe committed Feb 6, 2013
View
BIN res/drawable-hdpi/egg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/egg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/graph_minus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/graph_plus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/graph_standard.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-xhdpi/egg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-xhdpi/graph_minus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-xhdpi/graph_plus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-xhdpi/graph_standard.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
100 res/layout-land/matrix_pad.xml
@@ -22,10 +22,7 @@
android:id="@+id/simplePad"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_gravity="center"
- >
-
+ android:orientation="vertical" >
<LinearLayout
android:layout_weight="3"
android:layout_width="match_parent"
@@ -46,13 +43,19 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_transpose"
- android:text="@string/matrix_transpose"
+ android:id="@+id/minus_col"
+ android:text="@string/minus_col"
+ android:textSize="25sp"
style="@style/button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_inverse"
- android:text="@string/matrix_inverse"
+ android:id="@+id/plus"
+ android:text="@string/plus"
+ style="@style/button_style"
+ />
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix"
+ android:text="@string/matrix_new"
style="@style/button_style"
/>
</LinearLayout>
@@ -77,28 +80,23 @@
android:text="@string/digit6"
style="@style/digit_button_style"
/>
- <LinearLayout
- android:orientation="vertical"
- android:background="@android:color/transparent"
- style="@style/digit_button_style" >
- <com.android2.calculator3.view.ColorButton
- android:id="@+id/minus_col"
- android:text="@string/minus_col"
- android:textSize="25sp"
- style="@style/button_style"
- />
- <com.android2.calculator3.view.ColorButton
- android:id="@+id/plus_col"
- android:text="@string/plus_col"
- android:textSize="25sp"
- style="@style/button_style"
- />
- </LinearLayout>
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/plus_col"
+ android:text="@string/plus_col"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
<com.android2.calculator3.view.ColorButton
android:id="@+id/mul"
android:text="@string/mul"
style="@style/button_style"
/>
+ <ImageButton
+ android:id="@+id/easter"
+ android:src="@drawable/egg"
+ style="@style/button_style"
+ android:contentDescription="@null"
+ />
</LinearLayout>
<LinearLayout
@@ -121,26 +119,21 @@
android:text="@string/digit3"
style="@style/digit_button_style"
/>
- <LinearLayout
- android:orientation="vertical"
- android:background="@android:color/transparent"
- style="@style/digit_button_style" >
- <com.android2.calculator3.view.ColorButton
- android:id="@+id/minus_row"
- android:text="@string/minus_row"
- android:textSize="25sp"
- style="@style/button_style"
- />
- <com.android2.calculator3.view.ColorButton
- android:id="@+id/plus_row"
- android:text="@string/plus_row"
- android:textSize="25sp"
- style="@style/button_style"
- />
- </LinearLayout>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/plus"
- android:text="@string/plus"
+ android:id="@+id/minus_row"
+ android:text="@string/minus_row"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix_transpose"
+ android:text="@string/matrix_transpose"
+ style="@style/button_style"
+ />
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/next"
+ android:text="@string/next"
+ android:padding="20dp"
style="@style/button_style"
/>
</LinearLayout>
@@ -161,19 +154,24 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/equal"
- android:text="@string/equal"
+ android:id="@+id/sign"
+ android:text="@string/sign"
+ style="@style/digit_button_style"
+ />
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/plus_row"
+ android:text="@string/plus_row"
+ android:textSize="25sp"
style="@style/button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix"
- android:text="@string/matrix_new"
+ android:id="@+id/matrix_inverse"
+ android:text="@string/matrix_inverse"
style="@style/button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/next"
- android:text="@string/next"
- android:padding="20dp"
+ android:id="@+id/equal"
+ android:text="@string/equal"
style="@style/button_style"
/>
</LinearLayout>
View
55 res/layout-port/matrix_pad.xml
@@ -22,19 +22,28 @@
android:id="@+id/simplePad"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_gravity="center"
- >
-
+ android:orientation="vertical" >
<LinearLayout
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="0dp">
- <com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix"
- android:text="@string/matrix_new"
- style="@style/button_style"
- />
+ <LinearLayout
+ android:orientation="vertical"
+ android:background="@android:color/transparent"
+ style="@style/digit_button_style" >
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix_transpose"
+ android:text="@string/matrix_transpose"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix_inverse"
+ android:text="@string/matrix_inverse"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
+ </LinearLayout>
<LinearLayout
android:orientation="vertical"
android:background="@android:color/transparent"
@@ -70,8 +79,8 @@
/>
</LinearLayout>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_transpose"
- android:text="@string/matrix_transpose"
+ android:id="@+id/matrix"
+ android:text="@string/matrix_new"
style="@style/button_style"
/>
</LinearLayout>
@@ -96,8 +105,8 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_inverse"
- android:text="@string/matrix_inverse"
+ android:id="@+id/mul"
+ android:text="@string/mul"
style="@style/button_style"
/>
</LinearLayout>
@@ -123,8 +132,8 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/mul"
- android:text="@string/mul"
+ android:id="@+id/plus"
+ android:text="@string/plus"
style="@style/button_style"
/>
</LinearLayout>
@@ -150,8 +159,9 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/plus"
- android:text="@string/plus"
+ android:id="@+id/next"
+ android:text="@string/next"
+ android:padding="20dp"
style="@style/button_style"
/>
</LinearLayout>
@@ -172,14 +182,13 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/equal"
- android:text="@string/equal"
- style="@style/button_style"
+ android:id="@+id/sign"
+ android:text="@string/sign"
+ style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/next"
- android:text="@string/next"
- android:padding="20dp"
+ android:id="@+id/equal"
+ android:text="@string/equal"
style="@style/button_style"
/>
</LinearLayout>
View
55 res/layout-sw600dp-land/matrix_pad.xml
@@ -22,19 +22,28 @@
android:id="@+id/simplePad"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_gravity="center"
- >
-
+ android:orientation="vertical" >
<LinearLayout
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="0dp">
- <com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix"
- android:text="@string/matrix_new"
- style="@style/button_style"
- />
+ <LinearLayout
+ android:orientation="vertical"
+ android:background="@android:color/transparent"
+ style="@style/digit_button_style" >
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix_transpose"
+ android:text="@string/matrix_transpose"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix_inverse"
+ android:text="@string/matrix_inverse"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
+ </LinearLayout>
<LinearLayout
android:orientation="vertical"
android:background="@android:color/transparent"
@@ -70,8 +79,8 @@
/>
</LinearLayout>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_transpose"
- android:text="@string/matrix_transpose"
+ android:id="@+id/matrix"
+ android:text="@string/matrix_new"
style="@style/button_style"
/>
</LinearLayout>
@@ -96,8 +105,8 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_inverse"
- android:text="@string/matrix_inverse"
+ android:id="@+id/mul"
+ android:text="@string/mul"
style="@style/button_style"
/>
</LinearLayout>
@@ -123,8 +132,8 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/mul"
- android:text="@string/mul"
+ android:id="@+id/plus"
+ android:text="@string/plus"
style="@style/button_style"
/>
</LinearLayout>
@@ -150,8 +159,9 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/plus"
- android:text="@string/plus"
+ android:id="@+id/next"
+ android:text="@string/next"
+ android:padding="20dp"
style="@style/button_style"
/>
</LinearLayout>
@@ -172,14 +182,13 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/equal"
- android:text="@string/equal"
- style="@style/button_style"
+ android:id="@+id/sign"
+ android:text="@string/sign"
+ style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/next"
- android:text="@string/next"
- android:padding="20dp"
+ android:id="@+id/equal"
+ android:text="@string/equal"
style="@style/button_style"
/>
</LinearLayout>
View
55 res/layout-sw600dp-port/matrix_pad.xml
@@ -22,19 +22,28 @@
android:id="@+id/simplePad"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_gravity="center"
- >
-
+ android:orientation="vertical" >
<LinearLayout
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="0dp">
- <com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix"
- android:text="@string/matrix_new"
- style="@style/button_style"
- />
+ <LinearLayout
+ android:orientation="vertical"
+ android:background="@android:color/transparent"
+ style="@style/digit_button_style" >
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix_transpose"
+ android:text="@string/matrix_transpose"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
+ <com.android2.calculator3.view.ColorButton
+ android:id="@+id/matrix_inverse"
+ android:text="@string/matrix_inverse"
+ android:textSize="25sp"
+ style="@style/button_style"
+ />
+ </LinearLayout>
<LinearLayout
android:orientation="vertical"
android:background="@android:color/transparent"
@@ -70,8 +79,8 @@
/>
</LinearLayout>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_transpose"
- android:text="@string/matrix_transpose"
+ android:id="@+id/matrix"
+ android:text="@string/matrix_new"
style="@style/button_style"
/>
</LinearLayout>
@@ -96,8 +105,8 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/matrix_inverse"
- android:text="@string/matrix_inverse"
+ android:id="@+id/mul"
+ android:text="@string/mul"
style="@style/button_style"
/>
</LinearLayout>
@@ -123,8 +132,8 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/mul"
- android:text="@string/mul"
+ android:id="@+id/plus"
+ android:text="@string/plus"
style="@style/button_style"
/>
</LinearLayout>
@@ -150,8 +159,9 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/plus"
- android:text="@string/plus"
+ android:id="@+id/next"
+ android:text="@string/next"
+ android:padding="20dp"
style="@style/button_style"
/>
</LinearLayout>
@@ -172,14 +182,13 @@
style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/equal"
- android:text="@string/equal"
- style="@style/button_style"
+ android:id="@+id/sign"
+ android:text="@string/sign"
+ style="@style/digit_button_style"
/>
<com.android2.calculator3.view.ColorButton
- android:id="@+id/next"
- android:text="@string/next"
- android:padding="20dp"
+ android:id="@+id/equal"
+ android:text="@string/equal"
style="@style/button_style"
/>
</LinearLayout>
View
2 res/values/strings.xml
@@ -67,6 +67,8 @@
<string name="plus" translatable="false">+</string>
<!-- Do not translate. Unicode minus sign; don't translate. Displayed as button on screen. -->
<string name="minus" translatable="false">\u2212</string>
+ <!-- Do not translate. Plus sign / unicode minus sign; don't translate. Displayed as button on screen. -->
+ <string name="sign" translatable="false">+/\u2212</string>
<!-- Do not translate. Decimal point; don't translate. Displayed as button on screen. -->
<string name="dot" translatable="false">.</string>
<!-- Do not translate. Coma; don't translate. Displayed as button on screen. -->
View
2 src/com/android2/calculator3/Calculator.java
@@ -181,7 +181,7 @@ public void onSlide(Direction d) {
mGraph = new Graph(mLogic);
if(mPager != null) {
- mPager.setAdapter(new PageAdapter(mPager, mGraph, mLogic));
+ mPager.setAdapter(new PageAdapter(mPager, this, mGraph, mLogic));
mPager.setCurrentItem(state == null ? Panel.BASIC.getOrder() : state.getInt(STATE_CURRENT_VIEW, Panel.BASIC.getOrder()));
mPager.setOnPageChangeListener(this);
runCling(false);
View
25 src/com/android2/calculator3/EventListener.java
@@ -81,6 +81,7 @@ void setHandler(Context context, Logic handler, ViewPager pager) {
@Override
public void onClick(View view) {
View v;
+ EditText active;
int id = view.getId();
switch(id) {
case R.id.del:
@@ -159,7 +160,7 @@ public void onClick(View view) {
break;
case R.id.next:
- EditText active = mHandler.mDisplay.getActiveEditText();
+ active = mHandler.mDisplay.getActiveEditText();
if(active.getSelectionStart() == active.getText().length()) {
v = mHandler.mDisplay.getActiveEditText().focusSearch(View.FOCUS_FORWARD);
if(v != null) v.requestFocus();
@@ -171,6 +172,24 @@ public void onClick(View view) {
}
break;
+ case R.id.sign:
+ active = mHandler.mDisplay.getActiveEditText();
+ int selection = active.getSelectionStart();
+ if(active.getText().toString().matches(Logic.DECIMAL_NUMBER)) {
+ if(active.getText().toString().startsWith(String.valueOf(Logic.MINUS))) {
+ active.setText(active.getText().toString().substring(1));
+ selection--;
+ }
+ else {
+ active.setText(Logic.MINUS + active.getText().toString());
+ selection++;
+ }
+ if(selection > active.length()) selection--;
+ if(selection < 0) selection = 0;
+ active.setSelection(selection);
+ }
+ break;
+
case R.id.parentheses:
if(mHandler.getText().equals(mErrorString)) mHandler.setText("");
if(mHandler.getText().contains("=")) {
@@ -210,6 +229,10 @@ public void onClick(View view) {
returnToBasic();
break;
+ case R.id.easter:
+ Toast.makeText(mContext, "Magikarp used splash but nothing happened.", Toast.LENGTH_SHORT).show();
+ break;
+
default:
if(view instanceof Button) {
if(mHandler.getText().equals(mErrorString)) mHandler.setText("");
View
1 src/com/android2/calculator3/Logic.java
@@ -43,6 +43,7 @@
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*)?";
public static final String INFINITY_UNICODE = "\u221e";
// Double.toString() for Infinity
public static final String INFINITY = "Infinity";
View
8 src/com/android2/calculator3/PageAdapter.java
@@ -29,7 +29,7 @@
private int count = 0;
- public PageAdapter(CalculatorViewPager parent, Graph graph, Logic logic) {
+ public PageAdapter(CalculatorViewPager parent, Calculator calculator, Graph graph, Logic logic) {
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
final View graphPage = inflater.inflate(R.layout.graph_pad, parent, false);
final View functionPage = inflater.inflate(R.layout.function_pad, parent, false);
@@ -60,6 +60,12 @@ public PageAdapter(CalculatorViewPager parent, Graph graph, Logic logic) {
mHexPage.findViewById(R.id.hex).setBackgroundResource(R.color.pressed_color);
break;
}
+
+ View easterEgg = mMatrixPage.findViewById(R.id.easter);
+ if(easterEgg != null) {
+ easterEgg.setOnClickListener(calculator.mListener);
+ easterEgg.setOnLongClickListener(calculator.mListener);
+ }
}
@Override
View
5 src/com/android2/calculator3/view/CalculatorEditText.java
@@ -26,9 +26,11 @@
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.ActionMode;
+import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
@@ -175,6 +177,9 @@ public static String load(String text, final AdvancedDisplay parent, final int p
et.setTextAppearance(parent.getContext(), R.style.display_style);
et.setPadding(5, 0, 5, 0);
et.setEnabled(parent.isEnabled());
+ AdvancedDisplay.LayoutParams params = new AdvancedDisplay.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ params.gravity = Gravity.CENTER_VERTICAL;
+ et.setLayoutParams(params);
parent.addView(et, pos);
return "";
}
View
3 src/com/android2/calculator3/view/ColorButton.java
@@ -127,7 +127,8 @@ else if(isPressed()) {
if(hint != null) {
String[] exponents = hint.toString().split(Pattern.quote("^"));
int offsetX = LogicalDensity.convertDpToPixel(10, getContext());
- int offsetY = (int) ((mTextY + LogicalDensity.convertDpToPixel(20, getContext()) - getTextHeight(mHintPaint, hint.toString())) / 2);
+ int offsetY = (int) ((mTextY + LogicalDensity.convertDpToPixel(20, getContext()) - getTextHeight(mHintPaint, hint.toString())) / 2)
+ - getPaddingTop();
float textWidth = mHintPaint.measureText(hint.toString());
float width = getWidth() - getPaddingLeft() - getPaddingRight() - mTextX - offsetX;
View
18 src/com/android2/calculator3/view/MatrixEditText.java
@@ -16,9 +16,6 @@
package com.android2.calculator3.view;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import android.content.Context;
import android.text.Editable;
import android.text.InputType;
@@ -75,19 +72,8 @@ public int getInputType() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for(int i = start; i < end; i++) {
- String checkMe = String.valueOf(source.charAt(i));
-
- Pattern pattern;
- if(getText().toString().contains(".")) {
- pattern = Pattern.compile("[0123456789]");
- }
- else {
- pattern = Pattern.compile("[0123456789\\.]");
- }
- Matcher matcher = pattern.matcher(checkMe);
- boolean valid = matcher.matches();
- if(i == 0 && dstart == 0 && (checkMe.charAt(0) == '\u2212' || checkMe.equals("-"))) valid = true;
- if(!valid) {
+ String text = dest.toString().substring(0, dstart) + source.toString() + dest.toString().substring(dend);
+ if(!text.matches(Logic.DECIMAL_NUMBER)) {
return "";
}
}
View
4 src/com/android2/calculator3/view/MatrixView.java
@@ -6,6 +6,7 @@
import org.javia.arity.SyntaxException;
import android.content.Context;
+import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TableLayout;
@@ -242,6 +243,9 @@ public static boolean load(final MutableString text, final AdvancedDisplay paren
order++;
}
}
+ AdvancedDisplay.LayoutParams params = new AdvancedDisplay.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ params.gravity = Gravity.CENTER_VERTICAL;
+ mv.setLayoutParams(params);
parent.addView(mv, pos);
return true;

0 comments on commit 65cbad5

Please sign in to comment.