From 73f468dfcc73945c7051327b398e2a5e5881c35b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 21 Jul 2016 17:44:14 -0400 Subject: [PATCH] calculator: prettier Android variant MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- examples/calculator/Makefile | 5 +- examples/calculator/android/res/values/color.xml | 56 ++++++++++++++++++++++ examples/calculator/src/android_calculator.nit | 44 +++++++++++++---- 3 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 examples/calculator/android/res/values/color.xml diff --git a/examples/calculator/Makefile b/examples/calculator/Makefile index bf2a19e..d86b9ff 100644 --- a/examples/calculator/Makefile +++ b/examples/calculator/Makefile @@ -26,13 +26,14 @@ bin/scientific.apk: $(shell ${NITLS} -M src/scientific src/android_calculator.ni android-release: $(shell ${NITLS} -M src/scientific src/android_calculator.nit) ${NITC} android/res/drawable-hdpi/icon.png mkdir -p bin - ${NITC} -o bin/calculator.apk src/scientific -m src/android_calculator.nit --release + ${NITC} -o bin/calculator.apk src/android_calculator.nit --release + ${NITC} -o bin/scientific.apk src/scientific -m src/android_calculator.nit --release android/res/drawable-hdpi/icon.png: art/icon.svg ../../contrib/inkscape_tools/bin/svg_to_icons mkdir -p android/res ../../contrib/inkscape_tools/bin/svg_to_icons art/icon.svg --android --out android/res/ -src/scientific/android/res/drawable-hdpi/icon.png: art/icon_sci.svg ../../contrib/inkscape_tools/bin/svg_to_icons +src/scientific/android/res/drawable-hdpi/icon.png: art/icon-sci.svg ../../contrib/inkscape_tools/bin/svg_to_icons mkdir -p src/scientific/android/res ../../contrib/inkscape_tools/bin/svg_to_icons art/icon-sci.svg --android --out src/scientific/android/res/ diff --git a/examples/calculator/android/res/values/color.xml b/examples/calculator/android/res/values/color.xml new file mode 100644 index 0000000..3ed5b06 --- /dev/null +++ b/examples/calculator/android/res/values/color.xml @@ -0,0 +1,56 @@ + + + + + + + #00BCD4 + + + #F40056 + + + #FFF + + + #8A000000 + + + #6C000000 + + + #434343 + + + #636363 + + + #1DE9B6 + + + #FFF + + + #91000000 + + + #33FFFFFF + + + #1A000000 + + diff --git a/examples/calculator/src/android_calculator.nit b/examples/calculator/src/android_calculator.nit index 1d51073..8bdbdc8 100644 --- a/examples/calculator/src/android_calculator.nit +++ b/examples/calculator/src/android_calculator.nit @@ -19,18 +19,46 @@ import calculator import android redef class Button - init do set_android_style(native, (text or else "?").is_int) + init do set_android_style(native, app.native_activity, + (text or else "?").is_int, + ["+","-","×","C","÷","=","."].has(text)) - private fun set_android_style(java_button: NativeButton, is_number: Bool) + # Set color and text style + private fun set_android_style(java_button: NativeButton, activity: NativeActivity, + is_number: Bool, is_basic_op: Bool) in "Java" `{ - // Flatten the background and use a different color for digit buttons - int color = is_number? android.graphics.Color.DKGRAY: android.graphics.Color.TRANSPARENT; - java_button.setBackgroundColor(color); + // Set color + int back_color_id = 0; + if (is_number) + back_color_id = R.color.pad_numeric_background_color; + else if (is_basic_op) + back_color_id = R.color.pad_operator_background_color; + else { + back_color_id = R.color.pad_advanced_background_color; - // Center the label on both horizontal and vertical axes - java_button.setGravity(android.view.Gravity.CENTER); + int text_color = activity.getResources().getColor(R.color.pad_button_advanced_text_color); + java_button.setTextColor(text_color); + } + java_button.setBackgroundResource(back_color_id); - // Set lowercase text to correctly display constants like e and π + // Center label, use lowercase and make text bigger + java_button.setGravity(android.view.Gravity.CENTER); java_button.setAllCaps(false); + java_button.setTextSize(android.util.TypedValue.COMPLEX_UNIT_FRACTION, 100.0f); + `} +end + +redef class TextInput + init do set_android_style(native, app.native_activity) + + # Set text style and hide cursor + private fun set_android_style(java_edit_text: NativeEditText, activity: NativeActivity) + in "Java" `{ + java_edit_text.setBackgroundResource(R.color.display_background_color); + java_edit_text.setTextColor( + activity.getResources().getColor(R.color.display_formula_text_color)); + java_edit_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_FRACTION, 120.0f); + java_edit_text.setCursorVisible(false); + java_edit_text.setGravity(android.view.Gravity.CENTER_VERTICAL | android.view.Gravity.END); `} end -- 1.7.9.5