From 6f38860cd5907501d90eb5518ac42978d7dec834 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Fri, 30 Aug 2013 22:33:16 +0800 Subject: update --- .../Piztor/src/com/macaroon/piztor/AlertMaker.java | 24 +- client/Piztor/src/com/macaroon/piztor/AppMgr.java | 8 +- client/Piztor/src/com/macaroon/piztor/Convert.java | 63 ++++ .../Piztor/src/com/macaroon/piztor/EException.java | 75 +++++ .../Piztor/src/com/macaroon/piztor/Infomation.java | 8 +- client/Piztor/src/com/macaroon/piztor/InitAct.java | 9 +- client/Piztor/src/com/macaroon/piztor/LogInfo.java | 12 + client/Piztor/src/com/macaroon/piztor/Login.java | 27 +- client/Piztor/src/com/macaroon/piztor/Main.java | 227 ++++++------- .../src/com/macaroon/piztor/MainActivity.java | 133 ++++++++ client/Piztor/src/com/macaroon/piztor/MapInfo.java | 9 +- .../Piztor/src/com/macaroon/piztor/MapMaker.java | 85 ++--- .../Piztor/src/com/macaroon/piztor/PushClient.java | 106 ++---- client/Piztor/src/com/macaroon/piztor/RGroup.java | 10 + .../Piztor/src/com/macaroon/piztor/RUserInfo.java | 22 ++ client/Piztor/src/com/macaroon/piztor/Req.java | 100 +++++- .../src/com/macaroon/piztor/ReqLocation.java | 16 - .../Piztor/src/com/macaroon/piztor/ReqLogin.java | 16 - .../Piztor/src/com/macaroon/piztor/ReqLogout.java | 12 - .../src/com/macaroon/piztor/ReqSendMessage.java | 14 - .../src/com/macaroon/piztor/ReqStartPush.java | 12 - .../Piztor/src/com/macaroon/piztor/ReqUpdate.java | 16 - .../src/com/macaroon/piztor/ReqUserInfo.java | 15 - .../src/com/macaroon/piztor/ReqUserinfo.java | 15 - client/Piztor/src/com/macaroon/piztor/Res.java | 141 +++++++- .../src/com/macaroon/piztor/ResLocation.java | 18 - .../Piztor/src/com/macaroon/piztor/ResLogin.java | 17 - .../Piztor/src/com/macaroon/piztor/ResLogout.java | 13 - .../src/com/macaroon/piztor/ResPushLocation.java | 18 - .../src/com/macaroon/piztor/ResPushMessage.java | 15 - .../src/com/macaroon/piztor/ResSendMessage.java | 13 - .../src/com/macaroon/piztor/ResStartPush.java | 13 - .../Piztor/src/com/macaroon/piztor/ResUpdate.java | 13 - .../src/com/macaroon/piztor/ResUserInfo.java | 22 -- .../src/com/macaroon/piztor/ResUserinfo.java | 20 -- .../Piztor/src/com/macaroon/piztor/Settings.java | 131 ++++---- .../src/com/macaroon/piztor/SocketClient.java | 373 +++++++++++++-------- client/Piztor/src/com/macaroon/piztor/Transam.java | 219 ++++++------ .../Piztor/src/com/macaroon/piztor/UpdateInfo.java | 5 + 39 files changed, 1145 insertions(+), 920 deletions(-) create mode 100644 client/Piztor/src/com/macaroon/piztor/Convert.java create mode 100644 client/Piztor/src/com/macaroon/piztor/EException.java create mode 100644 client/Piztor/src/com/macaroon/piztor/LogInfo.java create mode 100644 client/Piztor/src/com/macaroon/piztor/MainActivity.java create mode 100644 client/Piztor/src/com/macaroon/piztor/RGroup.java create mode 100644 client/Piztor/src/com/macaroon/piztor/RUserInfo.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqLocation.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqLogin.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqLogout.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqStartPush.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqUpdate.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResLocation.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResLogin.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResLogout.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResPushLocation.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResPushMessage.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResSendMessage.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResStartPush.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResUpdate.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResUserInfo.java delete mode 100644 client/Piztor/src/com/macaroon/piztor/ResUserinfo.java create mode 100644 client/Piztor/src/com/macaroon/piztor/UpdateInfo.java (limited to 'client/Piztor/src') diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java index 839813a..cc70e62 100644 --- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java @@ -96,7 +96,7 @@ public class AlertMaker { mapMaker.DrawMarker(markerPoint); else { Toast toast = Toast.makeText(context, - "Too early!Give me more time!", Toast.LENGTH_LONG); + "Too early! Give me at least 2 minutes!", Toast.LENGTH_LONG); toast.show(); closeBoard(context); showMarkerAlert(markerPoint); @@ -108,26 +108,4 @@ public class AlertMaker { markerDialog.show(); } - public void showQuitAlert() { - - AlertDialog.Builder quitDialog = new AlertDialog.Builder(context); - closeBoard(context); - quitDialog.setTitle("Quit"); - quitDialog.setMessage("Do you want to logout and quit?"); - quitDialog.setPositiveButton("Quit", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - AppMgr.exit(); - } - }); - quitDialog.setNegativeButton("Cancel", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - closeBoard(context); - } - }); - quitDialog.show(); - } - } diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java index e322745..933d2db 100644 --- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java +++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java @@ -68,21 +68,15 @@ public class AppMgr { static void trigger(int event) { Intent i = new Intent(); - System.out.println(nowAct.id + " : " + event); - if (mp.get(nowAct.getClass()) == null) - System.out.println("first"); - else if (mp.get(nowAct.getClass()) == null) - System.out.println("second"); i.setClass(nowAct, mp.get(nowAct.getClass()).get(event)); if (event == errorToken) Infomation.token = null; if (event == loginSuccess) { mBMapManager.start(); - transam.startPush(Infomation.token, Infomation.username); + mapInfo.clear(); } if (event == logout) { mBMapManager.stop(); - transam.stopPush(); } nowAct.startActivity(i); } diff --git a/client/Piztor/src/com/macaroon/piztor/Convert.java b/client/Piztor/src/com/macaroon/piztor/Convert.java new file mode 100644 index 0000000..af7359c --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/Convert.java @@ -0,0 +1,63 @@ +package com.macaroon.piztor; + +import android.annotation.SuppressLint; + +public class Convert { + + @SuppressLint("DefaultLocale") + public static byte[] hexStringToBytes(String hexString) { + if (hexString == null || hexString.equals("")) { + return null; + } + hexString = hexString.toUpperCase(); + int length = hexString.length() / 2; + char[] hexChars = hexString.toCharArray(); + byte[] d = new byte[length]; + for (int i = 0; i < length; i++) { + int pos = i * 2; + d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); + } + return d; + } + + public static byte charToByte(char c) { + return (byte) "0123456789ABCDEF".indexOf(c); + } + + public static byte[] intToBytes(int i) { + byte[] d = new byte[4]; + d[0] = (byte)((i >> 24) & 0xFF); + d[1] = (byte)((i >> 16) & 0xFF); + d[2] = (byte)((i >> 8) & 0xFF); + d[3] = (byte)(i & 0xFF); + return d; + } + + public static byte[] doubleToBytes(double d){ + byte[] b=new byte[8]; + long l=Double.doubleToLongBits(d); + for(int i=0;i<8;i++){ + b[i] = (byte)(l >>> 8*(7-i)); + } + return b; + } + + public static void write(byte[] s,byte[] w,int l) { + + for(int i=0;i sublist; } diff --git a/client/Piztor/src/com/macaroon/piztor/InitAct.java b/client/Piztor/src/com/macaroon/piztor/InitAct.java index 272afe7..8145935 100644 --- a/client/Piztor/src/com/macaroon/piztor/InitAct.java +++ b/client/Piztor/src/com/macaroon/piztor/InitAct.java @@ -2,23 +2,16 @@ package com.macaroon.piztor; import android.os.Bundle; import android.view.Menu; -import android.content.Context; public class InitAct extends PiztorAct { - private CopyMap copyMap; - private String assetDir; - private String dir; - @Override protected void onCreate(Bundle savedInstanceState) { id = "initAct"; super.onCreate(savedInstanceState); - setContentView(R.layout.activity_init); - copyMap = new CopyMap(); - copyMap.testCopy(InitAct.this); AppMgr.init(getApplicationContext()); AppMgr.transam.setTimeOutTime(5000); + setContentView(R.layout.activity_init); } @Override diff --git a/client/Piztor/src/com/macaroon/piztor/LogInfo.java b/client/Piztor/src/com/macaroon/piztor/LogInfo.java new file mode 100644 index 0000000..2fd93ac --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/LogInfo.java @@ -0,0 +1,12 @@ +package com.macaroon.piztor; + +public class LogInfo { + static String login = "login"; + static String logout = "logout"; + static String update = "update"; + static String resquest = "resquest"; + static String push = "push"; + static String exception = "exception"; + static String s = "successfull"; + static String f = "failed"; +} diff --git a/client/Piztor/src/com/macaroon/piztor/Login.java b/client/Piztor/src/com/macaroon/piztor/Login.java index a1a6d0d..533eeac 100644 --- a/client/Piztor/src/com/macaroon/piztor/Login.java +++ b/client/Piztor/src/com/macaroon/piztor/Login.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.View; @@ -30,20 +31,19 @@ public class Login extends PiztorAct { } if (m.what == 0) { ResLogin res = (ResLogin) m.obj; - if (res.status == 1) { - actMgr.trigger(loginFailed); - return; - } + Log.d(LogInfo.login, LogInfo.s); Infomation.token = res.t; - Infomation.myInfo.uid = res.uid; - Infomation.username = edtUser.getText().toString(); - System.out.println(res.status + " :!!! " + res.type); + Infomation.sublist = res.sublist; + Infomation.username = res.uinfo.username; + Infomation.myInfo = new UserInfo(res.uinfo.uid); + Infomation.myInfo.setInfo(res.uinfo.gid.company, + res.uinfo.gid.section, res.uinfo.sex, + res.uinfo.nickname); + System.out.println("login !!!!" + res.sublist.size()); actMgr.trigger(AppMgr.loginSuccess); - System.out.println("............"); } else { - System.out.println("reveive other info ~~~~~~~~~~~~~~" + m.what); -// System.out.println("login de " + m.what); -// actMgr.trigger(loginFailed); + System.out.println("login handler reveive other info : " + + m.what); } } }; @@ -113,7 +113,10 @@ public class Login extends PiztorAct { @Override protected void onResume() { super.onResume(); - AppMgr.transam.setHandler(handler); + if (AppMgr.transam == null) + Log.d(LogInfo.exception, "transam = null"); + AppMgr.transam.setHandler(handler); + } @Override diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java index 1e46003..623595b 100644 --- a/client/Piztor/src/com/macaroon/piztor/Main.java +++ b/client/Piztor/src/com/macaroon/piztor/Main.java @@ -1,8 +1,6 @@ package com.macaroon.piztor; import java.util.Calendar; -import java.util.Timer; -import java.util.TimerTask; import java.util.Vector; import android.annotation.SuppressLint; @@ -39,14 +37,13 @@ public class Main extends PiztorAct { final static int FailedFetch = 5; final static int mapViewtouched = 7; - MapMaker mapMaker = null; MapView mMapView; AlertMaker alertMaker; private Calendar calendar; GeoPoint markerPoint = null; private MKMapTouchListener mapTouchListener; - + /** * Locating component */ @@ -56,100 +53,67 @@ public class Main extends PiztorAct { LocationData locData = null; public MyLocationListener myListener = new MyLocationListener(); boolean isFirstLocation = true; + public static int GPSrefreshrate = 5; ImageButton btnSearch, btnFetch, btnFocus, btnSettings; MapInfo mapInfo; + Transam transam; @SuppressLint("HandlerLeak") Handler handler = new Handler() { @Override public void handleMessage(Message m) { switch (m.what) { - case 1:// 上传自己信息成功or失败 - ResUpdate update = (ResUpdate) m.obj; - if (update.status == 0) - System.out.println("update success"); - else { - System.out.println("update failed"); - actMgr.trigger(AppMgr.errorToken); - } + case Res.Login:// 上传自己信息成功or失败 + Log.d("update location", "successfull"); break; - case 2:// 得到别人的信息 - ResLocation location = (ResLocation) m.obj; - if (location.status == 0) { - mapInfo.clear(); - for (RLocation i : location.l) { - System.out.println(i.id + " : " + i.latitude + " " - + i.longitude); - UserInfo info = new UserInfo(i.id); - info.setLocation(i.latitude, i.longitude); - mapInfo.addUserInfo(info); - } -// actMgr.trigger(SuccessFetch); - flushMap(); - } else { - System.out.println("resquest for location failed!"); - actMgr.trigger(AppMgr.errorToken); - } - break; - case 3:// 得到用户信息 - ResUserInfo r = (ResUserInfo) m.obj; - if (r.status == 0) { - System.out.println("id : " + r.uid + " sex : " + r.sex - + " group : " + r.section); - if (r.uid == Infomation.myInfo.uid) { - System.out.println("flush myself info!!!"); - Infomation.myInfo.section = r.section; - Infomation.myInfo.company = r.company; - Infomation.myInfo.sex = r.sex; + case Res.UserInfo:// 得到用户信息 + ResUserInfo userInfo = (ResUserInfo) m.obj; + System.out.println("revieve ........" + userInfo.uinfo.size()); + Vector uinfo = userInfo.uinfo; + for (RUserInfo info : uinfo) { + System.out.println(info.latitude + " " + + info.longitude); + UserInfo r = mapInfo.getUserInfo(info.uid); + if (r != null) { + r.setInfo(info.gid.company, info.gid.section, info.sex, + info.nickname); + r.setLocation(info.latitude, info.longitude); } else { - UserInfo user = mapInfo.getUserInfo(r.uid); - if (user != null) - user.setInfo(r.company, r.section, r.sex); - else - System.out.println("fuck!!!!"); + r = new UserInfo(info.uid); + r.setInfo(info.gid.company, info.gid.section, info.sex, + info.nickname); + r.setLocation(info.latitude, info.longitude); + mapInfo.addUserInfo(r); } - flushMap(); - } else { - System.out.println("reqest for userInfo must be wrong!!!"); - actMgr.trigger(AppMgr.errorToken); - } - break; - case 4:// 登出 - ResLogout logout = (ResLogout) m.obj; - if (logout.status == 0) { - actMgr.trigger(AppMgr.logout); - } else { - Toast toast = Toast.makeText(getApplicationContext(), - "logout failed", Toast.LENGTH_LONG); - toast.show(); } + System.out.println("now has info number : " + mapInfo.allUsers.size()); + flushMap(); break; - case Transam.StartPush: - ResStartPush startpush = (ResStartPush) m.obj; - if (startpush.status == 1) { - System.out.println("!!!!!!!!!!!!!jian gui le!!!!!!!!!!!!!"); - } + case Res.Logout:// 登出 + actMgr.trigger(AppMgr.logout); break; - case Transam.PushMessage: + case Res.PushMessage: ResPushMessage pushMessage = (ResPushMessage) m.obj; receiveMessage(pushMessage.message); break; - case Transam.SendMessage: - ResSendMessage resMessage = (ResSendMessage) m.obj; - System.out.println("res message " + resMessage.status); + case Res.SendMessage: + Log.d(LogInfo.resquest, "send message successfully"); break; - case Transam.PushLocation: + case Res.PushLocation: ResPushLocation pushLocation = (ResPushLocation) m.obj; - upDateInfo(pushLocation.l); + upMapInfo(pushLocation.l); + flushMap(); break; + case -1: + actMgr.trigger(AppMgr.logout); default: break; } } - void upDateInfo(Vector l) { - // TODO + void upMapInfo(Vector l) { + System.out.println("hahaha" + " " + l.size()); for (RLocation i : l) { UserInfo info = AppMgr.mapInfo.getUserInfo(i.id); if (info != null) { @@ -184,18 +148,16 @@ public class Main extends PiztorAct { if (mapMaker != null) mapMaker.UpdateMap(AppMgr.mapInfo); else - System.out - .println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + Log.d("exception", "!!!"); } - + void receiveMessage(String msg) { System.out.println("receiveed push message!!!!!"); System.out.println(msg); - Toast toast = Toast.makeText(getApplicationContext(), - msg, Toast.LENGTH_LONG); + Toast toast = Toast.makeText(getApplicationContext(), msg, + Toast.LENGTH_LONG); toast.show(); } - public class MyLocationListener implements BDLocationListener { int cnt = 0; @@ -229,7 +191,17 @@ public class Main extends PiztorAct { hasAnimation = true; isFirstLocation = false; } + int TMP = location.getLocType(); + if (TMP == 61) Toast.makeText(Main.this, "Piztor : Update from GPS result (" + GPSrefreshrate + "s)", 3000).show(); + if (TMP == 161) Toast.makeText(Main.this, "Piztor : Update from Network (" + GPSrefreshrate + "s)" , 3000).show(); + if (TMP == 65) Toast.makeText(Main.this, "Piztor : Update from Cache (" + GPSrefreshrate + "s)", 3000).show(); mapMaker.UpdateLocationOverlay(locData, hasAnimation); + + LocationClientOption option = new LocationClientOption(); + option.setOpenGps(true); + option.setCoorType("bd09ll"); + option.setScanSpan(GPSrefreshrate * 1000); + mLocClient.setLocOption(option); } @Override @@ -248,9 +220,6 @@ public class Main extends PiztorAct { if (e == ActMgr.Create) { System.out.println(Infomation.token + " " + Infomation.username + " " + Infomation.myInfo.uid); - AppMgr.transam.send(new ReqUserInfo(Infomation.token, - Infomation.username, Infomation.myInfo.uid, System - .currentTimeMillis(), 5000)); } if (e == SuccessFetch) flushMap(); @@ -263,74 +232,76 @@ public class Main extends PiztorAct { } - - void requesLocation(int company, int section) { - ReqLocation r = new ReqLocation(Infomation.token, Infomation.username, - company, section, System.currentTimeMillis(), 2000); - AppMgr.transam - .send(new ReqSendMessage(Infomation.token, Infomation.username, - "hahaha", System.currentTimeMillis(), 5000)); + void requestUserInfo() { + for (RGroup i : Infomation.sublist) { + ReqUserInfo r = new ReqUserInfo(Infomation.token, + Infomation.username, i, System.currentTimeMillis(), 2000); + transam.send(r); + } System.out.println("get others infomation!!!"); - AppMgr.transam.send(r); } void focusOn() { mapMaker.mMapController.animateTo(Infomation.myInfo.location); } - + public void InitTouchListenr() { mapTouchListener = new MKMapTouchListener() { - + @Override public void onMapLongClick(GeoPoint arg0) { closeBoard(Main.this); alertMaker.showMarkerAlert(arg0); } - + @Override public void onMapDoubleClick(GeoPoint arg0) { // TODO Auto-generated method stub - + } - + @Override public void onMapClick(GeoPoint arg0) { // TODO Auto-generated method stub - + } }; mMapView.regMapTouchListner(mapTouchListener); } - + @Override protected void onCreate(Bundle savedInstanceState) { id = "Main"; super.onCreate(savedInstanceState); - - locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE); - isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER); - + + locationManager = (LocationManager) this + .getSystemService(LOCATION_SERVICE); + isGPSEnabled = locationManager + .isProviderEnabled(locationManager.GPS_PROVIDER); + transam = AppMgr.transam; mapInfo = AppMgr.mapInfo; ActStatus[] r = new ActStatus[1]; ActStatus startStatus = r[0] = new StartStatus(); -// ActStatus fetchStatus = r[1] = new FetchStatus(); -// ActStatus focusStatus = r[2] = new FocusStatus(); - AppMgr.transam.setHandler(handler); + // ActStatus fetchStatus = r[1] = new FetchStatus(); + // ActStatus focusStatus = r[2] = new FocusStatus(); + if (transam == null) + Log.d(LogInfo.exception, "transam = null"); + transam.setHandler(handler); actMgr = new ActMgr(this, startStatus, r); -// actMgr.add(startStatus, FocuseButtonPress, focusStatus); -// actMgr.add(startStatus, Fetch, fetchStatus); -// actMgr.add(startStatus, SuccessFetch, startStatus); -// actMgr.add(startStatus, Fetch, startStatus); -// actMgr.add(fetchStatus, Fetch, startStatus); -// actMgr.add(fetchStatus, FailedFetch, startStatus); -// actMgr.add(fetchStatus, SuccessFetch, startStatus); -// actMgr.add(focusStatus, FocuseButtonPress, startStatus); -// actMgr.add(focusStatus, mapViewtouched, startStatus); -// actMgr.add(focusStatus, SuccessFetch, focusStatus); -// actMgr.add(focusStatus, Fetch, focusStatus); + // actMgr.add(startStatus, FocuseButtonPress, focusStatus); + // actMgr.add(startStatus, Fetch, fetchStatus); + // actMgr.add(startStatus, SuccessFetch, startStatus); + // actMgr.add(startStatus, Fetch, startStatus); + // actMgr.add(fetchStatus, Fetch, startStatus); + // actMgr.add(fetchStatus, FailedFetch, startStatus); + // actMgr.add(fetchStatus, SuccessFetch, startStatus); + // actMgr.add(focusStatus, FocuseButtonPress, startStatus); + // actMgr.add(focusStatus, mapViewtouched, startStatus); + // actMgr.add(focusStatus, SuccessFetch, focusStatus); + // actMgr.add(focusStatus, Fetch, focusStatus); setContentView(R.layout.activity_main); - + mMapView = (MapView) findViewById(R.id.bmapView); mapMaker = new MapMaker(mMapView, getApplicationContext()); alertMaker = new AlertMaker(Main.this, mapMaker); @@ -345,7 +316,7 @@ public class Main extends PiztorAct { LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setCoorType("bd09ll"); - option.setScanSpan(5000); + option.setScanSpan(GPSrefreshrate * 1000); mLocClient.setLocOption(option); mLocClient.start(); mapMaker.UpdateLocationOverlay(locData, false); @@ -354,11 +325,11 @@ public class Main extends PiztorAct { public static void closeBoard(Context cc) { InputMethodManager imm = (InputMethodManager) cc .getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm.isActive()) - imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, - InputMethodManager.HIDE_NOT_ALWAYS); - } - + if (imm.isActive()) + imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, + InputMethodManager.HIDE_NOT_ALWAYS); + } + /* * public boolean onTap(int index) { OverlayItem item = getItem(index); * mCurItem = item; if () } @@ -373,17 +344,17 @@ public class Main extends PiztorAct { btnFetch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { - requesLocation(Infomation.myInfo.company, Infomation.myInfo.section); + } }); - + btnFocus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { focusOn(); } }); - + btnSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { @@ -396,15 +367,15 @@ public class Main extends PiztorAct { @Override protected void onRestart() { super.onRestart(); - AppMgr.transam.setHandler(handler); + transam.setHandler(handler); } - + @Override protected void onResume() { isFirstLocation = true; + requestUserInfo(); mapMaker.onResume(); flushMap(); - requesLocation(Infomation.myInfo.company, Infomation.myInfo.section); super.onResume(); } @@ -431,7 +402,7 @@ public class Main extends PiztorAct { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { - alertMaker.showQuitAlert(); + AppMgr.exit(); return true; } return super.onKeyDown(keyCode, event); diff --git a/client/Piztor/src/com/macaroon/piztor/MainActivity.java b/client/Piztor/src/com/macaroon/piztor/MainActivity.java new file mode 100644 index 0000000..483112d --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/MainActivity.java @@ -0,0 +1,133 @@ +package com.macaroon.piztor; + +import java.util.Vector; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.Menu; +import android.view.View; + +public class MainActivity extends Activity { + public String token = ""; + public String uname = ""; + public int com; + public int sec; + public int step = 0; + Transam t; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + t = new Transam("192.168.1.171",2223,handler); + Thread thread = new Thread(t); + thread.start(); + + } + + Handler handler = new Handler() { + public void handleMessage(Message msg) { + switch (msg.what) { + case 0: + token = ((ResLogin) msg.obj ).t; + uname = ((ResLogin) msg.obj ).uinfo.username; + com = ((ResLogin) msg.obj ).uinfo.gid.company; + sec = ((ResLogin) msg.obj ).uinfo.gid.section; + System.out.println(com); + System.out.println(sec); + System.out.println(((ResLogin) msg.obj ).uinfo.sex); + for(int i=0;i<((ResLogin) msg.obj ).subscribeNumber;i++){ + System.out.println(((ResLogin) msg.obj ).sublist.get(i).company); + System.out.println(((ResLogin) msg.obj ).sublist.get(i).section); + } + System.out.println(token); + break; + case 2: + ResUserInfo r = (ResUserInfo) msg.obj ; + System.out.println(r.number); + for(int i=0;i ll = ((ResPushLocation)msg.obj).l; + for(int i=0;i mp; Vector allUsers; UserInfo myInfo; - Style layout; @SuppressLint("UseSparseArrays") MapInfo() { @@ -32,10 +31,6 @@ public class MapInfo { mp.put(userInfo.uid, userInfo); } - void setStyle(Style layout) { - this.layout = layout; - } - UserInfo getUserInfo(int uid) { if (mp.containsKey(uid)) return mp.get(uid); @@ -57,7 +52,7 @@ class UserInfo { int company; //group id int section; GeoPoint location; - + String nickname; UserInfo(int uid) { this.uid = uid; } @@ -66,7 +61,7 @@ class UserInfo { location = new GeoPoint((int)(lat * 1e6), (int)(lot * 1e6)); } - void setInfo(int company, int section, int sex) { + void setInfo(int company, int section, int sex, String nickName) { this.company = company; this.section = section; this.sex = sex; diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java index 0469702..ef79f73 100644 --- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java @@ -5,6 +5,8 @@ import java.util.HashMap; import java.util.Timer; import java.util.TimerTask; import java.util.Vector; + +import android.R.drawable; import android.util.Log; import android.util.AttributeSet; import android.annotation.SuppressLint; @@ -28,6 +30,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.widget.FrameLayout; import android.widget.Toast; @@ -100,6 +103,9 @@ public class MapMaker extends Activity { private Context context; private LocationManager locationManager = null; boolean isGPSEnabled; + private int[] myIcons; + private Drawable[] myBM; + private final int iconNum = 4; /** * Constructor @@ -171,7 +177,7 @@ public class MapMaker extends Activity { return false; } } - + /** * Initialize offline map */ @@ -265,7 +271,6 @@ public class MapMaker extends Activity { popLay = new PopupOverlay(mMapView, popListener); } - /** * Initialize touch listener @@ -281,9 +286,24 @@ public class MapMaker extends Activity { InitMyOverLay(); InitPopup(); InitOfflineMap(); + myBM = new Drawable[20]; + initMyIcons(); //InitTouchListenr(); } + public void initMyIcons() { + myBM[0] = context.getResources().getDrawable(R.drawable.circle_red); + myBM[1] = context.getResources().getDrawable(R.drawable.circle_green); + myBM[2] = context.getResources().getDrawable(R.drawable.circle_glass); + myBM[3] = context.getResources().getDrawable(R.drawable.circle_yellow); + myBM[4] = context.getResources().getDrawable(R.drawable.circle_wood); + } + + public Drawable getGroupIcon(int gid) { + if (gid == Infomation.myInfo.section) return myBM[0]; + else return myBM[gid % iconNum]; + } + /** * Update location layer when new location is received */ @@ -296,48 +316,10 @@ public class MapMaker extends Activity { , (int)(locationData.longitude * 1E6))); } } - + /** * Update to draw other users */ - /* - public void UpdateMap(MapInfo mapInfo) { - - if (mapInfo != null) { - preMapInfo = mapInfo; - if (mOverlay != null && mOverlay.getAllItem().size() != 0) { - mOverlay.removeAll(); - } - mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView); - GeoPoint p; - Vector allUsers = mapInfo.getVector(); - if (nowMarker != null) { - mOverlay.addItem(nowMarker); - } - for (int i =1; i < allUsers.size(); i++) { - // it's me! - if (allUsers.get(i).uid == Infomation.myInfo.uid) continue; - p = new GeoPoint((int)(allUsers.get(i).getLatitude() * 1E6), - (int)(allUsers.get(i).getLongitude()*1E6)); - curItem = new OverlayItem(p, "USERNAME HERE!!!!!", ""); - //TODO - //////////////////////////////////////////////////////////// - curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red)); - mOverlay.addItem(curItem); - } - mItems = new ArrayList(); - mItems.addAll(mOverlay.getAllItem()); - } - - if (mMapView != null) { - if (mMapView.getOverlays() != null) { - //mMapView.getOverlays().add(mOverlay); - mMapView.refresh(); - } - } - } - */ - public void UpdateMap(MapInfo mapInfo) { if (mapInfo == null) { @@ -367,7 +349,7 @@ public class MapMaker extends Activity { curItem = new OverlayItem(p, "USERNAME_HERE", "USER_SNIPPET_HERE"); //TODO getDrawable /////////////////////////////// - curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red)); + curItem.setMarker(getGroupIcon(i.section)); mOverlay.addItem(curItem); hash.put(i.uid, curItem); //if (mMapView != null) @@ -387,28 +369,35 @@ public class MapMaker extends Activity { preMapInfo = mapInfo; } - /** * Update marker - */ + * public void UpdateMarker() { - mOverlay.addItem(nowMarker); if (mMapView != null) { mMapView.getOverlays().add(mOverlay); mMapView.refresh(); } } + */ /** * Draw a marker */ public void DrawMarker(GeoPoint markerPoint) { - nowMarker = new OverlayItem(markerPoint, "THIS IS A MARKER", ""); + if (nowMarker != null) { + nowMarker.setGeoPoint(markerPoint); + mOverlay.updateItem(nowMarker); + mMapView.refresh(); + mMapController.animateTo(markerPoint); + return; + } + nowMarker = new OverlayItem(markerPoint, "MARKER_NAME", ""); nowMarker.setMarker(context.getResources().getDrawable(R.drawable.marker_red)); - Log.d("marker", "new marker created"); - UpdateMap(preMapInfo); + Log.d("marker", "new marker created"); + mOverlay.addItem(nowMarker); + mMapView.refresh(); mMapController.animateTo(markerPoint); } diff --git a/client/Piztor/src/com/macaroon/piztor/PushClient.java b/client/Piztor/src/com/macaroon/piztor/PushClient.java index ea32ad6..fff39fe 100644 --- a/client/Piztor/src/com/macaroon/piztor/PushClient.java +++ b/client/Piztor/src/com/macaroon/piztor/PushClient.java @@ -9,7 +9,6 @@ import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.util.Vector; -import android.annotation.SuppressLint; import android.os.Handler; import android.os.Message; @@ -25,18 +24,18 @@ public class PushClient { static final int TokenLength = 32; static final int FingerPrintLength = 32; - public final static int StartPush =5; + static final int StartPush =5; - public final static int Message = 0; - public final static int Location = 1; - public final static int PushMessage =100; - public final static int PushLocation =101; + static final int Message = 0; + static final int Location = 1; + static final int PushMessage =100; + static final int PushLocation =101; - public final static int Reconnect =-2; + static final int Reconnect =-2; - public final static int Failed = 2; - public final static int TimeOut = 1; - public final static int Success = 0; + static final int StatusFailed = 2; + static final int TimeOut = 1; + static final int Success = 0; private String LastPrint = ""; @@ -45,8 +44,8 @@ public class PushClient { IOException { try { client = new Socket(); - client.connect(new InetSocketAddress(site,port), 5000); - client.setSoTimeout(5000); + client.connect(new InetSocketAddress(site,port), retime); + client.setSoTimeout(2000); } catch (UnknownHostException e) { e.printStackTrace(); throw e; @@ -68,13 +67,13 @@ public class PushClient { len = IntLength+ByteLength+TokenLength+(r.uname).length()+ByteLength; byte[] b = new byte[len]; int pos = 0; - write(b,intToBytes(len),pos); + Convert.write(b,Convert.intToBytes(len),pos); pos+=IntLength; b[pos] = (byte) 5; pos+=ByteLength; - write(b,hexStringToBytes(r.token),pos); + Convert.write(b,Convert.hexStringToBytes(r.token),pos); pos+=TokenLength; - write(b,r.uname.getBytes(),pos); + Convert.write(b,r.uname.getBytes(),pos); pos+=r.uname.length(); b[pos] = 0; pos+=ByteLength; @@ -84,13 +83,11 @@ public class PushClient { in.readInt(); in.readUnsignedByte(); int status = in.readUnsignedByte(); - ResStartPush rchk = new ResStartPush(status); + if(status == 1) return StatusFailed; + ResStartPush rchk = new ResStartPush(); msg.obj = rchk; msg.what = StartPush; recall.sendMessage(msg); - if(status == 1) { - return Failed; - } return Success; } catch (SocketTimeoutException e){ e.printStackTrace(); @@ -105,7 +102,7 @@ public class PushClient { return client.isClosed(); } - public void listen(Handler recall,Handler h) throws IOException{ + public void listen(Handler recall) throws IOException{ client.setSoTimeout(0); DataInputStream in = new DataInputStream(client.getInputStream()); DataOutputStream out = new DataOutputStream(client.getOutputStream()); @@ -117,7 +114,7 @@ public class PushClient { int tmp = in.readUnsignedByte(); byte[] buffer = new byte[32]; in.read(buffer); - String p = byteToHexString(buffer); + String p = Convert.byteToHexString(buffer); int outlen; int pos=0; byte[] o = new byte[IntLength+ByteLength+FingerPrintLength];; @@ -135,11 +132,11 @@ public class PushClient { recall.sendMessage(msg); LastPrint = p; } - write(o,intToBytes(outlen),pos); //can be folded! + Convert.write(o,Convert.intToBytes(outlen),pos); //can be folded! pos+=IntLength; o[pos]=(byte) Message; pos+=ByteLength; - write(o,hexStringToBytes(p),pos); + Convert.write(o,Convert.hexStringToBytes(p),pos); pos+=FingerPrintLength; out.write(o); out.flush(); @@ -163,11 +160,11 @@ public class PushClient { recall.sendMessage(msg); LastPrint = p; } - write(o,intToBytes(outlen),pos); + Convert.write(o,Convert.intToBytes(outlen),pos); pos+=IntLength; o[pos]=(byte) Location; pos+=ByteLength; - write(o,hexStringToBytes(p),pos); + Convert.write(o,Convert.hexStringToBytes(p),pos); pos+=FingerPrintLength; out.write(o); out.flush(); @@ -189,64 +186,5 @@ public class PushClient { throw e; } } - - @SuppressLint("DefaultLocale") - private static byte[] hexStringToBytes(String hexString) { - if (hexString == null || hexString.equals("")) { - return null; - } - hexString = hexString.toUpperCase(); - int length = hexString.length() / 2; - char[] hexChars = hexString.toCharArray(); - byte[] d = new byte[length]; - for (int i = 0; i < length; i++) { - int pos = i * 2; - d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); - } - return d; - } - - private static byte charToByte(char c) { - return (byte) "0123456789ABCDEF".indexOf(c); - } - - private static byte[] intToBytes(int i) { - byte[] d = new byte[4]; - d[0] = (byte)((i >> 24) & 0xFF); - d[1] = (byte)((i >> 16) & 0xFF); - d[2] = (byte)((i >> 8) & 0xFF); - d[3] = (byte)(i & 0xFF); - return d; - } - - @SuppressLint("UseValueOf") - public static byte[] doubleToBytes(double d){ - byte[] b=new byte[8]; - long l=Double.doubleToLongBits(d); - for(int i=0;i < 8;i++){ - b[i]=new Long(l).byteValue(); - l=l>>8; - } - return b; - } - - private static void write(byte[] s,byte[] w,int l) { - - for(int i=0;i slist; //list of users' group id + + + ReqSubscription(String token,String name,int number,Vector sublist,long time,long alive){ + super(3,token,name,time,alive); //for type 3 + n = number; + slist = sublist; + } +} + +//--------------------------------------// +// Log out // +//--------------------------------------// + +class ReqLogout extends Req{ + + ReqLogout(String token,String name,long time,long alive){ + super(4,token,name,time,alive); //for type 4 + } +} + +//--------------------------------------// +// Start push // +//--------------------------------------// + +class ReqStartPush extends Req{ + + ReqStartPush(String token,String name){ + super(5,token,name,(long) 0,(long) 0); //for type 5 + } +} + +//--------------------------------------// +// Send Message // +//--------------------------------------// + +class ReqSendMessage extends Req{ + String msg; + + ReqSendMessage(String token,String name,String message,long time,long alive){ + super(6,token,name,time,alive); //for type 6 + msg = message; + } +} + diff --git a/client/Piztor/src/com/macaroon/piztor/ReqLocation.java b/client/Piztor/src/com/macaroon/piztor/ReqLocation.java deleted file mode 100644 index 4ed1ffc..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqLocation.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// Ask Location // -//--------------------------------------// - -public class ReqLocation extends Req{ - int company; //group id; - int section; - - ReqLocation(String token,String name,int com,int sec,long time,long alive){ - super(2,token,name,time,alive); //for type 2 - company = com; - section = sec; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ReqLogin.java b/client/Piztor/src/com/macaroon/piztor/ReqLogin.java deleted file mode 100644 index 23aba93..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqLogin.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// authentication // -//--------------------------------------// - -public class ReqLogin extends Req{ - String user; //username - String pass; //password - - ReqLogin(String u,String p,long time,long alive){ - super(0,"","",time,alive); //for type 0 - user = u; - pass = p; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ReqLogout.java b/client/Piztor/src/com/macaroon/piztor/ReqLogout.java deleted file mode 100644 index 22bddfa..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqLogout.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// Log out // -//--------------------------------------// - -public class ReqLogout extends Req{ - - ReqLogout(String token,String name,long time,long alive){ - super(4,token,name,time,alive); //for type 4 - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java b/client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java deleted file mode 100644 index d5bcef4..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// Send Message // -//--------------------------------------// - -public class ReqSendMessage extends Req{ - String msg; - - ReqSendMessage(String token,String name,String message,long time,long alive){ - super(6,token,name,time,alive); //for type 6 - msg = message; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ReqStartPush.java b/client/Piztor/src/com/macaroon/piztor/ReqStartPush.java deleted file mode 100644 index 91d8c0f..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqStartPush.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// Start push // -//--------------------------------------// - -public class ReqStartPush extends Req{ - - ReqStartPush(String token,String name){ - super(5,token,name,(long) 0,(long) 0); //for type 5 - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ReqUpdate.java b/client/Piztor/src/com/macaroon/piztor/ReqUpdate.java deleted file mode 100644 index 234114a..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqUpdate.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// Update Location // -//--------------------------------------// - -public class ReqUpdate extends Req{ - double latitude; //latitude - double longitude; //longitude - - ReqUpdate(String token,String name,double lat,double lot,long time,long alive){ - super(1,token,name,time,alive); //for type 1 - latitude = lat; - longitude = lot; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java b/client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java deleted file mode 100644 index 89c20ee..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// Ask user info // -//--------------------------------------// - -public class ReqUserInfo extends Req{ - int uid; //user id - - - ReqUserInfo(String token,String name,int id,long time,long alive){ - super(3,token,name,time,alive); //for type 3 - uid = id; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java b/client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java deleted file mode 100644 index 77bcf84..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.macaroon.piztor; - -//--------------------------------------// -// Ask user info // -//--------------------------------------// - -public class ReqUserinfo extends Req{ - int uid; //user id - - - ReqUserinfo(String token,String name,int id,long time,long alive){ - super(3,token,name,time,alive); //for type 3 - uid = id; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/Res.java b/client/Piztor/src/com/macaroon/piztor/Res.java index a225080..699de45 100644 --- a/client/Piztor/src/com/macaroon/piztor/Res.java +++ b/client/Piztor/src/com/macaroon/piztor/Res.java @@ -1,11 +1,146 @@ package com.macaroon.piztor; +import java.util.Vector; + public class Res{ + + static final int Login =0; + static final int Update =1; + static final int UserInfo =2; + static final int Subscription =3; + static final int Logout =4; + static final int StartPush =5; + static final int SendMessage =6; + static final int PushMessage =100; + static final int PushLocation =101; + int type; - int status; - Res(int t,int s){ + Res(int t){ type = t; - status = s; } } +//--------------------------------------// +// Respond to login // +//--------------------------------------// + +class ResLogin extends Res{ + String t; //user token + RUserInfo uinfo; //userinfo + Vector sublist; //list of users subscribed + int subscribeNumber; //number of users subscribed + + ResLogin(String token,RUserInfo rui,Vector slist,int subn){ + super(0); //for type 0 + t = token; + uinfo = rui; + sublist = slist; + subscribeNumber = subn; + } +} + +//--------------------------------------// +// Respond to update location // +//--------------------------------------// + +class ResUpdate extends Res{ + + ResUpdate(){ + super(1); //for type 1 + } +} + +//--------------------------------------// +// Respond to User Info // +//--------------------------------------// + +class ResUserInfo extends Res{ + int number; //number of users + Vector uinfo; + + ResUserInfo(int n,Vector rui){ + super(2); //for type 2 + number = n; + uinfo = rui; + } +} + +//--------------------------------------// +// Respond to Update Subscription // +//--------------------------------------// + +class ResSubscription extends Res{ + + ResSubscription(){ + super(3); //for type 3 + } +} + +//--------------------------------------// +// Respond to logout // +//--------------------------------------// + +class ResLogout extends Res{ + + ResLogout(){ + super(4); //for type 4 + } +} + +//--------------------------------------// +// Respond to start push // +//--------------------------------------// + +class ResStartPush extends Res{ + + ResStartPush(){ + super(5); //for type 5 + } +} + +//--------------------------------------// +// Respond to send Message // +//--------------------------------------// + +class ResSendMessage extends Res{ + + ResSendMessage(){ + super(6); //for type 6 + } +} + +//---------------------------------------------------------------------------------------------------// + + + +//---------------------------------------------------------------------------------------------------// + + + +//--------------------------------------// +// Push Message // +//--------------------------------------// + +class ResPushMessage extends Res{ + String message; + + ResPushMessage(String s){ + super(100); //for type 100 + message = s; + } +} + +//--------------------------------------// +// Push Location // +//--------------------------------------// + +class ResPushLocation extends Res{ + Vector l; //vector for location info + int n; //number of location info + + ResPushLocation(int num,Vector locationvec){ + super(101); //for type 101 + l = locationvec; + n = num; + } +} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResLocation.java b/client/Piztor/src/com/macaroon/piztor/ResLocation.java deleted file mode 100644 index a4f2622..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResLocation.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.macaroon.piztor; - -import java.util.Vector; - -//--------------------------------------// -// Location Info // -//--------------------------------------// - -public class ResLocation extends Res{ - Vector l; //vector for location info - int n; //number of location info - - ResLocation(int num,int status,Vector locationvec){ - super(2,status); //for type 2 - l = locationvec; - n = num; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResLogin.java b/client/Piztor/src/com/macaroon/piztor/ResLogin.java deleted file mode 100644 index e2f138c..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResLogin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Respond to login // -//--------------------------------------// - -public class ResLogin extends Res{ - String t; //user token - int uid; //userid - - ResLogin(int id,String token,int status){ - super(0,status); //for type 0 - t = token; - uid = id; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResLogout.java b/client/Piztor/src/com/macaroon/piztor/ResLogout.java deleted file mode 100644 index 4b2a8d1..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResLogout.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Respond to logout // -//--------------------------------------// - -public class ResLogout extends Res{ - - ResLogout(int status){ - super(4,status); //for type 4 - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResPushLocation.java b/client/Piztor/src/com/macaroon/piztor/ResPushLocation.java deleted file mode 100644 index c3e2b64..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResPushLocation.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.macaroon.piztor; - -import java.util.Vector; - -//--------------------------------------// -// Push Location // -//--------------------------------------// - -public class ResPushLocation extends Res{ - Vector l; //vector for location info - int n; //number of location info - - ResPushLocation(int num,Vector locationvec){ - super(101,0); //for type 101 - l = locationvec; - n = num; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResPushMessage.java b/client/Piztor/src/com/macaroon/piztor/ResPushMessage.java deleted file mode 100644 index ff61ee0..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResPushMessage.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Push Message // -//--------------------------------------// - -public class ResPushMessage extends Res{ - String message; - - ResPushMessage(String s){ - super(100,0); //for type 100 - message = s; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResSendMessage.java b/client/Piztor/src/com/macaroon/piztor/ResSendMessage.java deleted file mode 100644 index 09f3ffa..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResSendMessage.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Respond to send Message // -//--------------------------------------// - -public class ResSendMessage extends Res{ - - ResSendMessage(int status){ - super(6,status); //for type 6 - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResStartPush.java b/client/Piztor/src/com/macaroon/piztor/ResStartPush.java deleted file mode 100644 index 33343d7..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResStartPush.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Respond to start push // -//--------------------------------------// - -public class ResStartPush extends Res{ - - ResStartPush(int status){ - super(5,status); //for type 5 - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResUpdate.java b/client/Piztor/src/com/macaroon/piztor/ResUpdate.java deleted file mode 100644 index dd0d29b..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResUpdate.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Respond to update location // -//--------------------------------------// - -public class ResUpdate extends Res{ - - ResUpdate(int status){ - super(1,status); //for type 1 - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResUserInfo.java b/client/Piztor/src/com/macaroon/piztor/ResUserInfo.java deleted file mode 100644 index 2556c68..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResUserInfo.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Respond to User Info // -//--------------------------------------// - -public class ResUserInfo extends Res{ - int uid; //userid - int company; //group id - int section; - int sex; //type 0 for female,type 1 for male - - - ResUserInfo(int status,int u,int com,int sec,int s){ - super(3,status); //for type 3 - uid = u; - company = com; - section = sec; - sex =s; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/ResUserinfo.java b/client/Piztor/src/com/macaroon/piztor/ResUserinfo.java deleted file mode 100644 index ed981b4..0000000 --- a/client/Piztor/src/com/macaroon/piztor/ResUserinfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.macaroon.piztor; - - -//--------------------------------------// -// Respond to User Info // -//--------------------------------------// - -public class ResUserinfo extends Res{ - int uid; //userid - int gid; //groupid - int sex; //type 0 for female,type 1 for male - - - ResUserinfo(int status,int u,int g,int s){ - super(3,status); //for type 3 - uid = u; - gid = g; - sex =s; - } -} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/Settings.java b/client/Piztor/src/com/macaroon/piztor/Settings.java index c0ca901..b334cc4 100644 --- a/client/Piztor/src/com/macaroon/piztor/Settings.java +++ b/client/Piztor/src/com/macaroon/piztor/Settings.java @@ -1,9 +1,12 @@ package com.macaroon.piztor; +import java.util.Vector; + import android.annotation.SuppressLint; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; @@ -12,87 +15,78 @@ import android.widget.Toast; public class Settings extends PiztorAct { Button logout; MapInfo mapInfo; - + Transam transam; // Event final static int logoutButtonPressed = 10; final static int logoutFailed = 11; - - + @SuppressLint("HandlerLeak") Handler handler = new Handler() { @Override public void handleMessage(Message m) { - System.out.println("!!!!!!!!!!!!!!!!!!!!!settings" + m.what); switch (m.what) { - case 1:// 上传自己信息成功or失败 - ResUpdate update = (ResUpdate) m.obj; - if (update.status == 0) - System.out.println("update success"); - else { - System.out.println("update failed"); - actMgr.trigger(AppMgr.errorToken); - } + case Res.Update:// 上传自己信息成功or失败 + Log.d("update location", "successfull"); break; - case 2:// 得到别人的信息 - ResLocation location = (ResLocation) m.obj; - if (location.status == 0) { - mapInfo.clear(); - for (RLocation i : location.l) { - System.out.println(i.id + " : " + i.latitude + " " + i.longitude); - UserInfo info = new UserInfo(i.id); - info.setLocation(i.latitude, i.longitude); - mapInfo.addUserInfo(info); + case Res.UserInfo:// 得到用户信息 + ResUserInfo userInfo = (ResUserInfo) m.obj; + System.out.println("revieve ........" + userInfo.uinfo.size()); + Vector uinfo = userInfo.uinfo; + for (RUserInfo info : uinfo) { + System.out.println(info.latitude + " " + + info.longitude); + UserInfo r = mapInfo.getUserInfo(info.uid); + if (r != null) { + r.setInfo(info.gid.company, info.gid.section, info.sex, + info.nickname); + r.setLocation(info.latitude, info.longitude); + } else { + r = new UserInfo(info.uid); + r.setInfo(info.gid.company, info.gid.section, info.sex, + info.nickname); + r.setLocation(info.latitude, info.longitude); + mapInfo.addUserInfo(r); } - } else { - System.out.println("resquest for location failed!"); - actMgr.trigger(AppMgr.errorToken); } break; - case 3:// 得到用户信息 - ResUserInfo r = (ResUserInfo) m.obj; - if (r.status == 0) { - System.out.println("id : " + r.uid + " sex : " + r.sex - + " group : " + r.section); - UserInfo user = mapInfo.getUserInfo(r.uid); - user.setInfo(r.company, r.section, r.sex); - } else { - System.out.println("reqest for userInfo must be wrong!!!"); - actMgr.trigger(AppMgr.errorToken); - } + case Res.Logout:// 登出 + actMgr.trigger(AppMgr.logout); break; - case 4:// 登出 - ResLogout logout = (ResLogout) m.obj; - System.out.println("logout status" + logout.status); - if (logout.status == 0) { - Infomation.token = null; - Infomation.myInfo.company = -1; - Infomation.myInfo.section = -1; - Infomation.myInfo.uid = -1; - Infomation.username = null; - actMgr.trigger(AppMgr.logout); - break; - } else { - Toast toast = Toast.makeText(getApplicationContext(), - "logout failed", Toast.LENGTH_LONG); - toast.show(); - actMgr.trigger(logoutFailed); - } + case Res.PushMessage: + ResPushMessage pushMessage = (ResPushMessage) m.obj; + 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); break; default: break; } } }; - - class StartStatus extends ActStatus { - - @Override - void enter(int e) { + + void upMapInfo(Vector l) { + 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); + } } + } - @Override - void leave(int e) { - } + void receiveMessage(String msg) { + Log.d("recieve message", msg); + Toast toast = Toast.makeText(getApplicationContext(), msg, + Toast.LENGTH_LONG); + toast.show(); } class LogoutStatus extends ActStatus { @@ -100,28 +94,31 @@ public class Settings extends PiztorAct { @Override void enter(int e) { System.out.println("!!!!!!!logout info send!!!!!!!!"); - AppMgr.transam.send(new ReqLogout(Infomation.token, - Infomation.username, System.currentTimeMillis(), 2000)); + transam.send(new ReqLogout(Infomation.token, Infomation.username, + System.currentTimeMillis(), 2000)); } @Override void leave(int e) { - // TODO Auto-generated method stub } + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mapInfo = AppMgr.mapInfo; + transam = AppMgr.transam; + if (transam == null) + Log.d(LogInfo.exception, "transam = null"); + transam.setHandler(handler); ActStatus[] r = new ActStatus[3]; - ActStatus start = r[0] = new StartStatus(); + ActStatus start = r[0] = new EmptyStatus(); ActStatus logout = r[2] = new LogoutStatus(); actMgr = new ActMgr(this, start, r); actMgr.add(start, logoutButtonPressed, logout); actMgr.add(logout, logoutFailed, start); - AppMgr.transam.setHandler(handler); - mapInfo = AppMgr.mapInfo; setContentView(R.layout.activity_settings); } @@ -132,7 +129,7 @@ public class Settings extends PiztorAct { logout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - actMgr.trigger(logoutButtonPressed); + actMgr.trigger(logoutButtonPressed); } }); } diff --git a/client/Piztor/src/com/macaroon/piztor/SocketClient.java b/client/Piztor/src/com/macaroon/piztor/SocketClient.java index 622c581..58b20c7 100644 --- a/client/Piztor/src/com/macaroon/piztor/SocketClient.java +++ b/client/Piztor/src/com/macaroon/piztor/SocketClient.java @@ -9,7 +9,6 @@ import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.util.Vector; -import android.annotation.SuppressLint; import android.os.Handler; import android.os.Message; @@ -23,21 +22,33 @@ public class SocketClient { static final int DoubleLength = 8; static final int TokenLength = 32; - public final static int Login =0; - public final static int Update =1; - public final static int Location =2; - public final static int UserInfo =3; - public final static int Logout =4; - public final static int SendMessage =6; + static final int Login =0; + static final int Update =1; + static final int UserInfo =2; + static final int Subscription =3; + static final int Logout =4; + static final int StartPush =5; + static final int SendMessage =6; - public final static int GroupID =0; - public final static int Gender =1; + static final int ClosePush =-5; + + static final int UID =1; + static final int Uname =2; + static final int Nname =3; + static final int Gender =4; + static final int GroupID =5; + static final int Latitude =6; + static final int Longitude =7; + + static final int StatusFailed = 2; + static final int TimeOut = 1; + static final int Success = 0; public SocketClient(String site, int port, int retime) throws UnknownHostException, IOException { try { client = new Socket(); - client.connect(new InetSocketAddress(site,port), 5000); + client.connect(new InetSocketAddress(site,port), retime); client.setSoTimeout(retime); } catch (UnknownHostException e) { e.printStackTrace(); @@ -48,7 +59,7 @@ public class SocketClient { } } - public int sendMsg(Req req,Handler recall) throws IOException,SocketTimeoutException { + public int sendMsg(Req req,Handler recall,Handler h) throws IOException,SocketTimeoutException { try { DataOutputStream out = new DataOutputStream( client.getOutputStream()); @@ -61,15 +72,15 @@ public class SocketClient { ReqLogin rau = (ReqLogin) req; len = IntLength+ByteLength+rau.user.length()+ByteLength+rau.pass.length()+ByteLength; b = new byte[len]; - write(b,intToBytes(len),pos); + Convert.write(b,Convert.intToBytes(len),pos); pos+=IntLength; b[pos] = (byte) tmp; pos+=ByteLength; - write(b,rau.user.getBytes(),pos); + Convert.write(b,rau.user.getBytes(),pos); pos+=rau.user.length(); b[pos] = 0; pos+=ByteLength; - write(b, rau.pass.getBytes(),pos); + Convert.write(b, rau.pass.getBytes(),pos); pos+= rau.pass.length(); b[pos] = 0; pos+=ByteLength; @@ -79,71 +90,78 @@ public class SocketClient { ReqUpdate rup = (ReqUpdate) req; len = IntLength+ByteLength+TokenLength+(rup.uname).length()+ByteLength+DoubleLength+DoubleLength; b = new byte[len]; - write(b,intToBytes(len),pos); + Convert.write(b,Convert.intToBytes(len),pos); pos+=IntLength; b[pos] = (byte) tmp; pos+=ByteLength; - write(b,hexStringToBytes(rup.token),pos); + Convert.write(b,Convert.hexStringToBytes(rup.token),pos); pos+=TokenLength; - write(b,(rup.uname).getBytes(),pos); + Convert.write(b,(rup.uname).getBytes(),pos); pos+=(rup.uname).length(); b[pos] = 0; pos+=ByteLength; - write(b,doubleToBytes(rup.latitude),pos); + Convert.write(b,Convert.doubleToBytes(rup.latitude),pos); pos+=DoubleLength; - write(b,doubleToBytes(rup.longitude),pos); + Convert.write(b,Convert.doubleToBytes(rup.longitude),pos); pos+=DoubleLength; out.write(b); break; - case Location: - ReqLocation ras = (ReqLocation) req; - len = IntLength+ByteLength+TokenLength+ras.uname.length()+ByteLength+ByteLength+ByteLength; + case UserInfo: + ReqUserInfo rus = (ReqUserInfo) req; + len = IntLength+ByteLength+TokenLength+rus.uname.length()+ByteLength+ByteLength+ByteLength; b = new byte[len]; - write(b,intToBytes(len),pos); + Convert.write(b,Convert.intToBytes(len),pos); pos+=IntLength; b[pos] = (byte) tmp; pos+=ByteLength; - write(b,hexStringToBytes(ras.token),pos); + Convert.write(b,Convert.hexStringToBytes(rus.token),pos); pos+=TokenLength; - write(b,(ras.uname).getBytes(),pos); - pos+=(ras.uname).length(); + Convert.write(b,(rus.uname).getBytes(),pos); + pos+=(rus.uname).length(); b[pos] = 0; pos+=ByteLength; - b[pos] = (byte) ras.company; + b[pos] = (byte) rus.gid.company; + pos+=ByteLength; + b[pos] = (byte) rus.gid.section; pos+=ByteLength; - b[pos] = (byte) ras.section; - pos+=ByteLength; out.write(b); break; - case UserInfo: - ReqUserInfo rus = (ReqUserInfo) req; - len = IntLength+ByteLength+TokenLength+rus.uname.length()+ByteLength+IntLength; + case Subscription: + ReqSubscription rsu = (ReqSubscription) req; + int number = rsu.n; + len = IntLength+ByteLength+TokenLength+rsu.uname.length()+ByteLength+2*ByteLength*number+ByteLength; b = new byte[len]; - write(b,intToBytes(len),pos); + Convert.write(b,Convert.intToBytes(len),pos); pos+=IntLength; b[pos] = (byte) tmp; pos+=ByteLength; - write(b,hexStringToBytes(rus.token),pos); + Convert.write(b,Convert.hexStringToBytes(rsu.token),pos); pos+=TokenLength; - write(b,(rus.uname).getBytes(),pos); - pos+=(rus.uname).length(); + Convert.write(b,(rsu.uname).getBytes(),pos); + pos+=(rsu.uname).length(); + b[pos] = 0; + pos+=ByteLength; + for(int i=0;i vrg = new Vector(); + while(outlen > 1) { + int com = in.readUnsignedByte(); + int sec = in.readUnsignedByte(); + vrg.add(new RGroup(com,sec)); + outlen-=ByteLength*2; + number++; + } + in.readUnsignedByte(); + msg.obj = new ResLogin(tk, r, vrg, number); msg.what = Login; recall.sendMessage(msg); + Vector vs = new Vector(); + vs.add(uname); + vs.add(tk); + Message m = new Message(); + m.obj = vs; + m.what = StartPush; + h.sendMessage(m); break; case Update: - msg.obj = new ResUpdate(status); + msg.obj = new ResUpdate(); msg.what = Update; recall.sendMessage(msg); break; - case Location: - int n = 0; - outlen-=(IntLength+ByteLength+ByteLength); - Vector tmpv = new Vector(); - while(outlen > 0) { - int tid = in.readInt(); - double lat = in.readDouble(); - double lot = in.readDouble(); - tmpv.add(new RLocation(tid,lat,lot)); - outlen -= (IntLength+DoubleLength+DoubleLength); - n++; - } - msg.obj = new ResLocation(n,status,tmpv); - msg.what = Location; - recall.sendMessage(msg); - break; case UserInfo: outlen-=(IntLength+ByteLength+ByteLength); - ReqUserInfo rus = (ReqUserInfo) req; - int u = rus.uid; - int com = 0,sec = 0,s = 0; + int uid1 =0,s1 =0; + String uname1 ="",nname1 =""; + double lat1 =0.0,lot1 =0.0; + RGroup rg1 = null; + int k = 0; + byte[] bn = new byte[200]; + Vector v = new Vector(); + int n = 0; while(outlen > 0) { - int typ = in.readUnsignedByte(); - outlen-=ByteLength; - switch(typ){ - case GroupID: - com = in.readUnsignedByte(); - sec = in.readUnsignedByte(); - outlen-=(ByteLength+ByteLength); - break; - case Gender: - s = in.readUnsignedByte(); + int tmpcnt =0; + while(tmpcnt < 7) { + int typ = in.readUnsignedByte(); outlen-=ByteLength; - break; + switch(typ){ + case UID: + uid1 = in.readInt(); + outlen-=IntLength; + break; + case Uname: + k = 0; + while(true) { + bn[k] = in.readByte(); + if(bn[k] == 0)break; + k++; + } + byte[] wr = new byte[k]; + for(int j=0;j> 24) & 0xFF); - d[1] = (byte)((i >> 16) & 0xFF); - d[2] = (byte)((i >> 8) & 0xFF); - d[3] = (byte)(i & 0xFF); - return d; - } - - public static byte[] doubleToBytes(double d){ - byte[] b=new byte[8]; - long l=Double.doubleToLongBits(d); - for(int i=0;i<8;i++){ - b[i] = (byte)(l >>> 8*(7-i)); - } - return b; - } - - private static void write(byte[] s,byte[] w,int l) { - - for(int i=0;i reqtask ; //request task + private Timer timer; + private Timer pushtimer; + private boolean running = false; + private int cnt = 5; //retry times + private int tcnt; //current remain retry times + private int rcnt; //current remain retry times (push) + private int retime = 2000; //timeout time + private Req req; + private int p; //port + private String i; //ip + private Thread thread; + private Handler recall; //recall + private Queue reqtask ; //request task - public String itoken; - public String iname; + private String itoken; + private String iname; - Thread Pushthread; - PushClient push; - - - public final static int Reconnect =-2; - public final static int Exception =-1; - public final static int TimeOut =0; + private Thread Pushthread; + private PushClient push; Transam(String ip, int port,Handler Recall) { p = port; @@ -124,14 +120,14 @@ public class Transam implements Runnable { } - public void startPush(String token,String name) { + private void startPush(String token,String name) { itoken = token; iname = name; rcnt = cnt; connectpush(); } - public void stopPush() { + private void stopPush() { try{ if(push.isClosed() == false) { push.closeSocket(); @@ -181,7 +177,7 @@ public class Transam implements Runnable { } else{ //run the request running = true; - tcnt = cnt; + tcnt = cnt; connect(); } } @@ -201,7 +197,19 @@ public class Transam implements Runnable { Pushthread.start(); } - class reqpush implements Runnable { + class tmain extends TimerTask { + public void run() { + connect(); + } + }; + + class pmain extends TimerTask { + public void run() { + connectpush(); + } + }; + + private class reqpush implements Runnable { public void run() { try { if(itoken == null || iname == null) return; @@ -217,9 +225,14 @@ public class Transam implements Runnable { } else if (out == 2){ stopPush(); + Message msg = new Message(); + msg.what = Exception; + msg.obj = new EStatusFailedException(5,0); + recall.sendMessage(msg); } else { - push.listen(recall,handler); + rcnt = cnt; + push.listen(recall); } } catch (UnknownHostException e) { e.printStackTrace(); @@ -238,23 +251,30 @@ public class Transam implements Runnable { } } - class thd implements Runnable { + private class thd implements Runnable { public void run() { try { SocketClient client = new SocketClient(i,p,retime); - int out = client.sendMsg(req,recall); + int out = client.sendMsg(req,recall,handler); if(out == 0){ client.closeSocket(); running = false; } - else { + else if (out == 1){ client.closeSocket(); - Message m = new Message(); - EConnectFailedException c = new EConnectFailedException(req.type,req.time); - m.obj = c; - m.what = Exception; + Message m = new Message(); + m.obj = new ETimeOutException(req.type,req.time); + m.what = TimeOut; handler.sendMessage(m); - } + } + else { + client.closeSocket(); + Message msg = new Message(); + msg.what = Exception; + msg.obj = new EStatusFailedException(5,0); + recall.sendMessage(msg); + running = false; + } } catch (UnknownHostException e) { e.printStackTrace(); Message msg = new Message(); @@ -272,15 +292,18 @@ public class Transam implements Runnable { } } + @SuppressLint("HandlerLeak") - Handler handler = new Handler() { + private Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case Exception: if (tcnt > 0) { tcnt--; System.out.println(tcnt); - connect(); + timer = new Timer(); + TimerTask task = new tmain(); + timer.schedule(task,retime); } else if (tcnt == 0) { Message m = new Message(); m.obj = msg.obj; @@ -292,7 +315,10 @@ public class Transam implements Runnable { case TimeOut: if (tcnt > 0) { tcnt--; - connect(); + System.out.println(tcnt); + timer = new Timer(); + TimerTask task = new tmain(); + timer.schedule(task,retime); } else if (tcnt == 0) { Message m = new Message(); EConnectFailedException c = new EConnectFailedException(req.type,req.time); @@ -305,72 +331,33 @@ public class Transam implements Runnable { case Reconnect: if (rcnt > 0) { rcnt--; - connectpush(); + System.out.println(rcnt); + pushtimer = new Timer(); + TimerTask task = new pmain(); + pushtimer.schedule(task,retime); } else if (rcnt == 0) { Message m = new Message(); - //EPushFailedException c = new EPushFailedException(req.type); - m.obj = msg.obj; + EPushFailedException c = new EPushFailedException(5,0); + //m.obj = msg.obj; + m.obj = c; m.what = Exception; recall.sendMessage(m); } break; + case StartPush: + @SuppressWarnings("unchecked") + Vector s = (Vector) msg.obj; + startPush(s.get(1),s.get(0)); + System.out.println("startpush"); + break; + case ClosePush: + stopPush(); + System.out.println("closepush"); + break; } super.handleMessage(msg); } }; - class EException extends Exception { - private static final long serialVersionUID = 100L; - int Rtype; - int Etype; - long time; - public EException(int e,int r,long timep) { - super(); - Rtype = r; - Etype = e; - time = timep; - } - } - - class EConnectFailedException extends EException{ - private static final long serialVersionUID = 101L; - public EConnectFailedException(int t,long timep) { - super(101,t,timep); - } - } - - class ETimeOutException extends EException{ - private static final long serialVersionUID = 102L; - public ETimeOutException(int t,long timep) { - super(102,t,timep); - } - } - - class EJavaHostException extends EException{ - private static final long serialVersionUID = 103L; - public EJavaHostException(int t,long timep) { - super(103,t,timep); - } - } - - class EPushFailedException extends EException{ - private static final long serialVersionUID = 104L; - public EPushFailedException(int t,long timep) { - super(104,t,timep); - } - } - - class EIOException extends EException{ - private static final long serialVersionUID = 105L; - public EIOException(int t,long timep) { - super(105,t,timep); - } - } - class EUnknownHostException extends EException{ - private static final long serialVersionUID = 106L; - public EUnknownHostException(int t,long timep) { - super(106,t,timep); - } - } } \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java new file mode 100644 index 0000000..0521432 --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java @@ -0,0 +1,5 @@ +package com.macaroon.piztor; + +public class UpdateInfo { + +} -- cgit v1.2.3-70-g09d2