From: Alexis Laferrière Date: Tue, 9 Aug 2016 14:22:33 +0000 (-0400) Subject: calculator: add variant for Android 21 + X-Git-Url: http://nitlanguage.org calculator: add variant for Android 21 + Signed-off-by: Alexis Laferrière --- diff --git a/examples/calculator/Makefile b/examples/calculator/Makefile index d86b9ff..8cb0968 100644 --- a/examples/calculator/Makefile +++ b/examples/calculator/Makefile @@ -13,21 +13,35 @@ bin/scientific: $(shell ${NITLS} -M scientific linux) ${NITC} # --- # Android +# +# There are 4 versions, combining 2 variations: +# * scientific vs non-scientific +# * android API 21+ vs under 21 -android: bin/calculator.apk bin/scientific.apk +android: bin/calculator.apk bin/scientific.apk bin/calculator21.apk bin/scientific21.apk bin/calculator.apk: $(shell ${NITLS} -M src/android_calculator.nit) ${NITC} android/res/drawable-hdpi/icon.png mkdir -p bin ${NITC} -o $@ src/android_calculator.nit -D debug +bin/calculator21.apk: $(shell ${NITLS} -M src/android21) ${NITC} android/res/drawable-hdpi/icon.png + mkdir -p bin + ${NITC} -o $@ src/android21 -D debug + bin/scientific.apk: $(shell ${NITLS} -M src/scientific src/android_calculator.nit) ${NITC} src/scientific/android/res/drawable-hdpi/icon.png mkdir -p bin ${NITC} -o $@ src/scientific -m src/android_calculator.nit -D debug +bin/scientific21.apk: $(shell ${NITLS} -M src/scientific src/android21) ${NITC} src/scientific/android/res/drawable-hdpi/icon.png + mkdir -p bin + ${NITC} -o $@ src/scientific -m src/android21 -D debug + 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/android_calculator.nit --release + ${NITC} -o bin/calculator21.apk src/android21 --release ${NITC} -o bin/scientific.apk src/scientific -m src/android_calculator.nit --release + ${NITC} -o bin/scientific21.apk src/scientific -m src/android21 --release android/res/drawable-hdpi/icon.png: art/icon.svg ../../contrib/inkscape_tools/bin/svg_to_icons mkdir -p android/res diff --git a/examples/calculator/package.ini b/examples/calculator/package.ini index 8237327..014014d 100644 --- a/examples/calculator/package.ini +++ b/examples/calculator/package.ini @@ -9,4 +9,4 @@ git=https://github.com/nitlang/nit.git git.directory=examples/calculator/ homepage=http://nitlanguage.org issues=https://github.com/nitlang/nit/issues -apk=http://nitlanguage.org/fdroid/apk/calculator.apk +apk=http://nitlanguage.org/fdroid/apk/calculator21.apk diff --git a/examples/calculator/src/android21/android/res/values/styles.xml b/examples/calculator/src/android21/android/res/values/styles.xml new file mode 100644 index 0000000..95c844a --- /dev/null +++ b/examples/calculator/src/android21/android/res/values/styles.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + diff --git a/examples/calculator/src/android21/android21.nit b/examples/calculator/src/android21/android21.nit new file mode 100644 index 0000000..421bd1f --- /dev/null +++ b/examples/calculator/src/android21/android21.nit @@ -0,0 +1,50 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# 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. + +# Aesthetic adaptations for Android Lollypop (API 21) +module android21 is + android_api_min 21 + android_api_target 21 + android_manifest_activity """android:theme="@style/CalculatorTheme" """ + app_files +end + +import android_calculator + +redef class TextInput + init do + set_android_style(native, app.native_activity) + super + end + + # Deactivate the virtual keyboard and set the text style from XML resources + private fun set_android_style(java_edit_text: NativeEditText, activity: NativeActivity) + in "Java" `{ + java_edit_text.setShowSoftInputOnFocus(false); + java_edit_text.setTextAppearance(activity, R.style.DisplayEditTextStyle); + `} +end + +redef class Button + init do + set_text_style(native, app.native_activity) + super + end + + # Set the text style from XML resources + private fun set_text_style(java_button: NativeButton, activity: NativeActivity) + in "Java" `{ + java_button.setTextAppearance(activity, R.style.PadButtonStyle); + `} +end