From: Jean Privat Date: Mon, 8 Aug 2016 14:35:00 +0000 (-0400) Subject: Merge: modelize_class: Remove an unnecessary pre-condition X-Git-Url: http://nitlanguage.org?hp=7b096bae81278c3972b6052bf83715bdc0d58b7c Merge: modelize_class: Remove an unnecessary pre-condition `build_classes` calls itself recursively on imported modules. So, there is no point to specify that imported modules must be processed first. Signed-off-by: Jean-Christophe Beaupré Pull-Request: #2233 Reviewed-by: Jean Privat --- diff --git a/contrib/benitlux/src/client/android.nit b/contrib/benitlux/src/client/android.nit index f3391bf..c009b50 100644 --- a/contrib/benitlux/src/client/android.nit +++ b/contrib/benitlux/src/client/android.nit @@ -123,11 +123,10 @@ redef class SectionTitle end redef class ItemView - init do set_backgroud(native, app.native_context) + init do set_background(native, app.native_context) - private fun set_backgroud(view: NativeView, context: NativeContext) in "Java" `{ - int color = context.getResources().getIdentifier("item_background", "color", context.getPackageName()); - view.setBackgroundResource(color); + private fun set_background(view: NativeView, context: NativeContext) in "Java" `{ + view.setBackgroundResource(R.color.item_background); `} end @@ -141,9 +140,6 @@ end private fun native_notify(context: NativeService, id: Int, title, content: JavaString) in "Java" `{ - int icon = context.getResources().getIdentifier( - "notif", "drawable", context.getPackageName()); - android.app.Notification.BigTextStyle style = new android.app.Notification.BigTextStyle(); style.bigText(content); @@ -156,7 +152,7 @@ in "Java" `{ android.app.Notification notif = new android.app.Notification.Builder(context) .setContentTitle(title) .setContentText(content) - .setSmallIcon(icon) + .setSmallIcon(R.drawable.notif) .setAutoCancel(true) .setOngoing(false) .setStyle(style) @@ -225,8 +221,7 @@ redef class BeerView rating.setRating(final_rating); // Header bar - int icon = final_context.getResources().getIdentifier("notif", "drawable", final_context.getPackageName()); - dialog_builder.setIcon(icon); + dialog_builder.setIcon(R.drawable.notif); dialog_builder.setTitle(final_title); // Rating control diff --git a/contrib/crazy_moles/src/moles.nit b/contrib/crazy_moles/src/moles.nit index 505ce49..514b71f 100644 --- a/contrib/crazy_moles/src/moles.nit +++ b/contrib/crazy_moles/src/moles.nit @@ -308,16 +308,11 @@ redef class App # Elapsed time since program launch var clock = new Clock - redef fun on_start - do - super - assets.load_all self - end - redef fun on_create do super + assets.load_all self maximum_fps = 50.0 end diff --git a/contrib/crazy_moles/src/moles_android.nit b/contrib/crazy_moles/src/moles_android.nit index edf1251..c2c7f58 100644 --- a/contrib/crazy_moles/src/moles_android.nit +++ b/contrib/crazy_moles/src/moles_android.nit @@ -29,7 +29,7 @@ redef class Game end redef class App - redef fun on_start + redef fun on_create do # We use as a reference the Moto X var tw = 720 diff --git a/examples/calculator/Makefile b/examples/calculator/Makefile index 8265899..bf2a19e 100644 --- a/examples/calculator/Makefile +++ b/examples/calculator/Makefile @@ -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/ @@ -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 diff --git a/examples/calculator/art/icon-ios-sci.svg b/examples/calculator/art/icon-ios-sci.svg new file mode 100644 index 0000000..4ff6c5c --- /dev/null +++ b/examples/calculator/art/icon-ios-sci.svg @@ -0,0 +1,100 @@ + + + + + + + + + + image/svg+xml + + + + + + + x² + + + + √ + π + + diff --git a/examples/calculator/art/icon-sci.svg b/examples/calculator/art/icon-sci.svg new file mode 100644 index 0000000..187bb2d --- /dev/null +++ b/examples/calculator/art/icon-sci.svg @@ -0,0 +1,152 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + √ + π + x² + + diff --git a/examples/calculator/src/calculator.nit b/examples/calculator/src/calculator.nit index 3b89ec7..6cfb1aa 100644 --- a/examples/calculator/src/calculator.nit +++ b/examples/calculator/src/calculator.nit @@ -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 diff --git a/examples/calculator/src/scientific/android/.gitignore b/examples/calculator/src/scientific/android/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/examples/calculator/src/scientific/android/.gitignore @@ -0,0 +1 @@ +* diff --git a/examples/calculator/src/scientific/ios/.gitignore b/examples/calculator/src/scientific/ios/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/examples/calculator/src/scientific/ios/.gitignore @@ -0,0 +1 @@ +* diff --git a/examples/calculator/src/scientific_calculator.nit b/examples/calculator/src/scientific/scientific.nit similarity index 90% rename from examples/calculator/src/scientific_calculator.nit rename to examples/calculator/src/scientific/scientific.nit index b050aa3..0faf4ab 100644 --- a/examples/calculator/src/scientific_calculator.nit +++ b/examples/calculator/src/scientific/scientific.nit @@ -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 diff --git a/lib/android/game.nit b/lib/android/game.nit index 2d17054..d04e0f9 100644 --- a/lib/android/game.nit +++ b/lib/android/game.nit @@ -27,7 +27,6 @@ redef class App super on_create on_restore_state - on_start end redef fun term_window @@ -66,6 +65,4 @@ redef class App paused = false super end - - redef fun destroy do on_destroy end diff --git a/lib/android/nit_activity.nit b/lib/android/nit_activity.nit index 1668147..1bdf597 100644 --- a/lib/android/nit_activity.nit +++ b/lib/android/nit_activity.nit @@ -207,6 +207,14 @@ redef class App end end +redef class AppComponent + # The application is starting or restarting, it is visible to the user + fun on_start do end + + # The application is being destroyed + fun on_destroy do end +end + # An Android activity # # You must implement the callbacks (prefixed with `on_`) to follow the @@ -232,7 +240,7 @@ class Activity # Notification from Android, the activity has been restarted # # Followed by `on_start`. - fun on_restart do end + fun on_restart do app.on_restart # Notification from Android, the activity has been started # diff --git a/lib/android/ui/ui.nit b/lib/android/ui/ui.nit index 7e14b19..66791c7 100644 --- a/lib/android/ui/ui.nit +++ b/lib/android/ui/ui.nit @@ -79,6 +79,16 @@ redef class App native_activity.show_fragment(root_layout_id, window.native) super end + + redef fun on_start do window.on_start + + redef fun on_destroy do window.on_destroy +end + +redef class CompositeControl + redef fun on_start do for i in items do i.on_start + + redef fun on_destroy do for i in items do i.on_destroy end redef class Activity diff --git a/lib/app/README.md b/lib/app/README.md index 0e0187b..4baecf4 100644 --- a/lib/app/README.md +++ b/lib/app/README.md @@ -18,25 +18,25 @@ The _app.nit_ application life-cycle is compatible with all target platforms. It relies on the following sequence of events, represented here by their callback method name: 1. `on_create`: The application is being created. - You should build the UI at this time. + You should build the UI at this time and launch services. -2. `on_start`: The app is starting or restarting, background activities may +2. `on_resume`: The app enters the active state, it is in the foreground and interactive. -3. `on_resume`: The app enters the active state, it is in the foreground. - -4. `on_pause`: The app leaves the active state and the foreground. +3. `on_pause`: The app becomes inactive and it leaves the foreground. It may still be visible in the background. - It may then go back to `on_resume` or `on_stop`. -5. `on_stop`: The app is completely hidden. - It may then be destroyed (`on_destroy`) or go back to `on_start`. +4. `on_stop`: The app is completely hidden. + It may then be destroyed (without warning) or go back to the active state with `on_restart`. + +5. `on_restart`: The app goes back to the inactive state. + You can revert what was done by `on_stop`. -6. `on_destroy`: The app is being destroyed. +![_app.nit_ life-cycle](doc/app-nit-lifecycle.png) Life-cycle events related to saving and restoring the application state are provided by two special callback methods: * `on_save_state`: The app may be destroyed soon, save its state for a future `on_restore_state`. - More on how it can be done in the `app::data_store` section. + There is more on how it can be done in the `app::data_store` section. * `on_restore_state`: The app is launching, restore its state from a previous `on_save_state`. @@ -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 ~~~ diff --git a/lib/app/app_base.nit b/lib/app/app_base.nit index e709e84..b2c26f5 100644 --- a/lib/app/app_base.nit +++ b/lib/app/app_base.nit @@ -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 @@ -50,32 +51,57 @@ abstract class AppComponent # The application is being created # # You should build the UI at this time. + # + # Triggers are platform specific: + # * Android: `Activity.onCreate` + # * iOS: `UIApplicationDelegate application:didFinishLaunchingWithOptions` fun on_create do end - # The application is starting or restarting, it is visible to the user - fun on_start do end - # The application enters the active state, it is in the foreground and interactive + # + # Triggers are platform specific: + # * Android: `Activity.onResume` + # * iOS: `UIApplicationDelegate applicationDidBecomeActive` fun on_resume do end # The application leaves the active state but is still partially visible # - # It may still be visible in the background. # It may then go back to `on_resume` or `on_stop`. + # + # Triggers are platform specific: + # * Android: `Activity.onPause` + # * iOS: `UIApplicationDelegate applicationWillResignActive` fun on_pause do end # The application is completely hidden from the user # - # It may then be destroyed (`on_destroy`) or go back to `on_start`. + # It may then be destroyed or go back to a paused state with `on_restart`. + # + # Triggers are platform specific: + # * Android: `Activity.onStop` + # * iOS: `UIApplicationDelegate applicationDidEnterBackground` fun on_stop do end - # The application is being destroyed - fun on_destroy do end + # The application returns to a visible state from a previous `on_stop` + # + # Triggers are platform specific: + # * Android: `Activity.onRestart` + # * iOS: `UIApplicationDelegate applicationWillEnterForeground` + fun on_restart do end # The application may be destroyed soon, save its state for a future `on_restore_state` + # + # Triggers are platform specific: + # * Android: `Activity.onSaveInstanceState` + # * iOS: `UIApplicationDelegate applicationDidEnterBackground` fun on_save_state do end # The application is launching, restore its state from a previous `on_save_state` + # + # Triggers are platform specific: + # * Android: `Activity.onCreate`, _not_ `Activity.onRestoreInstanceState` + # as it is trigged only if there is a previous Android specific save state. + # * iOS: `UIApplicationDelegate applicationDidEnterBackground` fun on_restore_state do end end diff --git a/lib/app/doc/Makefile b/lib/app/doc/Makefile new file mode 100644 index 0000000..108bb91 --- /dev/null +++ b/lib/app/doc/Makefile @@ -0,0 +1,6 @@ +all: + rubber --pdf app-nit-lifecycle.tex + convert -density 130 app-nit-lifecycle.pdf -quality 90 app-nit-lifecycle.png + +clean: + rm -f *.log *.aux *.pdf diff --git a/lib/app/doc/app-nit-lifecycle.png b/lib/app/doc/app-nit-lifecycle.png new file mode 100644 index 0000000..b241c14 Binary files /dev/null and b/lib/app/doc/app-nit-lifecycle.png differ diff --git a/lib/app/doc/app-nit-lifecycle.tex b/lib/app/doc/app-nit-lifecycle.tex new file mode 100644 index 0000000..c0f2f48 --- /dev/null +++ b/lib/app/doc/app-nit-lifecycle.tex @@ -0,0 +1,19 @@ +\documentclass[tikz]{standalone} + +\usetikzlibrary{automata,positioning} + +\begin{document} +\begin{tikzpicture}[->,shorten >= 1pt,node distance=3cm,auto] + \node[state] (off) {off}; + \node[state] (inact) [right=of off,xshift=-0.5cm] {inactive}; + \node[state] (act) [below=of inact,yshift=2cm] {active}; + \node[state] (back) [right=of inact] {stopped}; + \path[->] + (off) edge [below] node {on\_create} (inact) + (inact) edge [left] node {on\_resume} (act) + edge [below] node {on\_stop} (back) + (back) edge [above] node {on\_restart} (inact) + edge [bend right=20] node {} (off) + (act) edge [right] node {on\_pause} (inact); +\end{tikzpicture} +\end{document} diff --git a/lib/app/ui.nit b/lib/app/ui.nit index 5f66ab4..1fdf801 100644 --- a/lib/app/ui.nit +++ b/lib/app/ui.nit @@ -56,16 +56,12 @@ redef class App redef fun on_create do window.on_create - redef fun on_start do window.on_start - redef fun on_resume do window.on_resume redef fun on_pause do window.on_pause redef fun on_stop do window.on_stop - redef fun on_destroy do window.on_destroy - redef fun on_restore_state do window.on_restore_state redef fun on_save_state do window.on_save_state @@ -165,16 +161,12 @@ class CompositeControl redef fun on_create do for i in items do i.on_create - redef fun on_start do for i in items do i.on_start - redef fun on_resume do for i in items do i.on_resume redef fun on_pause do for i in items do i.on_pause redef fun on_stop do for i in items do i.on_stop - redef fun on_destroy do for i in items do i.on_destroy - redef fun on_restore_state do for i in items do i.on_restore_state redef fun on_save_state do for i in items do i.on_save_state diff --git a/lib/ios/app.nit b/lib/ios/app.nit index b0ffb30..3070868 100644 --- a/lib/ios/app.nit +++ b/lib/ios/app.nit @@ -178,7 +178,7 @@ redef class App # inactive state. # # Redef to undo changes made on entering the background. - fun will_enter_foreground do on_start + fun will_enter_foreground do on_restart # The application just became active # @@ -196,7 +196,6 @@ redef class App on_save_state on_pause on_stop - on_destroy end end diff --git a/lib/linux/linux.nit b/lib/linux/linux.nit index 6b89eb8..e958e2d 100644 --- a/lib/linux/linux.nit +++ b/lib/linux/linux.nit @@ -32,7 +32,6 @@ redef class App on_create on_restore_state - on_start on_resume end @@ -43,7 +42,6 @@ redef class App on_pause on_save_state on_stop - on_destroy end end diff --git a/lib/linux/ui.nit b/lib/linux/ui.nit index 2c0eec1..8a6cc81 100644 --- a/lib/linux/ui.nit +++ b/lib/linux/ui.nit @@ -64,7 +64,6 @@ redef class App do app.on_create app.on_restore_state - app.on_start app.on_resume gtk_main @@ -72,7 +71,6 @@ redef class App app.on_pause app.on_stop app.on_save_state - app.on_destroy end # Spacing between GTK controls, default at 2 diff --git a/share/nitweb/directives/metrics/chart_properties.html b/share/nitweb/directives/metrics/chart_properties.html new file mode 100644 index 0000000..5e80e02 --- /dev/null +++ b/share/nitweb/directives/metrics/chart_properties.html @@ -0,0 +1 @@ +
diff --git a/share/nitweb/directives/metrics/metrics_list.html b/share/nitweb/directives/metrics/metrics_list.html new file mode 100644 index 0000000..2901b5b --- /dev/null +++ b/share/nitweb/directives/metrics/metrics_list.html @@ -0,0 +1,57 @@ +
+
+

{{listTitle}}

+
+
+ + + + + + + + + + + + + + + + +
avg.std dev.min.max.
+ + {{listMetrics[metric].name.toUpperCase()}} + + No classes in this module{{listMetrics[metric].avg}}{{listMetrics[metric].std_dev}} + {{listMetrics[metric].values[listMetrics[metric].min.full_name].value}} +  () + + {{listMetrics[metric].values[listMetrics[metric].max.full_name].value}} +  () +
+

+ +

+
+ + + + + + + + + +
+ + {{listMetrics[metric].name.toUpperCase()}} + +
+ {{listMetrics[metric].values[value.mentity.full_name].value}} +
+
+
+
diff --git a/share/nitweb/index.html b/share/nitweb/index.html index c615d41..b936f1d 100644 --- a/share/nitweb/index.html +++ b/share/nitweb/index.html @@ -17,6 +17,9 @@ + + +