lib/android: intro our very own NitActivity
[nit.git] / lib / android / NitActivity.java
1 /* This file is part of NIT ( http://www.nitlanguage.org ).
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package nit.app;
17
18 import android.app.Activity;
19 import android.os.Bundle;
20
21 /*
22 * Entry point to Nit applications on Android, redirect most calls to Nit
23 */
24 public class NitActivity extends Activity {
25
26 // Nit activity associated to `this`
27 protected int nitActivity = 0;
28
29 /*
30 * Calls to Nit or to the C framework
31 */
32
33 static {
34 System.loadLibrary("main");
35 }
36
37 /*
38 * Callbacks to Nit through C
39 */
40 protected native int nitRegisterActivity();
41 protected native void nitOnCreate(int activity, Bundle savedInstanceState);
42 protected native void nitOnStart(int activity);
43 protected native void nitOnRestart(int activity);
44 protected native void nitOnResume(int activity);
45 protected native void nitOnPause(int activity);
46 protected native void nitOnStop(int activity);
47 protected native void nitOnDestroy(int activity);
48 protected native void nitOnSaveInstanceState(int activity, Bundle savedInstanceState);
49 protected native void nitOnRestoreInstanceState(int activity, Bundle savedInstanceState);
50
51 /*
52 * Implementation of OS callbacks
53 */
54
55 @Override
56 public void onCreate(Bundle savedInstanceState) {
57 super.onCreate(savedInstanceState);
58
59 nitActivity = nitRegisterActivity();
60
61 nitOnCreate(nitActivity, savedInstanceState);
62 }
63
64 @Override
65 protected void onStart() {
66 super.onStart();
67 nitOnStart(nitActivity);
68 }
69
70 @Override
71 protected void onRestart() {
72 super.onRestart();
73 nitOnRestart(nitActivity);
74 }
75
76 @Override
77 protected void onResume() {
78 super.onResume();
79 nitOnResume(nitActivity);
80 }
81
82 @Override
83 protected void onPause() {
84 super.onPause();
85 nitOnPause(nitActivity);
86 }
87
88 @Override
89 protected void onStop() {
90 super.onStop();
91 nitOnStop(nitActivity);
92 }
93
94 @Override
95 protected void onDestroy() {
96 super.onDestroy();
97 nitOnDestroy(nitActivity);
98 }
99
100 @Override
101 public void onSaveInstanceState(Bundle savedInstanceState) {
102 super.onSaveInstanceState(savedInstanceState);
103 nitOnSaveInstanceState(nitActivity, savedInstanceState);
104 }
105
106 @Override
107 public void onRestoreInstanceState(Bundle savedInstanceState) {
108 super.onRestoreInstanceState(savedInstanceState);
109 nitOnRestoreInstanceState(nitActivity, savedInstanceState);
110 }
111 }