examples/calculator: add a debug option
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 21 Aug 2015 18:16:38 +0000 (14:16 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sat, 22 Aug 2015 21:46:34 +0000 (17:46 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/calculator/Makefile
examples/calculator/src/calculator.nit

index ed20940..edcfc14 100644 (file)
@@ -10,7 +10,7 @@ bin/calculator: $(shell ${NITLS} -M src/calculator.nit -m linux) ${NITC}
 bin/calculator.apk: $(shell ${NITLS} -M src/calculator.nit -m android) ${NITC} ../../contrib/inkscape_tools/bin/svg_to_icons
        mkdir -p bin res
        ../../contrib/inkscape_tools/bin/svg_to_icons art/icon.svg --android --out res/
-       ${NITC} -o $@ src/calculator.nit -m ../../lib/android/ui/
+       ${NITC} -o $@ src/calculator.nit -m ../../lib/android/ui/ -D debug
 
 ../../contrib/inkscape_tools/bin/svg_to_icons:
        make -C ../../contrib/inkscape_tools/
index 6ed8be7..76c3a0a 100644 (file)
@@ -29,9 +29,14 @@ import android::aware
 
 import calculator_logic
 
+# Show debug output?
+fun debug: Bool do return false
+
 redef class App
        redef fun on_create
        do
+               if debug then print "App::on_create"
+
                # Create the main window
                window = new CalculatorWindow
                super
@@ -56,6 +61,8 @@ class CalculatorWindow
 
        init
        do
+               if debug then print "CalculatorWindow::init"
+
                # All the button labels, row by row
                var rows = [["7", "8", "9", "+"],
                            ["4", "5", "6", "-"],
@@ -76,6 +83,8 @@ class CalculatorWindow
 
        redef fun on_event(event)
        do
+               if debug then print "CalculatorWindow::on_event {event}"
+
                if event isa ButtonPressEvent then
 
                        var op = event.sender.text
@@ -96,12 +105,16 @@ class CalculatorWindow
 
        redef fun on_save_state
        do
+               if debug then print "CalculatorWindow::on_save_state"
+
                app.data_store["context"] = context
                super
        end
 
        redef fun on_restore_state
        do
+               if debug then print "CalculatorWindow::on_restore_state"
+
                super
 
                var context = app.data_store["context"]