summaryrefslogtreecommitdiff
path: root/misc/client/Piztor/src
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-25 17:55:34 +0800
committerTeddy <[email protected]>2013-08-25 17:55:34 +0800
commitf4d0989ae888bc2f83f0bc09cc826f7c79b1b6b5 (patch)
tree79c9fbb49a5a857c56843cef01b032e3430aa085 /misc/client/Piztor/src
parentf74999631c4f83a0c8532d6b7adb348dcd5d5205 (diff)
parent0a76dad753ed88a7575c2aafdd068ef6caa7247f (diff)
Merge branch 'master' of github.com:Determinant/piztor
Diffstat (limited to 'misc/client/Piztor/src')
-rw-r--r--misc/client/Piztor/src/com/macaroon/piztor/ActMgr.java63
-rw-r--r--misc/client/Piztor/src/com/macaroon/piztor/AppMgr.java62
-rw-r--r--misc/client/Piztor/src/com/macaroon/piztor/InitAct.java22
-rw-r--r--misc/client/Piztor/src/com/macaroon/piztor/PiztorAct.java60
4 files changed, 207 insertions, 0 deletions
diff --git a/misc/client/Piztor/src/com/macaroon/piztor/ActMgr.java b/misc/client/Piztor/src/com/macaroon/piztor/ActMgr.java
new file mode 100644
index 0000000..81fa6f2
--- /dev/null
+++ b/misc/client/Piztor/src/com/macaroon/piztor/ActMgr.java
@@ -0,0 +1,63 @@
+package com.macaroon.piztor;
+
+import java.util.*;
+
+import android.annotation.SuppressLint;
+
+@SuppressLint("UseSparseArrays")
+public class ActMgr {
+ // event
+ PiztorAct act;
+ ActStatus nowStatus;
+ HashMap<ActStatus, HashMap<Integer, ActStatus>> mp;
+
+ ActMgr(PiztorAct act, ActStatus nowStatus, ActStatus[] r) {
+ this.act = act;
+ this.nowStatus = nowStatus;
+ mp = new HashMap<ActStatus, HashMap<Integer, ActStatus>>();
+ for (int i = 0; i < r.length; i++) {
+ mp.put(r[i], new HashMap<Integer, ActStatus>());
+ }
+ }
+
+ void trigger(int event) {
+ for (Integer i : mp.get(nowStatus).keySet())
+ System.out.println(i);
+ if (mp.get(nowStatus).containsKey(event)) {
+ nowStatus.leave(event);
+ nowStatus = mp.get(nowStatus).get(event);
+ nowStatus.enter(event);
+ } else if (AppMgr.mp.get(act.getClass()).containsKey(event)) {
+ AppMgr.trigger(event);
+ }
+ }
+
+ void add(ActStatus a, int event, ActStatus b) {
+ if (mp.containsKey(a)) {
+ HashMap<Integer, ActStatus> h = mp.get(a);
+ h.put(event, b);
+ mp.put(a, h);
+ } else {
+ HashMap<Integer, ActStatus> h = new HashMap<Integer, ActStatus>();
+ h.put(event, b);
+ mp.put(a, h);
+ }
+ }
+}
+
+abstract class ActStatus {
+ abstract void enter(int e);
+
+ abstract void leave(int e);
+}
+
+class EmptyStatus extends ActStatus {
+ @Override
+ void enter(int e) {
+ }
+
+ @Override
+ void leave(int e) {
+ }
+
+}
diff --git a/misc/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/misc/client/Piztor/src/com/macaroon/piztor/AppMgr.java
new file mode 100644
index 0000000..9259786
--- /dev/null
+++ b/misc/client/Piztor/src/com/macaroon/piztor/AppMgr.java
@@ -0,0 +1,62 @@
+package com.macaroon.piztor;
+
+import java.util.HashMap;
+
+import android.annotation.SuppressLint;
+import android.content.Intent;
+
+@SuppressLint("UseSparseArrays")
+public class AppMgr {
+ // Status
+ public enum ActivityStatus{
+ create, start, resume, restart, stop, pause, destroy
+ }
+ static ActivityStatus status;
+ static PiztorAct nowAct;
+
+ static HashMap<Class<?>, HashMap<Integer, Class<?>>> mp;
+
+ static void setStatus(ActivityStatus st) {
+ status = st;
+ }
+
+ static void trigger(int event) {
+
+ Intent i = new Intent();
+ i.setClass(nowAct, mp.get(nowAct.getClass()).get(event));
+ nowAct.startActivity(i);
+ }
+
+ static void add(Class<?> a, Integer event, Class<?> b) {
+ if (mp.containsKey(a))
+ mp.get(a).put(event, b);
+ else {
+ HashMap<Integer, Class<?>> h = new HashMap<Integer, Class<?>>();
+ h.put(event, b);
+ mp.put(a, h);
+ }
+ }
+
+ static void addTransition(Class<?> a, int i, Class<?> b) {
+ if (mp.containsKey(a)) {
+ HashMap<Integer, Class<?>> h = mp.get(a);
+ h.put(i, b);
+ mp.put(a, h);
+ } else {
+ HashMap<Integer, Class<?>> h = new HashMap<Integer, Class<?>>();
+ h.put(i, b);
+ mp.put(a, h);
+ }
+ }
+
+ static void addStatus(Class<?> a) {
+ mp.put(a, new HashMap<Integer, Class<?>>());
+ }
+
+ static void init() {
+ mp = new HashMap<Class<?>, HashMap<Integer, Class<?>>>();
+ addStatus(InitAct.class);
+
+ }
+
+}
diff --git a/misc/client/Piztor/src/com/macaroon/piztor/InitAct.java b/misc/client/Piztor/src/com/macaroon/piztor/InitAct.java
new file mode 100644
index 0000000..1ce492c
--- /dev/null
+++ b/misc/client/Piztor/src/com/macaroon/piztor/InitAct.java
@@ -0,0 +1,22 @@
+package com.macaroon.piztor;
+
+import android.os.Bundle;
+import android.app.Activity;
+import android.view.Menu;
+
+public class InitAct extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_init);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.init, menu);
+ return true;
+ }
+
+}
diff --git a/misc/client/Piztor/src/com/macaroon/piztor/PiztorAct.java b/misc/client/Piztor/src/com/macaroon/piztor/PiztorAct.java
new file mode 100644
index 0000000..ad12b17
--- /dev/null
+++ b/misc/client/Piztor/src/com/macaroon/piztor/PiztorAct.java
@@ -0,0 +1,60 @@
+package com.macaroon.piztor;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class PiztorAct extends Activity {
+ String id;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ System.out.println(id + " on create");
+ AppMgr.setStatus(AppMgr.ActivityStatus.create);
+ AppMgr.nowAct = this;
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ System.out.println(id + " on start");
+ AppMgr.setStatus(AppMgr.ActivityStatus.start);
+ AppMgr.nowAct = this;
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ System.out.println(id + " on stop");
+ AppMgr.setStatus(AppMgr.ActivityStatus.stop);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ System.out.println(id + " on resume");
+ AppMgr.setStatus(AppMgr.ActivityStatus.resume);
+ AppMgr.nowAct = this;
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ System.out.println(id + " on pause");
+ AppMgr.setStatus(AppMgr.ActivityStatus.pause);
+ }
+
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ System.out.println(id + " on restart");
+ AppMgr.setStatus(AppMgr.ActivityStatus.restart);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ System.out.println(id + " on destroy");
+ AppMgr.setStatus(AppMgr.ActivityStatus.destroy);
+ }
+
+}