calculator: add variant for Android 21 +
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 9 Aug 2016 14:22:33 +0000 (10:22 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 11 Aug 2016 18:34:30 +0000 (14:34 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/calculator/Makefile
examples/calculator/package.ini
examples/calculator/src/android21/android/res/values/styles.xml [new file with mode: 0644]
examples/calculator/src/android21/android21.nit [new file with mode: 0644]

index d86b9ff..8cb0968 100644 (file)
@@ -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
index 8237327..014014d 100644 (file)
@@ -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 (file)
index 0000000..95c844a
--- /dev/null
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  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.
+  -->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <style name="CalculatorTheme" parent="@android:style/Theme.Material.Light.NoActionBar">
+        <item name="android:colorPrimary">@color/calculator_accent_color</item>
+        <item name="android:navigationBarColor">@color/calculator_accent_color</item>
+        <item name="android:statusBarColor">@color/calculator_accent_color</item>
+        <item name="android:windowContentOverlay">@null</item>
+    </style>
+
+    <style name="DisplayEditTextStyle" parent="@android:style/Widget.Material.Light.EditText">
+        <item name="android:background">@android:color/transparent</item>
+        <item name="android:cursorVisible">false</item>
+        <item name="android:fontFamily">sans-serif-light</item>
+        <item name="android:includeFontPadding">false</item>
+        <item name="android:gravity">bottom|end</item>
+    </style>
+
+    <style name="PadButtonStyle" parent="@android:style/Widget.Material.Light.Button.Borderless">
+        <item name="android:layout_width">wrap_content</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:fontFamily">sans-serif-light</item>
+        <item name="android:gravity">center</item>
+        <item name="android:includeFontPadding">false</item>
+        <item name="android:minWidth">0dip</item>
+        <item name="android:minHeight">0dip</item>
+        <item name="android:textAllCaps">false</item>
+        <item name="android:textColor">@color/pad_button_text_color</item>
+    </style>
+
+    <style name="PadLayoutStyle">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">match_parent</item>
+    </style>
+</resources>
diff --git a/examples/calculator/src/android21/android21.nit b/examples/calculator/src/android21/android21.nit
new file mode 100644 (file)
index 0000000..421bd1f
--- /dev/null
@@ -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