summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com/macaroon
diff options
context:
space:
mode:
Diffstat (limited to 'client/Piztor/src/com/macaroon')
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java305
1 files changed, 201 insertions, 104 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
index 895d409..8af00ea 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
@@ -48,173 +48,237 @@ import com.baidu.mapapi.map.MyLocationOverlay;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.mapapi.map.PopupClickListener;
import com.baidu.mapapi.map.PopupOverlay;
+import com.baidu.mapapi.search.MKPoiInfo;
+import com.baidu.mapapi.search.MKPoiResult;
import com.baidu.platform.comapi.basestruct.GeoPoint;
-public class MapMaker extends Activity{
-
+public class MapMaker extends Activity {
+
+ // MapView controlling component
private MapView mMapView = null;
private MapController mMapController = null;
- private static GeoPoint sjtuCenter = new GeoPoint((int)(31.032247 * 1E6), (int)(121.445937 * 1E6));
+
+ // Default center
+ private final static GeoPoint sjtuCenter = new GeoPoint((int)(31.032247 * 1E6), (int)(121.445937 * 1E6));
+
+ // Map layers and items
private MyOverlay mOverlay = null;
private OverlayItem curItem = null;
- private ArrayList<OverlayItem> mItems = null;
private LocationOverlay mLocationOverlay;
+ private ArrayList<OverlayItem> mItems = null;
+ private MapInfo preMapInfo = null;
+
+ // marker layer
+ private MyOverlay markerOverlay;
+ private OverlayItem nowMarker = null;
+
+ //
private Context context;
- private MKMapTouchListener mapTouchListener;
- boolean isFirstLoc = true;
- /**
- * popups
- */
+ private MKMapTouchListener mapTouchListener;
+
+ // Popup component
private PopupOverlay popLay = null;
private TextView popupText = null;
private View viewCache = null;
private View popupInfo = null;
- public MapMaker(MapView mapView, Context c) {
+ /**
+ * Constructor
+ */
+ public MapMaker(MapView mapView, Context cc) {
+
mMapView = mapView;
mMapController = mMapView.getController();
+
mMapController.setCenter(sjtuCenter);
- mMapController.setZoom(17);
+ mMapController.setZoom(16);
mMapController.setRotation(-22);
mMapController.enableClick(true);
- context = c;
+
+ context = cc;
mLocationOverlay = null;
mOverlay = null;
}
+ /**
+ * Layer for my location
+ */
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);
+ /**
+ * Layer for items(other users)
+ */
+ public class MyOverlay extends ItemizedOverlay {
+
+ public MyOverlay(Drawable defaultMaker, MapView mapView) {
+ super(defaultMaker, mapView);
}
-
+
@Override
- public boolean onTap(int index){
- Log.d("123", "Marker tap");
+ public boolean onTap(int index) {
+
OverlayItem item = getItem(index);
- popupText.setText("^ _ ^");
- Bitmap bitmap = BMapUtil.getBitmapFromView(popupInfo);
- popLay.showPopup(bitmap,item.getPoint(),32);
+ //TODO
+ /////////////////////////////////////////////////////////
+ popupText.setText("^_^");
+ Bitmap bitmap = BMapUtil.getBitmapFromView(popupInfo);
+ popLay.showPopup(bitmap, item.getPoint(),32);
+
return true;
}
-
- @Override
- public boolean onTap(GeoPoint pt, MapView mMapView){
- Log.d("123", "Marker tap disappear");
- if (popLay != null){
- popLay.hidePop();
+ @Override
+ public boolean onTap(GeoPoint pt, MapView mapView) {
+
+ if(popLay != null) {
+ popLay.hidePop();
}
- return false;
- }
- }
- public void UpdateLocationOverlay(LocationData locationData, boolean hasAnimation) {
- /**
- * Update only location overlay
- */
- mLocationOverlay.setData(locationData);
- mMapView.refresh();
- if (hasAnimation || isFirstLoc) {
- mMapController.animateTo(new GeoPoint((int)(locationData.latitude * 1E6), (int)(locationData.longitude * 1E6)));
+ return false;
}
- isFirstLoc = true;
}
-
- public void InitMap() {
- /**
- * Initialize LocationOverlay
- */
- Log.d("GPS", "init");
+
+ /**
+ * Initialize location layer
+ */
+ public void InitLocationOverlay() {
+
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();
- mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView);
- Log.d("123", "MapView initialized");
+ }
- /**
- * Initialize pop up
- */
- LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
- Log.d("123", "OK 0");
+ /**
+ * Initialize other users layer
+ */
+ public void InitMyOverLay() {
+
+ //TODO
+ /////////////////////////////////////////////////////////////////
+ mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView);
+ markerOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.marker1), mMapView);
+ }
+
+ /**
+ * Initialize popup
+ */
+ public void InitPopup() {
+
+ LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
viewCache = inflater.inflate(R.layout.custom_text_view, null);
- Log.d("123", "OK 1");
- popupInfo = (View) viewCache.findViewById(R.id.popinfo);
- Log.d("123", "OK 2");
- popupText = (TextView) viewCache.findViewById(R.id.textcache);
- Log.d("123", "OK 3");
- Log.d("123", "Popup initialized");
+ popupInfo = (View)viewCache.findViewById(R.id.popinfo);
+ popupText = (TextView)viewCache.findViewById(R.id.textcache);
-
PopupClickListener popListener = new PopupClickListener() {
+
@Override
public void onClickedPopup(int index) {
- //
+ // when the popup is clicked
+ if (index == 0) {
+ // do nothing
+ }
+ if (index == 1) {
+ // this is a marker and remove it
+ }
}
};
+
popLay = new PopupOverlay(mMapView, popListener);
+ }
+
+
+ /**
+ * Initialize touch listener
+ */
+ public void InitTouchListenr() {
- /**
- * Initialize touch listener
- */
- /**
- * TODO
- */
mapTouchListener = new MKMapTouchListener() {
+
@Override
- public void onMapClick(GeoPoint point) {
- System.out.println("++++++++++++++++++++++++++++++++ SingleClick "
- + point.getLatitudeE6() * 1E-6 + " " + point.getLongitudeE6() * 1E-6);
+ public void onMapLongClick(GeoPoint arg0) {
+ DrawMarker(arg0);
+ Log.d("marker", "draw a new marker");
}
-
+
@Override
- public void onMapDoubleClick(GeoPoint point) {
- System.out.println("++++++++++++++++++++++++++++++++ DoubleClick "
- + point.getLatitudeE6() * 1E-6 + " " + point.getLongitudeE6() * 1E-6);
+ public void onMapDoubleClick(GeoPoint arg0) {
+ // TODO Auto-generated method stub
+
}
-
+
@Override
- public void onMapLongClick(GeoPoint point) {
- System.out.println("++++++++++++++++++++++++++++++++ LongClick "
- + point.getLatitudeE6() * 1E-6 + " " + point.getLongitudeE6() * 1E-6);
+ public void onMapClick(GeoPoint arg0) {
+ // TODO Auto-generated method stub
+
}
};
mMapView.regMapTouchListner(mapTouchListener);
+ }
+
+ /**
+ * Initialize map
+ */
+ public void InitMap() {
+
+ InitLocationOverlay();
+ InitMyOverLay();
+ InitPopup();
+ InitTouchListenr();
+ }
+ /**
+ * Update location layer when new location is received
+ */
+ public void UpdateLocationOverlay(LocationData locationData, boolean hasAnimation) {
+
+ mLocationOverlay.setData(locationData);
+ mMapView.refresh();
+ if (hasAnimation) {
+ mMapController.animateTo(new GeoPoint((int)(locationData.latitude * 1E6)
+ , (int)(locationData.longitude * 1E6)));
+ }
}
+ /**
+ * Update to draw other users
+ */
public void UpdateMap(MapInfo mapInfo) {
- /**
- * Update location of others
- */
- if (mOverlay != null && mOverlay.getAllItem().size() != 0) {
- clearOverlay(mMapView);
+
+ 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<UserInfo> allUsers = mapInfo.getVector();
+ for (int i = 0; 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<OverlayItem>();
+ mItems.addAll(mOverlay.getAllItem());
}
- mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView);
- //mMapView.refresh();
- GeoPoint p;
- Vector<UserInfo> allUsers = mapInfo.getVector();
- System.out.println("SSSSSSSSSSSSSSSSize "+allUsers.size());
- for(int i = 0; i < allUsers.size(); i++) {
- 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, "^_^", "");
- curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red));
- mOverlay.addItem(curItem);
+ if (nowMarker != null) {
+ Log.d("marker", "now marker is not null");
+ mOverlay.addItem(nowMarker);
}
- mItems = new ArrayList<OverlayItem>();
- mItems.addAll(mOverlay.getAllItem());
if (mMapView != null) {
if (mMapView.getOverlays() != null) {
mMapView.getOverlays().add(mOverlay);
@@ -222,19 +286,52 @@ public class MapMaker extends Activity{
}
}
}
+
+ /**
+ * 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", "");
+ nowMarker.setMarker(context.getResources().getDrawable(R.drawable.marker1));
+ Log.d("marker", "new marker created");
+ System.out.println("mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm " + markerPoint.getLatitudeE6() + " " + markerPoint.getLongitudeE6());
+
+ UpdateMap(preMapInfo);
+ }
-
+ /**
+ * Remove all other users
+ */
public void clearOverlay(View view) {
- mOverlay.removeAll();
- mMapView.refresh();
+
+ if(mOverlay != null && mOverlay.getAllItem().size() != 0) {
+ mOverlay.removeAll();
+ mMapView.refresh();
+ }
}
+ /**
+ * Reset other users over lay
+ */
public void resetOverlay(View view) {
+
clearOverlay(null);
mOverlay.addItem(mItems);
- mMapView.refresh();
}
-
+
@Override
protected void onPause() {
mMapView.onPause();
@@ -243,11 +340,11 @@ public class MapMaker extends Activity{
@Override
protected void onResume() {
mMapView.onResume();
- }
+ }
@Override
protected void onDestroy() {
mMapView.destroy();
}
+
}
-