diff options
author | sjtufs <sjtu_fs@outlook.com> | 2013-09-02 14:20:13 +0800 |
---|---|---|
committer | sjtufs <sjtu_fs@outlook.com> | 2013-09-02 14:20:13 +0800 |
commit | 4886fe2f439e7df2ab5451893a8915705d39b6fd (patch) | |
tree | 2f7fb57c3013b2e34dab49e06ed330993729412e | |
parent | f5b2d8c89daafaf2b54c21d00bea3aaddac7b5cb (diff) |
game version
18 files changed, 566 insertions, 445 deletions
diff --git a/client/Piztor/res/layout/activity_login.xml b/client/Piztor/res/layout/activity_login.xml index cb27495..16b11a0 100644 --- a/client/Piztor/res/layout/activity_login.xml +++ b/client/Piztor/res/layout/activity_login.xml @@ -18,9 +18,9 @@ android:layout_marginTop="16dip"> <ImageView - android:id="@+id/main_headbar_img" + android:id="@+id/login_img" android:layout_width="180dp" - android:layout_height="200dp" + android:layout_height="180dp" android:layout_gravity="center_horizontal" android:src="@drawable/title_logo" /> <TextView @@ -31,6 +31,15 @@ android:text="@string/app_name" android:textSize="30dip" android:textColor="#FFFFFF"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="Game version" + android:textSize="15dip" + android:textStyle="italic" /> + </LinearLayout> <LinearLayout diff --git a/client/Piztor/res/layout/checkindialog.xml b/client/Piztor/res/layout/checkindialog.xml index b84404b..1c1cff7 100644 --- a/client/Piztor/res/layout/checkindialog.xml +++ b/client/Piztor/res/layout/checkindialog.xml @@ -13,7 +13,7 @@ <ProgressBar android:id="@+id/checkin_progress" - android:layout_width="wrap_content" + android:layout_width="200dip" android:layout_height="wrap_content" android:max="10000" android:layout_gravity="center" diff --git a/client/Piztor/res/values/strings.xml b/client/Piztor/res/values/strings.xml index 25e980a..d0aa35b 100644 --- a/client/Piztor/res/values/strings.xml +++ b/client/Piztor/res/values/strings.xml @@ -4,7 +4,7 @@ <string name="app_name">Piztor</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> - <string name="settings">设置</string> + <string name="settings">开始</string> <string name="search">搜索</string> <string name="fetch">上传</string> <string name="checkin">签到</string> diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java index eec01f5..a8d1138 100644 --- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java @@ -51,8 +51,9 @@ public class AlertMaker { private GeoPoint markerPoint; private MapMaker mapMaker; private long timestamp; - int mHour; - int mMinute; + int mHour; + int mMinute; + int mid; public AlertMaker(Context cc, MapMaker mm) { context =cc; @@ -72,7 +73,7 @@ public class AlertMaker { closeBoard(context); AlertDialog.Builder gpsDialog = new AlertDialog.Builder(context); gpsDialog.setTitle("GPS设置"); - gpsDialog.setMessage("GPS未开启,是否前去打开?"); + gpsDialog.setMessage("请开启GPS定位"); gpsDialog.setPositiveButton("设置", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { @@ -80,12 +81,6 @@ public class AlertMaker { context.startActivity(intent); } }); - gpsDialog.setNegativeButton("不使用GPS", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); gpsDialog.show(); } @@ -104,32 +99,6 @@ public class AlertMaker { lateDialog.show(); closeBoard(context); } - -public void showRemoveMarkerAlert() { - - closeBoard(context); - AlertDialog.Builder removeDialog = new AlertDialog.Builder(context); - removeDialog.setTitle("取消路标"); - removeDialog.setMessage("是否取消路标?"); - removeDialog.setPositiveButton("确定", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - mapMaker.mOverlay.removeItem(mapMaker.nowMarker); - mapMaker.nowMarker = null; - mapMaker.mMapView.refresh(); - mapMaker.popLay.hidePop(); - } - }); - removeDialog.setNegativeButton("取消", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - mapMaker.popLay.hidePop(); - dialog.cancel(); - } - }); - removeDialog.show(); - closeBoard(context); - } public long toTimestamp(int hour, int minute) { @@ -140,65 +109,29 @@ public void showRemoveMarkerAlert() { hour,minute); return calendar.getTimeInMillis()/1000; } - - //TODO - public void updateMarkerTime(int hour, int minute) { - Log.d("time", hour + " " + minute); - Log.d("time", " " + toTimestamp(hour, minute)); - mapMaker.newMarkerHour = hour; - mapMaker.newMarkerMinute = minute; - mapMaker.newMarkerTimestamp = toTimestamp(hour, minute); - } - - public void showMarkerAlert(GeoPoint point) { - + + public void showScores() { + closeBoard(context); + AlertDialog.Builder scoreDialog = new AlertDialog.Builder(context); + scoreDialog.setTitle("得分"); + scoreDialog.setMessage("我方vs对方 - " + mapMaker.app.mapInfo.myScore + " vs " + mapMaker.app.mapInfo.otherScore); + scoreDialog.setNeutralButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface arg0, int arg1) { + arg0.cancel(); + } + }); + scoreDialog.show(); closeBoard(context); - boolean flag = false; - if (point == null) return; - markerPoint = point; - - calendar = Calendar.getInstance(); - TimePickerDialog markerDialog = new TimePickerDialog(context - , new TimePickerDialog.OnTimeSetListener() { - boolean flag = false; - @Override - public void onTimeSet(TimePicker view, int hourOfDay, int minute) { - ////// at least 2 minutes - if ( !flag && - ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute >= calendar.get(Calendar.MINUTE)) - || hourOfDay > calendar.get(Calendar.HOUR_OF_DAY))) { - updateMarkerTime(hourOfDay, minute); - mapMaker.DrawMarker(markerPoint); - flag = true; - Log.d("marker", "marker alert calls drawmarker"); - } else if (!flag) { - Toast toast = Toast.makeText(context, - "太早了!多给一点时间", Toast.LENGTH_LONG); - toast.show(); - closeBoard(context); - showMarkerAlert(markerPoint); - } - } - } - , calendar.get(Calendar.HOUR_OF_DAY) - , calendar.get(Calendar.MINUTE), true); - markerDialog.show(); - closeBoard(context); } - + public void showCheckinAlter() { closeBoard(context); final AlertDialog.Builder checkinDialog = new AlertDialog.Builder(context); LayoutInflater infaler = LayoutInflater.from(context); final LinearLayout layout = (LinearLayout)infaler.inflate(R.layout.checkindialog, null); checkinDialog.setView(layout); - checkinDialog.setNeutralButton("取消", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); - im.hideSoftInputFromWindow(layout.getWindowToken(), 0); - dialog.cancel(); - } - }); + final ProgressBar pbar = (ProgressBar)layout.findViewById(R.id.checkin_progress); final TextView checkinInfo = (TextView)layout.findViewById(R.id.checkin_info); checkinDialog.show(); @@ -211,15 +144,31 @@ public void showRemoveMarkerAlert() { } public void onFinish() { - //TODO - pbar.setVisibility(View.GONE); - mapMaker.removeMarker(); - Toast toast = Toast.makeText(context, "已签到!", 2000); - toast.setGravity(Gravity.TOP, 0, 80); - toast.show(); - checkinInfo.setText("成功!"); + pbar.setVisibility(View.GONE);; + mapMaker.app.mapInfo.sendCheckin(mid); + checkinInfo.setText("签到已提交"); } }.start(); + closeBoard(context); + } + + public void showStartAlter() { + closeBoard(context); + AlertDialog.Builder startDialog = new AlertDialog.Builder(context); + startDialog.setTitle("开始游戏"); + startDialog.setMessage("是否开始游戏?"); + startDialog.setPositiveButton("确定", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + mapMaker.app.gameStarted = true; + } + }); + startDialog.setNegativeButton("取消", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + startDialog.show(); } - } diff --git a/client/Piztor/src/com/macaroon/piztor/EException.java b/client/Piztor/src/com/macaroon/piztor/EException.java index 92f2ab7..aadae9a 100644 --- a/client/Piztor/src/com/macaroon/piztor/EException.java +++ b/client/Piztor/src/com/macaroon/piztor/EException.java @@ -14,6 +14,7 @@ public class EException extends Exception { static final int ELevelFailedException =108;
static final int EPasswordFailedException =109;
static final int ESubscribeFailedException =110;
+ static final int ECheckinFailedException =111;
private static final long serialVersionUID = 100L;
int Rtype;
@@ -97,4 +98,9 @@ public class EException extends Exception { }
}
-
\ No newline at end of file + class ECheckinFailedException extends EException{
+ private static final long serialVersionUID = 111L;
+ public ECheckinFailedException(int t,long timep) {
+ super(111,t,timep);
+ }
+ }
\ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/Login.java b/client/Piztor/src/com/macaroon/piztor/Login.java index 22c8c91..e86b543 100644 --- a/client/Piztor/src/com/macaroon/piztor/Login.java +++ b/client/Piztor/src/com/macaroon/piztor/Login.java @@ -1,5 +1,7 @@ package com.macaroon.piztor; +import com.baidu.platform.comapi.basestruct.GeoPoint; + import android.annotation.SuppressLint; import android.os.Bundle; import android.os.Handler; @@ -9,8 +11,11 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.View; import android.view.Window; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.Toast; public class Login extends PiztorAct { @@ -39,7 +44,22 @@ public class Login extends PiztorAct { res.uinfo.nickname); app.mapInfo.myInfo.level = res.uinfo.level; app.mapInfo.myInfo.nickname = res.uinfo.nickname; - System.out.println("login !!!!" + res.sublist.size()); + for (RMarker i : res.markerlist) { + MarkerInfo mInfo = new MarkerInfo(); + mInfo.level = i.level; + mInfo.markerId = i.markerID; + mInfo.markerPoint = new GeoPoint((int)(i.latitude * 1E6), (int)(i.longitude * 1E6)); + mInfo.score = i.score; + mInfo.markerTimestamp = i.deadline; + app.mapInfo.addMarkerInfo(mInfo); + } + if (app.mapInfo.myInfo.section == 1) { + app.mapInfo.myScore = res.AScore; + app.mapInfo.otherScore = res.BScore; + } else { + app.mapInfo.myScore = res.BScore; + app.mapInfo.otherScore = res.AScore; + } actMgr.trigger(AppMgr.loginSuccess); } else { System.out.println("login handler reveive other info : " @@ -87,11 +107,13 @@ public class Login extends PiztorAct { protected void onCreate(Bundle savedInstanceState) { id = "login"; super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.activity_login); - setProgressBarIndeterminateVisibility(true); - setProgressBarVisibility(true); + ImageView imageView = (ImageView) findViewById(R.id.login_img); + AlphaAnimation alphaUp = new AlphaAnimation(0.0f, 1.0f); + alphaUp.setDuration(2000); + alphaUp.setStartOffset(500); + alphaUp.setFillAfter(true); + imageView.startAnimation(alphaUp); } @Override diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java index 5951db1..bd6d709 100644 --- a/client/Piztor/src/com/macaroon/piztor/Main.java +++ b/client/Piztor/src/com/macaroon/piztor/Main.java @@ -17,6 +17,7 @@ import android.view.View; import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.ImageButton; +import android.widget.TextView; import android.widget.Toast; import com.baidu.location.BDLocation; @@ -45,6 +46,8 @@ public class Main extends PiztorAct { public static int show_by_team = 1; public static int show_by_sex = 2; + TextView settingsText; + /** * Locating component */ @@ -54,7 +57,7 @@ public class Main extends PiztorAct { LocationData locData = null; public MyLocationListener myListener = new MyLocationListener(); boolean isFirstLocation = true; - public static int GPSrefreshrate = 20; + public static int GPSrefreshrate = 5; private final double checkinRadius = 10.0; ImageButton btnCheckin, btnFetch, btnFocus, btnSettings; @@ -120,16 +123,44 @@ public class Main extends PiztorAct { case Res.PushMarker: ResPushMarker pushMarker = (ResPushMarker) m.obj; MarkerInfo markerInfo = new MarkerInfo(); - markerInfo.level = pushMarker.level; + markerInfo.level = pushMarker.marker.level; markerInfo.markerPoint = new GeoPoint( - (int) (pushMarker.latitude * 1e6), - (int) (pushMarker.longitude * 1e6)); - markerInfo.markerTimestamp = pushMarker.deadline; - Log.d("marker", "Marker received! " + pushMarker.deadline); + (int) (pushMarker.marker.latitude * 1e6), + (int) (pushMarker.marker.longitude * 1e6)); + markerInfo.markerTimestamp = pushMarker.marker.deadline; + markerInfo.score = pushMarker.marker.score; + markerInfo.markerId = pushMarker.marker.markerID; + + System.out.println("markerInfo " + markerInfo.markerId + " " + markerInfo.markerPoint.getLatitudeE6() + " " + markerInfo.markerPoint.getLongitudeE6()); out.mapMaker.receiveMarker(markerInfo); break; + case Res.PushRemoveMarker: + ResPushRemoveMarker res = (ResPushRemoveMarker) m.obj; + out.mapInfo.removeMarker(res.MarkerID); + Log.d("remove", "push remove marker"); + out.flushMap(); + break; + case Res.Checkin: + ResCheckin checkin = (ResCheckin) m.obj; + out.receiveMessage("签到成功!"); + break; + case Res.PushScore: + ResPushScore pushScore = (ResPushScore) m.obj; + if (out.mapInfo.myInfo.section == 1) { + out.mapInfo.myScore = pushScore.AScore; + out.mapInfo.otherScore = pushScore.BScore; + } else { + out.mapInfo.myScore = pushScore.BScore; + out.mapInfo.otherScore = pushScore.AScore; + } + break; case -1: - out.actMgr.trigger(AppMgr.logout); + EException e = (EException) m.obj; + if (e.Etype == EException.EPushFailedException) + out.receiveMessage("网络不稳定~"); + else if (e.Etype == EException.ECheckinFailedException) + out.receiveMessage("路点已过期!"); + else out.actMgr.trigger(AppMgr.logout); default: break; } @@ -165,7 +196,6 @@ public class Main extends PiztorAct { } } - // TODO flush map view void flushMap() { if (mapMaker != null) mapMaker.UpdateMap(mapInfo); @@ -174,8 +204,8 @@ public class Main extends PiztorAct { } void receiveMessage(String msg) { - Toast toast = Toast.makeText(getApplicationContext(), msg, - Toast.LENGTH_LONG); + Toast toast = Toast.makeText(getApplicationContext(), msg, 5000); + toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } @@ -222,22 +252,19 @@ public class Main extends PiztorAct { int TMP = location.getLocType(); if (TMP == 61) { Toast toast = Toast.makeText(Main.this, - "Piztor : 由GPS更新 (刷新时间" + GPSrefreshrate - + "s)", 2000); + "Piztor : 由GPS更新 (刷新时间" + GPSrefreshrate + "s)", 2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } if (TMP == 161) { Toast toast = Toast.makeText(Main.this, - "Piztor : 由网络更新 (刷新时间" + GPSrefreshrate - + "s)", 2000); + "Piztor : 由网络更新 (刷新时间" + GPSrefreshrate + "s)", 2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } if (TMP == 65) { Toast toast = Toast.makeText(Main.this, - "Piztor : 由缓存更新 (刷新时间" + GPSrefreshrate + "s)", - 2000); + "Piztor : 由缓存更新 (刷新时间" + GPSrefreshrate + "s)",2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } @@ -246,6 +273,7 @@ public class Main extends PiztorAct { LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setCoorType("bd09ll"); + option.setPriority(LocationClientOption.GpsFirst); option.setScanSpan(GPSrefreshrate * 1000); mLocClient.setLocOption(option); } @@ -293,54 +321,30 @@ public class Main extends PiztorAct { mapMaker.mMapController.animateTo(app.mapInfo.myInfo.location); } - public void InitTouchListenr() { - - mapTouchListener = new MKMapTouchListener() { - - @Override - public void onMapLongClick(GeoPoint arg0) { - closeBoard(Main.this); - if (app.mapInfo.myInfo.level != 0) { - alertMaker.showMarkerAlert(arg0); - closeBoard(Main.this); - } - } - - @Override - public void onMapDoubleClick(GeoPoint arg0) { - // TODO Auto-generated method stub - - } - - @Override - public void onMapClick(GeoPoint arg0) { - // TODO Auto-generated method stub - - } - }; - mMapView.regMapTouchListner(mapTouchListener); - } - public void markerCheckin() { - Log.d("checkin", "ok!!!"); - if (mapMaker.getMakerLocation() == null) { - Toast toast = Toast.makeText(Main.this, "暂无路标", 2000); - toast.setGravity(Gravity.TOP, 0, 80); - toast.show(); - return; - } + double minDis = 1000.0; + int mid = -1; mLocClient.requestLocation(); GeoPoint curPoint = new GeoPoint((int) (locData.latitude * 1E6), (int) (locData.longitude * 1E6)); - double disFromMarker = DistanceUtil.getDistance(curPoint, - mapMaker.getMakerLocation()); - if (disFromMarker < Math.max(Math.min(locData.accuracy, 20.0), (float)checkinRadius) ) { - alertMaker.showCheckinAlter(); - } else { + for (MarkerInfo i : app.mapInfo.markerInfo) { + double disFromMarker = DistanceUtil.getDistance(curPoint, i.markerPoint); + if (disFromMarker < minDis) { + minDis = disFromMarker; + mid = i.markerId; + } + } + //TODO + + if (minDis > 15.0 || mid == -1) { Toast toast = Toast.makeText(Main.this, - String.format("请靠近路标,现在距离%.2f米", disFromMarker), 2000); + String.format("请靠近路标,现在距离%.2f米",minDis), 4000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); + } else { + mapMaker.mMapController.animateTo(app.mapInfo.getMarkerInfo(mid).markerPoint); + alertMaker.mid = mid; + alertMaker.showCheckinAlter(); } } @@ -351,9 +355,6 @@ public class Main extends PiztorAct { handler = new ReCall(this); locationManager = (LocationManager) this .getSystemService(LOCATION_SERVICE); - isGPSEnabled = locationManager - .isProviderEnabled(locationManager.GPS_PROVIDER); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.activity_main); @@ -362,14 +363,19 @@ public class Main extends PiztorAct { app.mBMapManager.start(); + settingsText = (TextView) findViewById(R.id.footbar_btn_settings_text); + + if (app.mapInfo.myInfo.level < 2) + settingsText.setText("得分"); + mMapView = (MapView) findViewById(R.id.bmapView); mapMaker = new MapMaker(mMapView, Main.this, app); mapMaker.InitMap(); alertMaker = new AlertMaker(Main.this, mapMaker); + isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER); if (isGPSEnabled == false) alertMaker.showSettingsAlert(); mapMaker.clearOverlay(mMapView); - InitTouchListenr(); mLocClient = new LocationClient(this); mLocClient.setAK(myApp.getStrkey()); locData = new LocationData(); @@ -416,7 +422,16 @@ public class Main extends PiztorAct { btnSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { - actMgr.trigger(AppMgr.toSettings); + if (app.mapInfo.myInfo.level >= 2 && !app.gameStarted) { + app.gameStarted = true; + settingsText.setText("得分"); + //TODO + ReqGameStart req = new ReqGameStart(app.token, app.username, System.currentTimeMillis(), 10 * 1000); + transam.send(req); + } + else { + alertMaker.showScores(); + } } }); @@ -428,6 +443,7 @@ public class Main extends PiztorAct { mLocClient.requestLocation(); updateMyLocation(); focusOn(); + Log.d("jingdu", "发送的坐标" + locData.latitude + " " + locData.longitude); } }); } @@ -449,11 +465,15 @@ public class Main extends PiztorAct { transam.setHandler(handler); isFirstLocation = true; mLocClient.start(); + + isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER); + if (isGPSEnabled == false) + alertMaker.showSettingsAlert(); + if (app.token == null) { System.out.println("fuck!!"); } else requestUserInfo(); - // mapMaker.onResume(); flushMap(); super.onResume(); } diff --git a/client/Piztor/src/com/macaroon/piztor/MapInfo.java b/client/Piztor/src/com/macaroon/piztor/MapInfo.java index 10cb52b..9cd1dd3 100644 --- a/client/Piztor/src/com/macaroon/piztor/MapInfo.java +++ b/client/Piztor/src/com/macaroon/piztor/MapInfo.java @@ -1,5 +1,6 @@ package com.macaroon.piztor; +import java.io.Flushable; import java.util.HashMap; import java.util.Vector; @@ -12,24 +13,21 @@ import android.location.Location; public class MapInfo { HashMap<Integer, UserInfo> mp; + HashMap<Integer, MarkerInfo> pm; Vector<UserInfo> allUsers; - MarkerInfo markerInfo; + Vector<MarkerInfo> markerInfo; UserInfo myInfo; - - - MapInfo copy() { - MapInfo res = new MapInfo(); - res.mp = (HashMap<Integer, UserInfo>)mp.clone(); - res.allUsers = (Vector<UserInfo>) allUsers.clone(); - res.myInfo = myInfo.copy(); - return res; - } - + myApp app; + int myScore, otherScore; @SuppressLint("UseSparseArrays") - MapInfo() { + MapInfo(myApp ap) { mp = new HashMap<Integer, UserInfo>(); allUsers = new Vector<UserInfo>(); + markerInfo = new Vector<MarkerInfo>(); + pm = new HashMap<Integer, MarkerInfo>(); + app = ap; + myScore = otherScore = 0; } void clear() { @@ -41,6 +39,11 @@ public class MapInfo { allUsers.add(userInfo); mp.put(userInfo.uid, userInfo); } + + void addMarkerInfo(MarkerInfo mInfo) { + markerInfo.add(mInfo); + pm.put(mInfo.markerId, mInfo); + } UserInfo getUserInfo(int uid) { if (mp.containsKey(uid)) @@ -49,6 +52,27 @@ public class MapInfo { return null; } + MarkerInfo getMarkerInfo(int mid) { + if (pm.containsKey(mid)) + return pm.get(mid); + else + return null; + } + + void sendCheckin(int mid) { + if (pm.containsKey(mid)) { + ReqCheckin req = new ReqCheckin(app.token, app.username, mid, System.currentTimeMillis(), 10 * 1000); + app.transam.send(req); + } + } + + void removeMarker(int mid) { + if (pm.containsKey(mid)) { + markerInfo.remove(pm.get(mid)); + pm.remove(mid); + } + } + public Vector<UserInfo> getVector() { return allUsers; } @@ -61,6 +85,8 @@ public class MapInfo { class MarkerInfo { GeoPoint markerPoint; long markerTimestamp; + int score; + int markerId; int level; MarkerInfo copy() { diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java index 837df2b..18eb524 100644 --- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java @@ -9,8 +9,10 @@ import java.util.Vector; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.location.LocationManager; +import android.os.DropBoxManager.Entry; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; @@ -21,8 +23,6 @@ import android.widget.Toast; import com.baidu.mapapi.map.ItemizedOverlay; import com.baidu.mapapi.map.LocationData; import com.baidu.mapapi.map.MKOLUpdateElement; -import com.baidu.mapapi.map.MKOfflineMap; -import com.baidu.mapapi.map.MKOfflineMapListener; import com.baidu.mapapi.map.MapController; import com.baidu.mapapi.map.MapView; import com.baidu.mapapi.map.MyLocationOverlay; @@ -36,7 +36,6 @@ public class MapMaker { // MapView controlling component MapView mMapView = null; MapController mMapController = null; - MKOfflineMap mOffline = null; // Default center private final static GeoPoint sjtuCenter = new GeoPoint( @@ -47,24 +46,22 @@ public class MapMaker { private OverlayItem curItem = null; private LocationOverlay mLocationOverlay; private ArrayList<OverlayItem> mItems = null; - private MapInfo preMapInfo = null; - private MapInfo nowMapInfo = null; - private Vector<UserInfo> freshManInfo = null; // hash from uid to overlay item - private HashMap<Integer, OverlayItem> hash = null; - private HashMap<OverlayItem, Integer> markerToInt = null; + private HashMap<Integer, OverlayItem> userToItem = null; + private HashMap<OverlayItem, Integer> itemToUser = null; // marker layer - OverlayItem nowMarker = null; - static int nowMarkerHour; - static int nowMarkerMinute; - static long nowMarkerTimestamp; - static int newMarkerHour; - static int newMarkerMinute; - static long newMarkerTimestamp; - private int markerIndex; - private int nowMarkerLevel; + /* + * OverlayItem nowMarker = null; static int nowMarkerHour; static int + * nowMarkerMinute; static long nowMarkerTimestamp; static int + * newMarkerHour; static int newMarkerMinute; static long + * newMarkerTimestamp; private int markerIndex; private int nowMarkerLevel; + */ + HashMap<Integer, OverlayItem> markerToItem; + // from mid to item + HashMap<OverlayItem, Integer> itemToMarker; + // from item to mid // Popup component PopupOverlay popLay = null; @@ -124,19 +121,24 @@ public class MapMaker { @Override public boolean onTap(int index) { - - if (nowMarker != null && index == markerIndex) { + + if (app.mapInfo.markerInfo != null + && itemToMarker.containsKey(mOverlay.getItem(index))) { + Log.d("marker", "on tap" + index); OverlayItem item = getItem(index); - leftText.setText(nowMarkerHour + "点"); - popupText.setText(nowMarkerMinute + "分"); - Bitmap bitmap[] = { BMapUtil.getBitmapFromView(popupLeft), - BMapUtil.getBitmapFromView(popupInfo), - BMapUtil.getBitmapFromView(popupRight), }; + MarkerInfo mInfo = app.mapInfo.getMarkerInfo(itemToMarker + .get(item)); + leftText.setText("哈"); + popupText.setText("分数:" + mInfo.score); + Bitmap bitmap = BMapUtil.getBitmapFromView(popupInfo); popLay.showPopup(bitmap, item.getPoint(), 32); - } else { + } + if (itemToUser.containsKey(mOverlay.getItem(index))){ OverlayItem item = getItem(index); - UserInfo tmpInfo = app.mapInfo.getUserInfo(markerToInt.get(item)); - String itemInfo = tmpInfo.company + "连" + tmpInfo.section + "班 " + tmpInfo.nickname; + UserInfo tmpInfo = app.mapInfo.getUserInfo(itemToUser + .get(item)); + String itemInfo = tmpInfo.company + "连" + tmpInfo.section + + "班 " + tmpInfo.nickname; popupText.setText(itemInfo); Bitmap bitmap = BMapUtil.getBitmapFromView(popupInfo); popLay.showPopup(bitmap, item.getPoint(), 32); @@ -155,42 +157,6 @@ public class MapMaker { } /** - * Initialize offline map - */ - public void InitOfflineMap() { - - mOffline = new MKOfflineMap(); - mOffline.init(mMapController, new MKOfflineMapListener() { - - @Override - public void onGetOfflineMapState(int type, int state) { - switch (type) { - case MKOfflineMap.TYPE_DOWNLOAD_UPDATE: - MKOLUpdateElement update = mOffline.getUpdateInfo(state); - break; - case MKOfflineMap.TYPE_NEW_OFFLINE: - Log.d("offline", String.format("add offline map %d", state)); - break; - case MKOfflineMap.TYPE_VER_UPDATE: - Log.d("offline", String.format("new offline map version")); - break; - } - } - }); - int num = mOffline.scan(); - - if (num == 0) { - // msg = - // "No offline map found. It may have been loaded already or m |