summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-05-19 18:27:31 -0700
committerHans Boehm <hboehm@google.com>2015-05-20 18:26:03 -0700
commit425ed0a15c7c755a94701457b671b8b86765dc59 (patch)
tree28fa567b8fd76fd84dcf404047b1a03cd2239436 /src/com/android
parentffda52845ca6cca5f72795706988a11f6bcf5b03 (diff)
downloadandroid_packages_apps_ExactCalculator-425ed0a15c7c755a94701457b671b8b86765dc59.tar.gz
android_packages_apps_ExactCalculator-425ed0a15c7c755a94701457b671b8b86765dc59.tar.bz2
android_packages_apps_ExactCalculator-425ed0a15c7c755a94701457b671b8b86765dc59.zip
Use correct decimal separator in result.
Bug: 21282652 Consistently use key labels to internationalize result. This makes the Farsi locale, and possibly others where we diverge from the normal digit representation specified by the locale, work sanely. It remains unclear whether this divergence is a bug or a feature. Don't statically initialize mDecimalPt, since it is already initialized when needed, and may need to be reinitialized with locale changes. Always recognize ',' as a decimal separator. Remove mFactChar, since it doesn't seem to buy us anything. Change-Id: I3f7c413d380e009fc562903dc23475a7d7cd6d0a
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/calculator2/KeyMaps.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/com/android/calculator2/KeyMaps.java b/src/com/android/calculator2/KeyMaps.java
index 0f0f54d..670f895 100644
--- a/src/com/android/calculator2/KeyMaps.java
+++ b/src/com/android/calculator2/KeyMaps.java
@@ -164,13 +164,13 @@ public class KeyMaps {
}
}
- private static char mDecimalPt =
- DecimalFormatSymbols.getInstance().getDecimalSeparator();
+ // The following two are only used for recognizing additional
+ // input characters from a physical keyboard. They are not used
+ // for output internationalization.
+ private static char mDecimalPt;
private static char mPiChar;
- private static char mFactChar;
-
/**
* Character used as a placeholder for digits that are currently unknown
* in a result that is being computed. We initially generate blanks, and
@@ -205,7 +205,7 @@ public class KeyMaps {
}
// Return the button id corresponding to the supplied character
- // or NO_ID
+ // or return NO_ID.
// Called only by UI thread.
public static int keyForChar(char c) {
validateMaps();
@@ -215,6 +215,7 @@ public class KeyMaps {
}
switch (c) {
case '.':
+ case ',':
return R.id.dec_point;
case '-':
return R.id.op_sub;
@@ -297,17 +298,16 @@ public class KeyMaps {
// Set locale-dependent character "constants"
mDecimalPt =
DecimalFormatSymbols.getInstance().getDecimalSeparator();
+ // We recognize this in keyboard input, even if we use
+ // a different character.
Resources res = mActivity.getResources();
- mPiChar = mFactChar = 0;
+ mPiChar = 0;
String piString = res.getString(R.string.const_pi);
if (piString.length() == 1) mPiChar = piString.charAt(0);
- String factString = res.getString(R.string.op_fact);
- if (factString.length() == 1) mFactChar = factString.charAt(0);
sOutputForResultChar = new HashMap<Character, String>();
sOutputForResultChar.put('e', "E");
sOutputForResultChar.put('E', "E");
- sOutputForResultChar.put('.', String.valueOf(mDecimalPt));
sOutputForResultChar.put(' ', String.valueOf(CHAR_DIGIT_UNKNOWN));
sOutputForResultChar.put(ELLIPSIS.charAt(0), ELLIPSIS);
sOutputForResultChar.put('/', "/");
@@ -315,6 +315,7 @@ public class KeyMaps {
// the separating slash, which appears to be
// universal.
addButtonToOutputMap('-', R.id.op_sub);
+ addButtonToOutputMap('.', R.id.dec_point);
for (int i = 0; i <= 9; ++i) {
addButtonToOutputMap((char)('0' + i), keyForDigVal(i));
}