diff options
author | Teddy <ted.sybil@gmail.com> | 2013-08-26 09:48:29 +0800 |
---|---|---|
committer | Teddy <ted.sybil@gmail.com> | 2013-08-26 09:48:29 +0800 |
commit | 9b9993e33932058cc78d1882a301eefd22380b45 (patch) | |
tree | e0f86e718ffc18b7f5941cd71a721e3b461296c6 /client/Piztor/src/com/macaroon/piztor/ActMgr.java | |
parent | 7f91994a99cb7d23a22d949454e861e879a68e98 (diff) | |
parent | 6400b18210587cb25b475bc2d3979b9a6da5eda4 (diff) |
Merge branch 'master' of github.com:Determinant/piztor
Diffstat (limited to 'client/Piztor/src/com/macaroon/piztor/ActMgr.java')
-rw-r--r-- | client/Piztor/src/com/macaroon/piztor/ActMgr.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/ActMgr.java b/client/Piztor/src/com/macaroon/piztor/ActMgr.java new file mode 100644 index 0000000..f5ff994 --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/ActMgr.java @@ -0,0 +1,67 @@ +package com.macaroon.piztor; + +import java.util.*; + +import android.annotation.SuppressLint; + +@SuppressLint("UseSparseArrays") +public class ActMgr { + final static int Create = -1; + // event + PiztorAct act; + ActStatus nowStatus; + HashMap<ActStatus, HashMap<Integer, ActStatus>> mp; + + ActMgr(PiztorAct act, ActStatus nowStatus, ActStatus[] r) { + this.act = act; + this.nowStatus = nowStatus; + nowStatus.enter(Create); + 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) { + System.out.println(act.id + " : " + event); + 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); + } else { + System.out.println("can not trigger the event at " + act.id + " : " + + 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) { + } + +} |