diff options
author | Vikram Aggarwal <viki@google.com> | 2011-11-28 09:21:18 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-28 09:21:18 -0800 |
commit | c249f2edd5d7e03cae1970576e5909d012e0166e (patch) | |
tree | a6979ebd02ef03c0eb10ddf85e6bf6cd42a1251b /src | |
parent | 527c9079a6752a969c79daa794dc860b42326929 (diff) | |
download | Calculator-c249f2edd5d7e03cae1970576e5909d012e0166e.tar.gz |
Revert "Clean up calculator source code."
This reverts commit 527c9079a6752a969c79daa794dc860b42326929
CalculatorViewPager is referenced in main.xml, and cannot be deleted.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/calculator2/CalculatorEditText.java | 5 | ||||
-rw-r--r-- | src/com/android/calculator2/CalculatorEditable.java | 25 | ||||
-rw-r--r-- | src/com/android/calculator2/CalculatorViewPager.java | 40 | ||||
-rw-r--r-- | src/com/android/calculator2/EventListener.java | 2 | ||||
-rw-r--r-- | src/com/android/calculator2/HistoryAdapter.java | 11 | ||||
-rw-r--r-- | src/com/android/calculator2/HistoryEntry.java | 4 | ||||
-rw-r--r-- | src/com/android/calculator2/Logic.java | 4 | ||||
-rw-r--r-- | src/com/android/calculator2/PanelSwitcher.java | 1 |
8 files changed, 69 insertions, 23 deletions
diff --git a/src/com/android/calculator2/CalculatorEditText.java b/src/com/android/calculator2/CalculatorEditText.java index 7a8e6ea..170e116 100644 --- a/src/com/android/calculator2/CalculatorEditText.java +++ b/src/com/android/calculator2/CalculatorEditText.java @@ -63,7 +63,6 @@ public class CalculatorEditText extends EditText { } private class MenuHandler implements MenuItem.OnMenuItemClickListener { - @Override public boolean onMenuItemClick(MenuItem item) { return onTextContextMenuItem(item.getTitle()); } @@ -130,7 +129,7 @@ public class CalculatorEditText extends EditText { int textLength = text.length(); setSelection(0, textLength); setPrimaryClip(ClipData.newPlainText(null, text)); - getText().delete(0, textLength); + ((Editable) getText()).delete(0, textLength); setSelection(0); } @@ -146,7 +145,7 @@ public class CalculatorEditText extends EditText { for (int i = 0; i < clip.getItemCount(); i++) { CharSequence paste = clip.getItemAt(i).coerceToText(getContext()); if (canPaste(paste)) { - getText().insert(getSelectionEnd(), paste); + ((Editable) getText()).insert(getSelectionEnd(), paste); } } } diff --git a/src/com/android/calculator2/CalculatorEditable.java b/src/com/android/calculator2/CalculatorEditable.java index cfab25c..cfa39f6 100644 --- a/src/com/android/calculator2/CalculatorEditable.java +++ b/src/com/android/calculator2/CalculatorEditable.java @@ -31,23 +31,23 @@ class CalculatorEditable extends SpannableStringBuilder { } @Override - public SpannableStringBuilder + public SpannableStringBuilder replace(int start, int end, CharSequence tb, int tbstart, int tbend) { if (isInsideReplace) { return super.replace(start, end, tb, tbstart, tbend); - } else { - isInsideReplace = true; + } else { + isInsideReplace = true; try { - String delta = tb.subSequence(tbstart, tbend).toString(); + String delta = tb.subSequence(tbstart, tbend).toString(); return internalReplace(start, end, delta); } finally { isInsideReplace = false; } } } - + private SpannableStringBuilder internalReplace(int start, int end, String delta) { - if (!mLogic.acceptInsert(delta)) { + if (!mLogic.acceptInsert(delta)) { mLogic.cleared(); start = 0; end = length(); @@ -61,7 +61,7 @@ class CalculatorEditable extends SpannableStringBuilder { if (length == 1) { char text = delta.charAt(0); - // Don't allow two dots in the same number + //don't allow two dots in the same number if (text == '.') { int p = start - 1; while (p >= 0 && Character.isDigit(charAt(p))) { @@ -74,25 +74,25 @@ class CalculatorEditable extends SpannableStringBuilder { char prevChar = start > 0 ? charAt(start-1) : '\0'; - // Don't allow 2 successive minuses + //don't allow 2 successive minuses if (text == Logic.MINUS && prevChar == Logic.MINUS) { return super.replace(start, end, ""); } - // Don't allow multiple successive operators + //don't allow multiple successive operators if (Logic.isOperator(text)) { - while (Logic.isOperator(prevChar) && + while (Logic.isOperator(prevChar) && (text != Logic.MINUS || prevChar == '+')) { --start; prevChar = start > 0 ? charAt(start-1) : '\0'; } } - // Don't allow leading operator + * / + //don't allow leading operator + * / if (start == 0 && Logic.isOperator(text) && text != Logic.MINUS) { return super.replace(start, end, ""); } - } + } return super.replace(start, end, delta); } @@ -103,7 +103,6 @@ class CalculatorEditable extends SpannableStringBuilder { mLogic = logic; } - @Override public Editable newEditable(CharSequence source) { return new CalculatorEditable(source, mLogic); } diff --git a/src/com/android/calculator2/CalculatorViewPager.java b/src/com/android/calculator2/CalculatorViewPager.java new file mode 100644 index 0000000..880fcc8 --- /dev/null +++ b/src/com/android/calculator2/CalculatorViewPager.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.calculator2; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; + +public class CalculatorViewPager extends ViewPager { + public CalculatorViewPager(Context context) { + super(context); + } + + public CalculatorViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + /** + * ViewPager inherits ViewGroup's default behavior of delayed clicks + * on its children, but in order to make the calc buttons more responsive + * we disable that here. + */ + public boolean shouldDelayChildPressedState() { + return false; + } +} diff --git a/src/com/android/calculator2/EventListener.java b/src/com/android/calculator2/EventListener.java index 9f77715..1d6f5d5 100644 --- a/src/com/android/calculator2/EventListener.java +++ b/src/com/android/calculator2/EventListener.java @@ -88,6 +88,8 @@ class EventListener implements View.OnKeyListener, return true; // eat it } + //Calculator.log("KEY " + keyCode + "; " + action); + if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); diff --git a/src/com/android/calculator2/HistoryAdapter.java b/src/com/android/calculator2/HistoryAdapter.java index 50039dd..02ceeee 100644 --- a/src/com/android/calculator2/HistoryAdapter.java +++ b/src/com/android/calculator2/HistoryAdapter.java @@ -31,24 +31,24 @@ class HistoryAdapter extends BaseAdapter { private Vector<HistoryEntry> mEntries; private LayoutInflater mInflater; private Logic mEval; - + HistoryAdapter(Context context, History history, Logic evaluator) { mEntries = history.mEntries; mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mEval = evaluator; } - @Override + // @Override public int getCount() { return mEntries.size() - 1; } - @Override + // @Override public Object getItem(int position) { return mEntries.elementAt(position); } - @Override + // @Override public long getItemId(int position) { return position; } @@ -58,7 +58,7 @@ class HistoryAdapter extends BaseAdapter { return true; } - @Override + // @Override public View getView(int position, View convertView, ViewGroup parent) { View view; if (convertView == null) { @@ -84,3 +84,4 @@ class HistoryAdapter extends BaseAdapter { return view; } } + diff --git a/src/com/android/calculator2/HistoryEntry.java b/src/com/android/calculator2/HistoryEntry.java index ce10402..80319d8 100644 --- a/src/com/android/calculator2/HistoryEntry.java +++ b/src/com/android/calculator2/HistoryEntry.java @@ -34,14 +34,16 @@ class HistoryEntry { if (version >= VERSION_1) { mBase = in.readUTF(); mEdited = in.readUTF(); + //Calculator.log("load " + mEdited); } else { throw new IOException("invalid version " + version); } } - + void write(DataOutput out) throws IOException { out.writeUTF(mBase); out.writeUTF(mEdited); + //Calculator.log("save " + mEdited); } @Override diff --git a/src/com/android/calculator2/Logic.java b/src/com/android/calculator2/Logic.java index 9a28136..690e892 100644 --- a/src/com/android/calculator2/Logic.java +++ b/src/com/android/calculator2/Logic.java @@ -27,6 +27,7 @@ import java.util.Locale; import org.javia.arity.Symbols; import org.javia.arity.SyntaxException; +import org.javia.arity.Util; class Logic { private CalculatorDisplay mDisplay; @@ -40,7 +41,7 @@ class Logic { public static final String MARKER_EVALUATE_ON_RESUME = "?"; - // The two strings below are the result of Double.toString() for Infinity & NaN + // the two strings below are the result of Double.toString() for Infinity & NaN // they are not output to the user and don't require internationalization private static final String INFINITY = "Infinity"; private static final String NAN = "NaN"; @@ -217,6 +218,7 @@ class Logic { } } + private static final int ROUND_DIGITS = 1; String evaluate(String input) throws SyntaxException { if (input.trim().equals("")) { return ""; diff --git a/src/com/android/calculator2/PanelSwitcher.java b/src/com/android/calculator2/PanelSwitcher.java index 0933c21..6e64259 100644 --- a/src/com/android/calculator2/PanelSwitcher.java +++ b/src/com/android/calculator2/PanelSwitcher.java @@ -21,6 +21,7 @@ import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; +import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.TranslateAnimation; |