summaryrefslogtreecommitdiff
path: root/client/Piztor/src
diff options
context:
space:
mode:
Diffstat (limited to 'client/Piztor/src')
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ActMgr.java9
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AlertMaker.java105
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AppMgr.java124
-rw-r--r--client/Piztor/src/com/macaroon/piztor/CopyMap.java50
-rw-r--r--client/Piztor/src/com/macaroon/piztor/EException.java22
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Infomation.java15
-rw-r--r--client/Piztor/src/com/macaroon/piztor/InitAct.java40
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Login.java40
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java233
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapInfo.java38
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java416
-rw-r--r--client/Piztor/src/com/macaroon/piztor/PiztorAct.java33
-rw-r--r--client/Piztor/src/com/macaroon/piztor/PushClient.java26
-rw-r--r--client/Piztor/src/com/macaroon/piztor/RUserInfo.java4
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Req.java32
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Res.java48
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Settings.java181
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SocketClient.java91
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java391
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Transam.java205
-rw-r--r--client/Piztor/src/com/macaroon/piztor/UpdateInfo.java141
-rw-r--r--client/Piztor/src/com/macaroon/piztor/myApp.java52
22 files changed, 1584 insertions, 712 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/ActMgr.java b/client/Piztor/src/com/macaroon/piztor/ActMgr.java
index 903527e..a2ad23b 100644
--- a/client/Piztor/src/com/macaroon/piztor/ActMgr.java
+++ b/client/Piztor/src/com/macaroon/piztor/ActMgr.java
@@ -11,8 +11,9 @@ public class ActMgr {
PiztorAct act;
ActStatus nowStatus;
HashMap<ActStatus, HashMap<Integer, ActStatus>> mp;
-
- ActMgr(PiztorAct act, ActStatus nowStatus, ActStatus[] r) {
+ AppMgr appMgr;
+ ActMgr(AppMgr appMgr, PiztorAct act, ActStatus nowStatus, ActStatus[] r) {
+ this.appMgr = appMgr;
this.act = act;
this.nowStatus = nowStatus;
nowStatus.enter(Create);
@@ -29,8 +30,8 @@ public class ActMgr {
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 if (appMgr.mp.get(act.getClass()).containsKey(event)) {
+ appMgr.trigger(event);
} else {
System.out.println("can not trigger the event at " + act.id + " : "
+ event);
diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
index d7a9d69..b1087a2 100644
--- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
@@ -1,5 +1,6 @@
package com.macaroon.piztor;
+import java.io.Closeable;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
@@ -13,10 +14,12 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
+import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.util.Log;
+import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -24,6 +27,8 @@ import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
@@ -46,6 +51,8 @@ public class AlertMaker {
private GeoPoint markerPoint;
private MapMaker mapMaker;
private long timestamp;
+ int mHour;
+ int mMinute;
public AlertMaker(Context cc, MapMaker mm) {
context =cc;
@@ -64,16 +71,16 @@ public class AlertMaker {
closeBoard(context);
AlertDialog.Builder gpsDialog = new AlertDialog.Builder(context);
- gpsDialog.setTitle("GPS settings");
- gpsDialog.setMessage("GPS is not enabled. Please turn it on.");
- gpsDialog.setPositiveButton("Settings",
+ gpsDialog.setTitle("GPS设置");
+ gpsDialog.setMessage("GPS未开启,是否前去打开?");
+ gpsDialog.setPositiveButton("设置",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivity(intent);
}
});
- gpsDialog.setNegativeButton("Go without GPS",
+ gpsDialog.setNegativeButton("不使用GPS",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
@@ -81,44 +88,66 @@ public class AlertMaker {
});
gpsDialog.show();
}
+
+ public void showLateAlert() {
+
+ closeBoard(context);
+ AlertDialog.Builder lateDialog = new AlertDialog.Builder(context);
+ lateDialog.setTitle("阿哦");
+ lateDialog.setMessage("你迟到了!");
+ lateDialog.setNeutralButton("知道了", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ arg0.cancel();
+ }
+ });
+ lateDialog.show();
+ closeBoard(context);
+ }
public long toTimestamp(int hour, int minute) {
+
calendar = Calendar.getInstance();
- int nhour = calendar.get(Calendar.HOUR_OF_DAY);
- int nminute = calendar.get(Calendar.MINUTE);
- int tmp = 0;
- if (hour > nhour) tmp = (hour - nhour) * 60 + minute - nminute;
- else if (minute > nminute) tmp = minute - nminute;
- timestamp = System.currentTimeMillis() + tmp * 60 * 1000;
- return timestamp;
+ calendar.set(calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH),
+ hour,minute);
+ return calendar.getTimeInMillis();
}
//TODO
public void updateMarkerTime(int hour, int minute) {
Log.d("time", hour + " " + minute);
Log.d("time", " " + toTimestamp(hour, minute));
+ mapMaker.newMarkerHour = hour;
+ mapMaker.newMarkerMinute = minute;
+ mapMaker.newMarkerTimestamp = toTimestamp(hour, minute);
}
public void showMarkerAlert(GeoPoint point) {
closeBoard(context);
+ boolean flag = false;
if (point == null) return;
markerPoint = point;
+
calendar = Calendar.getInstance();
TimePickerDialog markerDialog = new TimePickerDialog(context
, new TimePickerDialog.OnTimeSetListener() {
-
+ boolean flag = false;
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
////// at least 2 minutes
- if ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute >= calendar.get(Calendar.MINUTE))
- || hourOfDay > calendar.get(Calendar.HOUR_OF_DAY)) {
- mapMaker.DrawMarker(markerPoint);
+ if ( !flag &&
+ ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute >= calendar.get(Calendar.MINUTE))
+ || hourOfDay > calendar.get(Calendar.HOUR_OF_DAY))) {
updateMarkerTime(hourOfDay, minute);
- }
- else {
+ mapMaker.DrawMarker(markerPoint);
+ flag = true;
+ Log.d("marker", "marker alert calls drawmarker");
+ } else if (!flag) {
Toast toast = Toast.makeText(context,
- "Too early! Give me at least 2 minutes!", Toast.LENGTH_LONG);
+ "太早了!多给一点时间", Toast.LENGTH_LONG);
toast.show();
closeBoard(context);
showMarkerAlert(markerPoint);
@@ -127,12 +156,44 @@ public class AlertMaker {
}
, calendar.get(Calendar.HOUR_OF_DAY)
, calendar.get(Calendar.MINUTE), true);
- markerDialog.show();
+ markerDialog.show();
+ closeBoard(context);
}
-
+
public void showCheckinAlter() {
closeBoard(context);
- AlertDialog.Builder checkinDialog = new AlertDialog.Builder(context);
+ final AlertDialog.Builder checkinDialog = new AlertDialog.Builder(context);
+ LayoutInflater infaler = LayoutInflater.from(context);
+ final LinearLayout layout = (LinearLayout)infaler.inflate(R.layout.checkindialog, null);
+ checkinDialog.setView(layout);
+ checkinDialog.setNeutralButton("取消", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ im.hideSoftInputFromWindow(layout.getWindowToken(), 0);
+ dialog.cancel();
+ }
+ });
+ final ProgressBar pbar = (ProgressBar)layout.findViewById(R.id.checkin_progress);
+ final TextView checkinInfo = (TextView)layout.findViewById(R.id.checkin_info);
+ checkinDialog.show();
+ closeBoard(context);
+ new CountDownTimer(5000, 1000) {
+
+ public void onTick(long millisUntilFinished) {
+ int ttt = (int)millisUntilFinished;
+ pbar.setProgress(ttt);
+ }
+
+ public void onFinish() {
+ //TODO
+ pbar.setVisibility(View.GONE);
+ mapMaker.removeMarker();
+ Toast toast = Toast.makeText(context, "已签到!", 2000);
+ toast.setGravity(Gravity.TOP, 0, 80);
+ toast.show();
+ checkinInfo.setText("成功!");
+ }
+ }.start();
}
-
+
}
diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
index 933d2db..a7f1af0 100644
--- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java
+++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
@@ -1,35 +1,13 @@
package com.macaroon.piztor;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.Stack;
import android.annotation.SuppressLint;
-import android.content.Context;
import android.content.Intent;
-import android.os.Handler;
-import android.util.Log;
-
-import com.baidu.mapapi.BMapManager;
-import com.baidu.mapapi.MKGeneralListener;
@SuppressLint("UseSparseArrays")
public class AppMgr {
-
- static final String strKey = "8a0ae50048d103b2b8b12b7066f4ea7d";
- static BMapManager mBMapManager = null;
-
- // Status
- public enum ActivityStatus {
- create, start, resume, restart, stop, pause, destroy
- }
-
- static ActivityStatus status;
- static PiztorAct nowAct;
- // TODO fix
- static Handler handler, fromGPS;
- static Transam transam = null;
- static Tracker tracker = null;
- static Thread tTransam, tGPS;
// Event
final static int noToken = 101;
final static int loginSuccess = 102;
@@ -37,51 +15,68 @@ public class AppMgr {
final static int hasToken = 104;
final static int toSettings = 105;
final static int logout = 106;
+ final static int subscribe = 107;
+ final static int account = 108;
+ final static int finish = 109;
- static MapInfo mapInfo;
+ public enum ActivityStatus {
+ create, start, resume, restart, stop, pause, destroy
+ }
- static HashMap<Class<?>, HashMap<Integer, Class<?>>> mp;
- static HashSet<PiztorAct> acts;
+ myApp app;
+ HashMap<Class<?>, HashMap<Integer, Class<?>>> mp;
+ Stack<PiztorAct> acts;
+ ActivityStatus status;
+ PiztorAct nowAct;
- static void addAct(PiztorAct act) {
+ void addAct(PiztorAct act) {
if (acts == null)
- acts = new HashSet<PiztorAct>();
- acts.add(act);
+ acts = new Stack<PiztorAct>();
+ acts.push(act);
}
- static void removeAct(PiztorAct act) {
- if (acts.contains(act))
- acts.remove(act);
- else
- System.out.println("Piztor has a bug!!!!");
- }
+ /*
+ * void removeAct(PiztorAct act) { if (acts.contains(act)) acts.remove(act);
+ * else System.out.println("Piztor has a bug!!!!"); }
+ */
- static void exit() {
- for (PiztorAct act : acts) {
- act.finish();
+ void exit() {
+ while (!acts.isEmpty()) {
+ acts.peek().finish();
+ acts.pop();
}
+ app.token = null;
+ app.mBMapManager.destroy();
}
- static void setStatus(ActivityStatus st) {
+ void setStatus(ActivityStatus st) {
status = st;
}
- static void trigger(int event) {
- Intent i = new Intent();
- i.setClass(nowAct, mp.get(nowAct.getClass()).get(event));
+ void trigger(int event) {
+ if (event == finish) {
+ nowAct.finish();
+ return;
+ }
if (event == errorToken)
- Infomation.token = null;
- if (event == loginSuccess) {
- mBMapManager.start();
- mapInfo.clear();
+ app.token = null;
+ if (event == loginSuccess || event == hasToken) {
+ app.mBMapManager.start();
+ app.mapInfo.clear();
}
if (event == logout) {
- mBMapManager.stop();
+ System.out.println("我来停一发!!!!");
+ app.isLogout = true;
+ app.mBMapManager.stop();
+ nowAct.finish();
+ return;
}
+ 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) {
+ void add(Class<?> a, Integer event, Class<?> b) {
if (mp.containsKey(a))
mp.get(a).put(event, b);
else {
@@ -91,7 +86,7 @@ public class AppMgr {
}
}
- static void addTransition(Class<?> a, int i, Class<?> b) {
+ void addTransition(Class<?> a, int i, Class<?> b) {
if (mp.containsKey(a)) {
HashMap<Integer, Class<?>> h = mp.get(a);
h.put(i, b);
@@ -103,38 +98,21 @@ public class AppMgr {
}
}
- static void addStatus(Class<?> a) {
+ void addStatus(Class<?> a) {
mp.put(a, new HashMap<Integer, Class<?>>());
}
- static void init(Context context) {
- if (mBMapManager == null) {
- mBMapManager = new BMapManager(context);
- mBMapManager.init(strKey, new MKGeneralListener() {
- @Override
- public void onGetNetworkState(int iError) {
- Log.d("Network", "failure");
- System.out.println("network wocao ni ma de !!!!!!!!!");
- }
-
- @Override
- public void onGetPermissionState(int iError) {
- Log.d("Permission", "wrong key");
- System.out.println("ju ran bu gei wo quan xian !!!!!!!!!!");
- }
- });
- }
+ public AppMgr(myApp app) {
mp = new HashMap<Class<?>, HashMap<Integer, Class<?>>>();
- handler = new Handler();
- transam = new Transam(Infomation.ip, Infomation.port, handler);
- tTransam = new Thread(transam);
- tTransam.start();
- mapInfo = new MapInfo();
- Infomation.myInfo = new UserInfo(-1);
+ this.app = app;
addStatus(InitAct.class);
addStatus(Login.class);
addStatus(Main.class);
addStatus(Settings.class);
+ addTransition(UpdateInfo.class, logout, Login.class);
+ addTransition(Settings.class, subscribe, SubscribeSettings.class);
+ addTransition(SubscribeSettings.class, logout, Login.class);
+ addTransition(Settings.class, account, UpdateInfo.class);
addTransition(InitAct.class, noToken, Login.class);
addTransition(InitAct.class, hasToken, Main.class);
addTransition(InitAct.class, errorToken, Login.class);
diff --git a/client/Piztor/src/com/macaroon/piztor/CopyMap.java b/client/Piztor/src/com/macaroon/piztor/CopyMap.java
deleted file mode 100644
index 6d49767..0000000
--- a/client/Piztor/src/com/macaroon/piztor/CopyMap.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.macaroon.piztor;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import android.content.Context;
-
-public class CopyMap {
- /**
- *
- * @param myContext
- * @param ASSETS_NAME 要复制的文件名
- * @param savePath 要保存的路径
- * @param saveName 复制后的文件名
- * testCopy(Context context)是一个测试例子。
- */
-
- public static void copy(Context myContext, String ASSETS_NAME,
- String savePath, String saveName) {
- String filename = savePath + "/" + saveName;
-
- File dir = new File(savePath);
- // 如果目录不中存在,创建这个目录
- if (!dir.exists())
- dir.mkdir();
- try {
- if (!(new File(filename)).exists()) {
- InputStream is = myContext.getResources().getAssets()
- .open(ASSETS_NAME);
- System.out.println(ASSETS_NAME);
- FileOutputStream fos = new FileOutputStream(filename);
- byte[] buffer = new byte[7168];
- int count = 0;
- while ((count = is.read(buffer)) > 0) {
- fos.write(buffer, 0, count);
- }
- fos.close();
- is.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void testCopy(Context context) {
- String path=context.getFilesDir().getAbsolutePath();
- String name="test";
- CopyMap.copy(context, name, path, name);
- }
-}
-
diff --git a/client/Piztor/src/com/macaroon/piztor/EException.java b/client/Piztor/src/com/macaroon/piztor/EException.java
index 5ce1fdb..39d53c8 100644
--- a/client/Piztor/src/com/macaroon/piztor/EException.java
+++ b/client/Piztor/src/com/macaroon/piztor/EException.java
@@ -10,7 +10,9 @@ public class EException extends Exception {
static final int EPushFailedException =104;
static final int EIOException =105;
static final int EUnknownHostException =106;
- static final int EStatusFailedException =107;
+ static final int EStatusFailedException =107;
+ static final int ELevelFailedException =108;
+ static final int EPasswordFailedException =109;
private static final long serialVersionUID = 100L;
@@ -72,4 +74,20 @@ public class EException extends Exception {
public EStatusFailedException(int t,long timep) {
super(107,t,timep);
}
- } \ No newline at end of file
+ }
+
+ class ELevelFailedException extends EException{
+ private static final long serialVersionUID = 108L;
+ public ELevelFailedException(int t,long timep) {
+ super(108,t,timep);
+ }
+ }
+
+ class EPasswordFailedException extends EException{
+ private static final long serialVersionUID = 109L;
+ public EPasswordFailedException(int t,long timep) {
+ super(109,t,timep);
+ }
+ }
+
+ \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/Infomation.java b/client/Piztor/src/com/macaroon/piztor/Infomation.java
deleted file mode 100644
index 60eb03f..0000000
--- a/client/Piztor/src/com/macaroon/piztor/Infomation.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.macaroon.piztor;
-
-import java.util.Vector;
-
-public class Infomation {
- static String ip = "202.120.7.4";
- //static String ip = "192.168.1.171";
-// static String ip = "69.85.86.42";
-// static String ip = "192.168.1.101";
- static int port = 2223;
- static String token = null;
- static String username = null;
- static UserInfo myInfo;
- static Vector<RGroup> sublist;
-}
diff --git a/client/Piztor/src/com/macaroon/piztor/InitAct.java b/client/Piztor/src/com/macaroon/piztor/InitAct.java
index 8145935..5f7f61d 100644
--- a/client/Piztor/src/com/macaroon/piztor/InitAct.java
+++ b/client/Piztor/src/com/macaroon/piztor/InitAct.java
@@ -1,16 +1,30 @@
package com.macaroon.piztor;
+import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
+import android.util.Log;
import android.view.Menu;
-public class InitAct extends PiztorAct {
+import com.baidu.mapapi.MKGeneralListener;
+public class InitAct extends PiztorAct {
@Override
protected void onCreate(Bundle savedInstanceState) {
id = "initAct";
super.onCreate(savedInstanceState);
- AppMgr.init(getApplicationContext());
- AppMgr.transam.setTimeOutTime(5000);
+ app.isExiting = false;
+ app.mBMapManager.init(app.getStrkey(), new MKGeneralListener() {
+ @Override
+ public void onGetNetworkState(int iError) {
+ Log.d("Network", "failure");
+ }
+
+ @Override
+ public void onGetPermissionState(int iError) {
+ Log.d("Permission", "wrong key");
+ }
+ });
setContentView(R.layout.activity_init);
}
@@ -21,23 +35,27 @@ public class InitAct extends PiztorAct {
@Override
protected void onResume() {
+ if (app.isExiting)
+ finish();
super.onResume();
- if (Infomation.token == null)
- AppMgr.trigger(AppMgr.noToken);
+ if (app.token == null || app.isLogout) {
+ app.appMgr.trigger(AppMgr.noToken);
+ }
else {
- AppMgr.trigger(AppMgr.hasToken);
+ app.appMgr.trigger(AppMgr.hasToken);
+ System.out.println("has token!!!");
}
}
@Override
- protected void onDestroy() {
- super.onDestroy();
- }
-
- @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.init, menu);
return false;
}
+
+ @Override
+ public void finishFromChild (Activity child) {
+ finish();
+ }
}
diff --git a/client/Piztor/src/com/macaroon/piztor/Login.java b/client/Piztor/src/com/macaroon/piztor/Login.java
index 533eeac..3b9cbc2 100644
--- a/client/Piztor/src/com/macaroon/piztor/Login.java
+++ b/client/Piztor/src/com/macaroon/piztor/Login.java
@@ -16,10 +16,7 @@ public class Login extends PiztorAct {
Button btnLogin;
EditText edtUser, edtPass;
-
int loginButtonClick = 1, retryButtonClick = 2, loginFailed = 3;
-
- @SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message m) {
@@ -32,13 +29,15 @@ public class Login extends PiztorAct {
if (m.what == 0) {
ResLogin res = (ResLogin) m.obj;
Log.d(LogInfo.login, LogInfo.s);
- Infomation.token = res.t;
- Infomation.sublist = res.sublist;
- Infomation.username = res.uinfo.username;
- Infomation.myInfo = new UserInfo(res.uinfo.uid);
- Infomation.myInfo.setInfo(res.uinfo.gid.company,
+ app.token = res.t;
+ app.sublist = res.sublist;
+ app.username = res.uinfo.username;
+ app.mapInfo.myInfo = new UserInfo(res.uinfo.uid);
+ app.mapInfo.myInfo.setInfo(res.uinfo.gid.company,
res.uinfo.gid.section, res.uinfo.sex,
res.uinfo.nickname);
+ app.mapInfo.myInfo.level = res.uinfo.level;
+ app.mapInfo.myInfo.nickname = res.uinfo.nickname;
System.out.println("login !!!!" + res.sublist.size());
actMgr.trigger(AppMgr.loginSuccess);
} else {
@@ -67,7 +66,7 @@ public class Login extends PiztorAct {
String pass = edtPass.getText().toString();
long nowtime = System.currentTimeMillis();
System.out.println(user + " : " + pass + "\n");
- AppMgr.transam.send(new ReqLogin(user, pass, nowtime, 5000));
+ transam.send(new ReqLogin(user, pass, nowtime, 5000));
}
@Override
@@ -87,12 +86,6 @@ public class Login extends PiztorAct {
protected void onCreate(Bundle savedInstanceState) {
id = "login";
super.onCreate(savedInstanceState);
- ActStatus[] r = new ActStatus[2];
- r[0] = new StartStatus();
- r[1] = new LoginStatus();
- actMgr = new ActMgr(this, r[0], r);
- actMgr.add(r[0], loginButtonClick, r[1]);
- actMgr.add(r[1], loginFailed, r[0]);
setContentView(R.layout.activity_login);
}
@@ -112,18 +105,23 @@ public class Login extends PiztorAct {
@Override
protected void onResume() {
+ if (app.isExiting)
+ finish();
+ app.isLogout = false;
super.onResume();
- if (AppMgr.transam == null)
- Log.d(LogInfo.exception, "transam = null");
- AppMgr.transam.setHandler(handler);
-
+ ActStatus[] r = new ActStatus[2];
+ r[0] = new StartStatus();
+ r[1] = new LoginStatus();
+ actMgr = new ActMgr(appMgr, this, r[0], r);
+ actMgr.add(r[0], loginButtonClick, r[1]);
+ actMgr.add(r[1], loginFailed, r[0]);
+ transam.setHandler(handler);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
- AppMgr.exit();
- return true;
+ app.isExiting = true;
}
return super.onKeyDown(keyCode, event);
}
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java
index 735b1a4..052e267 100644
--- a/client/Piztor/src/com/macaroon/piztor/Main.java
+++ b/client/Piztor/src/com/macaroon/piztor/Main.java
@@ -1,9 +1,9 @@
package com.macaroon.piztor;
+import java.lang.ref.WeakReference;
import java.util.Calendar;
import java.util.Vector;
-import android.annotation.SuppressLint;
import android.content.Context;
import android.location.LocationManager;
import android.os.Bundle;
@@ -16,7 +16,6 @@ import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageButton;
-import android.widget.TextView;
import android.widget.Toast;
import com.baidu.location.BDLocation;
@@ -26,8 +25,6 @@ import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.LocationData;
import com.baidu.mapapi.map.MKMapTouchListener;
import com.baidu.mapapi.map.MapView;
-import com.baidu.mapapi.map.OverlayItem;
-import com.baidu.mapapi.map.PopupOverlay;
import com.baidu.mapapi.utils.DistanceUtil;
import com.baidu.platform.comapi.basestruct.GeoPoint;
@@ -41,11 +38,12 @@ public class Main extends PiztorAct {
MapMaker mapMaker = null;
MapView mMapView;
AlertMaker alertMaker;
- private Calendar calendar;
GeoPoint markerPoint = null;
private MKMapTouchListener mapTouchListener;
- private final int checkinRadius = 10;
-
+ public static int colorMode = 1;
+ public static int show_by_team = 1;
+ public static int show_by_sex = 2;
+
/**
* Locating component
*/
@@ -56,15 +54,23 @@ public class Main extends PiztorAct {
public MyLocationListener myListener = new MyLocationListener();
boolean isFirstLocation = true;
public static int GPSrefreshrate = 5;
+ private final int checkinRadius = 10;
ImageButton btnCheckin, btnFetch, btnFocus, btnSettings;
- MapInfo mapInfo;
-
- Transam transam;
- @SuppressLint("HandlerLeak")
- Handler handler = new Handler() {
+
+ static class ReCall extends Handler {
+ WeakReference<Main> outerClass;
+
+ ReCall(Main activity) {
+ outerClass = new WeakReference<Main>(activity);
+ }
+
@Override
public void handleMessage(Message m) {
+ Main out = outerClass.get();
+ if (out == null) {
+ System.out.println("act被回收了");
+ }
switch (m.what) {
case Res.Login:// 上传自己信息成功or失败
Log.d("update location", "successfull");
@@ -74,9 +80,9 @@ public class Main extends PiztorAct {
System.out.println("revieve ........" + userInfo.uinfo.size());
Vector<RUserInfo> uinfo = userInfo.uinfo;
for (RUserInfo info : uinfo) {
- System.out.println(info.latitude + " "
- + info.longitude);
- UserInfo r = mapInfo.getUserInfo(info.uid);
+ System.out
+ .println(info.latitude + " " + info.longitude);
+ UserInfo r = out.mapInfo.getUserInfo(info.uid);
if (r != null) {
r.setInfo(info.gid.company, info.gid.section, info.sex,
info.nickname);
@@ -86,54 +92,64 @@ public class Main extends PiztorAct {
r.setInfo(info.gid.company, info.gid.section, info.sex,
info.nickname);
r.setLocation(info.latitude, info.longitude);
- mapInfo.addUserInfo(r);
+ out.mapInfo.addUserInfo(r);
}
}
- System.out.println("now has info number : " + mapInfo.allUsers.size());
- flushMap();
+ System.out.println("now has info number : "
+ + out.mapInfo.allUsers.size());
+ out.flushMap();
break;
case Res.Logout:// 登出
- actMgr.trigger(AppMgr.logout);
+ out.actMgr.trigger(AppMgr.logout);
break;
case Res.PushMessage:
ResPushMessage pushMessage = (ResPushMessage) m.obj;
- receiveMessage(pushMessage.message);
+ out.receiveMessage(pushMessage.message);
break;
case Res.SendMessage:
Log.d(LogInfo.resquest, "send message successfully");
break;
case Res.PushLocation:
ResPushLocation pushLocation = (ResPushLocation) m.obj;
- upMapInfo(pushLocation.l);
- flushMap();
+ out.upMapInfo(pushLocation.l);
+ out.flushMap();
+ break;
+ case Res.PushMarker:
+ ResPushMarker pushMarker = (ResPushMarker) m.obj;
+ MarkerInfo markerInfo = new MarkerInfo();
+ markerInfo.level = pushMarker.level;
+ markerInfo.markerPoint = new GeoPoint(
+ (int) (pushMarker.latitude * 1e6),
+ (int) (pushMarker.longitude * 1e6));
+ markerInfo.markerTimestamp = pushMarker.deadline;
+ out.mapMaker.receiveMarker(markerInfo);
break;
case -1:
- actMgr.trigger(AppMgr.logout);
+ out.actMgr.trigger(AppMgr.logout);
default:
break;
}
}
+ }
- void upMapInfo(Vector<RLocation> l) {
- System.out.println("hahaha" + " " + l.size());
- for (RLocation i : l) {
- UserInfo info = AppMgr.mapInfo.getUserInfo(i.id);
- if (info != null) {
- info.setLocation(i.latitude, i.longitude);
- } else {
- info = new UserInfo(i.id);
- info.setLocation(i.latitude, i.longitude);
- AppMgr.mapInfo.addUserInfo(info);
- }
+ void upMapInfo(Vector<RLocation> l) {
+ for (RLocation i : l) {
+ UserInfo info = mapInfo.getUserInfo(i.id);
+ if (info != null) {
+ info.setLocation(i.latitude, i.longitude);
+ } else {
+ info = new UserInfo(i.id);
+ info.setLocation(i.latitude, i.longitude);
+ mapInfo.addUserInfo(info);
}
- flushMap();
}
- };
+ flushMap();
+ }
+
+ Handler handler = null;
String cause(int t) {
switch (t) {
- case CheckinButtonPress:
- return "Checkin But