summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com/macaroon/piztor/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'client/Piztor/src/com/macaroon/piztor/Main.java')
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java212
1 files changed, 121 insertions, 91 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java
index 735b1a4..4efea11 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,10 +38,10 @@ 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 GPSrefreshrate = 5;
/**
* Locating component
@@ -55,16 +52,22 @@ public class Main extends PiztorAct {
LocationData locData = null;
public MyLocationListener myListener = new MyLocationListener();
boolean isFirstLocation = true;
- public static int GPSrefreshrate = 5;
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 +77,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 +89,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 Button Press";
case FocuseButtonPress:
return "Focuse Button Press";
case SuccessFetch:
@@ -148,14 +161,12 @@ public class Main extends PiztorAct {
// TODO flush map view
void flushMap() {
if (mapMaker != null)
- mapMaker.UpdateMap(AppMgr.mapInfo);
+ mapMaker.UpdateMap(mapInfo);
else
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.show();
@@ -164,6 +175,7 @@ public class Main extends PiztorAct {
public class MyLocationListener implements BDLocationListener {
int cnt = 0;
GeoPoint lastPoint = null;
+
@Override
public void onReceiveLocation(BDLocation location) {
Log.d("GPS", "Gotten");
@@ -175,15 +187,17 @@ public class Main extends PiztorAct {
locData.longitude = location.getLongitude();
locData.accuracy = location.getRadius();
locData.direction = location.getDerect();
-
- 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,
+
+ GeoPoint point = new GeoPoint((int) (locData.latitude * 1e6),
+ (int) (locData.longitude * 1e6));
+ if (lastPoint == null || cnt > 5
+ || DistanceUtil.getDistance(point, lastPoint) > 10) {
+ if (app.token != null) {
+ app.mapInfo.myInfo.setLocation(locData.latitude,
locData.longitude);
- AppMgr.transam.send(new ReqUpdate(Infomation.token,
- Infomation.username, locData.latitude,
- locData.longitude, System.currentTimeMillis(), 2000));
+ transam.send(new ReqUpdate(app.token, app.username,
+ locData.latitude, locData.longitude, System
+ .currentTimeMillis(), 2000));
lastPoint = point;
cnt = 0;
}
@@ -195,22 +209,28 @@ public class Main extends PiztorAct {
}
int TMP = location.getLocType();
if (TMP == 61) {
- Toast toast = Toast.makeText(Main.this, "Piztor : Update from GPS result (" + GPSrefreshrate + "s)", 2000);
+ Toast toast = Toast.makeText(Main.this,
+ "Piztor : Update from GPS result (" + GPSrefreshrate
+ + "s)", 2000);
toast.setGravity(Gravity.TOP, 0, 80);
toast.show();
}
if (TMP == 161) {
- Toast toast = Toast.makeText(Main.this, "Piztor : Update from Network (" + GPSrefreshrate + "s)", 2000);
+ Toast toast = Toast.makeText(Main.this,
+ "Piztor : Update from Network (" + GPSrefreshrate
+ + "s)", 2000);
toast.setGravity(Gravity.TOP, 0, 80);
toast.show();
}
if (TMP == 65) {
- Toast toast = Toast.makeText(Main.this, "Piztor : Update from Cache (" + GPSrefreshrate + "s)", 2000);
+ Toast toast = Toast.makeText(Main.this,
+ "Piztor : Update from Cache (" + GPSrefreshrate + "s)",
+ 2000);
toast.setGravity(Gravity.TOP, 0, 80);
toast.show();
}
mapMaker.UpdateLocationOverlay(locData, hasAnimation);
-
+
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);
option.setCoorType("bd09ll");
@@ -232,7 +252,8 @@ public class Main extends PiztorAct {
void enter(int e) {
System.out.println("enter start status!!!!");
if (e == ActMgr.Create) {
- System.out.println(Infomation.token + " " + Infomation.username + " " + Infomation.myInfo.uid);
+ System.out.println(app.token + " " + app.username + " "
+ + app.mapInfo.myInfo.uid);
}
if (e == SuccessFetch)
flushMap();
@@ -246,16 +267,18 @@ public class Main extends PiztorAct {
}
void requestUserInfo() {
- for (RGroup i : Infomation.sublist) {
- ReqUserInfo r = new ReqUserInfo(Infomation.token,
- Infomation.username, i, System.currentTimeMillis(), 2000);
+ mapInfo.clear();
+ System.out.println("cleared!!!!");
+ for (RGroup i : app.sublist) {
+ ReqUserInfo r = new ReqUserInfo(app.token, app.username, i,
+ System.currentTimeMillis(), 2000);
transam.send(r);
}
System.out.println("get others infomation!!!");
}
void focusOn() {
- mapMaker.mMapController.animateTo(Infomation.myInfo.location);
+ mapMaker.mMapController.animateTo(app.mapInfo.myInfo.location);
}
public void InitTouchListenr() {
@@ -265,7 +288,9 @@ public class Main extends PiztorAct {
@Override
public void onMapLongClick(GeoPoint arg0) {
closeBoard(Main.this);
- alertMaker.showMarkerAlert(arg0);
+ if (app.mapInfo.myInfo.level != 0) {
+ alertMaker.showMarkerAlert(arg0);
+ }
}
@Override
@@ -284,54 +309,55 @@ public class Main extends PiztorAct {
}
public void markerCheckin() {
+ Log.d("checkin", "ok!!!");
if (mapMaker.getMakerLocation() == null) {
Toast toast = Toast.makeText(Main.this, "No marker now!", 2000);
toast.setGravity(Gravity.TOP, 0, 80);
toast.show();
return;
}
- GeoPoint curPoint = new GeoPoint((int)(locData.latitude * 1E6), (int)(locData.longitude * 1E6));
- double disFromMarker = DistanceUtil.getDistance(curPoint, mapMaker.getMakerLocation());
+ mLocClient.requestLocation();
+ GeoPoint curPoint = new GeoPoint((int) (locData.latitude * 1E6),
+ (int) (locData.longitude * 1E6));
+ double disFromMarker = DistanceUtil.getDistance(curPoint,
+ mapMaker.getMakerLocation());
if (disFromMarker < locData.accuracy) {
- mapMaker.removeMarker();
- Toast toast = Toast.makeText(Main.this, "Marker checked!", 2000);
- toast.setGravity(Gravity.TOP, 0, 80);
- toast.show();
+ alertMaker.showCheckinAlter();
} else {
- Toast toast = Toast.makeText(Main.this, "Please get closer to the marker!", 2000);
+ Toast toast = Toast.makeText(Main.this,
+ "Please get closer to the marker!", 2000);
toast.setGravity(Gravity.TOP, 0, 80);
toast.show();
}
}
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
id = "Main";
super.onCreate(savedInstanceState);
-
+ handler = new ReCall(this);
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();
- if (transam == null)
- Log.d(LogInfo.exception, "transam = null");
- transam.setHandler(handler);
- actMgr = new ActMgr(this, startStatus, r);
+ transam = app.transam;
+
+ actMgr = new ActMgr(appMgr, this, startStatus, r);
setContentView(R.layout.activity_main);
+ app.mBMapManager.start();
mMapView = (MapView) findViewById(R.id.bmapView);
- mapMaker = new MapMaker(mMapView, getApplicationContext());
+ mapMaker = new MapMaker(mMapView, Main.this, app);
+ mapMaker.InitMap();
alertMaker = new AlertMaker(Main.this, mapMaker);
- if (isGPSEnabled == false) alertMaker.showSettingsAlert();
+ if (isGPSEnabled == false)
+ alertMaker.showSettingsAlert();
mapMaker.clearOverlay(mMapView);
- mapMaker.InitMap();
InitTouchListenr();
mLocClient = new LocationClient(this);
- mLocClient.setAK(AppMgr.strKey);
+ mLocClient.setAK(myApp.getStrkey());
locData = new LocationData();
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
@@ -339,7 +365,6 @@ public class Main extends PiztorAct {
option.setCoorType("bd09ll");
option.setScanSpan(GPSrefreshrate * 1000);
mLocClient.setLocOption(option);
- mLocClient.start();
mapMaker.UpdateLocationOverlay(locData, false);
}
@@ -358,21 +383,13 @@ public class Main extends PiztorAct {
btnFocus = (ImageButton) findViewById(R.id.footbar_btn_focus);
btnCheckin = (ImageButton) findViewById(R.id.footbar_btn_checkin);
btnSettings = (ImageButton) findViewById(R.id.footbar_btn_settings);
-
+
btnCheckin.setOnClickListener(new View.OnClickListener() {
-
@Override
public void onClick(View arg0) {
markerCheckin();
}
});
-
- btnFetch.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
-
- }
- });
btnFocus.setOnClickListener(new View.OnClickListener() {
@Override
@@ -398,21 +415,29 @@ public class Main extends PiztorAct {
@Override
protected void onResume() {
+ mMapView.onResume();
+ transam.setHandler(handler);
isFirstLocation = true;
+ mLocClient.start();
requestUserInfo();
- mapMaker.onResume();
+ // mapMaker.onResume();
flushMap();
super.onResume();
}
@Override
protected void onPause() {
- mapMaker.onPause();
+ // mapMaker.onPause();
+ // mapMaker = null;
+ mLocClient.stop();
+ mMapView.onPause();
+ // System.gc();
super.onPause();
}
@Override
public void onStop() {
+
super.onStop();
}
@@ -421,14 +446,19 @@ public class Main extends PiztorAct {
if (mLocClient != null) {
mLocClient.stop();
}
- mapMaker.onDestroy();
+ // mMapView.destroy();
+ // while null?
+ // mMapView.destroy();
+ //
super.onDestroy();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
- AppMgr.exit();
+ System.out.println("ready to exit!!!");
+ app.mBMapManager.stop();
+ appMgr.exit();
return true;
}
return super.onKeyDown(keyCode, event);