diff options
author | Vikram Aggarwal <viki@google.com> | 2011-11-21 09:43:25 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-21 09:43:25 -0800 |
commit | 358d87218f5dfa615be441e3229573e2a5818f83 (patch) | |
tree | 60460af4001c6a5eef8dca06c1217e2ea244e704 | |
parent | 8f0e42535039dd50bdae957f57f907d8528c5dfc (diff) | |
parent | 527c9079a6752a969c79daa794dc860b42326929 (diff) | |
download | android_packages_apps_ExactCalculator-358d87218f5dfa615be441e3229573e2a5818f83.tar.gz android_packages_apps_ExactCalculator-358d87218f5dfa615be441e3229573e2a5818f83.tar.bz2 android_packages_apps_ExactCalculator-358d87218f5dfa615be441e3229573e2a5818f83.zip |
Merge "Clean up calculator source code."
-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, 23 insertions, 69 deletions
diff --git a/src/com/android/calculator2/CalculatorEditText.java b/src/com/android/calculator2/CalculatorEditText.java index 170e116..7a8e6ea 100644 --- a/src/com/android/calculator2/CalculatorEditText.java +++ b/src/com/android/calculator2/CalculatorEditText.java @@ -63,6 +63,7 @@ public class CalculatorEditText extends EditText { } private class MenuHandler implements MenuItem.OnMenuItemClickListener { + @Override public boolean onMenuItemClick(MenuItem item) { return onTextContextMenuItem(item.getTitle()); } @@ -129,7 +130,7 @@ public class CalculatorEditText extends EditText { int textLength = text.length(); setSelection(0, textLength); setPrimaryClip(ClipData.newPlainText(null, text)); - ((Editable) getText()).delete(0, textLength); + getText().delete(0, textLength); setSelection(0); } @@ -145,7 +146,7 @@ public class CalculatorEditText extends EditText { for (int i = 0; i < clip.getItemCount(); i++) { CharSequence paste = clip.getItemAt(i).coerceToText(getContext()); if (canPaste(paste)) { - ((Editable) getText()).insert(getSelectionEnd(), paste); + getText().insert(getSelectionEnd(), paste); } } } diff --git a/src/com/android/calculator2/CalculatorEditable.java b/src/com/android/calculator2/CalculatorEditable.java index cfa39f6..cfab25c 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,6 +103,7 @@ 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 deleted file mode 100644 index 880fcc8..0000000 --- a/src/com/android/calculator2/CalculatorViewPager.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 1d6f5d5..9f77715 100644 --- a/src/com/android/calculator2/EventListener.java +++ b/src/com/android/calculator2/EventListener.java @@ -88,8 +88,6 @@ 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 02ceeee..50039dd 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,4 +84,3 @@ class HistoryAdapter extends BaseAdapter { return view; } } - diff --git a/src/com/android/calculator2/HistoryEntry.java b/src/com/android/calculator2/HistoryEntry.java index 80319d8..ce10402 100644 --- a/src/com/android/calculator2/HistoryEntry.java +++ b/src/com/android/calculator2/HistoryEntry.java @@ -34,16 +34,14 @@ 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 690e892..9a28136 100644 --- a/src/com/android/calculator2/Logic.java +++ b/src/com/android/calculator2/Logic.java @@ -27,7 +27,6 @@ import java.util.Locale; import org.javia.arity.Symbols; import org.javia.arity.SyntaxException; -import org.javia.arity.Util; class Logic { private CalculatorDisplay mDisplay; @@ -41,7 +40,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"; @@ -218,7 +217,6 @@ 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 6e64259..0933c21 100644 --- a/src/com/android/calculator2/PanelSwitcher.java +++ b/src/com/android/calculator2/PanelSwitcher.java @@ -21,7 +21,6 @@ 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; |