From 4886fe2f439e7df2ab5451893a8915705d39b6fd Mon Sep 17 00:00:00 2001 From: sjtufs Date: Mon, 2 Sep 2013 14:20:13 +0800 Subject: game version --- .../Piztor/src/com/macaroon/piztor/AlertMaker.java | 137 +++----- .../Piztor/src/com/macaroon/piztor/EException.java | 8 +- client/Piztor/src/com/macaroon/piztor/Login.java | 32 +- client/Piztor/src/com/macaroon/piztor/Main.java | 146 +++++---- client/Piztor/src/com/macaroon/piztor/MapInfo.java | 50 ++- .../Piztor/src/com/macaroon/piztor/MapMaker.java | 358 +++++++-------------- .../Piztor/src/com/macaroon/piztor/PushClient.java | 52 ++- client/Piztor/src/com/macaroon/piztor/RMarker.java | 19 ++ client/Piztor/src/com/macaroon/piztor/Req.java | 22 +- client/Piztor/src/com/macaroon/piztor/Res.java | 57 +++- .../Piztor/src/com/macaroon/piztor/Settings.java | 2 + .../src/com/macaroon/piztor/SocketClient.java | 70 +++- .../src/com/macaroon/piztor/SubscribeSettings.java | 6 +- client/Piztor/src/com/macaroon/piztor/Transam.java | 26 +- client/Piztor/src/com/macaroon/piztor/myApp.java | 9 +- 15 files changed, 553 insertions(+), 441 deletions(-) create mode 100644 client/Piztor/src/com/macaroon/piztor/RMarker.java (limited to 'client/Piztor/src') 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 mp; + HashMap pm; Vector allUsers; - MarkerInfo markerInfo; + Vector markerInfo; UserInfo myInfo; - - - MapInfo copy() { - MapInfo res = new MapInfo(); - res.mp = (HashMap)mp.clone(); - res.allUsers = (Vector) allUsers.clone(); - res.myInfo = myInfo.copy(); - return res; - } - + myApp app; + int myScore, otherScore; @SuppressLint("UseSparseArrays") - MapInfo() { + MapInfo(myApp ap) { mp = new HashMap(); allUsers = new Vector(); + markerInfo = new Vector(); + pm = new HashMap(); + 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 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 mItems = null; - private MapInfo preMapInfo = null; - private MapInfo nowMapInfo = null; - private Vector freshManInfo = null; // hash from uid to overlay item - private HashMap hash = null; - private HashMap markerToInt = null; + private HashMap userToItem = null; + private HashMap 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 markerToItem; + // from mid to item + HashMap 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); @@ -154,42 +156,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 misplaced."; - } else { - Toast.makeText(context, String.format("加载了%d个离线地图包", num), - Toast.LENGTH_SHORT).show(); - } - Log.d("offline", "inited"); - - } - /** * Initialize location layer */ @@ -210,8 +176,11 @@ public class MapMaker { // TODO // /////////////////////////////////////////////////////////////// - hash = new HashMap(); - markerToInt = new HashMap(); + userToItem = new HashMap(); + markerToItem = new HashMap(); + itemToMarker = new HashMap(); + itemToUser = new HashMap(); + mOverlay = new MyOverlay(context.getResources().getDrawable( R.drawable.circle_red), mMapView); mMapView.getOverlays().add(mOverlay); @@ -240,13 +209,7 @@ public class MapMaker { // do nothing } if (index == 2) { - // remove current marker if is higher or equal level - if (app.mapInfo.myInfo.level >= nowMarkerLevel) { - AlertMaker removeAlert = new AlertMaker(context, MapMaker.this); - removeAlert.showRemoveMarkerAlert(); - } else { - Toast.makeText(context, "权限不足", Toast.LENGTH_SHORT).show(); - } + // do nothing } } }; @@ -267,7 +230,6 @@ public class MapMaker { InitLocationOverlay(); InitMyOverLay(); InitPopup(); - //InitOfflineMap(); myBM = new Drawable[20]; initMyIcons(); // InitTouchListenr(); @@ -286,22 +248,15 @@ public class MapMaker { } public Drawable getGroupIcon(UserInfo userInfo) { - if (Main.colorMode == Main.show_by_team) { - if (userInfo.section == app.mapInfo.myInfo.section) - return myBM[0]; - else - return myBM[userInfo.section % iconNum + 1]; - } else { - if (userInfo.sex == app.mapInfo.myInfo.sex) return myBM[0]; - else return myBM[1]; - } + if (userInfo.section == app.mapInfo.myInfo.section) + return myBM[0]; + else return myBM[1]; } /** * Update location layer when new location is received */ - public void UpdateLocationOverlay(LocationData locationData, - boolean hasAnimation) { + public void UpdateLocationOverlay(LocationData locationData, boolean hasAnimation) { mLocationOverlay.setData(locationData); mMapView.refresh(); if (hasAnimation) { @@ -309,72 +264,123 @@ public class MapMaker { (int) (locationData.latitude * 1E6), (int) (locationData.longitude * 1E6))); } - checkMarkerTime(); } boolean isInvalidLocation(GeoPoint point) { - if (point == null) return false; - if (point.getLatitudeE6() / 1E6 > 180.0 || point.getLatitudeE6() / 1E6 < -180.0 - || point.getLongitudeE6() > 180.0 || point.getLongitudeE6() / 1E6 < -180.0) + if (point == null) + return false; + if (point.getLatitudeE6() / 1E6 > 180 + || point.getLatitudeE6() / 1E6 < -180 + || point.getLongitudeE6() > 180 + || point.getLongitudeE6() / 1E6 < -180) return false; return true; } - + /** * Update to draw other users */ public void UpdateMap(MapInfo mapInfo) { + if (mapInfo == null) { if (mOverlay != null && mOverlay.getAllItem().size() != 0) { mOverlay.removeAll(); } return; } - freshManInfo = new Vector(); + // first remove all old users that are not here now - if (preMapInfo != null) { - for (UserInfo i : preMapInfo.getVector()) { - if (i.uid == app.mapInfo.myInfo.uid) - continue; - if (mapInfo.getUserInfo(i.uid) == null) { - mOverlay.removeItem(hash.get(i.uid)); - markerToInt.remove(hash.get(i.uid)); - hash.remove(i.uid); - } - if (mapInfo.getUserInfo(i.uid) != null && isInvalidLocation(mapInfo.getUserInfo(i.uid).location)) { - mOverlay.removeItem(hash.get(i.uid)); - markerToInt.remove(hash.get(i.uid)); - hash.remove(i.uid); - } + + Vector delList = new Vector(); + + for (java.util.Map.Entry i : userToItem.entrySet()) { + if (mapInfo.getUserInfo(i.getKey()) == null) { + delList.add(i.getKey()); } } + for (int i : delList) { + mOverlay.removeItem(userToItem.get(i)); + itemToUser.remove(userToItem.get(i)); + } + for (int i : delList) { + userToItem.remove(i); + } mMapView.refresh(); - preMapInfo = mapInfo.copy(); + delList = new Vector(); + + for (java.util.Map.Entry i : markerToItem.entrySet()) { + if (mapInfo.getMarkerInfo(i.getKey()) == null) { + delList.add(i.getKey()); + } + } + // i is mid + Log.d("kram", "before del overlay " + mOverlay.getAllItem().size()); + for (int i : delList) { + mOverlay.removeItem(markerToItem.get(i)); + itemToMarker.remove(markerToItem.get(i)); + } + // i is mid + for (int i : delList) { + Log.d("kram", "remove id " + i); + markerToItem.remove(i); + + } + for (java.util.Map.Entry i : markerToItem.entrySet()) { + Log.d("kram", "current marker " + i.getKey()); + } + for (MarkerInfo i : mapInfo.markerInfo) { + Log.d("kram", "current makerInfo " + i.markerId); + } + + Log.d("kram", "after del overlay " + mOverlay.getAllItem().size()); + mMapView.refresh(); + // then update and add items + + Log.d("kram", "before update overlay " + mOverlay.getAllItem().size()); + int cnt = 0; + for (MarkerInfo i : mapInfo.markerInfo) { + if (markerToItem.containsKey(i.markerId) == false) { + Log.d("kram", "add id " + i.markerId); + cnt ++; + curItem = new OverlayItem(i.markerPoint, "MARKERNAME_HERE", + "MARKER_SNIPPET_HERE"); + Log.d("jingdu", "收到的坐标" + i.markerPoint.getLatitudeE6() / 1E6 + " " + i.markerPoint.getLongitudeE6() / 1E6); + Drawable d = context.getResources().getDrawable(R.drawable.marker_red); + //d.mutate().setAlpha(10); + curItem.setMarker(d); + mOverlay.addItem(curItem); + markerToItem.put(i.markerId, curItem); + itemToMarker.put(curItem, i.markerId); + } + } + Log.d("kram", "added " + cnt); + Log.d("kram", "after update overlay " + mOverlay.getAllItem().size()); + for (UserInfo i : mapInfo.getVector()) { if (i.uid == app.mapInfo.myInfo.uid) continue; - if (hash.containsKey(i.uid) == false) { + if (userToItem.containsKey(i.uid) == false) { if (isInvalidLocation(i.location)) { - + } else { curItem = new OverlayItem(i.location, "USERNAME_HERE", - "USER_SNIPPET_HERE"); + "USER_SNIPPET_HERE"); // TODO getDrawable // ///////////////////////////// curItem.setMarker(getGroupIcon(i)); mOverlay.addItem(curItem); - hash.put(i.uid, curItem); - markerToInt.put(curItem, i.uid); + userToItem.put(i.uid, curItem); + itemToUser.put(curItem, i.uid); } } else { if (isInvalidLocation(i.location)) { - mOverlay.removeItem(hash.get(i.uid)); - markerToInt.remove(hash.get(i.uid)); - hash.remove(i.uid); + mOverlay.removeItem(userToItem.get(i.uid)); + itemToUser.remove(userToItem.get(i.uid)); + userToItem.remove(i.uid); } else { - curItem = hash.get(i.uid); + curItem = userToItem.get(i.uid); curItem.setGeoPoint(i.location); mOverlay.updateItem(curItem); } @@ -383,131 +389,13 @@ public class MapMaker { if (mMapView != null) { mMapView.refresh(); } - checkMarkerTime(); - } - - public void receiveMarker(MarkerInfo markerInfo) { - if (nowMarker != null && markerInfo.level >= nowMarkerLevel) { - Log.d("marker", "Old marker replaced by marker with higher level!"); - nowMarker.setGeoPoint(markerInfo.markerPoint); - - final Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(markerInfo.markerTimestamp * 1000); - Date date = (Date) cal.getTime(); - nowMarkerHour = date.getHours(); - nowMarkerMinute = date.getMinutes(); - nowMarkerTimestamp = markerInfo.markerTimestamp; - nowMarkerLevel = markerInfo.level; - - mOverlay.updateItem(nowMarker); - mMapView.refresh(); - mMapController.animateTo(markerInfo.markerPoint); - Toast toast = Toast.makeText(context,"收到新路标,集合时间:" + nowMarkerHour + ":" + nowMarkerMinute, 5000); - toast.setGravity(Gravity.TOP, 0, 80); - toast.show(); - return; - } - if (nowMarker == null) { - Log.d("marker", "New marker created!"); - nowMarker = new OverlayItem(markerInfo.markerPoint, "MARKER_NAME", - ""); - nowMarker.setMarker(context.getResources().getDrawable( - R.drawable.marker_red)); - System.out.println(markerInfo.markerPoint.getLatitudeE6() + " " - + markerInfo.markerPoint.getLongitudeE6()); - final Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(markerInfo.markerTimestamp * 1000); - Date date = (Date) cal.getTime(); - nowMarkerHour = date.getHours(); - nowMarkerMinute = date.getMinutes(); - nowMarkerTimestamp = markerInfo.markerTimestamp; - nowMarkerLevel = markerInfo.level; - - markerIndex = mOverlay.getAllItem().size(); - mOverlay.addItem(nowMarker); - mMapView.refresh(); - mMapController.animateTo(markerInfo.markerPoint); - Toast toast = Toast.makeText(context,"收到新路标,集合时间:" + nowMarkerHour + ":" + nowMarkerMinute, 5000); - toast.setGravity(Gravity.TOP, 0, 80); - toast.show(); - return; - } - } - - void sendMarker() { - Log.d("marker", "Marker prepare! " + nowMarkerTimestamp); - ReqSetMarker req = new ReqSetMarker(app.token, app.username, nowMarker - .getPoint().getLatitudeE6() / 1e6, nowMarker.getPoint() - .getLongitudeE6() / 1e6, (int)nowMarkerTimestamp, - System.currentTimeMillis(), 3000l); - - Log.d("marker", "Marker sent! " + req.deadline); - app.transam.send(req); - } - - /** - * Draw a marker - */ - public void DrawMarker(GeoPoint markerPoint) { - - if (nowMarker != null && app.mapInfo.myInfo.level >= nowMarkerLevel) { - nowMarker.setGeoPoint(markerPoint); - nowMarkerHour = newMarkerHour; - nowMarkerMinute = newMarkerMinute; - nowMarkerTimestamp = newMarkerTimestamp; - nowMarkerLevel = app.mapInfo.myInfo.level; - - sendMarker(); - Log.d("marker", "Sent and replace"); - mOverlay.updateItem(nowMarker); - mMapView.refresh(); - mMapController.animateTo(markerPoint); - return; - } else if (nowMarker == null) { - nowMarker = new OverlayItem(markerPoint, "MARKER_NAME", ""); - nowMarker.setMarker(context.getResources().getDrawable( - R.drawable.marker_red)); - nowMarkerHour = newMarkerHour; - nowMarkerMinute = newMarkerMinute; - nowMarkerTimestamp = newMarkerTimestamp; - nowMarkerLevel = app.mapInfo.myInfo.level; - - sendMarker(); - Log.d("marker", "Send and new"); - markerIndex = mOverlay.getAllItem().size(); - Log.d("marker", "my new marker created"); - mOverlay.addItem(nowMarker); - mMapView.refresh(); - mMapController.animateTo(markerPoint); - } - Toast toast = Toast.makeText(context,"创建新路标,集合时间:" + nowMarkerHour + ":" + nowMarkerMinute, 5000); - toast.setGravity(Gravity.TOP, 0, 80); - toast.show(); } - public GeoPoint getMakerLocation() { - if (nowMarker == null) - return null; - else - return nowMarker.getPoint(); - } - - public void removeMarker() { - if (nowMarker == null) - return; - mOverlay.removeItem(nowMarker); - nowMarker = null; - mMapView.refresh(); + public void receiveMarker(MarkerInfo markerInfo) { + app.mapInfo.addMarkerInfo(markerInfo); + UpdateMap(app.mapInfo); } - public void checkMarkerTime() { - if (nowMarker != null && nowMarkerTimestamp <= System.currentTimeMillis() / 1000) { - AlertMaker lateAlert = new AlertMaker(context, this); - lateAlert.showLateAlert(); - removeMarker(); - } - } - /** * Remove all other users */ diff --git a/client/Piztor/src/com/macaroon/piztor/PushClient.java b/client/Piztor/src/com/macaroon/piztor/PushClient.java index 7bd82a6..a5b8be6 100644 --- a/client/Piztor/src/com/macaroon/piztor/PushClient.java +++ b/client/Piztor/src/com/macaroon/piztor/PushClient.java @@ -12,7 +12,6 @@ import java.util.Vector; import android.os.Handler; import android.os.Message; -import android.util.Log; @@ -31,9 +30,13 @@ public class PushClient { static final int Message = 0; static final int Location = 1; static final int Marker = 2; + static final int Remove =3; + static final int Score =4; static final int PushMessage =100; static final int PushLocation =101; static final int PushMarker =102; + static final int PushRemoveMarker =103; + static final int PushScore =104; static final int Reconnect =-2; @@ -44,7 +47,7 @@ public class PushClient { private String LastPrint = ""; - public PushClient(String site, int port,int retime, Handler handler) throws UnknownHostException, + public PushClient(String site, int port,int retime,Handler handler) throws UnknownHostException, IOException { try { client = new Socket(); @@ -180,11 +183,13 @@ public class PushClient { double lat = in.readDouble(); double lot = in.readDouble(); int dtime = in.readInt(); + int mid = in.readUnsignedByte(); + int score = in.readInt(); if(LastPrint != p) { - + System.out.println(p); Message msg = new Message(); msg.what = PushMarker; - msg.obj = new ResPushMarker(lat,lot,dtime,lv); + msg.obj = new ResPushMarker(lat,lot,dtime,lv,mid,score); recall.sendMessage(msg); LastPrint = p; } @@ -197,6 +202,45 @@ public class PushClient { out.write(o); out.flush(); break; + case Remove: + int id = in.readUnsignedByte(); + if(LastPrint != p) { + System.out.println(p); + Message msg = new Message(); + msg.what = PushRemoveMarker; + msg.obj = new ResPushRemoveMarker(id); + recall.sendMessage(msg); + LastPrint = p; + } + Convert.write(o,Convert.intToBytes(outlen),pos); + pos+=IntLength; + o[pos]=(byte) Remove; + pos+=ByteLength; + Convert.write(o,Convert.hexStringToBytes(p),pos); + pos+=FingerPrintLength; + out.write(o); + out.flush(); + break; + case Score: + int as = in.readInt(); + int bs = in.readInt(); + if(LastPrint != p) { + System.out.println(p); + Message msg = new Message(); + msg.what = PushScore; + msg.obj = new ResPushScore(as,bs); + recall.sendMessage(msg); + LastPrint = p; + } + Convert.write(o,Convert.intToBytes(outlen),pos); + pos+=IntLength; + o[pos]=(byte) Score; + pos+=ByteLength; + Convert.write(o,Convert.hexStringToBytes(p),pos); + pos+=FingerPrintLength; + out.write(o); + out.flush(); + break; } } } catch (SocketException e){ diff --git a/client/Piztor/src/com/macaroon/piztor/RMarker.java b/client/Piztor/src/com/macaroon/piztor/RMarker.java new file mode 100644 index 0000000..e9d82f9 --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/RMarker.java @@ -0,0 +1,19 @@ +package com.macaroon.piztor; + +class RMarker{ + double latitude; + double longitude; + int deadline; + int level; + int markerID; + int score; + + RMarker(double lat,double lot,int dtime,int lv,int markerid,int s){ + latitude = lat; + longitude = lot; + deadline = dtime; + level = lv; + markerID = markerid; + score = s; + } +} \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/Req.java b/client/Piztor/src/com/macaroon/piztor/Req.java index 4de1045..53cf6fe 100644 --- a/client/Piztor/src/com/macaroon/piztor/Req.java +++ b/client/Piztor/src/com/macaroon/piztor/Req.java @@ -138,9 +138,25 @@ class ReqSetPassword extends Req{ String newpassword; ReqSetPassword(String token,String name,String oldpass,String newpass,long time,long alive){ - super(8,token,name,time,alive); //for type 8 - oldpassword = oldpass; - newpassword = newpass; + super(8,token,name,time,alive); //for type 8 + oldpassword = oldpass; + newpassword = newpass; + } +} + +class ReqCheckin extends Req{ + int markerID; + + ReqCheckin(String token,String name,int markerid,long time,long alive){ + super(9,token,name,time,alive); //for type 9 + markerID = markerid; + } +} + +class ReqGameStart extends Req{ + + ReqGameStart(String token,String name,long time,long alive){ + super(10,token,name,time,alive); //for type 10 } } diff --git a/client/Piztor/src/com/macaroon/piztor/Res.java b/client/Piztor/src/com/macaroon/piztor/Res.java index 63e35aa..08c6805 100644 --- a/client/Piztor/src/com/macaroon/piztor/Res.java +++ b/client/Piztor/src/com/macaroon/piztor/Res.java @@ -13,10 +13,14 @@ public class Res{ static final int SendMessage =6; static final int SetMarker =7; static final int SetPassword =8; + static final int Checkin =9; + static final int GameStart = 10; static final int PushMessage =100; static final int PushLocation =101; static final int PushMarker =102; + static final int PushRemoveMarker =103; + static final int PushScore =104; int type; Res(int t){ @@ -33,13 +37,18 @@ class ResLogin extends Res{ RUserInfo uinfo; //userinfo Vector sublist; //list of users subscribed int subscribeNumber; //number of users subscribed + Vector markerlist; + int AScore, BScore; - ResLogin(String token,RUserInfo rui,Vector slist,int subn){ + ResLogin(String token,RUserInfo rui,Vector slist,int subn,Vector m, int as, int bs){ super(0); //for type 0 t = token; uinfo = rui; sublist = slist; subscribeNumber = subn; + markerlist = m; + AScore = as; + BScore = bs; } } @@ -135,6 +144,19 @@ class ResSetPassword extends Res{ } } +class ResCheckin extends Res{ + + ResCheckin(){ + super(9); //for type 9 + } +} + +class ResGameStart extends Res{ + + ResGameStart(){ + super(10); //for type 10 + } +} //---------------------------------------------------------------------------------------------------// @@ -177,16 +199,29 @@ class ResPushLocation extends Res{ //--------------------------------------// class ResPushMarker extends Res{ - double latitude; - double longitude; - int deadline; - int level; - - ResPushMarker(double lat,double lot,int dtime,int lv){ + RMarker marker; + ResPushMarker(double lat,double lot,int dtime,int lv,int markerid,int s){ super(102); //for type 102 - latitude = lat; - longitude = lot; - deadline = dtime; - level = lv; + marker = new RMarker(lat,lot,dtime,lv,markerid,s); + } +} + +class ResPushRemoveMarker extends Res{ + int MarkerID; + + ResPushRemoveMarker(int id){ + super(103); //for type 103 + MarkerID =id; + } +} + +class ResPushScore extends Res{ + int AScore; + int BScore; + + ResPushScore(int a,int b){ + super(104); //for type 104 + AScore = a; + BScore = b; } } \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/Settings.java b/client/Piztor/src/com/macaroon/piztor/Settings.java index 276d4f6..68fc078 100644 --- a/client/Piztor/src/com/macaroon/piztor/Settings.java +++ b/client/Piztor/src/com/macaroon/piztor/Settings.java @@ -48,6 +48,7 @@ public class Settings extends PiztorAct { if (out == null) { System.out.println("act被回收了"); } + /* switch (m.what) { case Res.Login:// 上传自己信息成功or失败 Log.d("update location", "successfull"); @@ -101,6 +102,7 @@ public class Settings extends PiztorAct { default: break; } + */ } } ReCall handler = new ReCall(this); diff --git a/client/Piztor/src/com/macaroon/piztor/SocketClient.java b/client/Piztor/src/com/macaroon/piztor/SocketClient.java index de26b63..9e73c2c 100644 --- a/client/Piztor/src/com/macaroon/piztor/SocketClient.java +++ b/client/Piztor/src/com/macaroon/piztor/SocketClient.java @@ -12,7 +12,6 @@ import java.util.Vector; import android.os.Handler; import android.os.Message; -import android.util.Log; @@ -33,6 +32,8 @@ public class SocketClient { static final int SendMessage =6; static final int SetMarker =7; static final int SetPassword =8; + static final int Checkin =9; + static final int GameStart =10; static final int ClosePush =-5; @@ -45,6 +46,7 @@ public class SocketClient { static final int Longitude =7; static final int Level =8; + static final int CheckinFailed =7; static final int SubscribeFailed =6; static final int PasswordFailed =5; static final int ServerFetchFailed =4; @@ -243,6 +245,40 @@ public class SocketClient { pos+=ByteLength; out.write(b); break; + case Checkin: + ReqCheckin rck = (ReqCheckin) req; + len = IntLength+ByteLength+TokenLength+(rck.uname).length()+ByteLength+ByteLength; + b = new byte[len]; + Convert.write(b,Convert.intToBytes(len),pos); + pos+=IntLength; + b[pos] = (byte) tmp; + pos+=ByteLength; + Convert.write(b,Convert.hexStringToBytes(rck.token),pos); + pos+=TokenLength; + Convert.write(b,(rck.uname).getBytes(),pos); + pos+=(rck.uname).length(); + b[pos] = 0; + pos+=ByteLength; + b[pos] = (byte) rck.markerID; + pos+=ByteLength; + out.write(b); + break; + case GameStart: + ReqGameStart rgs = (ReqGameStart) req; + len = IntLength+ByteLength+TokenLength+(rgs.uname).length()+ByteLength; + b = new byte[len]; + Convert.write(b,Convert.intToBytes(len),pos); + pos+=IntLength; + b[pos] = (byte) tmp; + pos+=ByteLength; + Convert.write(b,Convert.hexStringToBytes(rgs.token),pos); + pos+=TokenLength; + Convert.write(b,(rgs.uname).getBytes(),pos); + pos+=(rgs.uname).length(); + b[pos] = 0; + pos+=ByteLength; + out.write(b); + break; } out.flush(); DataInputStream in = new DataInputStream(client.getInputStream()); @@ -254,6 +290,7 @@ public class SocketClient { if(status == 2) return LevelFailed; if(status == 3) return PasswordFailed; if(status == 4) return SubscribeFailed; + if(status == 5) return CheckinFailed; switch (type) { case Login: byte[] buffer = new byte[32]; @@ -333,15 +370,30 @@ public class SocketClient { outlen-=ByteLength; int number =0; Vector vrg = new Vector(); - while(outlen > 1) { + while(true) { int com = in.readUnsignedByte(); + if(com == 0)break; int sec = in.readUnsignedByte(); vrg.add(new RGroup(com,sec)); outlen-=ByteLength*2; number++; } - in.readUnsignedByte(); - msg.obj = new ResLogin(tk, r, vrg, number); + outlen-=ByteLength; + Vector vrm = new Vector(); + while(outlen > IntLength + IntLength){ + + int lv = in.readUnsignedByte(); + double lati = in.readDouble(); + double logi = in.readDouble(); + int dtime = in.readInt(); + int mid = in.readUnsignedByte(); + int score = in.readInt(); + vrm.add(new RMarker(lati,logi,dtime,lv,mid,score)); + outlen -= (ByteLength + DoubleLength + DoubleLength + IntLength + ByteLength + IntLength); + } + int as = in.readInt(); + int bs = in.readInt(); + msg.obj = new ResLogin(tk, r, vrg, number,vrm, as, bs); msg.what = Login; recall.sendMessage(msg); Vector vs = new Vector(); @@ -467,6 +519,16 @@ public class SocketClient { msg.what = SetPassword; recall.sendMessage(msg); break; + case Checkin: + msg.obj = new ResCheckin(); + msg.what = Checkin; + recall.sendMessage(msg); + break; + case GameStart: + msg.obj = new ResGameStart(); + msg.what = GameStart; + recall.sendMessage(msg); + break; } return Success; diff --git a/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java b/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java index 4fdaa8a..3ed1e90 100644 --- a/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java +++ b/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java @@ -39,7 +39,8 @@ public class SubscribeSettings extends PiztorAct { ReCall(SubscribeSettings activity) { outerClass = new WeakReference(activity); } - + + /* @Override public void handleMessage(Message m) { SubscribeSettings out = outerClass.get(); @@ -115,6 +116,7 @@ public class SubscribeSettings extends PiztorAct { break; } } + */ } ReCall handler = new ReCall(this); @@ -221,7 +223,7 @@ public class SubscribeSettings extends PiztorAct { simpleAdapter.notifyDataSetChanged(); } for (RGroup i : ((myApp) getApplication()).sublist) { - if (i.section == 255) continue; + if (recSubcribe.contains(i.company)) continue; //else HashMap map = new HashMap(); map.put("subscribe_text", i.company + "连 " + i.section + "班"); diff --git a/client/Piztor/src/com/macaroon/piztor/Transam.java b/client/Piztor/src/com/macaroon/piztor/Transam.java index df2194f..ef30dc0 100644 --- a/client/Piztor/src/com/macaroon/piztor/Transam.java +++ b/client/Piztor/src/com/macaroon/piztor/Transam.java @@ -25,6 +25,7 @@ public class Transam implements Runnable { static final int SendMessage =6; static final int SetMarker =7; static final int SetPassword =8; + static final int Checkin =9; static final int ClosePush = -5; @@ -38,11 +39,13 @@ public class Transam implements Runnable { static final int ELevelFailedException =108; static final int EPasswordFailedException =109; static final int ESubscribeFailedException =110; + static final int ECheckinFailedException =111; static final int Reconnect =-2; static final int Exception =-1; static final int TimeOut =0; + static final int RCheckinFailed =7; static final int RSubscribeFailed =6; static final int RPasswordFailed =5; static final int RServerFetchFailed =4; @@ -276,6 +279,14 @@ public class Transam implements Runnable { recall.sendMessage(msg); running = false; } + else if (out == RCheckinFailed){ + client.closeSocket(); + Message msg = new Message(); + msg.what = Exception; + msg.obj = new ECheckinFailedException(req.type,req.time); + recall.sendMessage(msg); + running = false; + } } catch (UnknownHostException e) { e.printStackTrace(); Message msg = new Message(); @@ -311,11 +322,14 @@ public class Transam implements Runnable { TimerTask task = out.new tmain(); out.timer.schedule(task,out.retime); } else if (out.tcnt == 0) { + out.tcnt = out.cnt; Message m = new Message(); m.obj = msg.obj; m.what = Exception; out.recall.sendMessage(m); - out.running = false; + out.timer = new Timer(); + TimerTask task = out.new tmain(); + out.timer.schedule(task,out.retime); } break; case TimeOut: @@ -326,12 +340,15 @@ public class Transam implements Runnable { TimerTask task = out.new tmain(); out.timer.schedule(task,out.retime); } else if (out.tcnt == 0) { + out.tcnt = out.cnt; Message m = new Message(); EConnectFailedException c = new EConnectFailedException(out.req.type,out.req.time); m.obj = c; m.what = Exception; out.recall.sendMessage(m); - out.running = false; + out.timer = new Timer(); + TimerTask task = out.new tmain(); + out.timer.schedule(task,out.retime); } break; case Reconnect: @@ -342,13 +359,16 @@ public class Transam implements Runnable { TimerTask task = out.new pmain(); out.pushtimer.schedule(task,out.retime); } else if (out.rcnt == 0) { - out.pushing = false; + out.rcnt = out.cnt; Message m = new Message(); EPushFailedException c = new EPushFailedException(5,0); //m.obj = msg.obj; m.obj = c; m.what = Exception; out.recall.sendMessage(m); + out.pushtimer = new Timer(); + TimerTask task = out.new pmain(); + out.pushtimer.schedule(task,out.retime); } break; case StartPush: diff --git a/client/Piztor/src/com/macaroon/piztor/myApp.java b/client/Piztor/src/com/macaroon/piztor/myApp.java index ab38efa..d8cdc9c 100644 --- a/client/Piztor/src/com/macaroon/piztor/myApp.java +++ b/client/Piztor/src/com/macaroon/piztor/myApp.java @@ -10,14 +10,14 @@ import android.util.Log; @SuppressLint("UseSparseArrays") public class myApp extends Application { - private static final String strKey = "8a0ae50048d103b2b8b12b7066f4ea7d"; + private static final String strKey = "579bf85175473ea618258a7a3d3ba63b"; BMapManager mBMapManager; boolean isExiting = false; boolean isLogout = false; String ip = "202.120.7.4"; // static String ip = "69.85.86.42"; -// static String ip = "192.168.1.101"; - int port = 2223; +// static String ip = "192.168.1.171"; + int port = 2224; String token = null; String username = null; Vector sublist; @@ -29,12 +29,13 @@ public class myApp extends Application { Thread tTransam; MapInfo mapInfo; + boolean gameStarted = false; @Override public void onCreate() { super.onCreate(); System.out.println("我执行了,好开心~~~~~~~~~~"); - mapInfo = new MapInfo(); + mapInfo = new MapInfo(this); mBMapManager = new BMapManager(this); appMgr = new AppMgr(this); -- cgit v1.2.3-70-g09d2