From ac7633d8149a28af288ac0b850850cef9b13c151 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Sun, 25 Aug 2013 15:45:55 +0800 Subject: This is alpha --- .../Piztor/src/com/macaroon/piztor/ActMgr.java | 63 ++++++++++++++++++++++ .../Piztor/src/com/macaroon/piztor/AppMgr.java | 62 +++++++++++++++++++++ .../Piztor/src/com/macaroon/piztor/InitAct.java | 22 ++++++++ .../Piztor/src/com/macaroon/piztor/PiztorAct.java | 60 +++++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100644 misc/client/Piztor/src/com/macaroon/piztor/ActMgr.java create mode 100644 misc/client/Piztor/src/com/macaroon/piztor/AppMgr.java create mode 100644 misc/client/Piztor/src/com/macaroon/piztor/InitAct.java create mode 100644 misc/client/Piztor/src/com/macaroon/piztor/PiztorAct.java (limited to 'misc/client/Piztor/src/com') 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> mp; + + ActMgr(PiztorAct act, ActStatus nowStatus, ActStatus[] r) { + this.act = act; + this.nowStatus = nowStatus; + mp = new HashMap>(); + for (int i = 0; i < r.length; i++) { + mp.put(r[i], new HashMap()); + } + } + + 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 h = mp.get(a); + h.put(event, b); + mp.put(a, h); + } else { + HashMap h = new HashMap(); + 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, HashMap>> 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> h = new HashMap>(); + h.put(event, b); + mp.put(a, h); + } + } + + static void addTransition(Class a, int i, Class b) { + if (mp.containsKey(a)) { + HashMap> h = mp.get(a); + h.put(i, b); + mp.put(a, h); + } else { + HashMap> h = new HashMap>(); + h.put(i, b); + mp.put(a, h); + } + } + + static void addStatus(Class a) { + mp.put(a, new HashMap>()); + } + + static void init() { + mp = new HashMap, HashMap>>(); + 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); + } + +} -- cgit v1.2.3-70-g09d2