summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com
diff options
context:
space:
mode:
authorGoblin911 <[email protected]>2013-08-28 02:38:11 +0800
committerGoblin911 <[email protected]>2013-08-28 02:38:11 +0800
commit0a8315a94d8ed1252f3f96d4ca41ddc632c3bc98 (patch)
tree270d069ebfd636f19dff4cd507930367792a302f /client/Piztor/src/com
parent3baa5dd28c595c497a1669b3f25cda8c52139c87 (diff)
now can run!!!
Diffstat (limited to 'client/Piztor/src/com')
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AppMgr.java30
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Infomation.java7
-rw-r--r--client/Piztor/src/com/macaroon/piztor/InitAct.java2
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Login.java2
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java119
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapInfo.java28
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java165
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Settings.java4
8 files changed, 330 insertions, 27 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
index 0ba28e0..8e82384 100644
--- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java
+++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
@@ -2,14 +2,24 @@ package com.macaroon.piztor;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Stack;
import android.annotation.SuppressLint;
+import android.content.Context;
import android.content.Intent;
import android.os.Handler;
+import android.util.Log;
+
+import com.baidu.mapapi.BMapManager;
+import com.baidu.mapapi.MKGeneralListener;
@SuppressLint("UseSparseArrays")
public class AppMgr {
+
+ private static final String strKey = "5ba8abf7b4694ad49706b8b7538c9d6a";
+ static BMapManager mBMapManager = null;
+ static Context context;
+
+
// Status
public enum ActivityStatus {
create, start, resume, restart, stop, pause, destroy
@@ -102,13 +112,29 @@ public class AppMgr {
mp.put(a, new HashMap<Integer, Class<?>>());
}
- static void init() {
+ static void init(Context context) {
+ if (mBMapManager == null) {
+ mBMapManager = new BMapManager(context);
+ mBMapManager.init(strKey, new MKGeneralListener(){
+ @Override
+ public void onGetNetworkState(int iError) {
+ Log.d("Network","failure");
+ }
+
+ @Override
+ public void onGetPermissionState(int iError) {
+ Log.d("Permission","wrong key");
+ }
+ });
+ }
+ AppMgr.context = context;
mp = new HashMap<Class<?>, HashMap<Integer, Class<?>>>();
handler = new Handler();
transam = new Transam(Infomation.ip, Infomation.port, handler);
tTransam = new Thread(transam);
tTransam.start();
mapInfo = new MapInfo();
+ Infomation.myInfo = new UserInfo(-1);
addStatus(InitAct.class);
addStatus(Login.class);
addStatus(Main.class);
diff --git a/client/Piztor/src/com/macaroon/piztor/Infomation.java b/client/Piztor/src/com/macaroon/piztor/Infomation.java
index 3cad2ba..cd0b49e 100644
--- a/client/Piztor/src/com/macaroon/piztor/Infomation.java
+++ b/client/Piztor/src/com/macaroon/piztor/Infomation.java
@@ -1,11 +1,10 @@
package com.macaroon.piztor;
public class Infomation {
-// static String ip = "69.85.86.42";
- static String ip = "192.168.1.101";
+ static String ip = "69.85.86.42";
+// static String ip = "192.168.1.101";
static int port = 2222;
static String token = null;
static String username = null;
- static int uid = -1;
- static int gid = -1;
+ static UserInfo myInfo;
}
diff --git a/client/Piztor/src/com/macaroon/piztor/InitAct.java b/client/Piztor/src/com/macaroon/piztor/InitAct.java
index 8090f3b..8a7ad7a 100644
--- a/client/Piztor/src/com/macaroon/piztor/InitAct.java
+++ b/client/Piztor/src/com/macaroon/piztor/InitAct.java
@@ -9,7 +9,7 @@ public class InitAct extends PiztorAct {
protected void onCreate(Bundle savedInstanceState) {
id = "initAct";
super.onCreate(savedInstanceState);
- AppMgr.init();
+ AppMgr.init(getApplicationContext());
AppMgr.transam.setTimeOutTime(5000);
setContentView(R.layout.activity_init);
}
diff --git a/client/Piztor/src/com/macaroon/piztor/Login.java b/client/Piztor/src/com/macaroon/piztor/Login.java
index ab523f8..b55cd2e 100644
--- a/client/Piztor/src/com/macaroon/piztor/Login.java
+++ b/client/Piztor/src/com/macaroon/piztor/Login.java
@@ -35,7 +35,7 @@ public class Login extends PiztorAct {
return;
}
Infomation.token = res.t;
- Infomation.uid = res.uid;
+ Infomation.myInfo.uid = res.uid;
Infomation.username = edtUser.getText().toString();
System.out.println(res.s + " :!!! " + res.t);
actMgr.trigger(AppMgr.loginSuccess);
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java
index 28a32ff..2820090 100644
--- a/client/Piztor/src/com/macaroon/piztor/Main.java
+++ b/client/Piztor/src/com/macaroon/piztor/Main.java
@@ -2,19 +2,25 @@ package com.macaroon.piztor;
import java.util.Timer;
import java.util.TimerTask;
-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.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
-import android.widget.ImageView;
import android.widget.Toast;
+import com.baidu.location.BDLocation;
+import com.baidu.location.BDLocationListener;
+import com.baidu.location.LocationClient;
+import com.baidu.location.LocationClientOption;
+import com.baidu.mapapi.map.LocationData;
+import com.baidu.mapapi.map.MapView;
+
public class Main extends PiztorAct {
final static int SearchButtonPress = 1;
final static int FocuseButtonPress = 3;
@@ -22,6 +28,17 @@ public class Main extends PiztorAct {
final static int FailedFetch = 5;
final static int Fetch = 6;
final static int mapViewtouched = 7;
+
+ MapMaker mapMaker = null;
+ MapView mMapView;
+
+ /**
+ * Locating component
+ */
+ LocationClient mLocClient;
+ LocationData locData = null;
+ public MyLocationListener myListener = new MyLocationListener();
+
ImageButton btnSearch, btnFetch, btnFocus, btnSettings;
Timer autodate;
MapInfo mapInfo;
@@ -71,9 +88,13 @@ public class Main extends PiztorAct {
if (r.s == 0) {
System.out.println("id : " + r.uid + " sex : " + r.sex
+ " group : " + r.gid);
- if (r.uid == Infomation.uid) {
- Infomation.gid = r.gid;
- autodate.schedule(new AutoUpdate(), 0, 5000);
+ if (r.uid == Infomation.myInfo.uid) {
+ Infomation.myInfo.gid = r.gid;
+ try {
+ autodate.schedule(new AutoUpdate(), 0, 5000);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
} else {
UserInfo user = mapInfo.getUserInfo(r.uid);
if (user != null)
@@ -120,6 +141,31 @@ public class Main extends PiztorAct {
}
+ public class MyLocationListener implements BDLocationListener {
+ @Override
+ public void onReceiveLocation(BDLocation location) {
+ Log.d("GPS", "Gotten");
+ if (location == null) {
+ return;
+ }
+
+ locData.latitude = location.getLatitude();
+ locData.longitude = location.getLongitude();
+ locData.accuracy = location.getRadius();
+ locData.direction = location.getDerect();
+
+ mapMaker.UpdateLocationOverlay(locData, false);
+
+ }
+
+ @Override
+ public void onReceivePoi(BDLocation poiLocation) {
+ if (poiLocation == null) {
+ return;
+ }
+ }
+ }
+
class StartStatus extends ActStatus {
@Override
@@ -127,15 +173,15 @@ public class Main extends PiztorAct {
System.out.println("enter start status!!!!");
if (e == ActMgr.Create) {
System.out.println(Infomation.token + " "
- + Infomation.username + " " + Infomation.uid);
+ + Infomation.username + " " + Infomation.myInfo.uid);
AppMgr.transam.send(new ReqUserinfo(Infomation.token,
- Infomation.username, Infomation.uid, System
+ Infomation.username, Infomation.myInfo.uid, System
.currentTimeMillis(), 5000));
// TODO flush mapinfo.myinfo
}
if (e == Fetch) {
- requesLocation(Infomation.gid);
+ requesLocation(Infomation.myInfo.gid);
}
if (e == SuccessFetch)
flushMap();
@@ -154,7 +200,7 @@ public class Main extends PiztorAct {
void enter(int e) {
System.out.println("enter Fetch status!!!!");
if (e == Fetch) {
- requesLocation(Infomation.gid);
+ requesLocation(Infomation.myInfo.gid);
}
if (e == SuccessFetch) {
flushMap();
@@ -175,13 +221,13 @@ public class Main extends PiztorAct {
// TODO
switch (e) {
case Fetch:
- requesLocation(Infomation.gid);
+ requesLocation(Infomation.myInfo.gid);
break;
case FocuseButtonPress:
// TODO setFocus
break;
case SuccessFetch:
- requesLocation(Infomation.gid);
+ requesLocation(Infomation.myInfo.gid);
break;
default:
break;
@@ -238,6 +284,19 @@ public class Main extends PiztorAct {
// ImageView view = (ImageView) findViewById(R.id.main_mapview);
// view.setOnTouchListener(new MultiTouchListener());
setContentView(R.layout.activity_main);
+ mMapView = (MapView) findViewById(R.id.bmapView);
+ mapMaker = new MapMaker(mMapView, getApplicationContext());
+ mapMaker.InitMap();
+ mLocClient = new LocationClient(this);
+ locData = new LocationData();
+ mLocClient.registerLocationListener(myListener);
+ LocationClientOption option = new LocationClientOption();
+ option.setOpenGps(true);
+ option.setCoorType("bd09ll");
+ option.setScanSpan(5000);
+ mLocClient.setLocOption(option);
+ mLocClient.start();
+ mapMaker.UpdateLocationOverlay(locData, false);
}
@Override
@@ -265,16 +324,37 @@ public class Main extends PiztorAct {
actMgr.trigger(AppMgr.toSettings);
}
});
-
+
+ }
+
+ @Override
+ protected void onResume() {
+ mapMaker.onResume();
+ super.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ mapMaker.onPause();
+ super.onPause();
}
@Override
public void onStop() {
- super.onStart();
+ super.onStop();
autodate.cancel();
}
@Override
+ protected void onDestroy() {
+ if (mLocClient != null) {
+ mLocClient.stop();
+ }
+ mapMaker.onDestroy();
+ super.onDestroy();
+ }
+
+ @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
AppMgr.exit();
@@ -290,4 +370,17 @@ public class Main extends PiztorAct {
return false;
}
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mMapView.onSaveInstanceState(outState);
+
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ mMapView.onRestoreInstanceState(savedInstanceState);
+ }
+
}
diff --git a/client/Piztor/src/com/macaroon/piztor/MapInfo.java b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
index 37e3002..f5840c7 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapInfo.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
@@ -3,10 +3,12 @@ package com.macaroon.piztor;
import java.util.HashMap;
import java.util.Vector;
+import com.baidu.platform.comapi.basestruct.GeoPoint;
+
import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
+import android.location.Location;
-import com.baidu.platform.comapi.basestruct.GeoPoint;
public class MapInfo {
HashMap<Integer, UserInfo> mp;
@@ -41,27 +43,45 @@ public class MapInfo {
return null;
}
+ public Vector<UserInfo> getVector() {
+ return allUsers;
+ }
+
+ public UserInfo getMyInfo() {
+ return myInfo;
+ }
}
class UserInfo {
int uid, gid, sex;
- GeoPoint p;
+ GeoPoint location;
UserInfo(int uid) {
this.uid = uid;
}
void setLocation(double lat, double lot) {
- p = new GeoPoint((int) (lat * 10e6), (int) (lot * 10e6));
+ location = new GeoPoint((int)(lat * 1e6), (int)(lot * 1e6));
}
void setInfo(int gid, int sex) {
this.gid = gid;
this.sex = sex;
}
+
+ public GeoPoint getLocation(){
+ return location;
+ }
+
+ public double getLatitude() {
+ return location.getLatitudeE6() / 1e6;
+ }
+ public double getLongitude() {
+ return location.getLongitudeE6() / 1e6;
+ }
}
interface Style {
Drawable getDrawable(UserInfo user);
-} \ No newline at end of file
+}
diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
new file mode 100644
index 0000000..bdc3554
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
@@ -0,0 +1,165 @@
+package com.macaroon.piztor;
+
+import java.util.ArrayList;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.Vector;
+import android.util.Log;
+import android.util.AttributeSet;
+import android.annotation.SuppressLint;
+import android.location.Location;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.app.Activity;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.drawable.Drawable;
+import android.widget.FrameLayout;
+import android.widget.Toast;
+import android.view.View.OnClickListener;
+import android.widget.RadioGroup;
+import android.widget.RadioGroup.OnCheckedChangeListener;
+
+import com.baidu.location.BDLocation;
+import com.baidu.location.BDLocationListener;
+import com.baidu.location.LocationClient;
+import com.baidu.location.LocationClientOption;
+
+import com.baidu.mapapi.map.LocationData;
+import com.baidu.mapapi.BMapManager;
+import com.baidu.mapapi.MKGeneralListener;
+import com.baidu.mapapi.map.ItemizedOverlay;
+import com.baidu.mapapi.map.MKMapViewListener;
+import com.baidu.mapapi.map.MapController;
+import com.baidu.mapapi.map.MapPoi;
+import com.baidu.mapapi.map.MapView;
+import com.baidu.mapapi.map.MyLocationOverlay;
+import com.baidu.mapapi.map.OverlayItem;
+import com.baidu.mapapi.map.PopupOverlay;
+import com.baidu.platform.comapi.basestruct.GeoPoint;
+
+public class MapMaker extends Activity{
+
+ private MapView mMapView = null;
+ private MapController mMapController = null;
+ private static GeoPoint sjtuCenter = new GeoPoint((int)(31.032247 * 1E6), (int)(121.445937 * 1E6));
+ private MyOverlay mOverlay = null;
+ private MapView.LayoutParams layoutParam = null;
+ private OverlayItem curItem = null;
+ private ArrayList<OverlayItem> mItems = null;
+ private LocationOverlay mLocationOverlay;
+ private Context context;
+
+ public MapMaker(MapView mapView, Context c) {
+ mMapView = mapView;
+ mMapController = mMapView.getController();
+ mMapController.setCenter(sjtuCenter);
+ mMapController.setZoom(17);
+ mMapController.setRotation(-22);
+ mMapController.enableClick(true);
+ context = c;
+ mLocationOverlay = null;
+ mOverlay = null;
+ }
+
+ public class LocationOverlay extends MyLocationOverlay {
+ public LocationOverlay(MapView mapView) {
+ super(mapView);
+ }
+ }
+
+ public class MyOverlay extends ItemizedOverlay {
+ public MyOverlay(Drawable defaultMarker, MapView mapView) {
+ super(defaultMarker, mapView);
+ }
+ }
+
+ public void UpdateLocationOverlay(LocationData locationData, boolean hasAnimation) {
+ /**
+ * Update only location overlay
+ */
+ mLocationOverlay.setData(locationData);
+ mMapView.refresh();
+ if (hasAnimation) {
+ mMapController.animateTo(new GeoPoint((int)(locationData.latitude * 1E6), (int)(locationData.longitude * 1E6)));
+ }
+ }
+
+ public void InitMap() {
+ Log.d("GPS", "init");
+ mLocationOverlay = new LocationOverlay(mMapView);
+ //mLocationOverlay.setMarker(context.getResources().getDrawable(R.drawable.marker1));
+ LocationData locationData = new LocationData();
+ mLocationOverlay.setData(locationData);
+ mMapView.getOverlays().add(mLocationOverlay);
+ mLocationOverlay.enableCompass();
+ mMapView.refresh();
+ }
+
+ public void UpdateMap(MapInfo mapInfo) {
+ /**
+ * Update Location Overlay
+ */
+ GeoPoint location = mapInfo.getMyInfo().getLocation();
+ LocationData locationData = new LocationData();
+ locationData.latitude = location.getLatitudeE6() / 1e6;
+ locationData.longitude = location.getLongitudeE6() / 1e6;
+ mLocationOverlay.setData(locationData);
+ mMapView.refresh();
+
+ /**
+ * Update location of others
+ */
+ mOverlay.removeAll();
+ //mMapView.refresh();
+ GeoPoint p;
+ Vector<UserInfo> allUsers = mapInfo.getVector();
+
+ for(int i = 0; i < allUsers.size(); i++) {
+ p = new GeoPoint((int)(allUsers.get(i).getLatitude() * 1E6)
+ ,(int)(allUsers.get(i).getLongitude() * 1E6));
+ curItem = new OverlayItem(p, "^_^", "");
+ curItem.setMarker(context.getResources().getDrawable(R.drawable.marka));
+ mOverlay.addItem(curItem);
+ }
+ mItems = new ArrayList<OverlayItem>();
+ mItems.addAll(mOverlay.getAllItem());
+ mMapView.getOverlays().add(mOverlay);
+ mMapView.refresh();
+ }
+
+
+ public void clearOverlay(View view) {
+ mOverlay.removeAll();
+ mMapView.refresh();
+ }
+
+ public void resetOverlay(View view) {
+ clearOverlay(null);
+ mOverlay.addItem(mItems);
+ mMapView.refresh();
+ }
+
+ @Override
+ protected void onPause() {
+ mMapView.onPause();
+ }
+
+ @Override
+ protected void onResume() {
+ mMapView.onResume();
+ }
+
+ @Override
+ protected void onDestroy() {
+ mMapView.destroy();
+ }
+}
+
diff --git a/client/Piztor/src/com/macaroon/piztor/Settings.java b/client/Piztor/src/com/macaroon/piztor/Settings.java
index 457d916..8ad44b5 100644
--- a/client/Piztor/src/com/macaroon/piztor/Settings.java
+++ b/client/Piztor/src/com/macaroon/piztor/Settings.java
@@ -63,8 +63,8 @@ public class Settings extends PiztorAct {
System.out.println("logout status" + logout.s);
if (logout.s == 0) {
Infomation.token = null;
- Infomation.gid = -1;
- Infomation.uid = -1;
+ Infomation.myInfo.gid = -1;
+ Infomation.myInfo.uid = -1;
Infomation.username = null;
actMgr.trigger(AppMgr.logout);
break;