Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
packages_apps_Calculator
Commits
17bb4d3d
Commit
17bb4d3d
authored
10 years ago
by
Narayan Kamath
Committed by
Gerrit Code Review
10 years ago
Browse files
Options
Download
Plain Diff
Merge "Replace the use of manually translated digits in Calculator."
parents
f7ff30be
411fc19c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
173 additions
and
59 deletions
+173
-59
res/layout/pad_numeric.xml
res/layout/pad_numeric.xml
+13
-24
res/values-fa/config.xml
res/values-fa/config.xml
+21
-0
res/values/config.xml
res/values/config.xml
+21
-0
res/values/strings.xml
res/values/strings.xml
+0
-24
src/com/android/calculator2/CalculatorExpressionTokenizer.java
...om/android/calculator2/CalculatorExpressionTokenizer.java
+19
-11
src/com/android/calculator2/CalculatorNumericPadLayout.java
src/com/android/calculator2/CalculatorNumericPadLayout.java
+99
-0
No files found.
res/layout/pad_numeric.xml
View file @
17bb4d3d
...
...
@@ -15,7 +15,7 @@
limitations under the License.
-->
<com.android.calculator2.CalculatorPadLayout
<com.android.calculator2.Calculator
Numeric
PadLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/pad_numeric"
style=
"@style/PadLayoutStyle.Numeric"
...
...
@@ -26,68 +26,57 @@
<Button
android:id=
"@+id/digit_7"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_7"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_8"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_8"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_9"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_9"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_4"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_4"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_5"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_5"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_6"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_6"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_1"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_1"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_2"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_2"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_3"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_3"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/dec_point"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/dec_point"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/digit_0"
style=
"@style/PadButtonStyle.Numeric"
android:onClick=
"onButtonClick"
android:text=
"@string/digit_0"
/>
android:onClick=
"onButtonClick"
/>
<Button
android:id=
"@+id/eq"
...
...
@@ -96,4 +85,4 @@
android:onClick=
"onButtonClick"
android:text=
"@string/eq"
/>
</com.android.calculator2.CalculatorPadLayout>
</com.android.calculator2.Calculator
Numeric
PadLayout>
This diff is collapsed.
Click to expand it.
res/values-fa/config.xml
0 → 100644
View file @
17bb4d3d
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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.
-->
<resources>
<!-- Whether to use localized digits in the numeric pad. -->
<bool
name=
"use_localized_digits"
>
true
</bool>
</resources>
This diff is collapsed.
Click to expand it.
res/values/config.xml
0 → 100644
View file @
17bb4d3d
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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.
-->
<resources>
<!-- Whether to use localized digits in the numeric pad. -->
<bool
name=
"use_localized_digits"
>
false
</bool>
</resources>
This diff is collapsed.
Click to expand it.
res/values/strings.xml
View file @
17bb4d3d
...
...
@@ -25,30 +25,6 @@
<!-- Error displayed when expression contains a syntax error. [CHAR_LIMIT=14] -->
<string
name=
"error_syntax"
>
Error
</string>
<!-- Decimal separator (e.g. "1.23"). [CHAR_LIMIT=1] -->
<string
name=
"dec_point"
>
.
</string>
<!-- Decimal representation of zero (e.g. "0", "10", "1.0", "1e0"). [CHAR_LIMIT=1] -->
<string
name=
"digit_0"
>
0
</string>
<!-- Decimal representation of one (e.g. "1", "11", "1.1", "1e1"). [CHAR_LIMIT=1] -->
<string
name=
"digit_1"
>
1
</string>
<!-- Decimal representation of two (e.g. "2", "22", "2.2", "2e2"). [CHAR_LIMIT=1] -->
<string
name=
"digit_2"
>
2
</string>
<!-- Decimal representation of three (e.g. "3", "33", "3.3", "3e3"). [CHAR_LIMIT=1] -->
<string
name=
"digit_3"
>
3
</string>
<!-- Decimal representation of four (e.g. "4", "44", "4.4", "4e4"). [CHAR_LIMIT=1] -->
<string
name=
"digit_4"
>
4
</string>
<!-- Decimal representation of five (e.g. "5", "55", "5.5", "5e5"). [CHAR_LIMIT=1] -->
<string
name=
"digit_5"
>
5
</string>
<!-- Decimal representation of six (e.g. "6", "66", "6.6", "6e6"). [CHAR_LIMIT=1] -->
<string
name=
"digit_6"
>
6
</string>
<!-- Decimal representation of seven (e.g. "7", "77", "7.7", "7e7"). [CHAR_LIMIT=1] -->
<string
name=
"digit_7"
>
7
</string>
<!-- Decimal representation of eight (e.g. "8", "88", "8.8", "8e8"). [CHAR_LIMIT=1] -->
<string
name=
"digit_8"
>
8
</string>
<!-- Decimal representation of eight (e.g. "9", "99", "9.9", "9e9"). [CHAR_LIMIT=1] -->
<string
name=
"digit_9"
>
9
</string>
<!-- Abbrev. name of cosine function (e.g. "cos(π)". [CHAR_LIMIT=3] -->
<string
name=
"fun_cos"
>
cos
</string>
<!-- Natural logarithm function (e.g. "ln(2)"). [CHAR_LIMIT=3] -->
...
...
This diff is collapsed.
Click to expand it.
src/com/android/calculator2/CalculatorExpressionTokenizer.java
View file @
17bb4d3d
...
...
@@ -18,7 +18,11 @@ package com.android.calculator2;
import
android.content.Context
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormatSymbols
;
import
java.text.NumberFormat
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map.Entry
;
...
...
@@ -29,18 +33,22 @@ public class CalculatorExpressionTokenizer {
public
CalculatorExpressionTokenizer
(
Context
context
)
{
mReplacementMap
=
new
HashMap
<>();
mReplacementMap
.
put
(
"."
,
context
.
getString
(
R
.
string
.
dec_point
));
Locale
locale
=
context
.
getResources
().
getConfiguration
().
locale
;
if
(!
context
.
getResources
().
getBoolean
(
R
.
bool
.
use_localized_digits
))
{
locale
=
new
Locale
.
Builder
()
.
setLocale
(
locale
)
.
setUnicodeLocaleKeyword
(
"nu"
,
"latn"
)
.
build
();
}
final
DecimalFormatSymbols
symbols
=
new
DecimalFormatSymbols
(
locale
);
final
char
zeroDigit
=
symbols
.
getZeroDigit
();
mReplacementMap
.
put
(
"0"
,
context
.
getString
(
R
.
string
.
digit_0
));
mReplacementMap
.
put
(
"1"
,
context
.
getString
(
R
.
string
.
digit_1
));
mReplacementMap
.
put
(
"2"
,
context
.
getString
(
R
.
string
.
digit_2
));
mReplacementMap
.
put
(
"3"
,
context
.
getString
(
R
.
string
.
digit_3
));
mReplacementMap
.
put
(
"4"
,
context
.
getString
(
R
.
string
.
digit_4
));
mReplacementMap
.
put
(
"5"
,
context
.
getString
(
R
.
string
.
digit_5
));
mReplacementMap
.
put
(
"6"
,
context
.
getString
(
R
.
string
.
digit_6
));
mReplacementMap
.
put
(
"7"
,
context
.
getString
(
R
.
string
.
digit_7
));
mReplacementMap
.
put
(
"8"
,
context
.
getString
(
R
.
string
.
digit_8
));
mReplacementMap
.
put
(
"9"
,
context
.
getString
(
R
.
string
.
digit_9
));
mReplacementMap
.
put
(
"."
,
String
.
valueOf
(
symbols
.
getDecimalSeparator
()));
for
(
int
i
=
0
;
i
<=
9
;
++
i
)
{
mReplacementMap
.
put
(
Integer
.
toString
(
i
),
String
.
valueOf
((
char
)
(
i
+
zeroDigit
)));
}
mReplacementMap
.
put
(
"/"
,
context
.
getString
(
R
.
string
.
op_div
));
mReplacementMap
.
put
(
"*"
,
context
.
getString
(
R
.
string
.
op_mul
));
...
...
This diff is collapsed.
Click to expand it.
src/com/android/calculator2/CalculatorNumericPadLayout.java
0 → 100644
View file @
17bb4d3d
/*
* Copyright (C) 2014 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.util.AttributeSet
;
import
android.widget.Button
;
import
android.view.View
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormatSymbols
;
import
java.text.NumberFormat
;
import
java.util.Locale
;
public
class
CalculatorNumericPadLayout
extends
CalculatorPadLayout
{
public
CalculatorNumericPadLayout
(
Context
context
)
{
this
(
context
,
null
);
}
public
CalculatorNumericPadLayout
(
Context
context
,
AttributeSet
attrs
)
{
this
(
context
,
attrs
,
0
);
}
public
CalculatorNumericPadLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyle
)
{
super
(
context
,
attrs
,
defStyle
);
}
@Override
public
void
onFinishInflate
()
{
super
.
onFinishInflate
();
Locale
locale
=
getResources
().
getConfiguration
().
locale
;
if
(!
getResources
().
getBoolean
(
R
.
bool
.
use_localized_digits
))
{
locale
=
new
Locale
.
Builder
()
.
setLocale
(
locale
)
.
setUnicodeLocaleKeyword
(
"nu"
,
"latn"
)
.
build
();
}
final
DecimalFormatSymbols
symbols
=
DecimalFormatSymbols
.
getInstance
(
locale
);
final
char
zeroDigit
=
symbols
.
getZeroDigit
();
for
(
int
childIndex
=
getChildCount
()
-
1
;
childIndex
>=
0
;
--
childIndex
)
{
final
View
v
=
getChildAt
(
childIndex
);
if
(
v
instanceof
Button
)
{
final
Button
b
=
(
Button
)
v
;
switch
(
b
.
getId
())
{
case
R
.
id
.
digit_0
:
b
.
setText
(
String
.
valueOf
(
zeroDigit
));
break
;
case
R
.
id
.
digit_1
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
1
)));
break
;
case
R
.
id
.
digit_2
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
2
)));
break
;
case
R
.
id
.
digit_3
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
3
)));
break
;
case
R
.
id
.
digit_4
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
4
)));
break
;
case
R
.
id
.
digit_5
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
5
)));
break
;
case
R
.
id
.
digit_6
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
6
)));
break
;
case
R
.
id
.
digit_7
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
7
)));
break
;
case
R
.
id
.
digit_8
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
8
)));
break
;
case
R
.
id
.
digit_9
:
b
.
setText
(
String
.
valueOf
((
char
)
(
zeroDigit
+
9
)));
break
;
case
R
.
id
.
dec_point
:
b
.
setText
(
String
.
valueOf
(
symbols
.
getDecimalSeparator
()));
break
;
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment