diff options
Diffstat (limited to 'client/Piztor/src')
5 files changed, 154 insertions, 134 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java index 8e82384..aed8ca6 100644 --- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java +++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java @@ -15,10 +15,8 @@ import com.baidu.mapapi.MKGeneralListener; @SuppressLint("UseSparseArrays") public class AppMgr { - private static final String strKey = "5ba8abf7b4694ad49706b8b7538c9d6a"; + private static final String strKey = "8a0ae50048d103b2b8b12b7066f4ea7d"; static BMapManager mBMapManager = null; - static Context context; - // Status public enum ActivityStatus { @@ -83,6 +81,8 @@ public class AppMgr { i.putExtra("status", true); else i.putExtra("status", false); } + if (event == loginSuccess) mBMapManager.start(); + if (event == logout) mBMapManager.stop(); nowAct.startActivity(i); } @@ -127,7 +127,6 @@ public class AppMgr { } }); } - AppMgr.context = context; mp = new HashMap<Class<?>, HashMap<Integer, Class<?>>>(); handler = new Handler(); transam = new Transam(Infomation.ip, Infomation.port, handler); diff --git a/client/Piztor/src/com/macaroon/piztor/BMapUtil.java b/client/Piztor/src/com/macaroon/piztor/BMapUtil.java new file mode 100644 index 0000000..38d9f7d --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/BMapUtil.java @@ -0,0 +1,17 @@ +package com.macaroon.piztor; + +import android.graphics.Bitmap; +import android.view.View; + +public class BMapUtil { + + public static Bitmap getBitmapFromView(View view) { + view.destroyDrawingCache(); + view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); + view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); + view.setDrawingCacheEnabled(true); + Bitmap bitmap = view.getDrawingCache(true); + return bitmap; + } +} diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java index 2820090..5aa767d 100644 --- a/client/Piztor/src/com/macaroon/piztor/Main.java +++ b/client/Piztor/src/com/macaroon/piztor/Main.java @@ -4,6 +4,8 @@ import java.util.Timer; import java.util.TimerTask; import android.annotation.SuppressLint; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -12,14 +14,22 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.View; import android.widget.ImageButton; +import android.widget.TextView; 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.ItemizedOverlay; import com.baidu.mapapi.map.LocationData; import com.baidu.mapapi.map.MapView; +import com.baidu.mapapi.map.OverlayItem; +import com.baidu.mapapi.map.PopupClickListener; +import com.baidu.mapapi.map.PopupOverlay; +import com.baidu.platform.comapi.basestruct.GeoPoint; + +import com.macaroon.piztor.BMapUtil; public class Main extends PiztorAct { final static int SearchButtonPress = 1; @@ -40,7 +50,7 @@ public class Main extends PiztorAct { public MyLocationListener myListener = new MyLocationListener(); ImageButton btnSearch, btnFetch, btnFocus, btnSettings; - Timer autodate; + //Timer autodate; MapInfo mapInfo; /* * @SuppressLint("HandlerLeak") Handler fromGPS = new Handler() { @@ -91,7 +101,7 @@ public class Main extends PiztorAct { if (r.uid == Infomation.myInfo.uid) { Infomation.myInfo.gid = r.gid; try { - autodate.schedule(new AutoUpdate(), 0, 5000); + //autodate.schedule(new AutoUpdate(), 0, 5000); } catch (Exception e) { e.printStackTrace(); } @@ -138,7 +148,8 @@ public class Main extends PiztorAct { // TODO flush map view void flushMap() { - + if (mapMaker != null) + mapMaker.UpdateMap(AppMgr.mapInfo); } public class MyLocationListener implements BDLocationListener { @@ -155,7 +166,8 @@ public class Main extends PiztorAct { locData.direction = location.getDerect(); mapMaker.UpdateLocationOverlay(locData, false); - + if (Infomation.token != null) + AppMgr.transam.send(new ReqUpdate(Infomation.token, Infomation.username, locData.latitude, locData.longitude, System.currentTimeMillis(), 2000)); } @Override @@ -224,10 +236,12 @@ public class Main extends PiztorAct { requesLocation(Infomation.myInfo.gid); break; case FocuseButtonPress: - // TODO setFocus + if( locData != null) { + mapMaker.UpdateLocationOverlay(locData, true); + } else mapMaker.InitMap(); break; case SuccessFetch: - requesLocation(Infomation.myInfo.gid); + flushMap(); break; default: break; @@ -279,16 +293,16 @@ public class Main extends PiztorAct { actMgr.add(focusStatus, mapViewtouched, startStatus); actMgr.add(focusStatus, SuccessFetch, focusStatus); actMgr.add(focusStatus, Fetch, focusStatus); - autodate = new Timer(); + //autodate = new Timer(); flushMap(); - // 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(); + locData.latitude = 31.032247; + locData.longitude = 121.445937; mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); @@ -342,7 +356,7 @@ public class Main extends PiztorAct { @Override public void onStop() { super.onStop(); - autodate.cancel(); + //autodate.cancel(); } @Override diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java index bdc3554..895d409 100644 --- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java @@ -12,14 +12,17 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.TextView; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; +import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.widget.FrameLayout; import android.widget.Toast; @@ -36,12 +39,14 @@ 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.MKMapTouchListener; 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.PopupClickListener; import com.baidu.mapapi.map.PopupOverlay; import com.baidu.platform.comapi.basestruct.GeoPoint; @@ -51,11 +56,20 @@ public class MapMaker extends Activity{ 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; + private MKMapTouchListener mapTouchListener; + boolean isFirstLoc = true; + + /** + * popups + */ + private PopupOverlay popLay = null; + private TextView popupText = null; + private View viewCache = null; + private View popupInfo = null; public MapMaker(MapView mapView, Context c) { mMapView = mapView; @@ -75,11 +89,31 @@ public class MapMaker extends Activity{ } } - public class MyOverlay extends ItemizedOverlay { + public class MyOverlay extends ItemizedOverlay{ public MyOverlay(Drawable defaultMarker, MapView mapView) { super(defaultMarker, mapView); } - } + + @Override + public boolean onTap(int index){ + Log.d("123", "Marker tap"); + OverlayItem item = getItem(index); + 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(); + } + return false; + } + } public void UpdateLocationOverlay(LocationData locationData, boolean hasAnimation) { /** @@ -87,12 +121,16 @@ public class MapMaker extends Activity{ */ mLocationOverlay.setData(locationData); mMapView.refresh(); - if (hasAnimation) { + if (hasAnimation || isFirstLoc) { mMapController.animateTo(new GeoPoint((int)(locationData.latitude * 1E6), (int)(locationData.longitude * 1E6))); } + isFirstLoc = true; } public void InitMap() { + /** + * Initialize LocationOverlay + */ Log.d("GPS", "init"); mLocationOverlay = new LocationOverlay(mMapView); //mLocationOverlay.setMarker(context.getResources().getDrawable(R.drawable.marker1)); @@ -101,38 +139,88 @@ public class MapMaker extends Activity{ mMapView.getOverlays().add(mLocationOverlay); mLocationOverlay.enableCompass(); mMapView.refresh(); - } - - public void UpdateMap(MapInfo mapInfo) { + mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView); + Log.d("123", "MapView initialized"); + /** - * Update Location Overlay + * Initialize pop up */ - GeoPoint location = mapInfo.getMyInfo().getLocation(); - LocationData locationData = new LocationData(); - locationData.latitude = location.getLatitudeE6() / 1e6; - locationData.longitude = location.getLongitudeE6() / 1e6; - mLocationOverlay.setData(locationData); - mMapView.refresh(); + LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); + Log.d("123", "OK 0"); + 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"); + + PopupClickListener popListener = new PopupClickListener() { + @Override + public void onClickedPopup(int index) { + // + } + }; + popLay = new PopupOverlay(mMapView, popListener); + + /** + * 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); + } + + @Override + public void onMapDoubleClick(GeoPoint point) { + System.out.println("++++++++++++++++++++++++++++++++ DoubleClick " + + point.getLatitudeE6() * 1E-6 + " " + point.getLongitudeE6() * 1E-6); + } + + @Override + public void onMapLongClick(GeoPoint point) { + System.out.println("++++++++++++++++++++++++++++++++ LongClick " + + point.getLatitudeE6() * 1E-6 + " " + point.getLongitudeE6() * 1E-6); + } + }; + mMapView.regMapTouchListner(mapTouchListener); + + } + + public void UpdateMap(MapInfo mapInfo) { /** * Update location of others */ - mOverlay.removeAll(); + if (mOverlay != null && mOverlay.getAllItem().size() != 0) { + clearOverlay(mMapView); + } + 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.marka)); + curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red)); mOverlay.addItem(curItem); } mItems = new ArrayList<OverlayItem>(); mItems.addAll(mOverlay.getAllItem()); - mMapView.getOverlays().add(mOverlay); - mMapView.refresh(); + if (mMapView != null) { + if (mMapView.getOverlays() != null) { + mMapView.getOverlays().add(mOverlay); + mMapView.refresh(); + } + } } @@ -146,17 +234,17 @@ public class MapMaker extends Activity{ 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/MultiTouchListener.java b/client/Piztor/src/com/macaroon/piztor/MultiTouchListener.java deleted file mode 100644 index cf4911b..0000000 --- a/client/Piztor/src/com/macaroon/piztor/MultiTouchListener.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.macaroon.piztor; - -import android.annotation.SuppressLint; -import android.graphics.Matrix; -import android.graphics.PointF; -import android.util.FloatMath; -import android.view.MotionEvent; -import android.view.View; -import android.view.View.OnTouchListener; -import android.widget.ImageView; - -@SuppressLint("FloatMath") -public class MultiTouchListener implements OnTouchListener { - - private Matrix matrix = new Matrix(); - private Matrix preMatrix = new Matrix(); - - private static final int NONE = 0; - private static final int DRAG = 1; - private static final int ZOOM = 2; - private int mode = NONE; - - private PointF start = new PointF(); - private PointF mid = new PointF(); - private float preDis = 1f; - /*private float d = 0f; - private float newRot = 0f; - private float[] values;*/ - - @Override - public boolean onTouch(View v, MotionEvent event) { - float[] values = new float[9]; - matrix.getValues(values); - //System.out.println("1111111"+values[1]); - //Log.d("Touch", "onTouch......."); - ImageView view = (ImageView) v; - switch (event.getAction() & MotionEvent.ACTION_MASK) { - case MotionEvent.ACTION_DOWN: - //Log.d("Touch", "ACTION_DOWN"); - preMatrix.set(matrix); - start.set(event.getX(), event.getY()); - mode = DRAG; - break; - case MotionEvent.ACTION_POINTER_DOWN: - //Log.d("Touch", "ACTION_POINTER_DOWN"); - preDis = spacing(event); - if(preDis > 10f) { - preMatrix.set(matrix); - midPoint(mid, event); - mode = ZOOM; - } - break; - case MotionEvent.ACTION_UP: - //Log.d("Touch", "ACTION_UP"); - case MotionEvent.ACTION_POINTER_UP: - //Log.d("Touch", "ACTION_POINTER_UP"); - mode = NONE; - break; - case MotionEvent.ACTION_MOVE: - //Log.d("Touch", "ACTION_MOVE"); - if(mode == DRAG) { - //Log.d("Touch", "Draging"); - matrix.set(preMatrix); - float dx = event.getX() - start.x; - float dy = event.getY() - start.y; - matrix.postTranslate(dx, dy); - } else if (mode == ZOOM) { - //Log.d("Touch","Zooming"); - float newDis = spacing(event); - if (newDis > 10f) { - matrix.set(preMatrix); - float scale = (newDis / preDis); - matrix.postScale(scale,scale,mid.x,mid.y); - //System.out.println("ssssssssssssssssss" + scale); - } - } - break; - } - matrix.getValues(values); - //System.out.println("222222"+values[1]); - view.setImageMatrix(matrix); - matrix.getValues(values); - //System.out.println("333333"+values[1]); - return true; - } - - private float spacing(MotionEvent event) { - float x = event.getX(0) - event.getX(1); - float y = event.getY(0) - event.getY(1); - return FloatMath.sqrt(x * x + y * y); - } - - private void midPoint(PointF point, MotionEvent event) { - float x = event.getX(0) + event.getY(1); - float y = event.getY(0) + event.getY(1); - point.set(x / 2, y / 2); - } -} |