Skip to content

Commit

Permalink
Merge: app.nit: Intro the app_files annotation, and use it in calcu…
Browse files Browse the repository at this point in the history
…lator

Intro `app_files`, an annotation to specify where to find more Android and iOS specific files. This effectively associates resources to a specific Nit module. It can be used to have different icons per branding, or to package graphical assets with a module from the lib.

It is used in the calculator to assign a different icon to the scientific calculator variant.

Pull-Request: #2228
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <romain.chanoir@viacesi.fr>
  • Loading branch information
privat committed Aug 3, 2016
2 parents 3a6c485 + b71627c commit 0ec26df
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 58 deletions.
38 changes: 28 additions & 10 deletions examples/calculator/Makefile
Expand Up @@ -7,27 +7,35 @@ bin/calculator: $(shell ${NITLS} -M src/calculator.nit linux) ${NITC}
mkdir -p bin
${NITC} -o $@ src/calculator.nit -m linux

bin/scientific_calculator: $(shell ${NITLS} -M src/scientific_calculator.nit linux) ${NITC}
bin/scientific: $(shell ${NITLS} -M scientific linux) ${NITC}
mkdir -p bin
${NITC} -o $@ src/scientific_calculator.nit -m linux
${NITC} -o $@ src/scientific -m linux

# ---
# Android

android: bin/calculator.apk
android: bin/calculator.apk bin/scientific.apk

bin/calculator.apk: $(shell ${NITLS} -M src/scientific_calculator.nit src/android_calculator.nit) ${NITC} android/res/
bin/calculator.apk: $(shell ${NITLS} -M src/android_calculator.nit) ${NITC} android/res/drawable-hdpi/icon.png
mkdir -p bin
${NITC} -o $@ src/scientific_calculator.nit -m src/android_calculator.nit -D debug
${NITC} -o $@ src/android_calculator.nit -D debug

android-release: $(shell ${NITLS} -M src/scientific_calculator.nit src/android_calculator.nit) ${NITC} android/res/
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 bin/calculator.apk src/scientific_calculator.nit -m src/android_calculator.nit --release
${NITC} -o $@ src/scientific -m src/android_calculator.nit -D debug

android/res/: art/icon.svg ../../contrib/inkscape_tools/bin/svg_to_icons
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

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
mkdir -p src/scientific/android/res
../../contrib/inkscape_tools/bin/svg_to_icons art/icon-sci.svg --android --out src/scientific/android/res/

../../contrib/inkscape_tools/bin/svg_to_icons:
make -C ../../contrib/inkscape_tools/

Expand All @@ -37,14 +45,24 @@ android-install: bin/calculator.apk
# ---
# iOS

bin/calculator.app: $(shell ${NITLS} -M src/scientific_calculator.nit src/ios_calculator.nit) ${NITC} ios/AppIcon.appiconset/Contents.json
ios: bin/calculator.app bin/scientific.app

bin/calculator.app: $(shell ${NITLS} -M src/ios_calculator.nit) ${NITC} ios/AppIcon.appiconset/Contents.json
mkdir -p bin
${NITC} -o $@ src/scientific_calculator.nit -m src/ios_calculator.nit -D debug
${NITC} -o $@ src/ios_calculator.nit -D debug

bin/scientific.app: $(shell ${NITLS} -M src/scientific src/ios_calculator.nit) ${NITC} src/scientific/ios/AppIcon.appiconset/Contents.json
mkdir -p bin
${NITC} -o $@ src/scientific -m src/ios_calculator.nit -D debug

ios/AppIcon.appiconset/Contents.json: art/icon-ios.svg
mkdir -p ios
../../contrib/inkscape_tools/bin/svg_to_icons art/icon-ios.svg --ios --out ios/AppIcon.appiconset/

src/scientific/ios/AppIcon.appiconset/Contents.json: art/icon-ios.svg
mkdir -p ios
../../contrib/inkscape_tools/bin/svg_to_icons art/icon-ios-sci.svg --ios --out src/scientific/ios/AppIcon.appiconset/

# ---
# Tests

Expand Down
100 changes: 100 additions & 0 deletions examples/calculator/art/icon-ios-sci.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 152 additions & 0 deletions examples/calculator/art/icon-sci.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/calculator/src/calculator.nit
Expand Up @@ -14,8 +14,8 @@

# Portable calculator UI
module calculator is
app_name "app.nit Calc."
app_version(0, 1, git_revision)
app_name "app.nit Calc"
app_version(0, 2, git_revision)
app_namespace "org.nitlanguage.calculator"

# Lock in portrait mode
Expand Down
1 change: 1 addition & 0 deletions examples/calculator/src/scientific/android/.gitignore
@@ -0,0 +1 @@
*
1 change: 1 addition & 0 deletions examples/calculator/src/scientific/ios/.gitignore
@@ -0,0 +1 @@
*
Expand Up @@ -13,7 +13,11 @@
# limitations under the License.

# Extends the portable calculator app with scientific operations
module scientific_calculator
module scientific is
app_name "app.nit Calc Sci"
app_namespace "org.nitlanguage.scientific_calculator"
app_files
end

import calculator

Expand Down
11 changes: 11 additions & 0 deletions lib/app/README.md
Expand Up @@ -150,6 +150,17 @@ The _app.nit_ framework defines three annotations to customize the application p
The special function `git_revision` will use the prefix of the hash of the latest git commit.
By default, the version is 0.1.

* `app_files` tells the compiler where to find platform specific resource files associated to a module.
By default, only the root of the project is searched for the folders `android` and `ios`.
The `android` folder is used as base for the generated Android project,
it can be used to specify the resource files, libs and even Java source files.
The `ios` folder is searched for icons only.

Each argument of `app_files` is a relative path to a folder containing extra `android` or `ios` folders.
If there is no arguments, the parent folder of the annotated module is used.
In case of name conflicts in the resource files, the files from the project root have the lowest priority,
those associated to modules lower in the importation hierarchy have higher priority.

## Usage Example

~~~
Expand Down
1 change: 1 addition & 0 deletions lib/app/app_base.nit
Expand Up @@ -19,6 +19,7 @@ module app_base is
new_annotation app_name
new_annotation app_namespace
new_annotation app_version
new_annotation app_files
end

# App subclasses are cross-platform applications
Expand Down

0 comments on commit 0ec26df

Please sign in to comment.