diff options
Diffstat (limited to 'client/Piztor/src/com/macaroon/piztor/Main.java')
-rw-r--r-- | client/Piztor/src/com/macaroon/piztor/Main.java | 259 |
1 files changed, 122 insertions, 137 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java index eeab207..be01c6a 100644 --- a/client/Piztor/src/com/macaroon/piztor/Main.java +++ b/client/Piztor/src/com/macaroon/piztor/Main.java @@ -3,27 +3,21 @@ package com.macaroon.piztor; import java.util.Calendar; import java.util.Timer; import java.util.TimerTask; +import java.util.Vector; import android.annotation.SuppressLint; -import android.app.AlertDialog; -import android.app.TimePickerDialog; import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.provider.Settings; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.View; import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; import android.widget.ImageButton; import android.widget.TextView; -import android.widget.TimePicker; import android.widget.Toast; import com.baidu.location.BDLocation; @@ -35,27 +29,23 @@ 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; public class Main extends PiztorAct { - final static int SearchButtonPress = 1; final static int FocuseButtonPress = 3; final static int SuccessFetch = 4; final static int FailedFetch = 5; - final static int Fetch = 6; final static int mapViewtouched = 7; - + + MapMaker mapMaker = null; MapView mMapView; AlertMaker alertMaker; private Calendar calendar; GeoPoint markerPoint = null; - - // map touch listener - private MKMapTouchListener mapTouchListener; - - boolean isFirstLocation = true; + private MKMapTouchListener mapTouchListener; /** * Locating component @@ -65,21 +55,11 @@ public class Main extends PiztorAct { LocationClient mLocClient; LocationData locData = null; public MyLocationListener myListener = new MyLocationListener(); + boolean isFirstLocation = true; ImageButton btnSearch, btnFetch, btnFocus, btnSettings; - // Timer autodate; MapInfo mapInfo; - /* - * @SuppressLint("HandlerLeak") Handler fromGPS = new Handler() { - * - * @Override public void handleMessage(Message m) { if (m.what != 0) { - * Location l = (Location) m.obj; if (l == null) - * System.out.println("fuck!!!"); else { ReqUpdate r = new - * ReqUpdate(Infomation.token, Infomation.username, l.getLatitude(), - * l.getLongitude(), System.currentTimeMillis(), 1000); - * AppMgr.transam.send(r); } } } }; - */ - + @SuppressLint("HandlerLeak") Handler handler = new Handler() { @Override @@ -87,7 +67,7 @@ public class Main extends PiztorAct { switch (m.what) { case 1:// 上传自己信息成功or失败 ResUpdate update = (ResUpdate) m.obj; - if (update.s == 0) + if (update.status == 0) System.out.println("update success"); else { System.out.println("update failed"); @@ -96,32 +76,36 @@ public class Main extends PiztorAct { break; case 2:// 得到别人的信息 ResLocation location = (ResLocation) m.obj; - if (location.s == 0) { + if (location.status == 0) { mapInfo.clear(); - for (Rlocation i : location.l) { - System.out.println(i.i + " : " + i.lat + " " + i.lot); - UserInfo info = new UserInfo(i.i); - info.setLocation(i.lat, i.lot); + 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); +// 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.s == 0) { + ResUserInfo r = (ResUserInfo) m.obj; + if (r.status == 0) { System.out.println("id : " + r.uid + " sex : " + r.sex - + " group : " + r.gid); + + " group : " + r.section); if (r.uid == Infomation.myInfo.uid) { - Infomation.myInfo.gid = r.gid; + System.out.println("flush myself info!!!"); + Infomation.myInfo.section = r.section; + Infomation.myInfo.company = r.company; Infomation.myInfo.sex = r.sex; } else { UserInfo user = mapInfo.getUserInfo(r.uid); if (user != null) - user.setInfo(r.gid, r.sex); + user.setInfo(r.company, r.section, r.sex); else System.out.println("fuck!!!!"); } @@ -133,7 +117,7 @@ public class Main extends PiztorAct { break; case 4:// 登出 ResLogout logout = (ResLogout) m.obj; - if (logout.s == 0) { + if (logout.status == 0) { actMgr.trigger(AppMgr.logout); } else { Toast toast = Toast.makeText(getApplicationContext(), @@ -141,18 +125,49 @@ public class Main extends PiztorAct { toast.show(); } break; + case Transam.StartPush: + ResStartPush startpush = (ResStartPush) m.obj; + if (startpush.status == 1) { + System.out.println("!!!!!!!!!!!!!jian gui le!!!!!!!!!!!!!"); + } + break; + case Transam.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); + break; + case Transam.PushLocation: + ResPushLocation pushLocation = (ResPushLocation) m.obj; + upDateInfo(pushLocation.l); + break; default: break; } } + + void upDateInfo(Vector<RLocation> l) { + // TODO + 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); + } + } + flushMap(); + } }; String cause(int t) { switch (t) { case SearchButtonPress: return "Search Button Press"; - case Fetch: - return "Fetch "; case FocuseButtonPress: return "Focuse Button Press"; case SuccessFetch: @@ -172,29 +187,44 @@ public class Main extends PiztorAct { System.out .println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); } + + void receiveMessage(String msg) { + System.out.println("receiveed push message!!!!!"); + System.out.println(msg); + Toast toast = Toast.makeText(getApplicationContext(), + msg, Toast.LENGTH_LONG); + toast.show(); + } + public class MyLocationListener implements BDLocationListener { + int cnt = 0; + GeoPoint lastPoint = null; @Override public void onReceiveLocation(BDLocation location) { Log.d("GPS", "Gotten"); + cnt++; if (location == null) { return; } - locData.latitude = location.getLatitude(); locData.longitude = location.getLongitude(); locData.accuracy = location.getRadius(); locData.direction = location.getDerect(); - - System.out.println("LLLLLLLLLLLLLLLLLLLLLLL " + locData.latitude + " " + locData.longitude); - mapMaker.UpdateLocationOverlay(locData, isFirstLocation); - isFirstLocation = false; - if (Infomation.token != null) { - AppMgr.transam.send(new ReqUpdate(Infomation.token, - Infomation.username, locData.latitude, - locData.longitude, System.currentTimeMillis(), 2000)); - Infomation.myInfo.setLocation(locData.latitude, locData.longitude); + + GeoPoint point = new GeoPoint((int)(locData.latitude * 1e6), (int)(locData.longitude * 1e6)); + if (lastPoint == null || cnt > 5 || DistanceUtil.getDistance(point, lastPoint) > 10 ) { + if (Infomation.token != null) { + Infomation.myInfo.setLocation(locData.latitude, + locData.longitude); + AppMgr.transam.send(new ReqUpdate(Infomation.token, + Infomation.username, locData.latitude, + locData.longitude, System.currentTimeMillis(), 2000)); + lastPoint = point; + cnt = 0; + } } + mapMaker.UpdateLocationOverlay(locData, false); } @Override @@ -213,14 +243,9 @@ 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, + AppMgr.transam.send(new ReqUserInfo(Infomation.token, Infomation.username, Infomation.myInfo.uid, System .currentTimeMillis(), 5000)); - // TODO flush mapinfo.myinfo - } - - if (e == Fetch) { - requesLocation(Infomation.myInfo.gid); } if (e == SuccessFetch) flushMap(); @@ -233,67 +258,19 @@ public class Main extends PiztorAct { } - class FetchStatus extends ActStatus { - - @Override - void enter(int e) { - System.out.println("enter Fetch status!!!!"); - if (e == Fetch) { - requesLocation(Infomation.myInfo.gid); - } - if (e == SuccessFetch) { - flushMap(); - } - } - @Override - void leave(int e) { - System.out.println("leave fetch status!!!! because" + cause(e)); - } - - } - - class FocusStatus extends ActStatus { - - @Override - void enter(int e) { - // TODO - switch (e) { - case Fetch: - requesLocation(Infomation.myInfo.gid); - break; - case FocuseButtonPress: - mapMaker.UpdateLocationOverlay(locData, true); - break; - case SuccessFetch: - flushMap(); - break; - default: - break; - } - System.out.println("enter focus status!!!!"); - } - - @Override - void leave(int e) { - // TODO leave focus - System.out.println("leave focus status!!!! because" + cause(e)); - } - - } - - void requesLocation(int gid) { + void requesLocation(int company, int section) { ReqLocation r = new ReqLocation(Infomation.token, Infomation.username, - gid, System.currentTimeMillis(), 2000); + company, section, System.currentTimeMillis(), 2000); + AppMgr.transam + .send(new ReqSendMessage(Infomation.token, Infomation.username, + "hahaha", System.currentTimeMillis(), 5000)); System.out.println("get others infomation!!!"); AppMgr.transam.send(r); } - class AutoUpdate extends TimerTask { - @Override - public void run() { - actMgr.trigger(Main.Fetch); - } + void focusOn() { + mapMaker.mMapController.animateTo(Infomation.myInfo.location); } public void InitTouchListenr() { @@ -304,11 +281,6 @@ public class Main extends PiztorAct { public void onMapLongClick(GeoPoint arg0) { closeBoard(Main.this); alertMaker.showMarkerAlert(arg0); - /* - if (mapMaker != null) - mapMaker.DrawMarker(arg0); - Log.d("marker", "draw a new marker"); - */ } @Override @@ -335,24 +307,25 @@ public class Main extends PiztorAct { isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER); mapInfo = AppMgr.mapInfo; - ActStatus[] r = new ActStatus[3]; + ActStatus[] r = new ActStatus[1]; ActStatus startStatus = r[0] = new StartStatus(); - ActStatus fetchStatus = r[1] = new FetchStatus(); - ActStatus focusStatus = r[2] = new FocusStatus(); +// ActStatus fetchStatus = r[1] = new FetchStatus(); +// ActStatus focusStatus = r[2] = new FocusStatus(); AppMgr.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); @@ -371,7 +344,7 @@ public class Main extends PiztorAct { mLocClient.start(); mapMaker.UpdateLocationOverlay(locData, false); } - + public static void closeBoard(Context cc) { InputMethodManager imm = (InputMethodManager) cc .getSystemService(Context.INPUT_METHOD_SERVICE); @@ -379,7 +352,11 @@ public class Main extends PiztorAct { imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); } - + + /* + * public boolean onTap(int index) { OverlayItem item = getItem(index); + * mCurItem = item; if () } + */ @Override protected void onStart() { super.onStart(); @@ -390,15 +367,17 @@ public class Main extends PiztorAct { btnFetch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { - actMgr.trigger(Fetch); + requesLocation(Infomation.myInfo.company, Infomation.myInfo.section); } }); + btnFocus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - actMgr.trigger(FocuseButtonPress); + focusOn(); } }); + btnSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { @@ -409,10 +388,17 @@ public class Main extends PiztorAct { } @Override + protected void onRestart() { + super.onRestart(); + AppMgr.transam.setHandler(handler); + } + + @Override protected void onResume() { isFirstLocation = true; mapMaker.onResume(); flushMap(); + requesLocation(Infomation.myInfo.company, Infomation.myInfo.section); super.onResume(); } @@ -456,7 +442,6 @@ public class Main extends PiztorAct { protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); - } @Override |