Merge: new `with` statement
[nit.git] / examples / calculator / src / calculator_android.nit
index 9b79886..1b1e686 100644 (file)
@@ -18,7 +18,7 @@
 module calculator_android is
        app_name "app.nit Calc."
        app_version(0, 1, git_revision)
-       java_package "org.nitlanguage.calculator"
+       app_namespace "org.nitlanguage.calculator"
 
        # Lock in portrait mode
        android_manifest_activity """android:screenOrientation="portrait""""
@@ -86,6 +86,32 @@ redef class Activity
                native.content_view = layout
        end
 
+       redef fun on_save_instance_state(state)
+       do
+               super
+
+               var nity = new Bundle.from(state)
+               nity["context"] = context.to_json
+       end
+
+       redef fun on_restore_instance_state(state)
+       do
+               super
+
+               var nity = new Bundle.from(state)
+               if not nity.has("context") then return
+
+               var json = nity.string("context")
+               if json == null then return
+
+               context = new CalculatorContext.from_json(json)
+       end
+
+       redef fun on_resume
+       do
+               display.text = context.display_text
+       end
+
        redef fun catch_event(event)
        do
                if event isa ClickEvent then