From 0410d0b9c6bb502f8467c3f2c62183e9a74e69fc Mon Sep 17 00:00:00 2001 From: sjtufs Date: Sun, 1 Sep 2013 00:32:38 +0800 Subject: update for 0831. preparing for rc1 --- client/Piztor/AndroidManifest.xml | 91 +++--- client/Piztor/res/layout/activity_login.xml | 3 +- .../res/layout/activity_subscribe_settings.xml | 16 + client/Piztor/res/layout/checkindialog.xml | 4 +- client/Piztor/res/menu/subscribe_settings.xml | 9 + client/Piztor/res/values/strings.xml | 3 + .../src/com/macaroon/piztor/AccountSettings.java | 5 + client/Piztor/src/com/macaroon/piztor/ActMgr.java | 9 +- .../Piztor/src/com/macaroon/piztor/AlertMaker.java | 68 +++- client/Piztor/src/com/macaroon/piztor/AppMgr.java | 93 ++---- .../Piztor/src/com/macaroon/piztor/EException.java | 22 +- .../Piztor/src/com/macaroon/piztor/Infomation.java | 10 +- client/Piztor/src/com/macaroon/piztor/InitAct.java | 35 ++- client/Piztor/src/com/macaroon/piztor/Login.java | 25 +- client/Piztor/src/com/macaroon/piztor/Main.java | 212 +++++++------ .../src/com/macaroon/piztor/MainActivity.java | 133 ++++++++ client/Piztor/src/com/macaroon/piztor/MapInfo.java | 38 +++ .../Piztor/src/com/macaroon/piztor/MapMaker.java | 346 ++++++++++++--------- .../Piztor/src/com/macaroon/piztor/PiztorAct.java | 33 +- .../Piztor/src/com/macaroon/piztor/PushClient.java | 26 +- .../Piztor/src/com/macaroon/piztor/RUserInfo.java | 4 +- client/Piztor/src/com/macaroon/piztor/Req.java | 32 ++ client/Piztor/src/com/macaroon/piztor/Res.java | 48 ++- .../Piztor/src/com/macaroon/piztor/Rlocation.java | 13 + .../Piztor/src/com/macaroon/piztor/Settings.java | 144 +++++++-- .../src/com/macaroon/piztor/SocketClient.java | 91 +++++- .../src/com/macaroon/piztor/SubscribeSettings.java | 322 +++++++++++++------ client/Piztor/src/com/macaroon/piztor/Transam.java | 205 ++++++------ client/Piztor/src/com/macaroon/piztor/myApp.java | 52 ++++ 29 files changed, 1450 insertions(+), 642 deletions(-) create mode 100644 client/Piztor/res/layout/activity_subscribe_settings.xml create mode 100644 client/Piztor/res/menu/subscribe_settings.xml create mode 100644 client/Piztor/src/com/macaroon/piztor/AccountSettings.java create mode 100644 client/Piztor/src/com/macaroon/piztor/MainActivity.java create mode 100644 client/Piztor/src/com/macaroon/piztor/Rlocation.java create mode 100644 client/Piztor/src/com/macaroon/piztor/myApp.java diff --git a/client/Piztor/AndroidManifest.xml b/client/Piztor/AndroidManifest.xml index f336200..f81ece8 100644 --- a/client/Piztor/AndroidManifest.xml +++ b/client/Piztor/AndroidManifest.xml @@ -8,36 +8,38 @@ android:minSdkVersion="8" android:targetSdkVersion="17" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -56,27 +59,35 @@ + android:configChanges="orientation" + android:label="@string/title_activity_main" + android:screenOrientation="portrait" > + android:configChanges="orientation" + android:label="@string/title_activity_settings" + android:screenOrientation="portrait" > + + + - - + + diff --git a/client/Piztor/res/layout/activity_login.xml b/client/Piztor/res/layout/activity_login.xml index a8cf47f..232f1e7 100644 --- a/client/Piztor/res/layout/activity_login.xml +++ b/client/Piztor/res/layout/activity_login.xml @@ -39,7 +39,8 @@ android:paddingLeft="12.0dip" android:layout_width="fill_parent" android:layout_height="44.0dip" - android:hint="@string/username" android:maxLines="1" + android:hint="@string/username" + android:maxLines="1" android:maxLength="16"/> + + + + diff --git a/client/Piztor/res/layout/checkindialog.xml b/client/Piztor/res/layout/checkindialog.xml index 4174deb..d72f223 100644 --- a/client/Piztor/res/layout/checkindialog.xml +++ b/client/Piztor/res/layout/checkindialog.xml @@ -8,12 +8,14 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" - android:text="Checking in..."/> + android:text="Checking in..." + android:id="@+id/checkin_info"/> diff --git a/client/Piztor/res/menu/subscribe_settings.xml b/client/Piztor/res/menu/subscribe_settings.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/client/Piztor/res/menu/subscribe_settings.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/client/Piztor/res/values/strings.xml b/client/Piztor/res/values/strings.xml index a0843df..8752b0d 100644 --- a/client/Piztor/res/values/strings.xml +++ b/client/Piztor/res/values/strings.xml @@ -1,3 +1,4 @@ + Piztor @@ -25,5 +26,7 @@ My Account Subscribe information Check & Update + SubscribeSettings + SubscribeSettings diff --git a/client/Piztor/src/com/macaroon/piztor/AccountSettings.java b/client/Piztor/src/com/macaroon/piztor/AccountSettings.java new file mode 100644 index 0000000..150bc64 --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/AccountSettings.java @@ -0,0 +1,5 @@ +package com.macaroon.piztor; + +public class AccountSettings extends PiztorAct{ + +} diff --git a/client/Piztor/src/com/macaroon/piztor/ActMgr.java b/client/Piztor/src/com/macaroon/piztor/ActMgr.java index 903527e..a2ad23b 100644 --- a/client/Piztor/src/com/macaroon/piztor/ActMgr.java +++ b/client/Piztor/src/com/macaroon/piztor/ActMgr.java @@ -11,8 +11,9 @@ public class ActMgr { PiztorAct act; ActStatus nowStatus; HashMap> mp; - - ActMgr(PiztorAct act, ActStatus nowStatus, ActStatus[] r) { + AppMgr appMgr; + ActMgr(AppMgr appMgr, PiztorAct act, ActStatus nowStatus, ActStatus[] r) { + this.appMgr = appMgr; this.act = act; this.nowStatus = nowStatus; nowStatus.enter(Create); @@ -29,8 +30,8 @@ public class ActMgr { nowStatus.leave(event); nowStatus = mp.get(nowStatus).get(event); nowStatus.enter(event); - } else if (AppMgr.mp.get(act.getClass()).containsKey(event)) { - AppMgr.trigger(event); + } else if (appMgr.mp.get(act.getClass()).containsKey(event)) { + appMgr.trigger(event); } else { System.out.println("can not trigger the event at " + act.id + " : " + event); diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java index d7a9d69..7e36310 100644 --- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java @@ -13,10 +13,12 @@ import android.content.DialogInterface; import android.content.Intent; import android.location.LocationManager; import android.os.Bundle; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; import android.provider.Settings; import android.util.Log; +import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -24,6 +26,8 @@ import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; @@ -46,6 +50,8 @@ public class AlertMaker { private GeoPoint markerPoint; private MapMaker mapMaker; private long timestamp; + int mHour; + int mMinute; public AlertMaker(Context cc, MapMaker mm) { context =cc; @@ -92,33 +98,40 @@ public class AlertMaker { timestamp = System.currentTimeMillis() + tmp * 60 * 1000; return timestamp; } - + //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) { 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 ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute >= calendar.get(Calendar.MINUTE)) - || hourOfDay > calendar.get(Calendar.HOUR_OF_DAY)) { - mapMaker.DrawMarker(markerPoint); + if ( !flag && + ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute >= calendar.get(Calendar.MINUTE)) + || hourOfDay > calendar.get(Calendar.HOUR_OF_DAY))) { updateMarkerTime(hourOfDay, minute); - } - else { + mapMaker.DrawMarker(markerPoint); + flag = true; + Log.d("marker", "marker alert calls drawmarker"); + } else if (!flag) { Toast toast = Toast.makeText(context, - "Too early! Give me at least 2 minutes!", Toast.LENGTH_LONG); + "Too early! Give me at least 2 minutes!", Toast.LENGTH_LONG); toast.show(); closeBoard(context); showMarkerAlert(markerPoint); @@ -127,12 +140,43 @@ public class AlertMaker { } , calendar.get(Calendar.HOUR_OF_DAY) , calendar.get(Calendar.MINUTE), true); - markerDialog.show(); + markerDialog.show(); } - + public void showCheckinAlter() { closeBoard(context); - AlertDialog.Builder checkinDialog = new AlertDialog.Builder(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("cancel", 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(); + closeBoard(context); + new CountDownTimer(5000, 1000) { + + public void onTick(long millisUntilFinished) { + int ttt = (int)millisUntilFinished; + pbar.setProgress(ttt); + } + + public void onFinish() { + //TODO + pbar.setVisibility(View.GONE); + mapMaker.removeMarker(); + Toast toast = Toast.makeText(context, "Marker checked!", 2000); + toast.setGravity(Gravity.TOP, 0, 80); + toast.show(); + checkinInfo.setText("Success!"); + } + }.start(); } - + } diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java index 933d2db..f1a3445 100644 --- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java +++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java @@ -4,32 +4,11 @@ import java.util.HashMap; import java.util.HashSet; import android.annotation.SuppressLint; -import android.content.Context; import android.content.Intent; -import android.os.Handler; -import android.util.Log; - import com.baidu.mapapi.BMapManager; -import com.baidu.mapapi.MKGeneralListener; @SuppressLint("UseSparseArrays") public class AppMgr { - - static final String strKey = "8a0ae50048d103b2b8b12b7066f4ea7d"; - static BMapManager mBMapManager = null; - - // Status - public enum ActivityStatus { - create, start, resume, restart, stop, pause, destroy - } - - static ActivityStatus status; - static PiztorAct nowAct; - // TODO fix - static Handler handler, fromGPS; - static Transam transam = null; - static Tracker tracker = null; - static Thread tTransam, tGPS; // Event final static int noToken = 101; final static int loginSuccess = 102; @@ -37,51 +16,59 @@ public class AppMgr { final static int hasToken = 104; final static int toSettings = 105; final static int logout = 106; + final static int subscribe = 107; + final static int account = 108; + public enum ActivityStatus { + create, start, resume, restart, stop, pause, destroy + } + myApp app; + HashMap, HashMap>> mp; + HashSet acts; + ActivityStatus status; + PiztorAct nowAct; - static MapInfo mapInfo; - - static HashMap, HashMap>> mp; - static HashSet acts; - - static void addAct(PiztorAct act) { + void addAct(PiztorAct act) { if (acts == null) acts = new HashSet(); acts.add(act); } - static void removeAct(PiztorAct act) { + void removeAct(PiztorAct act) { if (acts.contains(act)) acts.remove(act); else System.out.println("Piztor has a bug!!!!"); } - static void exit() { + void exit() { for (PiztorAct act : acts) { act.finish(); } + app.token = null; + app.mBMapManager.destroy(); } - static void setStatus(ActivityStatus st) { + void setStatus(ActivityStatus st) { status = st; } - static void trigger(int event) { + void trigger(int event) { Intent i = new Intent(); i.setClass(nowAct, mp.get(nowAct.getClass()).get(event)); if (event == errorToken) - Infomation.token = null; - if (event == loginSuccess) { - mBMapManager.start(); - mapInfo.clear(); + app.token = null; + if (event == loginSuccess || event == hasToken) { + app.mBMapManager.start(); + app.mapInfo.clear(); } if (event == logout) { - mBMapManager.stop(); + System.out.println("我来停一发!!!!"); + app.mBMapManager.stop(); } nowAct.startActivity(i); } - static void add(Class a, Integer event, Class b) { + void add(Class a, Integer event, Class b) { if (mp.containsKey(a)) mp.get(a).put(event, b); else { @@ -91,7 +78,7 @@ public class AppMgr { } } - static void addTransition(Class a, int i, Class b) { + void addTransition(Class a, int i, Class b) { if (mp.containsKey(a)) { HashMap> h = mp.get(a); h.put(i, b); @@ -103,38 +90,20 @@ public class AppMgr { } } - static void addStatus(Class a) { + void addStatus(Class a) { mp.put(a, new HashMap>()); } - static void init(Context context) { - if (mBMapManager == null) { - mBMapManager = new BMapManager(context); - mBMapManager.init(strKey, new MKGeneralListener() { - @Override - public void onGetNetworkState(int iError) { - Log.d("Network", "failure"); - System.out.println("network wocao ni ma de !!!!!!!!!"); - } - - @Override - public void onGetPermissionState(int iError) { - Log.d("Permission", "wrong key"); - System.out.println("ju ran bu gei wo quan xian !!!!!!!!!!"); - } - }); - } + public AppMgr(myApp app) { mp = new HashMap, HashMap>>(); - handler = new Handler(); - transam = new Transam(Infomation.ip, Infomation.port, handler); - tTransam = new Thread(transam); - tTransam.start(); - mapInfo = new MapInfo(); - Infomation.myInfo = new UserInfo(-1); + this.app = app; addStatus(InitAct.class); addStatus(Login.class); addStatus(Main.class); addStatus(Settings.class); + addTransition(Settings.class, subscribe, SubscribeSettings.class); + addTransition(SubscribeSettings.class, logout, Login.class); + addTransition(Settings.class, account, AccountSettings.class); addTransition(InitAct.class, noToken, Login.class); addTransition(InitAct.class, hasToken, Main.class); addTransition(InitAct.class, errorToken, Login.class); diff --git a/client/Piztor/src/com/macaroon/piztor/EException.java b/client/Piztor/src/com/macaroon/piztor/EException.java index 5ce1fdb..39d53c8 100644 --- a/client/Piztor/src/com/macaroon/piztor/EException.java +++ b/client/Piztor/src/com/macaroon/piztor/EException.java @@ -10,7 +10,9 @@ public class EException extends Exception { static final int EPushFailedException =104; static final int EIOException =105; static final int EUnknownHostException =106; - static final int EStatusFailedException =107; + static final int EStatusFailedException =107; + static final int ELevelFailedException =108; + static final int EPasswordFailedException =109; private static final long serialVersionUID = 100L; @@ -72,4 +74,20 @@ public class EException extends Exception { public EStatusFailedException(int t,long timep) { super(107,t,timep); } - } \ No newline at end of file + } + + class ELevelFailedException extends EException{ + private static final long serialVersionUID = 108L; + public ELevelFailedException(int t,long timep) { + super(108,t,timep); + } + } + + class EPasswordFailedException extends EException{ + private static final long serialVersionUID = 109L; + public EPasswordFailedException(int t,long timep) { + super(109,t,timep); + } + } + + \ No newline at end of file diff --git a/client/Piztor/src/com/macaroon/piztor/Infomation.java b/client/Piztor/src/com/macaroon/piztor/Infomation.java index 60eb03f..dbae0a0 100644 --- a/client/Piztor/src/com/macaroon/piztor/Infomation.java +++ b/client/Piztor/src/com/macaroon/piztor/Infomation.java @@ -3,13 +3,5 @@ package com.macaroon.piztor; import java.util.Vector; public class Infomation { - static String ip = "202.120.7.4"; - //static String ip = "192.168.1.171"; -// static String ip = "69.85.86.42"; -// static String ip = "192.168.1.101"; - static int port = 2223; - static String token = null; - static String username = null; - static UserInfo myInfo; - static Vector sublist; + } diff --git a/client/Piztor/src/com/macaroon/piztor/InitAct.java b/client/Piztor/src/com/macaroon/piztor/InitAct.java index 8145935..a4f82ff 100644 --- a/client/Piztor/src/com/macaroon/piztor/InitAct.java +++ b/client/Piztor/src/com/macaroon/piztor/InitAct.java @@ -1,16 +1,28 @@ package com.macaroon.piztor; +import com.baidu.mapapi.MKGeneralListener; + +import android.app.Activity; import android.os.Bundle; +import android.util.Log; import android.view.Menu; public class InitAct extends PiztorAct { - @Override protected void onCreate(Bundle savedInstanceState) { id = "initAct"; super.onCreate(savedInstanceState); - AppMgr.init(getApplicationContext()); - AppMgr.transam.setTimeOutTime(5000); + app.mBMapManager.init(app.getStrkey(), new MKGeneralListener() { + @Override + public void onGetNetworkState(int iError) { + Log.d("Network", "failure"); + } + + @Override + public void onGetPermissionState(int iError) { + Log.d("Permission", "wrong key"); + } + }); setContentView(R.layout.activity_init); } @@ -22,22 +34,23 @@ public class InitAct extends PiztorAct { @Override protected void onResume() { super.onResume(); - if (Infomation.token == null) - AppMgr.trigger(AppMgr.noToken); + if (app.token == null) + app.appMgr.trigger(AppMgr.noToken); else { - AppMgr.trigger(AppMgr.hasToken); + System.out.println("has token!!!"); + app.appMgr.trigger(AppMgr.hasToken); } } - @Override - protected void onDestroy() { - super.onDestroy(); - } - @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.init, menu); return false; } + + @Override + public void finishFromChild (Activity child) { + finish(); + } } diff --git a/client/Piztor/src/com/macaroon/piztor/Login.java b/client/Piztor/src/com/macaroon/piztor/Login.java index 533eeac..bdbf7ed 100644 --- a/client/Piztor/src/com/macaroon/piztor/Login.java +++ b/client/Piztor/src/com/macaroon/piztor/Login.java @@ -16,10 +16,7 @@ public class Login extends PiztorAct { Button btnLogin; EditText edtUser, edtPass; - int loginButtonClick = 1, retryButtonClick = 2, loginFailed = 3; - - @SuppressLint("HandlerLeak") Handler handler = new Handler() { @Override public void handleMessage(Message m) { @@ -32,13 +29,14 @@ public class Login extends PiztorAct { if (m.what == 0) { ResLogin res = (ResLogin) m.obj; Log.d(LogInfo.login, LogInfo.s); - Infomation.token = res.t; - Infomation.sublist = res.sublist; - Infomation.username = res.uinfo.username; - Infomation.myInfo = new UserInfo(res.uinfo.uid); - Infomation.myInfo.setInfo(res.uinfo.gid.company, + app.token = res.t; + app.sublist = res.sublist; + app.username = res.uinfo.username; + app.mapInfo.myInfo = new UserInfo(res.uinfo.uid); + app.mapInfo.myInfo.setInfo(res.uinfo.gid.company, res.uinfo.gid.section, res.uinfo.sex, res.uinfo.nickname); + app.mapInfo.myInfo.level = res.uinfo.level; System.out.println("login !!!!" + res.sublist.size()); actMgr.trigger(AppMgr.loginSuccess); } else { @@ -67,7 +65,7 @@ public class Login extends PiztorAct { String pass = edtPass.getText().toString(); long nowtime = System.currentTimeMillis(); System.out.println(user + " : " + pass + "\n"); - AppMgr.transam.send(new ReqLogin(user, pass, nowtime, 5000)); + transam.send(new ReqLogin(user, pass, nowtime, 5000)); } @Override @@ -90,7 +88,7 @@ public class Login extends PiztorAct { ActStatus[] r = new ActStatus[2]; r[0] = new StartStatus(); r[1] = new LoginStatus(); - actMgr = new ActMgr(this, r[0], r); + actMgr = new ActMgr(appMgr, this, r[0], r); actMgr.add(r[0], loginButtonClick, r[1]); actMgr.add(r[1], loginFailed, r[0]); setContentView(R.layout.activity_login); @@ -113,16 +111,13 @@ public class Login extends PiztorAct { @Override protected void onResume() { super.onResume(); - if (AppMgr.transam == null) - Log.d(LogInfo.exception, "transam = null"); - AppMgr.transam.setHandler(handler); - + transam.setHandler(handler); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { - AppMgr.exit(); + appMgr.exit(); return true; } return super.onKeyDown(keyCode, event); diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java index 735b1a4..4efea11 100644 --- a/client/Piztor/src/com/macaroon/piztor/Main.java +++ b/client/Piztor/src/com/macaroon/piztor/Main.java @@ -1,9 +1,9 @@ package com.macaroon.piztor; +import java.lang.ref.WeakReference; import java.util.Calendar; import java.util.Vector; -import android.annotation.SuppressLint; import android.content.Context; import android.location.LocationManager; import android.os.Bundle; @@ -16,7 +16,6 @@ import android.view.Menu; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.ImageButton; -import android.widget.TextView; import android.widget.Toast; import com.baidu.location.BDLocation; @@ -26,8 +25,6 @@ import com.baidu.location.LocationClientOption; import com.baidu.mapapi.map.LocationData; import com.baidu.mapapi.map.MKMapTouchListener; import com.baidu.mapapi.map.MapView; -import com.baidu.mapapi.map.OverlayItem; -import com.baidu.mapapi.map.PopupOverlay; import com.baidu.mapapi.utils.DistanceUtil; import com.baidu.platform.comapi.basestruct.GeoPoint; @@ -41,10 +38,10 @@ public class Main extends PiztorAct { MapMaker mapMaker = null; MapView mMapView; AlertMaker alertMaker; - private Calendar calendar; GeoPoint markerPoint = null; private MKMapTouchListener mapTouchListener; private final int checkinRadius = 10; + public static int GPSrefreshrate = 5; /** * Locating component @@ -55,16 +52,22 @@ public class Main extends PiztorAct { LocationData locData = null; public MyLocationListener myListener = new MyLocationListener(); boolean isFirstLocation = true; - public static int GPSrefreshrate = 5; ImageButton btnCheckin, btnFetch, btnFocus, btnSettings; - MapInfo mapInfo; - - Transam transam; - @SuppressLint("HandlerLeak") - Handler handler = new Handler() { + + static class ReCall extends Handler { + WeakReference
outerClass; + + ReCall(Main activity) { + outerClass = new WeakReference
(activity); + } + @Override public void handleMessage(Message m) { + Main out = outerClass.get(); + if (out == null) { + System.out.println("act被回收了"); + } switch (m.what) { case Res.Login:// 上传自己信息成功or失败 Log.d("update location", "successfull"); @@ -74,9 +77,9 @@ public class Main extends PiztorAct { System.out.println("revieve ........" + userInfo.uinfo.size()); Vector uinfo = userInfo.uinfo; for (RUserInfo info : uinfo) { - System.out.println(info.latitude + " " - + info.longitude); - UserInfo r = mapInfo.getUserInfo(info.uid); + System.out + .println(info.latitude + " " + info.longitude); + UserInfo r = out.mapInfo.getUserInfo(info.uid); if (r != null) { r.setInfo(info.gid.company, info.gid.section, info.sex, info.nickname); @@ -86,54 +89,64 @@ public class Main extends PiztorAct { r.setInfo(info.gid.company, info.gid.section, info.sex, info.nickname); r.setLocation(info.latitude, info.longitude); - mapInfo.addUserInfo(r); + out.mapInfo.addUserInfo(r); } } - System.out.println("now has info number : " + mapInfo.allUsers.size()); - flushMap(); + System.out.println("now has info number : " + + out.mapInfo.allUsers.size()); + out.flushMap(); break; case Res.Logout:// 登出 - actMgr.trigger(AppMgr.logout); + out.actMgr.trigger(AppMgr.logout); break; case Res.PushMessage: ResPushMessage pushMessage = (ResPushMessage) m.obj; - receiveMessage(pushMessage.message); + out.receiveMessage(pushMessage.message); break; case Res.SendMessage: Log.d(LogInfo.resquest, "send message successfully"); break; case Res.PushLocation: ResPushLocation pushLocation = (ResPushLocation) m.obj; - upMapInfo(pushLocation.l); - flushMap(); + out.upMapInfo(pushLocation.l); + out.flushMap(); + break; + case Res.PushMarker: + ResPushMarker pushMarker = (ResPushMarker) m.obj; + MarkerInfo markerInfo = new MarkerInfo(); + markerInfo.level = pushMarker.level; + markerInfo.markerPoint = new GeoPoint( + (int) (pushMarker.latitude * 1e6), + (int) (pushMarker.longitude * 1e6)); + markerInfo.markerTimestamp = pushMarker.deadline; + out.mapMaker.receiveMarker(markerInfo); break; case -1: - actMgr.trigger(AppMgr.logout); + out.actMgr.trigger(AppMgr.logout); default: break; } } + } - void upMapInfo(Vector l) { - System.out.println("hahaha" + " " + l.size()); - for (RLocation i : l) { - UserInfo info = AppMgr.mapInfo.getUserInfo(i.id); - if (info != null) { - info.setLocation(i.latitude, i.longitude); - } else { - info = new UserInfo(i.id); - info.setLocation(i.latitude, i.longitude); - AppMgr.mapInfo.addUserInfo(info); - } + void upMapInfo(Vector l) { + for (RLocation i : l) { + UserInfo info = mapInfo.getUserInfo(i.id); + if (info != null) { + info.setLocation(i.latitude, i.longitude); + } else { + info = new UserInfo(i.id); + info.setLocation(i.latitude, i.longitude); + mapInfo.addUserInfo(info); } - flushMap(); } - }; + flushMap(); + } + + Handler handler = null; String cause(int t) { switch (t) { - case CheckinButtonPress: - return "Checkin Button Press"; case FocuseButtonPress: return "Focuse Button Press"; case SuccessFetch: @@ -148,14 +161,12 @@ public class Main extends PiztorAct { // TODO flush map view void flushMap() { if (mapMaker != null) - mapMaker.UpdateMap(AppMgr.mapInfo); + mapMaker.UpdateMap(mapInfo); else Log.d("exception", "!!!"); } void receiveMessage(String msg) { - System.out.println("receiveed push message!!!!!"); - System.out.println(msg); Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG); toast.show(); @@ -164,6 +175,7 @@ public class Main extends PiztorAct { public class MyLocationListener implements BDLocationListener { int cnt = 0; GeoPoint lastPoint = null; + @Override public void onReceiveLocation(BDLocation location) { Log.d("GPS", "Gotten"); @@ -175,15 +187,17 @@ public class Main extends PiztorAct { locData.longitude = location.getLongitude(); locData.accuracy = location.getRadius(); locData.direction = location.getDerect(); - - GeoPoint point = new GeoPoint((int)(locData.latitude * 1e6), (int)(locData.longitude * 1e6)); - if (lastPoint == null || cnt > 5 || DistanceUtil.getDistance(point, lastPoint) > 10 ) { - if (Infomation.token != null) { - Infomation.myInfo.setLocation(locData.latitude, + + GeoPoint point = new GeoPoint((int) (locData.latitude * 1e6), + (int) (locData.longitude * 1e6)); + if (lastPoint == null || cnt > 5 + || DistanceUtil.getDistance(point, lastPoint) > 10) { + if (app.token != null) { + app.mapInfo.myInfo.setLocation(locData.latitude, locData.longitude); - AppMgr.transam.send(new ReqUpdate(Infomation.token, - Infomation.username, locData.latitude, - locData.longitude, System.currentTimeMillis(), 2000)); + transam.send(new ReqUpdate(app.token, app.username, + locData.latitude, locData.longitude, System + .currentTimeMillis(), 2000)); lastPoint = point; cnt = 0; } @@ -195,22 +209,28 @@ public class Main extends PiztorAct { } int TMP = location.getLocType(); if (TMP == 61) { - Toast toast = Toast.makeText(Main.this, "Piztor : Update from GPS result (" + GPSrefreshrate + "s)", 2000); + Toast toast = Toast.makeText(Main.this, + "Piztor : Update from GPS result (" + GPSrefreshrate + + "s)", 2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } if (TMP == 161) { - Toast toast = Toast.makeText(Main.this, "Piztor : Update from Network (" + GPSrefreshrate + "s)", 2000); + Toast toast = Toast.makeText(Main.this, + "Piztor : Update from Network (" + GPSrefreshrate + + "s)", 2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } if (TMP == 65) { - Toast toast = Toast.makeText(Main.this, "Piztor : Update from Cache (" + GPSrefreshrate + "s)", 2000); + Toast toast = Toast.makeText(Main.this, + "Piztor : Update from Cache (" + GPSrefreshrate + "s)", + 2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } mapMaker.UpdateLocationOverlay(locData, hasAnimation); - + LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setCoorType("bd09ll"); @@ -232,7 +252,8 @@ public class Main extends PiztorAct { void enter(int e) { System.out.println("enter start status!!!!"); if (e == ActMgr.Create) { - System.out.println(Infomation.token + " " + Infomation.username + " " + Infomation.myInfo.uid); + System.out.println(app.token + " " + app.username + " " + + app.mapInfo.myInfo.uid); } if (e == SuccessFetch) flushMap(); @@ -246,16 +267,18 @@ public class Main extends PiztorAct { } void requestUserInfo() { - for (RGroup i : Infomation.sublist) { - ReqUserInfo r = new ReqUserInfo(Infomation.token, - Infomation.username, i, System.currentTimeMillis(), 2000); + mapInfo.clear(); + System.out.println("cleared!!!!"); + for (RGroup i : app.sublist) { + ReqUserInfo r = new ReqUserInfo(app.token, app.username, i, + System.currentTimeMillis(), 2000); transam.send(r); } System.out.println("get others infomation!!!"); } void focusOn() { - mapMaker.mMapController.animateTo(Infomation.myInfo.location); + mapMaker.mMapController.animateTo(app.mapInfo.myInfo.location); } public void InitTouchListenr() { @@ -265,7 +288,9 @@ public class Main extends PiztorAct { @Override public void onMapLongClick(GeoPoint arg0) { closeBoard(Main.this); - alertMaker.showMarkerAlert(arg0); + if (app.mapInfo.myInfo.level != 0) { + alertMaker.showMarkerAlert(arg0); + } } @Override @@ -284,54 +309,55 @@ public class Main extends PiztorAct { } public void markerCheckin() { + Log.d("checkin", "ok!!!"); if (mapMaker.getMakerLocation() == null) { Toast toast = Toast.makeText(Main.this, "No marker now!", 2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); return; } - GeoPoint curPoint = new GeoPoint((int)(locData.latitude * 1E6), (int)(locData.longitude * 1E6)); - double disFromMarker = DistanceUtil.getDistance(curPoint, mapMaker.getMakerLocation()); + mLocClient.requestLocation(); + GeoPoint curPoint = new GeoPoint((int) (locData.latitude * 1E6), + (int) (locData.longitude * 1E6)); + double disFromMarker = DistanceUtil.getDistance(curPoint, + mapMaker.getMakerLocation()); if (disFromMarker < locData.accuracy) { - mapMaker.removeMarker(); - Toast toast = Toast.makeText(Main.this, "Marker checked!", 2000); - toast.setGravity(Gravity.TOP, 0, 80); - toast.show(); + alertMaker.showCheckinAlter(); } else { - Toast toast = Toast.makeText(Main.this, "Please get closer to the marker!", 2000); + Toast toast = Toast.makeText(Main.this, + "Please get closer to the marker!", 2000); toast.setGravity(Gravity.TOP, 0, 80); toast.show(); } } - + @Override protected void onCreate(Bundle savedInstanceState) { id = "Main"; super.onCreate(savedInstanceState); - + handler = new ReCall(this); locationManager = (LocationManager) this .getSystemService(LOCATION_SERVICE); isGPSEnabled = locationManager .isProviderEnabled(locationManager.GPS_PROVIDER); - transam = AppMgr.transam; - mapInfo = AppMgr.mapInfo; ActStatus[] r = new ActStatus[1]; ActStatus startStatus = r[0] = new StartStatus(); - if (transam == null) - Log.d(LogInfo.exception, "transam = null"); - transam.setHandler(handler); - actMgr = new ActMgr(this, startStatus, r); + transam = app.transam; + + actMgr = new ActMgr(appMgr, this, startStatus, r); setContentView(R.layout.activity_main); + app.mBMapManager.start(); mMapView = (MapView) findViewById(R.id.bmapView); - mapMaker = new MapMaker(mMapView, getApplicationContext()); + mapMaker = new MapMaker(mMapView, Main.this, app); + mapMaker.InitMap(); alertMaker = new AlertMaker(Main.this, mapMaker); - if (isGPSEnabled == false) alertMaker.showSettingsAlert(); + if (isGPSEnabled == false) + alertMaker.showSettingsAlert(); mapMaker.clearOverlay(mMapView); - mapMaker.InitMap(); InitTouchListenr(); mLocClient = new LocationClient(this); - mLocClient.setAK(AppMgr.strKey); + mLocClient.setAK(myApp.getStrkey()); locData = new LocationData(); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); @@ -339,7 +365,6 @@ public class Main extends PiztorAct { option.setCoorType("bd09ll"); option.setScanSpan(GPSrefreshrate * 1000); mLocClient.setLocOption(option); - mLocClient.start(); mapMaker.UpdateLocationOverlay(locData, false); } @@ -358,21 +383,13 @@ public class Main extends PiztorAct { btnFocus = (ImageButton) findViewById(R.id.footbar_btn_focus); btnCheckin = (ImageButton) findViewById(R.id.footbar_btn_checkin); btnSettings = (ImageButton) findViewById(R.id.footbar_btn_settings); - + btnCheckin.setOnClickListener(new View.OnClickListener() { - @Override public void onClick(View arg0) { markerCheckin(); } }); - - btnFetch.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View arg0) { - - } - }); btnFocus.setOnClickListener(new View.OnClickListener() { @Override @@ -398,21 +415,29 @@ public class Main extends PiztorAct { @Override protected void onResume() { + mMapView.onResume(); + transam.setHandler(handler); isFirstLocation = true; + mLocClient.start(); requestUserInfo(); - mapMaker.onResume(); + // mapMaker.onResume(); flushMap(); super.onResume(); } @Override protected void onPause() { - mapMaker.onPause(); + // mapMaker.onPause(); + // mapMaker = null; + mLocClient.stop(); + mMapView.onPause(); + // System.gc(); super.onPause(); } @Override public void onStop() { + super.onStop(); } @@ -421,14 +446,19 @@ public class Main extends PiztorAct { if (mLocClient != null) { mLocClient.stop(); } - mapMaker.onDestroy(); + // mMapView.destroy(); + // while null? + // mMapView.destroy(); + // super.onDestroy(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { - AppMgr.exit(); + System.out.println("ready to exit!!!"); + app.mBMapManager.stop(); + appMgr.exit(); return true; } return super.onKeyDown(keyCode, event); diff --git a/client/Piztor/src/com/macaroon/piztor/MainActivity.java b/client/Piztor/src/com/macaroon/piztor/MainActivity.java new file mode 100644 index 0000000..483112d --- /dev/null +++ b/client/Piztor/src/com/macaroon/piztor/MainActivity.java @@ -0,0 +1,133 @@ +package com.macaroon.piztor; + +import java.util.Vector; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.Menu; +import android.view.View; + +public class MainActivity extends Activity { + public String token = ""; + public String uname = ""; + public int com; + public int sec; + public int step = 0; + Transam t; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + t = new Transam("192.168.1.171",2223,handler); + Thread thread = new Thread(t); + thread.start(); + + } + + Handler handler = new Handler() { + public void handleMessage(Message msg) { + switch (msg.what) { + case 0: + token = ((ResLogin) msg.obj ).t; + uname = ((ResLogin) msg.obj ).uinfo.username; + com = ((ResLogin) msg.obj ).uinfo.gid.company; + sec = ((ResLogin) msg.obj ).uinfo.gid.section; + System.out.println(com); + System.out.println(sec); + System.out.println(((ResLogin) msg.obj ).uinfo.sex); + for(int i=0;i<((ResLogin) msg.obj ).subscribeNumber;i++){ + System.out.println(((ResLogin) msg.obj ).sublist.get(i).company); + System.out.println(((ResLogin) msg.obj ).sublist.get(i).section); + } + System.out.println(token); + break; + case 2: + ResUserInfo r = (ResUserInfo) msg.obj ; + System.out.println(r.number); + for(int i=0;i ll = ((ResPushLocation)msg.obj).l; + for(int i=0;i mp; Vector allUsers; + MarkerInfo 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; + } + + @SuppressLint("UseSparseArrays") MapInfo() { mp = new HashMap(); @@ -47,12 +58,39 @@ public class MapInfo { } } +class MarkerInfo { + GeoPoint markerPoint; + long markerTimestamp; + int level; + + MarkerInfo copy() { + MarkerInfo res = new MarkerInfo(); + res.level = level; + res.markerPoint = new GeoPoint(markerPoint.getLatitudeE6(), markerPoint.getLongitudeE6()); + res.markerTimestamp = markerTimestamp; + return res; + } + +} + class UserInfo { int uid, sex; int company; //group id int section; + int level; GeoPoint location; String nickname; + + UserInfo copy() { + UserInfo res = new UserInfo(uid); + res.location = location; + res.nickname = nickname; + res.section = section; + res.company = company; + res.level = level; + return res; + } + UserInfo(int uid) { this.uid = uid; } diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java index 8df1f8a..3268a57 100644 --- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java @@ -1,79 +1,45 @@ package com.macaroon.piztor; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; -import java.util.Timer; -import java.util.TimerTask; import java.util.Vector; -import android.R.drawable; -import android.util.Log; -import android.util.AttributeSet; -import android.annotation.SuppressLint; -import android.location.Location; +import android.app.Activity; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; import android.location.LocationManager; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.view.KeyEvent; +import android.util.Log; 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.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.res.Configuration; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.drawable.Drawable; -import android.widget.FrameLayout; -import android.widget.Toast; -import android.view.View.OnClickListener; -import android.widget.RadioGroup; -import android.widget.RadioGroup.OnCheckedChangeListener; -import android.provider.Settings; - -import com.baidu.location.BDLocation; -import com.baidu.location.BDLocationListener; -import com.baidu.location.LocationClient; -import com.baidu.location.LocationClientOption; +import android.widget.Toast; -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.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; -import com.baidu.mapapi.map.MKOLSearchRecord; -import com.baidu.mapapi.map.MKOLUpdateElement; import com.baidu.mapapi.map.OverlayItem; import com.baidu.mapapi.map.PopupClickListener; import com.baidu.mapapi.map.PopupOverlay; -import com.baidu.mapapi.map.MKOfflineMap; -import com.baidu.mapapi.map.MKOfflineMapListener; -import com.baidu.mapapi.search.MKPoiInfo; -import com.baidu.mapapi.search.MKPoiResult; -import com.baidu.platform.comapi.basestruct.GeoPoint; +import com.baidu.platform.comapi.basestruct.GeoPoint; public class MapMaker extends Activity { - + // MapView controlling component private MapView mMapView = null; MapController mMapController = null; MKOfflineMap mOffline = null; // Default center - private final static GeoPoint sjtuCenter = new GeoPoint((int)(31.032247 * 1E6), (int)(121.445937 * 1E6)); + private final static GeoPoint sjtuCenter = new GeoPoint( + (int) (31.032247 * 1E6), (int) (121.445937 * 1E6)); // Map layers and items private MyOverlay mOverlay = null; @@ -83,12 +49,21 @@ public class MapMaker extends Activity { 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; // marker layer - private MyOverlay markerOverlay; private 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; // Popup component private PopupOverlay popLay = null; @@ -99,7 +74,7 @@ public class MapMaker extends Activity { private View popupLeft = null; private View popupRight = null; - //misc + // misc private Context context; private LocationManager locationManager = null; boolean isGPSEnabled; @@ -107,14 +82,16 @@ public class MapMaker extends Activity { private Drawable[] myBM; private final int iconNum = 4; + myApp app; + /** * Constructor */ - public MapMaker(MapView mapView, Context cc) { - + public MapMaker(MapView mapView, Context cc, myApp app) { + this.app = app; mMapView = mapView; mMapController = mMapView.getController(); - + mMapController.setCenter(sjtuCenter); mMapController.setZoom(16); mMapController.setRotation(-22); @@ -129,7 +106,7 @@ public class MapMaker extends Activity { * Layer for my location */ public class LocationOverlay extends MyLocationOverlay { - + public LocationOverlay(MapView mapView) { super(mapView); } @@ -139,29 +116,30 @@ public class MapMaker extends Activity { * Layer for items(other users) */ public class MyOverlay extends ItemizedOverlay { - + public MyOverlay(Drawable defaultMaker, MapView mapView) { super(defaultMaker, mapView); } - + @Override public boolean onTap(int index) { - - if (index == 0 && nowMarker != null) { + + if (nowMarker != null && index == markerIndex) { OverlayItem item = getItem(index); - //TODO - ///////////////////////////////////////////////////////// - popupText.setText("hour"); - leftText.setText("minute"); - Bitmap bitmap [] = { - BMapUtil.getBitmapFromView(popupLeft), + // TODO + // /////////////////////////////////////////////////////// + leftText.setText(nowMarkerHour + "点"); + popupText.setText(nowMarkerMinute + "分"); + Bitmap bitmap[] = { BMapUtil.getBitmapFromView(popupLeft), BMapUtil.getBitmapFromView(popupInfo), - BMapUtil.getBitmapFromView(popupRight), - }; - popLay.showPopup(bitmap, item.getPoint(),32); + BMapUtil.getBitmapFromView(popupRight), }; + popLay.showPopup(bitmap, item.getPoint(), 32); } else { OverlayItem item = getItem(index); - popupText.setText("UID"); + UserInfo tmpInfo = preMapInfo + .getUserInfo(markerToInt.get(item)); + String itemInfo = tmpInfo.company + "连" + tmpInfo.section + "班"; + popupText.setText(itemInfo); Bitmap bitmap = BMapUtil.getBitmapFromView(popupInfo); popLay.showPopup(bitmap, item.getPoint(), 32); } @@ -170,22 +148,22 @@ public class MapMaker extends Activity { @Override public boolean onTap(GeoPoint pt, MapView mapView) { - - if(popLay != null) { + + if (popLay != null) { popLay.hidePop(); } return false; } } - + /** * Initialize offline map */ public void InitOfflineMap() { - + mOffline = new MKOfflineMap(); mOffline.init(mMapController, new MKOfflineMapListener() { - + @Override public void onGetOfflineMapState(int type, int state) { switch (type) { @@ -204,7 +182,8 @@ public class MapMaker extends Activity { int num = mOffline.scan(); String msg = ""; if (num == 0) { - //msg = "No offline map found. It may have been loaded already or misplaced."; + // msg = + // "No offline map found. It may have been loaded already or misplaced."; } else { msg = String.format("Loaded %d offline maps.", num); } @@ -229,30 +208,32 @@ public class MapMaker extends Activity { * Initialize other users layer */ public void InitMyOverLay() { - - //TODO - ///////////////////////////////////////////////////////////////// + + // TODO + // /////////////////////////////////////////////////////////////// hash = new HashMap(); - mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView); + markerToInt = new HashMap(); + mOverlay = new MyOverlay(context.getResources().getDrawable( + R.drawable.circle_red), mMapView); mMapView.getOverlays().add(mOverlay); - markerOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.marker1), mMapView); } - + /** * Initialize popup */ public void InitPopup() { - - LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); viewCache = inflater.inflate(R.layout.custom_text_view, null); - popupInfo = (View)viewCache.findViewById(R.id.popinfo); - popupLeft = (View)viewCache.findViewById(R.id.popleft); - popupRight = (View)viewCache.findViewById(R.id.popright); - popupText = (TextView)viewCache.findViewById(R.id.textcache); - leftText = (TextView)viewCache.findViewById(R.id.popleft); + popupInfo = (View) viewCache.findViewById(R.id.popinfo); + popupLeft = (View) viewCache.findViewById(R.id.popleft); + popupRight = (View) viewCache.findViewById(R.id.popright); + popupText = (TextView) viewCache.findViewById(R.id.textcache); + leftText = (TextView) viewCache.findViewById(R.id.popleft); PopupClickListener popListener = new PopupClickListener() { - + @Override public void onClickedPopup(int index) { // when the popup is clicked @@ -281,47 +262,51 @@ public class MapMaker extends Activity { * Initialize map */ public void InitMap() { - + InitLocationOverlay(); InitMyOverLay(); InitPopup(); InitOfflineMap(); myBM = new Drawable[20]; initMyIcons(); - //InitTouchListenr(); + // InitTouchListenr(); } public void initMyIcons() { - myBM[0] = context.getResources().getDrawable(R.drawable.circle_red); + myBM[0] = context.getResources().getDrawable(R.drawable.circle_blue); myBM[1] = context.getResources().getDrawable(R.drawable.circle_green); myBM[2] = context.getResources().getDrawable(R.drawable.circle_glass); myBM[3] = context.getResources().getDrawable(R.drawable.circle_yellow); myBM[4] = context.getResources().getDrawable(R.drawable.circle_wood); - } - + } + public Drawable getGroupIcon(int gid) { - if (gid == Infomation.myInfo.section) return myBM[0]; - else return myBM[gid % iconNum]; + if (gid == preMapInfo.myInfo.section) + return myBM[0]; + else + return myBM[gid % iconNum]; } - + /** * 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) { - mMapController.animateTo(new GeoPoint((int)(locationData.latitude * 1E6) - , (int)(locationData.longitude * 1E6))); + mMapController.animateTo(new GeoPoint( + (int) (locationData.latitude * 1E6), + (int) (locationData.longitude * 1E6))); } } - + /** * Update to draw other users */ public void UpdateMap(MapInfo mapInfo) { - + if (mapInfo == null) { if (mOverlay != null && mOverlay.getAllItem().size() != 0) { mOverlay.removeAll(); @@ -332,84 +317,167 @@ public class MapMaker extends Activity { // first remove all old users that are not here now if (preMapInfo != null) { for (UserInfo i : preMapInfo.getVector()) { - if (i.uid == Infomation.myInfo.uid) continue; + if (i.uid == preMapInfo.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); } } } mMapView.refresh(); + preMapInfo = mapInfo.copy(); // then update and add items for (UserInfo i : mapInfo.getVector()) { - if (i.uid == Infomation.myInfo.uid) continue; - if (hash.containsKey(i.uid) == false) { - GeoPoint p = new GeoPoint((int)(i.getLatitude() * 1E6), (int)(i.getLongitude() * 1E6)); - curItem = new OverlayItem(p, "USERNAME_HERE", "USER_SNIPPET_HERE"); - //TODO getDrawable - /////////////////////////////// + if (i.uid == preMapInfo.myInfo.uid) + continue; + if (hash.containsKey(i.uid) == false) { + GeoPoint p = new GeoPoint((int) (i.getLatitude() * 1E6), + (int) (i.getLongitude() * 1E6)); + curItem = new OverlayItem(p, "USERNAME_HERE", + "USER_SNIPPET_HERE"); + // TODO getDrawable + // ///////////////////////////// curItem.setMarker(getGroupIcon(i.section)); mOverlay.addItem(curItem); hash.put(i.uid, curItem); - //if (mMapView != null) - // mMapView.refresh(); + markerToInt.put(curItem, i.uid); + // if (mMapView != null) + // mMapView.refresh(); } else { - GeoPoint p = new GeoPoint((int)(i.getLatitude() * 1E6), (int)(i.getLongitude() * 1E6)); + GeoPoint p = new GeoPoint((int) (i.getLatitude() * 1E6), + (int) (i.getLongitude() * 1E6)); curItem = hash.get(i.uid); curItem.setGeoPoint(p); mOverlay.updateItem(curItem); - //if (mMapView != null) - // mMapView.refresh(); + // if (mMapView != null) + // mMapView.refresh(); } } if (mMapView != null) { mMapView.refresh(); } - preMapInfo = mapInfo; } - + + @SuppressWarnings("deprecation") + public void receiveMarker(MarkerInfo markerInfo) { + Log.d("marker", "Marker received!"); + 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); + 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); + 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); + 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); + return; + } + } + + void sendMarker() { + ReqSetMarker req = new ReqSetMarker(app.token, app.username, nowMarker + .getPoint().getLatitudeE6() / 1e6, nowMarker.getPoint() + .getLongitudeE6() / 1e6, (int)nowMarkerTimestamp, + System.currentTimeMillis(), 3000l); + Log.d("marker", "Sent marker" + nowMarker.getPoint().getLatitudeE6() + " " + + nowMarker.getPoint().getLongitudeE6()); + app.transam.send(req); + } + /** * Draw a marker */ public void DrawMarker(GeoPoint markerPoint) { - - if (nowMarker != null) { + + if (preMapInfo == null) return; + + if (nowMarker != null && preMapInfo.myInfo.level >= nowMarkerLevel) { nowMarker.setGeoPoint(markerPoint); + nowMarkerHour = newMarkerHour; + nowMarkerMinute = newMarkerMinute; + nowMarkerTimestamp = newMarkerTimestamp; + nowMarkerLevel = preMapInfo.myInfo.level; + + sendMarker(); + Log.d("marker", "Sent and replace"); mOverlay.updateItem(nowMarker); mMapView.refresh(); mMapCo