summaryrefslogtreecommitdiff
path: root/client/Piztor
diff options
context:
space:
mode:
Diffstat (limited to 'client/Piztor')
-rw-r--r--client/Piztor/AndroidManifest.xml91
-rw-r--r--client/Piztor/res/layout/activity_login.xml3
-rw-r--r--client/Piztor/res/layout/activity_subscribe_settings.xml16
-rw-r--r--client/Piztor/res/layout/checkindialog.xml4
-rw-r--r--client/Piztor/res/menu/subscribe_settings.xml9
-rw-r--r--client/Piztor/res/values/strings.xml3
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AccountSettings.java5
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ActMgr.java9
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AlertMaker.java68
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AppMgr.java93
-rw-r--r--client/Piztor/src/com/macaroon/piztor/EException.java22
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Infomation.java10
-rw-r--r--client/Piztor/src/com/macaroon/piztor/InitAct.java35
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Login.java25
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java212
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MainActivity.java133
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapInfo.java38
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java346
-rw-r--r--client/Piztor/src/com/macaroon/piztor/PiztorAct.java33
-rw-r--r--client/Piztor/src/com/macaroon/piztor/PushClient.java26
-rw-r--r--client/Piztor/src/com/macaroon/piztor/RUserInfo.java4
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Req.java32
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Res.java48
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Rlocation.java13
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Settings.java144
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SocketClient.java91
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java322
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Transam.java205
-rw-r--r--client/Piztor/src/com/macaroon/piztor/myApp.java52
29 files changed, 1450 insertions, 642 deletions
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" />
- <!--使用网络功能所需权限 -->
-<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
-</uses-permission>
-<uses-permission android:name="android.permission.INTERNET">
-</uses-permission>
-<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
-</uses-permission>
-<uses-permission android:name="android.permission.CHANGE_WIFI_STATE">
-</uses-permission>
-<!-- SDK离线地图和cache功能需要读写外部存储器 -->
-<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
-</uses-permission>
-<!-- 获取设置信息和详情页直接拨打电话需要以下权限 -->
-<uses-permission android:name="android.permission.READ_PHONE_STATE">
-</uses-permission>
-<!-- 使用定位功能所需权限,demo已集成百度定位SDK,不使用定位功能可去掉以下6项 -->
-<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
-</uses-permission>
-<permission android:name="android.permission.BAIDU_LOCATION_SERVICE">
-</permission>
-<uses-permission android:name="android.permission.BAIDU_LOCATION_SERVICE">
-</uses-permission>
-<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
-</uses-permission>
-<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION">
-</uses-permission>
-<uses-permission android:name="android.permission.ACCESS_GPS"/>
-
+ <!-- 使用网络功能所需权限 -->
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
+ </uses-permission>
+ <uses-permission android:name="android.permission.INTERNET" >
+ </uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
+ </uses-permission>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >
+ </uses-permission>
+ <!-- SDK离线地图和cache功能需要读写外部存储器 -->
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
+ </uses-permission>
+ <!-- 获取设置信息和详情页直接拨打电话需要以下权限 -->
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" >
+ </uses-permission>
+ <!-- 使用定位功能所需权限,demo已集成百度定位SDK,不使用定位功能可去掉以下6项 -->
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
+ </uses-permission>
+
+ <permission android:name="android.permission.BAIDU_LOCATION_SERVICE" >
+ </permission>
+
+ <uses-permission android:name="android.permission.BAIDU_LOCATION_SERVICE" >
+ </uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >
+ </uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" >
+ </uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_GPS" />
<application
+ android:name=".myApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
@@ -47,6 +49,7 @@
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
+
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@@ -56,27 +59,35 @@
</activity>
<activity
android:name="com.macaroon.piztor.Main"
- android:label="@string/title_activity_main"
- android:screenOrientation="portrait"
- android:configChanges="orientation">
+ android:configChanges="orientation"
+ android:label="@string/title_activity_main"
+ android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.macaroon.piztor.Settings"
- android:label="@string/title_activity_settings"
- android:screenOrientation="portrait"
- android:configChanges="orientation">
+ android:configChanges="orientation"
+ android:label="@string/title_activity_settings"
+ android:screenOrientation="portrait" >
</activity>
+ <activity
+ android:name="com.macaroon.piztor.SubscribeSettings"
+ android:configChanges="orientation"
+ android:label="@string/title_activity_subscribesettings"
+ android:screenOrientation="portrait" >
+ </activity>
+
<service
android:name="com.baidu.location.f"
android:enabled="true"
android:process=":remote" >
</service>
</application>
-
- <supports-screens android:largeScreens="true"
- android:normalScreens="true"
- android:smallScreens="true"
- android:resizeable="true"
- android:anyDensity="true"/>
+
+ <supports-screens
+ android:anyDensity="true"
+ android:largeScreens="true"
+ android:normalScreens="true"
+ android:resizeable="true"
+ android:smallScreens="true" />
</manifest>
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"/>
<View
android:background="#ffc0c3c4"
diff --git a/client/Piztor/res/layout/activity_subscribe_settings.xml b/client/Piztor/res/layout/activity_subscribe_settings.xml
new file mode 100644
index 0000000..53ff8ee
--- /dev/null
+++ b/client/Piztor/res/layout/activity_subscribe_settings.xml
@@ -0,0 +1,16 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context=".SubscribeSettings" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/hello_world" />
+
+</RelativeLayout>
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"/>
<ProgressBar
android:id="@+id/checkin_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:max="10000"
android:layout_gravity="center"
android:gravity="center" />
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 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item
+ android:id="@+id/action_settings"
+ android:orderInCategory="100"
+ android:showAsAction="never"
+ android:title="@string/action_settings"/>
+
+</menu>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Piztor</string>
@@ -25,5 +26,7 @@
<string name="update_info">My Account</string>
<string name="subscribe_info">Subscribe information</string>
<string name="change">Check &amp; Update</string>
+ <string name="title_activity_subscribesettings">SubscribeSettings</string>
+ <string name="title_activity_subscribe_settings">SubscribeSettings</string>
</resources>
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<ActStatus, HashMap<Integer, ActStatus>> 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<Class<?>, HashMap<Integer, Class<?>>> mp;
+ HashSet<PiztorAct> acts;
+ ActivityStatus status;
+ PiztorAct nowAct;
- static MapInfo mapInfo;
-
- static HashMap<Class<?>, HashMap<Integer, Class<?>>> mp;
- static HashSet<PiztorAct> acts;
-
- static void addAct(PiztorAct act) {
+ void addAct(PiztorAct act) {
if (acts == null)
acts = new HashSet<PiztorAct>();
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<Integer, Class<?>> 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<Integer, Class<?>>());
}
- 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<Class<?>, HashMap<Integer, Class<?>>>();
- 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<RGroup> 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<Main> outerClass;
+
+ ReCall(Main activity) {
+ outerClass = new WeakReference<Main>(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<RUserInfo> 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<RLocation> 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<RLocation> 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<r.number;i++){
+ System.out.println(r.uinfo.get(i).nickname);
+ System.out.println(r.uinfo.get(i).latitude);
+ System.out.println(r.uinfo.get(i).longitude);
+ }
+ break;
+ case 100:
+ System.out.println(((ResPushMessage) msg.obj).message);
+ break;
+ case 101:
+ int nn = ((ResPushLocation)msg.obj).n;
+ Vector<RLocation> ll = ((ResPushLocation)msg.obj).l;
+ for(int i=0;i<nn;i++){
+ System.out.println(ll.get(i).latitude + " " + ll.get(i).longitude);
+ }
+ break;
+ case -1:
+ System.out.println(-1);
+ }
+ super.handleMessage(msg);
+ }
+ };
+
+
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+
+
+
+
+ public void sendMessage(View view) {
+
+ if(step == 0){
+ long time = System.currentTimeMillis();
+ ReqLogin r = new ReqLogin("hello","world",time,2000);
+ t.send(r);
+ step++;
+ }
+ else if(step == 1){
+ long time = System.currentTimeMillis();
+ ReqUpdate r = new ReqUpdate (token,uname,123.456,654.321,time,2000);
+ t.send(r);
+ step++;
+ }
+ else if(step == 2){
+ long time = System.currentTimeMillis();
+ ReqSendMessage r = new ReqSendMessage (token,uname,"wurusai",time,2000);
+ t.send(r);
+ step++;
+ }
+ else if(step == 3){
+ long time = System.currentTimeMillis();
+ ReqLogout r = new ReqLogout(token,uname,time,2000);
+ t.send(r);
+ step++;
+ }
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+}
+
+
+
+
+
+
diff --git a/client/Piztor/src/com/macaroon/piztor/MapInfo.java b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
index d49ac1e..857ea66 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapInfo.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
@@ -13,8 +13,19 @@ import android.location.Location;
public class MapInfo {
HashMap<Integer, UserInfo> mp;
Vector<UserInfo> allUsers;
+ MarkerInfo markerInfo;
UserInfo myInfo;
+
+ MapInfo copy() {
+ MapInfo res = new MapInfo();
+ res.mp = (HashMap<Integer, UserInfo>)mp.clone();
+ res.allUsers = (Vector<UserInfo>) allUsers.clone();
+ res.myInfo = myInfo.copy();
+ return res;
+ }
+
+
@SuppressLint("UseSparseArrays")
MapInfo() {
mp = new HashMap<Integer, UserInfo>();
@@ -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<UserInfo> freshManInfo = null;
+
// hash from uid to overlay item
private HashMap<Integer, OverlayItem> hash = null;
+ private HashMap<OverlayItem, Integer> 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<Integer, OverlayItem>();
- mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView);
+ markerToInt = new HashMap<OverlayItem, Integer>();
+ 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();
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 = preMapInfo.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);
}
- nowMarker = new OverlayItem(markerPoint, "MARKER_NAME", "");
- nowMarker.setMarker(context.getResources().getDrawable(R.drawable.marker_red));
- Log.d("marker", "new marker created");
- mOverlay.addItem(nowMarker);
- mMapView.refresh();
- mMapController.animateTo(markerPoint);
}
public GeoPoint getMakerLocation() {
- if (nowMarker == null) return null;
- else return nowMarker.getPoint();
+ if (nowMarker == null)
+ return null;
+ else
+ return nowMarker.getPoint();
}
-
+
public void removeMarker() {
- if (nowMarker == null) return;
+ if (nowMarker == null)
+ return;
mOverlay.removeItem(nowMarker);
nowMarker = null;
mMapView.refresh();
}
-
+
/**
* Remove all other users
*/
public void clearOverlay(View view) {
-
- if(mOverlay != null && mOverlay.getAllItem().size() != 0) {
+
+ if (mOverlay != null && mOverlay.getAllItem().size() != 0) {
mOverlay.removeAll();
mMapView.refresh();
- }
+ }
}
/**
@@ -420,20 +488,20 @@ public class MapMaker extends Activity {
clearOverlay(null);
mOverlay.addItem(mItems);
}
-
+
@Override
protected void onPause() {
mMapView.onPause();
}
- @Override
+ @Override
protected void onResume() {
mMapView.onResume();
- }
+ }
@Override
protected void onDestroy() {
mMapView.destroy();
}
-
+
}
diff --git a/client/Piztor/src/com/macaroon/piztor/PiztorAct.java b/client/Piztor/src/com/macaroon/piztor/PiztorAct.java
index abfab12..0116273 100644
--- a/client/Piztor/src/com/macaroon/piztor/PiztorAct.java
+++ b/client/Piztor/src/com/macaroon/piztor/PiztorAct.java
@@ -6,59 +6,66 @@ import android.os.Bundle;
public class PiztorAct extends Activity {
String id;
ActMgr actMgr;
-
+ AppMgr appMgr;
+ MapInfo mapInfo;
+ Transam transam;
+ myApp app;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println(id + " on create");
- AppMgr.addAct(this);
- AppMgr.setStatus(AppMgr.ActivityStatus.create);
- AppMgr.nowAct = this;
+ app = (myApp) getApplication();
+ transam = app.transam;
+ appMgr = app.appMgr;
+ mapInfo = app.mapInfo;
+ appMgr.addAct(this);
+ appMgr.setStatus(AppMgr.ActivityStatus.create);
+ appMgr.nowAct = this;
}
@Override
protected void onStart() {
super.onStart();
System.out.println(id + " on start");
- AppMgr.setStatus(AppMgr.ActivityStatus.start);
- AppMgr.nowAct = this;
+ appMgr.setStatus(AppMgr.ActivityStatus.start);
+ appMgr.nowAct = this;
}
@Override
protected void onStop() {
super.onStop();
System.out.println(id + " on stop");
- AppMgr.setStatus(AppMgr.ActivityStatus.stop);
+ appMgr.setStatus(AppMgr.ActivityStatus.stop);
}
@Override
protected void onResume() {
super.onResume();
System.out.println(id + " on resume");
- AppMgr.setStatus(AppMgr.ActivityStatus.resume);
- AppMgr.nowAct = this;
+ appMgr.setStatus(AppMgr.ActivityStatus.resume);
+ appMgr.nowAct = this;
}
@Override
protected void onPause() {
super.onPause();
System.out.println(id + " on pause");
- AppMgr.setStatus(AppMgr.ActivityStatus.pause);
+ appMgr.setStatus(AppMgr.ActivityStatus.pause);
}
@Override
protected void onRestart() {
super.onRestart();
System.out.println(id + " on restart");
- AppMgr.setStatus(AppMgr.ActivityStatus.restart);
+ appMgr.setStatus(AppMgr.ActivityStatus.restart);
}
@Override
protected void onDestroy() {
super.onDestroy();
- AppMgr.removeAct(this);
+// appMgr.removeAct(this);
System.out.println(id + " on destroy");
- AppMgr.setStatus(AppMgr.ActivityStatus.destroy);
+ appMgr.setStatus(AppMgr.ActivityStatus.destroy);
}
}
diff --git a/client/Piztor/src/com/macaroon/piztor/PushClient.java b/client/Piztor/src/com/macaroon/piztor/PushClient.java
index fff39fe..7cecfba 100644
--- a/client/Piztor/src/com/macaroon/piztor/PushClient.java
+++ b/client/Piztor/src/com/macaroon/piztor/PushClient.java
@@ -28,8 +28,10 @@ public class PushClient {
static final int Message = 0;
static final int Location = 1;
+ static final int Marker = 2;
static final int PushMessage =100;
static final int PushLocation =101;
+ static final int PushMarker =102;
static final int Reconnect =-2;
@@ -46,6 +48,7 @@ public class PushClient {
client = new Socket();
client.connect(new InetSocketAddress(site,port), retime);
client.setSoTimeout(2000);
+ //client.setTcpNoDelay(true);
} catch (UnknownHostException e) {
e.printStackTrace();
throw e;
@@ -169,7 +172,28 @@ public class PushClient {
out.write(o);
out.flush();
break;
- }
+ case Marker:
+ int lv = in.readUnsignedByte();
+ double lat = in.readDouble();
+ double lot = in.readDouble();
+ int dtime = in.readInt();
+ if(LastPrint != p) {
+ Message msg = new Message();
+ msg.what = PushMarker;
+ msg.obj = new ResPushMarker(lat,lot,dtime,lv);
+ recall.sendMessage(msg);
+ LastPrint = p;
+ }
+ Convert.write(o,Convert.intToBytes(outlen),pos);
+ pos+=IntLength;
+ o[pos]=(byte) Marker;
+ pos+=ByteLength;
+ Convert.write(o,Convert.hexStringToBytes(p),pos);
+ pos+=FingerPrintLength;
+ out.write(o);
+ out.flush();
+ break;
+ }
} catch (IOException e) {
e.printStackTrace();
diff --git a/client/Piztor/src/com/macaroon/piztor/RUserInfo.java b/client/Piztor/src/com/macaroon/piztor/RUserInfo.java
index 3b24aa2..7deadf4 100644
--- a/client/Piztor/src/com/macaroon/piztor/RUserInfo.java
+++ b/client/Piztor/src/com/macaroon/piztor/RUserInfo.java
@@ -8,9 +8,10 @@ public class RUserInfo {
double longitude; //longitude
RGroup gid; //gid
int sex; //type 0 for female,type 1 for male
+ int level; //user level
- RUserInfo(int u,String user,String nick,double lat,double lot,RGroup g,int s){
+ RUserInfo(int u,String user,String nick,double lat,double lot,RGroup g,int s,int l){
uid = u;
username = user;
nickname = nick;
@@ -18,5 +19,6 @@ public class RUserInfo {
longitude = lot;
gid = g;
sex =s;
+ level = l;
}
} \ 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 f4c3a1f..4de1045 100644
--- a/client/Piztor/src/com/macaroon/piztor/Req.java
+++ b/client/Piztor/src/com/macaroon/piztor/Req.java
@@ -112,3 +112,35 @@ class ReqSendMessage extends Req{
}
}
+//--------------------------------------//
+// Set Marker //
+//--------------------------------------//
+
+class ReqSetMarker extends Req{
+ double latitude;
+ double longitude;
+ int deadline;
+
+ ReqSetMarker(String token,String name,double lat,double lot,int dtime,long time,long alive){
+ super(7,token,name,time,alive); //for type 7
+ latitude = lat;
+ longitude = lot;
+ deadline = dtime;
+ }
+}
+
+//--------------------------------------//
+// Set Password //
+//--------------------------------------//
+
+class ReqSetPassword extends Req{
+ String oldpassword;
+ 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;
+ }
+}
+
diff --git a/client/Piztor/src/com/macaroon/piztor/Res.java b/client/Piztor/src/com/macaroon/piztor/Res.java
index 699de45..63e35aa 100644
--- a/client/Piztor/src/com/macaroon/piztor/Res.java
+++ b/client/Piztor/src/com/macaroon/piztor/Res.java
@@ -11,8 +11,12 @@ public class Res{
static final int Logout =4;
static final int StartPush =5;
static final int SendMessage =6;
+ static final int SetMarker =7;
+ static final int SetPassword =8;
+
static final int PushMessage =100;
- static final int PushLocation =101;
+ static final int PushLocation =101;
+ static final int PushMarker =102;
int type;
Res(int t){
@@ -109,6 +113,29 @@ class ResSendMessage extends Res{
}
}
+//--------------------------------------//
+// Respond to set marker //
+//--------------------------------------//
+
+class ResSetMarker extends Res{
+
+ ResSetMarker(){
+ super(7); //for type 7
+ }
+}
+
+//--------------------------------------//
+// Respond to set password //
+//--------------------------------------//
+
+class ResSetPassword extends Res{
+
+ ResSetPassword(){
+ super(8); //for type 8
+ }
+}
+
+
//---------------------------------------------------------------------------------------------------//
@@ -143,4 +170,23 @@ class ResPushLocation extends Res{
l = locationvec;
n = num;
}
+}
+
+//--------------------------------------//
+// Push Marker //
+//--------------------------------------//
+
+class ResPushMarker extends Res{
+ double latitude;
+ double longitude;
+ int deadline;
+ int level;
+
+ ResPushMarker(double lat,double lot,int dtime,int lv){
+ super(102); //for type 102
+ latitude = lat;
+ longitude = lot;
+ deadline = dtime;
+ level = lv;
+ }
} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/Rlocation.java b/client/Piztor/src/com/macaroon/piztor/Rlocation.java
new file mode 100644
index 0000000..c2d429c
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/Rlocation.java
@@ -0,0 +1,13 @@
+package com.macaroon.piztor;
+
+class Rlocation{
+ int id; //id
+ double latitude; //latitude
+ double longitude; //longitude
+
+ Rlocation(int i,double lat,double lot){
+ id = i;
+ latitude = lat;
+ longitude = lot;
+ }
+} \ 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 b334cc4..ad98662 100644
--- a/client/Piztor/src/com/macaroon/piztor/Settings.java
+++ b/client/Piztor/src/com/macaroon/piztor/Settings.java
@@ -1,7 +1,10 @@
package com.macaroon.piztor;
+import java.lang.ref.WeakReference;
import java.util.Vector;
+import com.baidu.platform.comapi.basestruct.GeoPoint;
+
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
@@ -10,22 +13,35 @@ import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
+import android.widget.SeekBar;
+import android.widget.TextView;
import android.widget.Toast;
public class Settings extends PiztorAct {
- Button logout;
+ Button logout, subscribe, account;
MapInfo mapInfo;
Transam transam;
// Event
final static int logoutButtonPressed = 10;
final static int logoutFailed = 11;
+
+ private int currentRate;
+
+ static class ReCall extends Handler {
+ WeakReference<Settings> outerClass;
+
+ ReCall(Settings activity) {
+ outerClass = new WeakReference<Settings>(activity);
+ }
- @SuppressLint("HandlerLeak")
- Handler handler = new Handler() {
@Override
public void handleMessage(Message m) {
+ Settings out = outerClass.get();
+ if (out == null) {
+ System.out.println("act被回收了");
+ }
switch (m.what) {
- case Res.Update:// 上传自己信息成功or失败
+ case Res.Login:// 上传自己信息成功or失败
Log.d("update location", "successfull");
break;
case Res.UserInfo:// 得到用户信息
@@ -33,9 +49,9 @@ public class Settings extends PiztorAct {
System.out.println("revieve ........" + userInfo.uinfo.size());
Vector<RUserInfo> 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);
@@ -45,39 +61,50 @@ public class Settings 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 : "
+ + out.mapInfo.allUsers.size());
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);
+ out.upMapInfo(pushLocation.l);
+ 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;
break;
+ case -1:
+ out.actMgr.trigger(AppMgr.logout);
default:
break;
}
}
- };
-
+ }
+ ReCall handler = new ReCall(this);
void upMapInfo(Vector<RLocation> l) {
for (RLocation i : l) {
- UserInfo info = AppMgr.mapInfo.getUserInfo(i.id);
+ 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);
- AppMgr.mapInfo.addUserInfo(info);
+ mapInfo.addUserInfo(info);
}
}
}
@@ -94,7 +121,7 @@ public class Settings extends PiztorAct {
@Override
void enter(int e) {
System.out.println("!!!!!!!logout info send!!!!!!!!");
- transam.send(new ReqLogout(Infomation.token, Infomation.username,
+ transam.send(new ReqLogout(app.token, app.username,
System.currentTimeMillis(), 2000));
}
@@ -105,18 +132,46 @@ public class Settings extends PiztorAct {
}
+ public class mySeekBarListener implements SeekBar.OnSeekBarChangeListener {
+
+ private SeekBar seekBar;
+ private TextView refreshrate;
+
+ public mySeekBarListener() {
+ Log.d("seek", "new");
+ seekBar = (SeekBar) Settings.this.findViewById(R.id.settings_GPSrefreshrate_bar);
+ refreshrate = (TextView) Settings.this.findViewById(R.id.settings_GPSrefreshrate);
+ seekBar.setOnSeekBarChangeListener(this);
+ }
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress,
+ boolean fromUser) {
+ if (progress == 0) progress = 1;
+ refreshrate.setText(progress + "s each update");
+ currentRate = progress;
+ Log.d("seek", "cur " + progress);
+ }
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mapInfo = AppMgr.mapInfo;
- transam = AppMgr.transam;
- if (transam == null)
- Log.d(LogInfo.exception, "transam = null");
+ app = (myApp) getApplication();
+ appMgr = app.appMgr;
+ mapInfo = app.mapInfo;
+ transam = app.transam;
transam.setHandler(handler);
ActStatus[] r = new ActStatus[3];
ActStatus start = r[0] = new EmptyStatus();
ActStatus logout = r[2] = new LogoutStatus();
- actMgr = new ActMgr(this, start, r);
+ actMgr = new ActMgr(appMgr, this, start, r);
actMgr.add(start, logoutButtonPressed, logout);
actMgr.add(logout, logoutFailed, start);
setContentView(R.layout.activity_settings);
@@ -126,14 +181,61 @@ public class Settings extends PiztorAct {
protected void onStart() {
super.onStart();
logout = (Button) findViewById(R.id.settings_btn_logout);
+ subscribe = (Button) findViewById(R.id.settings_btn_subscribe);
+ account = (Button) findViewById(R.id.settings_btn_updateinfo);
+ initGPSrate();
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actMgr.trigger(logoutButtonPressed);
}
});
+ subscribe.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ actMgr.trigger(AppMgr.subscribe);
+ }
+ });
+ account.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ actMgr.trigger(AppMgr.account);
+ }
+ });
}
+ private void setGPSrate() {
+ if (currentRate == 0) currentRate = 1;
+ Main.GPSrefreshrate = currentRate;
+ }
+
+ private void initGPSrate() {
+ currentRate = Main.GPSrefreshrate;
+ TextView text1 = (TextView) Settings.this.findViewById(R.id.settings_GPSrefreshrate);
+ text1.setText(currentRate + "s each update");
+ SeekBar bar1 = (SeekBar) Settings.this.findViewById(R.id.settings_GPSrefreshrate_bar);
+ bar1.setProgress(currentRate);
+ bar1.setOnSeekBarChangeListener(new mySeekBarListener());
+ }
+
+ @Override
+ protected void onDestroy() {
+ setGPSrate();
+ super.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ setGPSrate();
+ super.onPause();
+ }
+
+ @Override
+ protected void onPause() {
+ setGPSrate();
+ super.onPause();
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
diff --git a/client/Piztor/src/com/macaroon/piztor/SocketClient.java b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
index 58b20c7..befe7fa 100644
--- a/client/Piztor/src/com/macaroon/piztor/SocketClient.java
+++ b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
@@ -2,6 +2,7 @@ package com.macaroon.piztor;
import java.io.DataInputStream;
import java.io.DataOutputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -29,6 +30,8 @@ public class SocketClient {
static final int Logout =4;
static final int StartPush =5;
static final int SendMessage =6;
+ static final int SetMarker =7;
+ static final int SetPassword =8;
static final int ClosePush =-5;
@@ -39,7 +42,11 @@ public class SocketClient {
static final int GroupID =5;
static final int Latitude =6;
static final int Longitude =7;
+ static final int Level =8;
+ static final int PasswordFailed =5;
+ static final int ServerFetchFailed =4;
+ static final int LevelFailed =3;
static final int StatusFailed = 2;
static final int TimeOut = 1;
static final int Success = 0;
@@ -50,6 +57,7 @@ public class SocketClient {
client = new Socket();
client.connect(new InetSocketAddress(site,port), retime);
client.setSoTimeout(retime);
+ //client.setTcpNoDelay(true);
} catch (UnknownHostException e) {
e.printStackTrace();
throw e;
@@ -187,6 +195,52 @@ public class SocketClient {
pos+=ByteLength;
out.write(b);
break;
+ case SetMarker:
+ ReqSetMarker rsm = (ReqSetMarker) req;
+ len = IntLength+ByteLength+TokenLength+(rsm.uname).length()+ByteLength+DoubleLength+DoubleLength+IntLength;
+ b = new byte[len];
+ Convert.write(b,Convert.intToBytes(len),pos);
+ pos+=IntLength;
+ b[pos] = (byte) tmp;
+ pos+=ByteLength;
+ Convert.write(b,Convert.hexStringToBytes(rsm.token),pos);
+ pos+=TokenLength;
+ Convert.write(b,(rsm.uname).getBytes(),pos);
+ pos+=(rsm.uname).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ Convert.write(b,Convert.doubleToBytes(rsm.latitude),pos);
+ pos+=DoubleLength;
+ Convert.write(b,Convert.doubleToBytes(rsm.longitude),pos);
+ pos+=DoubleLength;
+ Convert.write(b,Convert.intToBytes(rsm.deadline),pos);
+ pos+=IntLength;
+ out.write(b);
+ break;
+ case SetPassword:
+ ReqSetPassword rsp = (ReqSetPassword) req;
+ len = IntLength+ByteLength+TokenLength+(rsp.uname).length()+ByteLength+(rsp.oldpassword).length()+ByteLength+(rsp.newpassword).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(rsp.token),pos);
+ pos+=TokenLength;
+ Convert.write(b,(rsp.uname).getBytes(),pos);
+ pos+=(rsp.uname).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ Convert.write(b,(rsp.oldpassword).getBytes(),pos);
+ pos+=(rsp.oldpassword).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ Convert.write(b,(rsp.newpassword).getBytes(),pos);
+ pos+=(rsp.newpassword).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ out.write(b);
+ break;
}
out.flush();
DataInputStream in = new DataInputStream(client.getInputStream());
@@ -195,6 +249,8 @@ public class SocketClient {
int type = in.readUnsignedByte();
int status = in.readUnsignedByte();
if(status == 1) return StatusFailed;
+ if(status == 2) return LevelFailed;
+ if(status == 3) return PasswordFailed;
switch (type) {
case Login:
byte[] buffer = new byte[32];
@@ -202,13 +258,13 @@ public class SocketClient {
String tk = Convert.byteToHexString(buffer);
outlen-=(IntLength+ByteLength+TokenLength+ByteLength);
int cnt = 0;
- int uid =0,s =0;
+ int uid =0,s =0,l =0;
String uname ="",nname ="";
double lat =0.0,lot =0.0;
RGroup rg = null;
int i = 0;
byte[] bu = new byte[200];
- while(cnt < 7) {
+ while(cnt < 8) {
int typ = in.readUnsignedByte();
outlen-=ByteLength;
switch(typ){
@@ -262,14 +318,17 @@ public class SocketClient {
lot = in.readDouble();
outlen-=DoubleLength;
break;
+ case Level:
+ l = in.readUnsignedByte();
+ outlen-=ByteLength;
+ break;
}
cnt++;
}
- RUserInfo r = new RUserInfo(uid,uname,nname,lat,lot,rg,s);
+ RUserInfo r = new RUserInfo(uid,uname,nname,lat,lot,rg,s,l);
in.readUnsignedByte();
outlen-=ByteLength;
int number =0;
- System.out.println("read "+ outlen);
Vector<RGroup> vrg = new Vector<RGroup>();
while(outlen > 1) {
int com = in.readUnsignedByte();
@@ -297,7 +356,7 @@ public class SocketClient {
break;
case UserInfo:
outlen-=(IntLength+ByteLength+ByteLength);
- int uid1 =0,s1 =0;
+ int uid1 =0,s1 =0,l1 =0;
String uname1 ="",nname1 ="";
double lat1 =0.0,lot1 =0.0;
RGroup rg1 = null;
@@ -307,7 +366,7 @@ public class SocketClient {
int n = 0;
while(outlen > 0) {
int tmpcnt =0;
- while(tmpcnt < 7) {
+ while(tmpcnt < 8) {
int typ = in.readUnsignedByte();
outlen-=ByteLength;
switch(typ){
@@ -361,12 +420,16 @@ public class SocketClient {
lot1 = in.readDouble();
outlen-=DoubleLength;
break;
+ case Level:
+ l1 = in.readUnsignedByte();
+ outlen-=ByteLength;
+ break;
}
tmpcnt++;
}
in.readUnsignedByte();
outlen-=ByteLength;
- v.add(new RUserInfo(uid1,uname1,nname1,lat1,lot1,rg1,s1));
+ v.add(new RUserInfo(uid1,uname1,nname1,lat1,lot1,rg1,s1,l1));
n++;
}
msg.obj = new ResUserInfo(n,v);
@@ -391,12 +454,26 @@ public class SocketClient {
msg.what = SendMessage;
recall.sendMessage(msg);
break;
+ case SetMarker:
+ msg.obj = new ResSetMarker();
+ msg.what = SetMarker;
+ recall.sendMessage(msg);
+ break;
+ case SetPassword:
+ msg.obj = new ResSetPassword();
+ msg.what = SetPassword;
+ recall.sendMessage(msg);
+ break;
}
return Success;
} catch (SocketTimeoutException e){
e.printStackTrace();
return TimeOut;
+ } catch (EOFException e) {
+ e.printStackTrace();
+ //return ServerFetchFailed;
+ throw e;
} catch (IOException e) {
e.printStackTrace();
throw e;
diff --git a/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java b/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
index 3716549..74d1b83 100644
--- a/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
+++ b/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
@@ -1,5 +1,6 @@
package com.macaroon.piztor;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -11,6 +12,7 @@ import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@@ -18,105 +20,227 @@ import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
+import android.widget.Toast;
+import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.macaroon.piztor.RGroup;
-
-public class SubscribeSettings extends Activity {
-
- private static final int BUTTON_ADD = 1;
- private static final int BUTTON_DELETE = 2;
-
- private ListView mListView;
- private ArrayList<HashMap<String, Object>> mList;
- private TextView mShowInfo;
- private EditText edit_company;
- private EditText edit_section;
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.subscribe_settings);
-
- mListView = (ListView) findViewById(R.id.listView1);
- edit_company = (EditText) findViewById(R.id.subscribe_company);
- edit_section = (EditText) findViewById(R.id.subscribe_section);
- mList = new ArrayList<HashMap<String, Object>>();
- final MySimpleAdapter simpleAdapter = new MySimpleAdapter(this, mList,
- R.layout.subscribe_item, new String[] {"subscribe_text", "btnadd"}, new int[] {R.id.textView1, R.id.button_add});
- mListView.setAdapter(simpleAdapter);
- //TODO get current subscribe
- for (RGroup i : Infomation.sublist) {
- HashMap<String, Object> map = new HashMap<String, Object>();
- int cc = i.company;
- int ss = i.section;
- map.put("subscribe_text", cc+ "连 " + ss + "班");
- }
- Button btnadd = (Button)findViewById(R.id.button_add);
- btnadd.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- int cc = Integer.parseInt(edit_company.getText().toString());
- int ss = Integer.parseInt(edit_section.getText().toString());
- simpleAdapter.notifyDataSetChanged();
- HashMap<String, Object> map = new HashMap<String, Object>();
- map.put("subscribe_text", cc + "连 " + ss + "班");
- mList.add(map);
- mShowInfo.setText("添加了一条订阅");
- }
- });
- mShowInfo = (TextView) findViewById(R.id.textView1);
- }
-
- private class MySimpleAdapter extends SimpleAdapter {
-
- public MySimpleAdapter(Context context,
- List<? extends Map<String, ?>> data, int resource,
- String[] from, int[] to) {
- super(context, data, resource, from, to);
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // TODO Auto-generated method stub
- final int mPosition = position;
- convertView = super.getView(position, convertView, parent);
- Button buttonDelete = (Button) convertView
- .findViewById(R.id.button_delete);
- buttonDelete.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- mHandler.obtainMessage(BUTTON_DELETE, mPosition, 0).sendToTarget();
- }
- });
- return convertView;
- }
-
- private Handler mHandler = new Handler() {
-
- @Override
- public void handleMessage(Message msg) {
- // TODO Auto-generated method stub
- super.handleMessage(msg);
- switch (msg.what) {
- case BUTTON_ADD:
- HashMap<String, Object> map = new HashMap<String, Object>();
- mList.add(map);
- notifyDataSetChanged();
- break;
-
- case BUTTON_DELETE:
- mList.remove(msg.arg1);
- notifyDataSetChanged();
- mShowInfo.setText("删除了第" + (msg.arg1 + 1) + "条订阅");
- break;
- }
- }
-
- };
-
- }
+import com.macaroon.piztor.Settings.ReCall;
+
+public class SubscribeSettings extends PiztorAct {
+
+ private static final int BUTTON_ADD = 1;
+ private static final int BUTTON_DELETE = 2;
+
+ static class ReCall extends Handler {
+ WeakReference<SubscribeSettings> outerClass;
+
+ ReCall(SubscribeSettings activity) {
+ outerClass = new WeakReference<SubscribeSettings>(activity);
+ }
+
+ @Override
+ public void handleMessage(Message m) {
+ SubscribeSettings out = outerClass.get();
+ if (out == null) {
+ System.out.println("act被回收了");
+ }
+ switch (m.what) {
+ case Res.Login:// 上传自己信息成功or失败
+ Log.d("update location", "successfull");
+ break;
+ case Res.UserInfo:// 得到用户信息
+ ResUserInfo userInfo = (ResUserInfo) m.obj;
+ System.out.println("revieve ........" + userInfo.uinfo.size());
+ Vector<RUserInfo> uinfo = userInfo.uinfo;
+ for (RUserInfo info : uinfo) {
+ 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);
+ r.setLocation(info.latitude, info.longitude);
+ } else {
+ r = new UserInfo(info.uid);
+ r.setInfo(info.gid.company, info.gid.section, info.sex,
+ info.nickname);
+ r.setLocation(info.latitude, info.longitude);
+ out.mapInfo.addUserInfo(r);
+ }
+ }
+ break;
+ case Res.Logout:// 登出
+ out.actMgr.trigger(AppMgr.logout);
+ break;
+ case Res.PushMessage:
+ ResPushMessage pushMessage = (ResPushMessage) m.obj;
+ out.receiveMessage(pushMessage.message);
+ break;
+ case Res.SendMessage:
+ Log.d(LogInfo.resquest, "send message successfully");
+ break;
+ case Res.PushLocation:
+ ResPushLocation pushLocation = (ResPushLocation) m.obj;
+ out.upMapInfo(pushLocation.l);
+ 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.mapInfo.markerInfo = markerInfo;
+ break;
+ case Res.Subscription:
+ out.app.sublist = out.listGroup;
+ break;
+ case -1:
+ out.actMgr.trigger(AppMgr.logout);
+ default:
+ break;
+ }
+ }
+ }
+ ReCall handler = new ReCall(this);
+
+ private ListView mListView;
+ private ArrayList<HashMap<String, Object>> mList;
+ private TextView mShowInfo;
+ private EditText edit_company;
+ private EditText edit_section;
+ private Vector<RGroup> listGroup;
+
+
+ void upMapInfo(Vector<RLocation> 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);
+ }
+ }
+ }
+
+ void receiveMessage(String msg) {
+ Log.d("recieve message", msg);
+ Toast toast = Toast.makeText(getApplicationContext(), msg,
+ Toast.LENGTH_LONG);
+ toast.show();
+ }
+
+ void subscribe() {
+ ReqSubscription req = new ReqSubscription(app.token, app.username,
+ listGroup.size(), listGroup, System.currentTimeMillis(), 3000);
+ app.transam.send(req);
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.subscribe_settings);
+ listGroup = new Vector<RGroup>();
+ app = (myApp) getApplication();
+ app.transam.setHandler(handler);
+ mListView = (ListView) findViewById(R.id.listView1);
+ edit_company = (EditText) findViewById(R.id.subscribe_company);
+ edit_section = (EditText) findViewById(R.id.subscribe_section);
+ mList = new ArrayList<HashMap<String, Object>>();
+ final MySimpleAdapter simpleAdapter = new MySimpleAdapter(this, mList,
+ R.layout.subscribe_item, new String[] { "subscribe_text",
+ "btnadd" },
+ new int[] { R.id.textView1, R.id.button_add });
+ mListView.setAdapter(simpleAdapter);
+ // TODO get current subscribe
+ for (RGroup i : ((myApp) getApplication()).sublist) {
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ int cc = i.company;
+ int ss = i.section;
+
+ map.put("subscribe_text", cc + "连 " + ss + "班");
+ mList.add(map);
+
+ RGroup listItem = new RGroup(cc, ss);
+ listGroup.add(listItem);
+ simpleAdapter.notifyDataSetChanged();
+ }
+ Button btnadd = (Button) findViewById(R.id.button_add);
+ btnadd.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ int cc = Integer.parseInt(edit_company.getText().toString());
+ int ss = Integer.parseInt(edit_section.getText().toString());
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("subscribe_text", cc + "连 " + ss + "班");
+ mList.add(map);
+
+ RGroup listItem = new RGroup(cc, ss);
+ listGroup.add(listItem);
+ subscribe();
+
+ simpleAdapter.notifyDataSetChanged();
+ mShowInfo.setText("添加了一条订阅");
+ }
+ });
+ mShowInfo = (TextView) findViewById(R.id.textView1);
+ }
+
+ private class MySimpleAdapter extends SimpleAdapter {
+
+ public MySimpleAdapter(Context context,
+ List<? extends Map<String, ?>> data, int resource,
+ String[] from, int[] to) {
+ super(context, data, resource, from, to);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ // TODO Auto-generated method stub
+ final int mPosition = position;
+ convertView = super.getView(position, convertView, parent);
+ Button buttonDelete = (Button) convertView
+ .findViewById(R.id.button_delete);
+ buttonDelete.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ mHandler.obtainMessage(BUTTON_DELETE, mPosition, 0)
+ .sendToTarget();
+ }
+ });
+ return convertView;
+ }
+
+ private Handler mHandler = new Handler() {
+
+ @Override
+ public void handleMessage(Message msg) {
+ // TODO Auto-generated method stub
+ super.handleMessage(msg);
+ switch (msg.what) {
+ case BUTTON_ADD:
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ mList.add(map);
+ notifyDataSetChanged();
+ break;
+
+ case BUTTON_DELETE:
+ mList.remove(msg.arg1);
+ RGroup listItem = listGroup.get(msg.arg1);
+ listGroup.remove(msg.arg1);
+ subscribe();
+ notifyDataSetChanged();
+ mShowInfo.setText("删除了第" + (msg.arg1 + 1) + "条订阅");
+ break;
+ }
+ }
+
+ };
+
+ }
} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/Transam.java b/client/Piztor/src/com/macaroon/piztor/Transam.java
index ea5790d..bbded99 100644
--- a/client/Piztor/src/com/macaroon/piztor/Transam.java
+++ b/client/Piztor/src/com/macaroon/piztor/Transam.java
@@ -1,6 +1,7 @@
package com.macaroon.piztor;
import java.io.IOException;
+import java.lang.ref.WeakReference;
import java.net.UnknownHostException;
import java.util.LinkedList;
import java.util.Queue;
@@ -8,61 +9,10 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
-import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
-// Piztor Transmission Protocol v2.0 beta //
-
-//------------------------------------------------//
-// //
-// *return msg type* //
-// 0 for login //
-// 1 for updateLocation //
-// 2 for locationRequest //
-// 3 for userinfo //
-// 4 for logout //
-// 5 for requestpush //
-// 6 for sendmessage //
-// //
-// 100 for pushmessage //
-// 101 for pushlocation //
-// //
-// ----------I'm the division line-------- //
-// //
-// -1 for Exceptions //
-// Exception (req type,ex type,exception type) //
-// //
-// ----------I'm the division line-------- //
-// //
-// *Request form* //
-// login -- username & password //
-//update -- token & username & latitude & longitude//
-//getlocation -- token & username & company & section//
-// getuserinfo -- token & userinfo & userid //
-// logout -- token & username //
-// send message -- token & username & message //
-// //
-// ----------I'm the division line-------- //
-// //
-// *Respond form* //
-// login -- status & userid & token //
-// update -- status //
-// getlocation -- status & entrynumber & data //
-// entry -- userid & latitude & longitude //
-// //
-//getuserinfo -- status & uid & company & section & gender//
-// logout -- status //
-// request push -- status //
-// send message -- status //
-// //
-// status -- 0 for success //
-// 1 for failed/invalid //
-// //
-// //
-//------------------------------------------------//
-
-
+// Piztor Transmission Protocol v2.0b beta //
public class Transam implements Runnable {
@@ -73,6 +23,7 @@ public class Transam implements Runnable {
static final int Logout =4;
static final int StartPush =5;
static final int SendMessage =6;
+ static final int SetMarker =7;
static final int ClosePush = -5;
@@ -83,41 +34,50 @@ public class Transam implements Runnable {
static final int EIOException =105;
static final int EUnknownHostException =106;
static final int EStatusFailedException =107;
+ static final int ELevelFailedException =108;
static final int Reconnect =-2;
static final int Exception =-1;
static final int TimeOut =0;
- private Timer timer;
- private Timer pushtimer;
- private boolean running = false;
- private int cnt = 5; //retry times
- private int tcnt; //current remain retry times
- private int rcnt; //current remain retry times (push)
- private int retime = 2000; //timeout time
- private Req req;
- private int p; //port
- private String i; //ip
- private Thread thread;
- private Handler recall; //recall
- private Queue<Req> reqtask ; //request task
+ static final int RPasswordFailed =5;
+ static final int RServerFetchFailed =4;
+ static final int RLevelFailed =3;
+ static final int RStatusFailed = 2;
+ static final int RTimeOut = 1;
+ static final int RSuccess = 0;
- private String itoken;
- private String iname;
+ Timer timer;
+ Timer pushtimer;
+ boolean running = false;
+ int cnt = 5; //retry times
+ int tcnt; //current remain retry times
+ int rcnt; //current remain retry times (push)
+ int retime = 2000; //timeout time
+ Req req;
+ int p; //port
+ String i; //ip
+ Thread thread;
+ Handler recall; //recall
+ Handler handler; //manager
+ Queue<Req> reqtask ; //request task
- private Thread Pushthread;
- private PushClient push;
+ String itoken;
+ String iname;
+
+ Thread Pushthread;
+ PushClient push;
Transam(String ip, int port,Handler Recall) {
p = port;
i = ip;
recall = Recall;
reqtask = new LinkedList<Req>();
+ handler = new Manager(this);
}
public void send(Req r){
- reqtask.offer(r);
-
+ reqtask.offer(r);
}
private void startPush(String token,String name) {
@@ -157,7 +117,6 @@ public class Transam implements Runnable {
if(push != null) {
push.setPushHandler(Recall);
}
- reqtask.clear();
}
@@ -191,8 +150,9 @@ public class Transam implements Runnable {
thread.start();
}
+
private void connectpush() {
- reqpush r = new reqpush();
+ final reqpush r = new reqpush();
Pushthread = new Thread(r);
Pushthread.start();
}
@@ -216,21 +176,21 @@ public class Transam implements Runnable {
push = new PushClient(i,p,retime);
push.setPushHandler(recall);
int out = push.start(new ReqStartPush(itoken,iname));
- if(out == 1) {
+ if(out == RTimeOut) {
push.closeSocket();
Message msg = new Message();
msg.what = Reconnect;
msg.obj = new ETimeOutException(5,0);
handler.sendMessage(msg);
}
- else if (out == 2){
+ else if (out == RStatusFailed){
stopPush();
Message msg = new Message();
msg.what = Exception;
msg.obj = new EStatusFailedException(5,0);
recall.sendMessage(msg);
}
- else {
+ else if (out == RSuccess){
rcnt = cnt;
push.listen(recall);
}
@@ -256,22 +216,38 @@ public class Transam implements Runnable {
try {
SocketClient client = new SocketClient(i,p,retime);
int out = client.sendMsg(req,recall,handler);
- if(out == 0){
+ if(out == RSuccess){
client.closeSocket();
running = false;
}
- else if (out == 1){
+ else if (out == RTimeOut){
client.closeSocket();
Message m = new Message();
m.obj = new ETimeOutException(req.type,req.time);
m.what = TimeOut;
handler.sendMessage(m);
}
- else {
+ else if (out == RLevelFailed){
+ client.closeSocket();
+ Message m = new Message();
+ m.obj = new ELevelFailedException(req.type,req.time);
+ m.what = Exception;
+ recall.sendMessage(m);
+ running = false;
+ }
+ else if (out == RStatusFailed){
client.closeSocket();
Message msg = new Message();
msg.what = Exception;
- msg.obj = new EStatusFailedException(5,0);
+ msg.obj = new EStatusFailedException(req.type,req.time);
+ recall.sendMessage(msg);
+ running = false;
+ }
+ else if (out == RPasswordFailed){
+ client.closeSocket();
+ Message msg = new Message();
+ msg.what = Exception;
+ msg.obj = new EPasswordFailedException(req.type,req.time);
recall.sendMessage(msg);
running = false;
}
@@ -293,65 +269,70 @@ public class Transam implements Runnable {
}
- @SuppressLint("HandlerLeak")
- private Handler handler = new Handler() {
- public void handleMessage(Message msg) {
+ static class Manager extends Handler {
+ WeakReference<Transam> outerClass;
+ Manager(Transam t) {
+ outerClass = new WeakReference<Transam>(t);
+ }
+ @Override
+ public void handleMessage(Message msg) {
+ Transam out = outerClass.get();
switch (msg.what) {
case Exception:
- if (tcnt > 0) {
- tcnt--;
- System.out.println(tcnt);
- timer = new Timer();
- TimerTask task = new tmain();
- timer.schedule(task,retime);
- } else if (tcnt == 0) {
+ if (out.tcnt > 0) {
+ out.tcnt--;
+ System.out.println(out.tcnt);
+ out.timer = new Timer();
+ TimerTask task = out.new tmain();
+ out.timer.schedule(task,out.retime);
+ } else if (out.tcnt == 0) {
Message m = new Message();
m.obj = msg.obj;
m.what = Exception;
- recall.sendMessage(m);
- running = false;
+ out.recall.sendMessage(m);
+ out.running = false;
}
break;
case TimeOut:
- if (tcnt > 0) {
- tcnt--;
- System.out.println(tcnt);
- timer = new Timer();
- TimerTask task = new tmain();
- timer.schedule(task,retime);
- } else if (tcnt == 0) {
+ if (out.tcnt > 0) {
+ out.tcnt--;
+ System.out.println(out.tcnt);
+ out.timer = new Timer();
+ TimerTask task = out.new tmain();
+ out.timer.schedule(task,out.retime);
+ } else if (out.tcnt == 0) {
Message m = new Message();
- EConnectFailedException c = new EConnectFailedException(req.type,req.time);
+ EConnectFailedException c = new EConnectFailedException(out.req.type,out.req.time);
m.obj = c;
m.what = Exception;
- recall.sendMessage(m);
- running = false;
+ out.recall.sendMessage(m);
+ out.running = false;
}
break;
case Reconnect:
- if (rcnt > 0) {
- rcnt--;
- System.out.println(rcnt);
- pushtimer = new Timer();
- TimerTask task = new pmain();
- pushtimer.schedule(task,retime);
- } else if (rcnt == 0) {
+ if (out.rcnt > 0) {
+ out.rcnt--;
+ System.out.println(out.rcnt);
+ out.pushtimer = new Timer();
+ TimerTask task = out.new pmain();
+ out.pushtimer.schedule(task,out.retime);
+ } else if (out.rcnt == 0) {
Message m = new Message();
EPushFailedException c = new EPushFailedException(5,0);
//m.obj = msg.obj;
m.obj = c;
m.what = Exception;
- recall.sendMessage(m);
+ out.recall.sendMessage(m);
}
break;
case StartPush:
@SuppressWarnings("unchecked")
Vector<String> s = (Vector<String>) msg.obj;
- startPush(s.get(1),s.get(0));
+ out.startPush(s.get(1),s.get(0));
System.out.println("startpush");
break;
case ClosePush:
- stopPush();
+ out.stopPush();
System.out.println("closepush");
break;
}
diff --git a/client/Piztor/src/com/macaroon/piztor/myApp.java b/client/Piztor/src/com/macaroon/piztor/myApp.java
new file mode 100644
index 0000000..e60e9b4
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/myApp.java
@@ -0,0 +1,52 @@
+package com.macaroon.piztor;
+import java.util.Vector;
+
+import com.baidu.mapapi.BMapManager;
+import com.baidu.mapapi.MKGeneralListener;
+import android.annotation.SuppressLint;
+import android.app.Application;
+import android.os.Handler;
+import android.util.Log;
+
+@SuppressLint("UseSparseArrays")
+public class myApp extends Application {
+ private static final String strKey = "8a0ae50048d103b2b8b12b7066f4ea7d";
+ BMapManager mBMapManager;
+
+ String ip = "202.120.7.4";
+// static String ip = "69.85.86.42";
+// static String ip = "192.168.1.101";
+ int port = 2223;
+ String token = null;
+ String username = null;
+ Vector<RGroup> sublist;
+
+ AppMgr appMgr;
+
+ // TODO fix
+ Handler handler;
+ Transam transam;
+ Thread tTransam;
+
+ MapInfo mapInfo;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ System.out.println("我执行了,好开心~~~~~~~~~~");
+ mapInfo = new MapInfo();
+ mBMapManager = new BMapManager(this);
+
+ appMgr = new AppMgr(this);
+ System.out.println("appmgr already!!!");
+ transam = new Transam(ip, port, new Handler());
+ tTransam = new Thread(transam);
+ System.out.println("transam start!!!!");
+ tTransam.start();
+ }
+
+ public static String getStrkey() {
+ return strKey;
+ }
+
+}