summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-09-01 11:42:25 +0800
committerTeddy <[email protected]>2013-09-01 11:42:25 +0800
commit2f3d03524da427faf407903b5764ab745613313d (patch)
treeb9dcf3b6f4eda2eec2278e536df1314267b5c2c6 /client
parentd3c6b23cfade2cc91b45dda5eb62e8a7d2398a18 (diff)
parent8b8109ff5dadf03dfeb68a5c47ee0fe0465de197 (diff)
Merge branch 'master' of github.com:Determinant/piztor
Diffstat (limited to 'client')
-rw-r--r--client/Piztor/AndroidManifest.xml96
-rw-r--r--client/Piztor/libs/baidumapapi_v2_1_3.jarbin843490 -> 840002 bytes
-rw-r--r--client/Piztor/project.properties2
-rw-r--r--client/Piztor/res/drawable/circle_blue.pngbin1070 -> 3236 bytes
-rw-r--r--client/Piztor/res/drawable/circle_glass.pngbin1173 -> 3253 bytes
-rw-r--r--client/Piztor/res/drawable/circle_green.pngbin1079 -> 3242 bytes
-rw-r--r--client/Piztor/res/drawable/circle_metal.pngbin894 -> 3196 bytes
-rw-r--r--client/Piztor/res/drawable/circle_paper.pngbin965 -> 3187 bytes
-rw-r--r--client/Piztor/res/drawable/circle_tan.pngbin916 -> 3189 bytes
-rw-r--r--client/Piztor/res/drawable/circle_wood.pngbin1359 -> 3237 bytes
-rw-r--r--client/Piztor/res/drawable/circle_yellow.pngbin946 -> 3186 bytes
-rw-r--r--client/Piztor/res/layout/activity_login.xml5
-rw-r--r--client/Piztor/res/layout/activity_settings.xml76
-rw-r--r--client/Piztor/res/layout/activity_subscribe_settings.xml16
-rw-r--r--client/Piztor/res/layout/activity_updateinfo.xml188
-rw-r--r--client/Piztor/res/layout/checkindialog.xml4
-rw-r--r--client/Piztor/res/layout/subscribe_item.xml26
-rw-r--r--client/Piztor/res/layout/subscribe_settings.xml22
-rw-r--r--client/Piztor/res/menu/subscribe_settings.xml9
-rw-r--r--client/Piztor/res/menu/update_info.xml9
-rw-r--r--client/Piztor/res/values/strings.xml42
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ActMgr.java9
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AlertMaker.java105
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AppMgr.java124
-rw-r--r--client/Piztor/src/com/macaroon/piztor/CopyMap.java50
-rw-r--r--client/Piztor/src/com/macaroon/piztor/EException.java22
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Infomation.java15
-rw-r--r--client/Piztor/src/com/macaroon/piztor/InitAct.java40
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Login.java40
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java233
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapInfo.java38
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java416
-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/Settings.java181
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SocketClient.java91
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java391
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Transam.java205
-rw-r--r--client/Piztor/src/com/macaroon/piztor/UpdateInfo.java141
-rw-r--r--client/Piztor/src/com/macaroon/piztor/myApp.java52
43 files changed, 1890 insertions, 901 deletions
diff --git a/client/Piztor/AndroidManifest.xml b/client/Piztor/AndroidManifest.xml
index f336200..8e9973c 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="com.macaroon.piztor.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,40 @@
</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>
+
+ <activity
+ android:name="com.macaroon.piztor.UpdateInfo"
+ android:label="@string/title_activity_update_info" >
+ </activity>
</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/libs/baidumapapi_v2_1_3.jar b/client/Piztor/libs/baidumapapi_v2_1_3.jar
index c4d1a3f..b6d2c93 100644
--- a/client/Piztor/libs/baidumapapi_v2_1_3.jar
+++ b/client/Piztor/libs/baidumapapi_v2_1_3.jar
Binary files differ
diff --git a/client/Piztor/project.properties b/client/Piztor/project.properties
index b7c2081..ce39f2d 100644
--- a/client/Piztor/project.properties
+++ b/client/Piztor/project.properties
@@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
-target=android-10
+target=android-18
diff --git a/client/Piztor/res/drawable/circle_blue.png b/client/Piztor/res/drawable/circle_blue.png
index 09c3658..d174635 100644
--- a/client/Piztor/res/drawable/circle_blue.png
+++ b/client/Piztor/res/drawable/circle_blue.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_glass.png b/client/Piztor/res/drawable/circle_glass.png
index 826b2b7..d5dbec4 100644
--- a/client/Piztor/res/drawable/circle_glass.png
+++ b/client/Piztor/res/drawable/circle_glass.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_green.png b/client/Piztor/res/drawable/circle_green.png
index ded6938..3ab51d4 100644
--- a/client/Piztor/res/drawable/circle_green.png
+++ b/client/Piztor/res/drawable/circle_green.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_metal.png b/client/Piztor/res/drawable/circle_metal.png
index d84e1ad..07c72f0 100644
--- a/client/Piztor/res/drawable/circle_metal.png
+++ b/client/Piztor/res/drawable/circle_metal.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_paper.png b/client/Piztor/res/drawable/circle_paper.png
index 973787d..b8d7b0d 100644
--- a/client/Piztor/res/drawable/circle_paper.png
+++ b/client/Piztor/res/drawable/circle_paper.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_tan.png b/client/Piztor/res/drawable/circle_tan.png
index 27d10ad..667cc25 100644
--- a/client/Piztor/res/drawable/circle_tan.png
+++ b/client/Piztor/res/drawable/circle_tan.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_wood.png b/client/Piztor/res/drawable/circle_wood.png
index ea18f7a..b2752de 100644
--- a/client/Piztor/res/drawable/circle_wood.png
+++ b/client/Piztor/res/drawable/circle_wood.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_yellow.png b/client/Piztor/res/drawable/circle_yellow.png
index 7c1dfc7..c596806 100644
--- a/client/Piztor/res/drawable/circle_yellow.png
+++ b/client/Piztor/res/drawable/circle_yellow.png
Binary files differ
diff --git a/client/Piztor/res/layout/activity_login.xml b/client/Piztor/res/layout/activity_login.xml
index a8cf47f..c408a1d 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"
@@ -75,7 +76,7 @@
android:layout_marginLeft="70.0dip"
android:layout_marginRight="70.0dip"
android:layout_marginTop="12.0dip"
- android:text="login"
+ android:text="@string/login"
android:layout_below="@id/user_layout" />
</RelativeLayout> \ No newline at end of file
diff --git a/client/Piztor/res/layout/activity_settings.xml b/client/Piztor/res/layout/activity_settings.xml
index 49e8dfe..36bacf3 100644
--- a/client/Piztor/res/layout/activity_settings.xml
+++ b/client/Piztor/res/layout/activity_settings.xml
@@ -16,14 +16,21 @@
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="horizontal">
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:layout_centerVertical="true"
+ android:layout_centerHorizontal="true"
+ >
<TextView
android:id="@+id/settings_GPSrefreshrate_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
+ android:gravity="center"
android:layout_marginTop="10dip"
- android:layout_marginLeft="60dip"
- android:text="GPS refresh rate"
+ android:text="@string/GPSrefreshrate"
android:textColor="@android:color/white"
android:textSize="20dip" />
<TextView
@@ -32,12 +39,12 @@
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_marginTop="10dip"
- android:layout_marginLeft="20dip"
+ android:layout_marginLeft="10dip"
android:layout_gravity="center_vertical"
android:textColor="@android:color/white"
android:layout_toRightOf="@+id/settings_GPSrefreshrate_text"
android:text="30s"/>
-
+ </LinearLayout>
</RelativeLayout>
<SeekBar
@@ -80,24 +87,22 @@
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:background="#ffc0c3c4" />
-
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_gravity="center"
- android:gravity="center"
- android:textSize="30dip"
- android:textColor="@android:color/white"
- android:text="@string/subscribe_info"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
- android:layout_marginTop="20dip"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
+ android:layout_marginTop="10dip"
android:orientation="horizontal">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:textSize="30dip"
+ android:textColor="@android:color/white"
+ android:text="@string/subscribe_info"/>
+
<Button
android:id="@+id/settings_btn_subscribe"
android:layout_width="wrap_content"
@@ -116,6 +121,45 @@
android:layout_marginRight="20dip"
android:background="#ffc0c3c4" />
<LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="20dip"
+ android:text="@string/colormode"
+ android:textColor="#FFFFFF"/>
+ <RadioGroup
+ android:id="@+id/radioGroup"
+ android:contentDescription="@string/colormode"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:orientation="horizontal">
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/show_by_team"
+ android:text="@string/show_team"
+ android:checked="true"/>
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/show_by_sex"
+ android:text="@string/show_sex"/>
+ </RadioGroup>
+ </LinearLayout>
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1.0px"
+ android:layout_marginTop="20dip"
+ android:layout_marginBottom="20dip"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
+ android:background="#ffc0c3c4" />
+ <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"
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/activity_updateinfo.xml b/client/Piztor/res/layout/activity_updateinfo.xml
index de9ecc6..5d0c66c 100644
--- a/client/Piztor/res/layout/activity_updateinfo.xml
+++ b/client/Piztor/res/layout/activity_updateinfo.xml
@@ -7,7 +7,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:layout_marginTop="20dip"
+ android:layout_marginTop="20dip"
android:orientation="vertical" >
<include layout="@layout/settings_headbar"></include>
@@ -17,105 +17,105 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dip"
- android:gravity="center"
+ android:gravity="center"
android:textSize="20dip"
android:textColor="#FFFFFF"
- android:text="haha"
- android:id="@+id/username_text" />
+ android:id="@+id/username" />
<View
- android:layout_width="fill_parent"
- android:layout_height="1.0px"
- android:layout_marginTop="10dip"
- android:layout_marginBottom="20dip"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
- android:background="#ffc0c3c4" />
+ android:layout_width="fill_parent"
+ android:layout_height="1.0px"
+ android:layout_marginTop="10dip"
+ android:layout_marginBottom="20dip"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
+ android:background="#ffc0c3c4" />
- <EditText
- android:id="@+id/editText1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="25dip"
- android:layout_marginRight="25dip"
- android:hint=" new nickname"
- android:ems="10" >
- </EditText>
- <View
- android:layout_width="fill_parent"
- android:layout_height="1.0px"
- android:layout_marginTop="20dip"
- android:layout_marginBottom="20dip"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
- android:background="#ffc0c3c4" />
+ <TextView
+ android:id="@+id/nickname"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:layout_marginLeft="25dip"
+ android:layout_marginRight="25dip"
+ android:textSize="20dip"
+ android:ems="10" >
+ </TextView>
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1.0px"
+ android:layout_marginTop="20dip"
+ android:layout_marginBottom="20dip"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
+ android:background="#ffc0c3c4" />
- <EditText
- android:id="@+id/editText2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="25dip"
- android:layout_marginRight="25dip"
- android:ems="10"
- android:inputType="textPassword"
- android:hint=" * old password"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="25dip"
- android:layout_marginRight="25dip"
- android:layout_marginBottom="10dip"
- android:layout_gravity="center"
- android:gravity="center"
- android:textSize="14dip"
- android:text="Must enter your current password"
- android:textColor="#808080"/>
+ <EditText
+ android:id="@+id/password_old"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="25dip"
+ android:layout_marginRight="25dip"
+ android:ems="10"
+ android:inputType="textPassword"
+ android:hint="@string/old_password"/>
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="25dip"
+ android:layout_marginRight="25dip"
+ android:layout_marginBottom="10dip"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:textSize="14dip"
+ android:textColor="#808080"/>
- <EditText
- android:id="@+id/editText3"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="25dip"
- android:layout_marginRight="25dip"
- android:ems="10"
- android:inputType="textPassword"
- android:hint=" new password"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="25dip"
- android:layout_marginRight="25dip"
- android:layout_gravity="center"
- android:gravity="center"
- android:textSize="14dip"
- android:text="Keep this blank if you don't want to change"
- android:textColor="#808080"/>
- <View
- android:layout_width="fill_parent"
- android:layout_height="1.0px"
- android:layout_marginTop="20dip"
- android:layout_marginBottom="20dip"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
- android:background="#ffc0c3c4" />
+ <EditText
+ android:id="@+id/password_new"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="25dip"
+ android:layout_marginRight="25dip"
+ android:ems="10"
+ android:inputType="textPassword"
+ android:hint="@string/new_password"/>
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="25dip"
+ android:layout_marginRight="25dip"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:textSize="14dip"
+ android:textColor="#808080"/>
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1.0px"
+ android:layout_marginTop="20dip"
+ android:layout_marginBottom="20dip"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
+ android:background="#ffc0c3c4" />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_gravity="center"
- android:gravity="center">
- <Button
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:paddingLeft="30dip"
- android:paddingRight="30dip"
- android:paddingTop="4dip"
- android:paddingBottom="4dip"
- android:background="#0F9D58"
- android:textColor="#FFFFFF"
- android:textSize="25dip"
- android:text="Submit"/>
- </LinearLayout>
-
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:layout_gravity="center"
+ android:gravity="center">
+ <Button
+ android:id="@+id/btn_submit"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:paddingLeft="30dip"
+ android:paddingRight="30dip"
+ android:paddingTop="4dip"
+ android:paddingBottom="4dip"
+ android:background="#0F9D58"
+ android:textColor="#FFFFFF"
+ android:textSize="25dip"
+ android:text="@string/submit"/>
+ </LinearLayout>
+
</LinearLayout>
</ScrollView> \ No newline at end of file
diff --git a/client/Piztor/res/layout/checkindialog.xml b/client/Piztor/res/layout/checkindialog.xml
index 4174deb..b84404b 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="正在签到..."
+ 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/layout/subscribe_item.xml b/client/Piztor/res/layout/subscribe_item.xml
index 902da5a..2d53865 100644
--- a/client/Piztor/res/layout/subscribe_item.xml
+++ b/client/Piztor/res/layout/subscribe_item.xml
@@ -4,33 +4,39 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
+ <View
+ android:id="@+id/seperator"
+ android:layout_width="fill_parent"
+ android:layout_height="1.0px"
+ android:layout_alignParentTop="true"
+ android:layout_marginTop="10dip"
+ android:layout_marginBottom="10dip"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
+ android:background="#ffc0c3c4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
+ android:layout_below="@+id/seperator"
android:textSize="20dip"
android:layout_marginLeft="10dip"
android:layout_alignParentLeft="true"
android:text="company section"/>
<Button
- android:text="remove"
+ android:text="@string/remove"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
+ android:paddingTop="3dip"
+ android:paddingBottom="3dip"
+ android:layout_below="@+id/seperator"
android:textColor="#FFFFFF"
android:background="#DB4437"
android:id="@+id/button_delete"
android:textSize="20dip"
/>
- <View
- android:layout_width="fill_parent"
- android:layout_height="1.0px"
- android:layout_below="@+id/button_delete"
- android:layout_marginTop="20dip"
- android:layout_marginBottom="20dip"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
- android:background="#ffc0c3c4" />
+
</RelativeLayout>
diff --git a/client/Piztor/res/layout/subscribe_settings.xml b/client/Piztor/res/layout/subscribe_settings.xml
index c27e3c8..1bfd975 100644
--- a/client/Piztor/res/layout/subscribe_settings.xml
+++ b/client/Piztor/res/layout/subscribe_settings.xml
@@ -4,6 +4,14 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/textView1"
+ android:text="TextView"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="10dp"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@@ -16,7 +24,7 @@
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:textSize="20dip"
- android:hint="company"
+ android:hint="@string/company"
android:phoneNumber="true"
android:id="@+id/subscribe_company"/>
<EditText
@@ -25,7 +33,7 @@
android:layout_marginLeft="10dip"
android:layout_toRightOf="@+id/subscribe_company"
android:textSize="20dip"
- android:hint="section"
+ android:hint="@string/section"
android:phoneNumber="true"
android:id="@+id/subscribe_section"/>
<Button
@@ -33,7 +41,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
- android:text="add"
+ android:text="@string/add"
android:textColor="#FFFFFF"
android:background="#0F9D58"
android:textSize="20dip"
@@ -55,12 +63,4 @@
android:focusable="true">
</ListView>
</LinearLayout>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/textView1"
- android:text="TextView"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="10dp"/>
</LinearLayout>
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/menu/update_info.xml b/client/Piztor/res/menu/update_info.xml
new file mode 100644
index 0000000..c002028
--- /dev/null
+++ b/client/Piztor/res/menu/update_info.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..82132ed 100644
--- a/client/Piztor/res/values/strings.xml
+++ b/client/Piztor/res/values/strings.xml
@@ -1,29 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Piztor</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
- <string name="settings">Settings</string>
- <string name="search">Search</string>
- <string name="fetch">Fetch</string>
- <string name="checkin">Checkin</string>
- <string name="focus">Focus</string>
- <string name="show_sex">Show sex: </string>
+ <string name="settings">设置</string>
+ <string name="search">搜索</string>
+ <string name="fetch">获取</string>
+ <string name="checkin">签到</string>
+ <string name="focus">聚焦</string>
+ <string name="show_sex">按性别</string>
<string name="male">Male</string>
<string name="female">Female</string>
- <string name="show_team">Show team: </string>
+ <string name="show_team">按班级</string>
<string name="all">All</string>
<string name="mine">Mine</string>
<string name="title_activity_login">Login</string>
<string name="title_activity_main">Main</string>
<string name="title_activity_settings">Settings</string>
- <string name="password">password</string>
- <string name="username">username</string>
- <string name="login">login</string>
+ <string name="password">密码</string>
+ <string name="username">用户名</string>
+ <string name="login">登录</string>
<string name="desc">desc</string>
- <string name="logout">Logout</string>
- <string name="update_info">My Account</string>
- <string name="subscribe_info">Subscribe information</string>
- <string name="change">Check &amp; Update</string>
+ <string name="logout">注销</string>
+ <string name="update_info">修改密码</string>
+ <string name="subscribe_info">关注信息</string>
+ <string name="change">查看及修改</string>
+ <string name="title_activity_subscribesettings">SubscribeSettings</string>
+ <string name="title_activity_subscribe_settings">SubscribeSettings</string>
+ <string name="title_activity_update_info">UpdateInfo</string>
+ <string name="cancel">取消</string>
+ <string name="remove">移除</string>
+ <string name="company">连队</string>
+ <string name="section">班级</string>
+ <string name="add">添加</string>
+ <string name="GPSrefreshrate">GPS刷新率 每</string>
+ <string name="old_password">旧密码</string>
+ <string name="new_password">新密码</string>
+ <string name="submit">提交</string>
+ <string name="colormode">着色方式</string>
</resources>
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..b1087a2 100644
--- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
@@ -1,5 +1,6 @@
package com.macaroon.piztor;
+import java.io.Closeable;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
@@ -13,10 +14,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 +27,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 +51,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;
@@ -64,16 +71,16 @@ public class AlertMaker {
closeBoard(context);
AlertDialog.Builder gpsDialog = new AlertDialog.Builder(context);
- gpsDialog.setTitle("GPS settings");
- gpsDialog.setMessage("GPS is not enabled. Please turn it on.");
- gpsDialog.setPositiveButton("Settings",
+ gpsDialog.setTitle("GPS设置");
+ gpsDialog.setMessage("GPS未开启,是否前去打开?");
+ gpsDialog.setPositiveButton("设置",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivity(intent);
}
});
- gpsDialog.setNegativeButton("Go without GPS",
+ gpsDialog.setNegativeButton("不使用GPS",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
@@ -81,44 +88,66 @@ public class AlertMaker {
});
gpsDialog.show();
}
+
+ public void showLateAlert() {
+
+ closeBoard(context);
+ AlertDialog.Builder lateDialog = new AlertDialog.Builder(context);
+ lateDialog.setTitle("阿哦");
+ lateDialog.setMessage("你迟到了!");
+ lateDialog.setNeutralButton("知道了", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ arg0.cancel();
+ }
+ });
+ lateDialog.show();
+ closeBoard(context);
+ }
public long toTimestamp(int hour, int minute) {
+
calendar = Calendar.getInstance();
- int nhour = calendar.get(Calendar.HOUR_OF_DAY);
- int nminute = calendar.get(Calendar.MINUTE);
- int tmp = 0;
- if (hour > nhour) tmp = (hour - nhour) * 60 + minute - nminute;
- else if (minute > nminute) tmp = minute - nminute;
- timestamp = System.currentTimeMillis() + tmp * 60 * 1000;
- return timestamp;
+ calendar.set(calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH),
+ hour,minute);
+ return calendar.getTimeInMillis();
}
//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);
+ "太早了!多给一点时间", Toast.LENGTH_LONG);
toast.show();
closeBoard(context);
showMarkerAlert(markerPoint);
@@ -127,12 +156,44 @@ public class AlertMaker {
}
, calendar.get(Calendar.HOUR_OF_DAY)
, calendar.get(Calendar.MINUTE), true);
- markerDialog.show();
+ markerDialog.show();
+ closeBoard(context);
}
-
+
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("取消", 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, "已签到!", 2000);
+ toast.setGravity(Gravity.TOP, 0, 80);
+ toast.show();
+ checkinInfo.setText("成功!");
+ }
+ }.start();
}
-
+
}
diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
index 933d2db..a7f1af0 100644
--- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java
+++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
@@ -1,35 +1,13 @@
package com.macaroon.piztor;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.Stack;
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 +15,68 @@ 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;
+ final static int finish = 109;
- static MapInfo mapInfo;
+ public enum ActivityStatus {
+ create, start, resume, restart, stop, pause, destroy
+ }
- static HashMap<Class<?>, HashMap<Integer, Class<?>>> mp;
- static HashSet<PiztorAct> acts;
+ myApp app;
+ HashMap<Class<?>, HashMap<Integer, Class<?>>> mp;
+ Stack<PiztorAct> acts;
+ ActivityStatus status;
+ PiztorAct nowAct;
- static void addAct(PiztorAct act) {
+ void addAct(PiztorAct act) {
if (acts == null)
- acts = new HashSet<PiztorAct>();
- acts.add(act);
+ acts = new Stack<PiztorAct>();
+ acts.push(act);
}
- static void removeAct(PiztorAct act) {
- if (acts.contains(act))
- acts.remove(act);
- else
- System.out.println("Piztor has a bug!!!!");
- }
+ /*
+ * void removeAct(PiztorAct act) { if (acts.contains(act)) acts.remove(act);
+ * else System.out.println("Piztor has a bug!!!!"); }
+ */
- static void exit() {
- for (PiztorAct act : acts) {
- act.finish();
+ void exit() {
+ while (!acts.isEmpty()) {
+ acts.peek().finish();
+ acts.pop();
}
+ app.token = null;
+ app.mBMapManager.destroy();
}
- static void setStatus(ActivityStatus st) {
+ void setStatus(ActivityStatus st) {
status = st;
}
- static void trigger(int event) {
- Intent i = new Intent();
- i.setClass(nowAct, mp.get(nowAct.getClass()).get(event));
+ void trigger(int event) {
+ if (event == finish) {
+ nowAct.finish();
+ return;
+ }
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.isLogout = true;
+ app.mBMapManager.stop();
+ nowAct.finish();
+ return;
}
+ Intent i = new Intent();
+ i.setClass(nowAct, mp.get(nowAct.getClass()).get(event));
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 +86,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 +98,21 @@ 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(UpdateInfo.class, logout, Login.class);
+ addTransition(Settings.class, subscribe, SubscribeSettings.class);
+ addTransition(SubscribeSettings.class, logout, Login.class);
+ addTransition(Settings.class, account, UpdateInfo.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/CopyMap.java b/client/Piztor/src/com/macaroon/piztor/CopyMap.java
deleted file mode 100644
index 6d49767..0000000
--- a/client/Piztor/src/com/macaroon/piztor/CopyMap.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.macaroon.piztor;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import android.content.Context;
-
-public class CopyMap {
- /**
- *
- * @param myContext
- * @param ASSETS_NAME 要复制的文件名
- * @param savePath 要保存的路径
- * @param saveName 复制后的文件名
- * testCopy(Context context)是一个测试例子。
- */
-
- public static void copy(Context myContext, String ASSETS_NAME,
- String savePath, String saveName) {
- String filename = savePath + "/" + saveName;
-
- File dir = new File(savePath);
- // 如果目录不中存在,创建这个目录
- if (!dir.exists())
- dir.mkdir();
- try {
- if (!(new File(filename)).exists()) {
- InputStream is = myContext.getResources().getAssets()
- .open(ASSETS_NAME);
- System.out.println(ASSETS_NAME);
- FileOutputStream fos = new FileOutputStream(filename);
- byte[] buffer = new byte[7168];
- int count = 0;
- while ((count = is.read(buffer)) > 0) {
- fos.write(buffer, 0, count);
- }
- fos.close();
- is.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void testCopy(Context context) {
- String path=context.getFilesDir().getAbsolutePath();
- String name="test";
- CopyMap.copy(context, name, path, name);
- }
-}
-
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
deleted file mode 100644
index 60eb03f..0000000
--- a/client/Piztor/src/com/macaroon/piztor/Infomation.java
+++ /dev/null
@@ -1,15 +0,0 @@
-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..5f7f61d 100644
--- a/client/Piztor/src/com/macaroon/piztor/InitAct.java
+++ b/client/Piztor/src/com/macaroon/piztor/InitAct.java
@@ -1,16 +1,30 @@
package com.macaroon.piztor;
+import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
+import android.util.Log;
import android.view.Menu;
-public class InitAct extends PiztorAct {
+import com.baidu.mapapi.MKGeneralListener;
+public class InitAct extends PiztorAct {
@Override
protected void onCreate(Bundle savedInstanceState) {
id = "initAct";
super.onCreate(savedInstanceState);
- AppMgr.init(getApplicationContext());
- AppMgr.transam.setTimeOutTime(5000);
+ app.isExiting = false;
+ 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);
}
@@ -21,23 +35,27 @@ public class InitAct extends PiztorAct {
@Override
protected void onResume() {
+ if (app.isExiting)
+ finish();
super.onResume();
- if (Infomation.token == null)
- AppMgr.trigger(AppMgr.noToken);
+ if (app.token == null || app.isLogout) {
+ app.appMgr.trigger(AppMgr.noToken);
+ }
else {
- AppMgr.trigger(AppMgr.hasToken);
+ app.appMgr.trigger(AppMgr.hasToken);
+ System.out.println("has token!!!");
}
}
@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..3b9cbc2 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,15 @@ 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;
+ app.mapInfo.myInfo.nickname = res.uinfo.nickname;
System.out.println("login !!!!" + res.sublist.size());
actMgr.trigger(AppMgr.loginSuccess);
} else {
@@ -67,7 +66,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
@@ -87,12 +86,6 @@ public class Login extends PiztorAct {
protected void onCreate(Bundle savedInstanceState) {
id = "login";
super.onCreate(savedInstanceState);
- ActStatus[] r = new ActStatus[2];
- r[0] = new StartStatus();
- r[1] = new LoginStatus();
- actMgr = new ActMgr(this, r[0], r);
- actMgr.add(r[0], loginButtonClick, r[1]);
- actMgr.add(r[1], loginFailed, r[0]);
setContentView(R.layout.activity_login);
}
@@ -112,18 +105,23 @@ public class Login extends PiztorAct {
@Override
protected void onResume() {
+ if (app.isExiting)
+ finish();
+ app.isLogout = false;
super.onResume();
- if (AppMgr.transam == null)
- Log.d(LogInfo.exception, "transam = null");
- AppMgr.transam.setHandler(handler);
-
+ ActStatus[] r = new ActStatus[2];
+ r[0] = new StartStatus();
+ r[1] = new LoginStatus();
+ actMgr = new ActMgr(appMgr, this, r[0], r);
+ actMgr.add(r[0], loginButtonClick, r[1]);
+ actMgr.add(r[1], loginFailed, r[0]);
+ transam.setHandler(handler);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
- AppMgr.exit();
- return true;
+ app.isExiting = 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..052e267 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,11 +38,12 @@ 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 colorMode = 1;
+ public static int show_by_team = 1;
+ public static int show_by_sex = 2;
+
/**
* Locating component
*/
@@ -56,15 +54,23 @@ public class Main extends PiztorAct {
public MyLocationListener myListener = new MyLocationListener();
boolean isFirstLocation = true;
public static int GPSrefreshrate = 5;
+ private final int checkinRadius = 10;
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 +80,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 +92,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 +164,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 +178,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 +190,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 +212,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 : 由GPS更新 (刷新时间" + 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 : 由网络更新 (刷新时间" + 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 : 由缓存更新 (刷新时间" + 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 +255,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 +270,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 +291,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 +312,50 @@ 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 toast = Toast.makeText(Main.this, "暂无路标", 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,
+ "请靠近路标", 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);
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 +363,6 @@ public class Main extends PiztorAct {
option.setCoorType("bd09ll");
option.setScanSpan(GPSrefreshrate * 1000);
mLocClient.setLocOption(option);
- mLocClient.start();
mapMaker.UpdateLocationOverlay(locData, false);
}
@@ -358,21 +381,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 +413,37 @@ public class Main extends PiztorAct {
@Override
protected void onResume() {
+ if (app.isExiting || app.isLogout)
+ finish();
+ ActStatus[] r = new ActStatus[1];
+ ActStatus startStatus = r[0] = new StartStatus();
+ actMgr = new ActMgr(appMgr, this, startStatus, r);
+ mMapView.onResume();
+ transam.setHandler(handler);
isFirstLocation = true;
- requestUserInfo();
- mapMaker.onResume();
+ mLocClient.start();
+ if (app.token == null) {
+ System.out.println("fuck!!");
+ } else
+ requestUserInfo();
+ // 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,15 +452,21 @@ public class Main extends PiztorAct {
if (mLocClient != null) {
mLocClient.stop();
}
- mapMaker.onDestroy();
+ // mapMaker.mOffline.destroy();
+ mMapView.destroy();
+ app.mBMapManager.stop();
+ // while null?
+ // mMapView.destroy();
+ //
super.onDestroy();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
- AppMgr.exit();
- return true;
+ System.out.println("ready to exit!!!");
+ //
+ app.isExiting = true;
}
return super.onKeyDown(keyCode, event);
}
@@ -437,7 +474,7 @@ public class Main extends PiztorAct {
@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);
+ // getMenuInflater().inflate(R.menu.main, menu);
return false;
}
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..967a34d 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
@@ -1,79 +1,46 @@
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.Gravity;
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 {
-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 +50,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,22 +75,24 @@ public class MapMaker extends Activity {
private View popupLeft = null;
private View popupRight = null;
- //misc
+ // misc
private Context context;
private LocationManager locationManager = null;
boolean isGPSEnabled;
private int[] myIcons;
private Drawable[] myBM;
- private final int iconNum = 4;
+ private final int iconNum = 9;
+
+ 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 +107,7 @@ public class MapMaker extends Activity {
* Layer for my location
*/
public class LocationOverlay extends MyLocationOverlay {
-
+
public LocationOverlay(MapView mapView) {
super(mapView);
}
@@ -139,29 +117,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 + "班 " + tmpInfo.nickname;
+ popupText.setText(itemInfo);
Bitmap bitmap = BMapUtil.getBitmapFromView(popupInfo);
popLay.showPopup(bitmap, item.getPoint(), 32);
}
@@ -170,22 +149,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) {
@@ -202,14 +181,16 @@ 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);
+ Toast.makeText(context, String.format("加载了%d个离线地图包", num),
+ Toast.LENGTH_SHORT).show();
}
Log.d("offline", "inited");
- Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+
}
/**
@@ -229,30 +210,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 +264,66 @@ public class MapMaker extends Activity {
* Initialize map
*/
public void InitMap() {
-
+
InitLocationOverlay();
InitMyOverLay();
InitPopup();
- InitOfflineMap();
+ //InitOfflineMap();
myBM = new Drawable[20];
initMyIcons();
- //InitTouchListenr();
+ // InitTouchListenr();
}
public void initMyIcons() {
- myBM[0] = context.getResources().getDrawable(R.drawable.circle_red);
- myBM[1] = context.getResources().getDrawable(R.drawable.circle_green);
+ myBM[0] = context.getResources().getDrawable(R.drawable.circle_blue);
+ myBM[1] = context.getResources().getDrawable(R.drawable.circle_red);
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);
+ myBM[5] = context.getResources().getDrawable(R.drawable.circle_green);
+ myBM[6] = context.getResources().getDrawable(R.drawable.circle_metal);
+ myBM[7] = context.getResources().getDrawable(R.drawable.circle_paper);
+ myBM[8] = context.getResources().getDrawable(R.drawable.circle_tan);
+ }
+
+ public Drawable getGroupIcon(UserInfo userInfo) {
+ if (Main.colorMode == Main.show_by_team) {
+ if (userInfo.section == preMapInfo.myInfo.section)
+ return myBM[0];
+ else
+ return myBM[userInfo.section % iconNum + 1];
+ } else {
+ return myBM[userInfo.sex ^ preMapInfo.myInfo.sex];
}
-
- public Drawable getGroupIcon(int gid) {
- if (gid == Infomation.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)));
}
+ checkMarkerTime();
+ }
+
+ boolean isInvalidLocation(GeoPoint point) {
+ if (point == null) return false;
+ if (point.getLatitudeE6() / 1E6 > 180.0 || point.getLatitudeE6() / 1E6 < -180.0
+ || point.getLongitudeE6() > 180.0 || point.getLongitudeE6() / 1E6 < -180.0)
+ return false;
+ return true;
}
/**
* Update to draw other users
*/
public void UpdateMap(MapInfo mapInfo) {
-
if (mapInfo == null) {
if (mOverlay != null && mOverlay.getAllItem().size() != 0) {
mOverlay.removeAll();
@@ -332,84 +334,192 @@ 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);
+ }
+ if (mapInfo.getUserInfo(i.uid) != null && isInvalidLocation(mapInfo.getUserInfo(i.uid).location)) {
+ mOverlay.removeItem(hash.get(i.uid));
+ markerToInt.remove(hash.get(i.uid));
hash.remove(i.uid);
}
}
}
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
- ///////////////////////////////
- curItem.setMarker(getGroupIcon(i.section));
- mOverlay.addItem(curItem);
- hash.put(i.uid, curItem);
- //if (mMapView != null)
- // mMapView.refresh();
+ if (i.uid == preMapInfo.myInfo.uid)
+ continue;
+ if (hash.containsKey(i.uid) == false) {
+ if (isInvalidLocation(i.location)) {
+
+ } else {
+ curItem = new OverlayItem(i.location, "USERNAME_HERE",
+ "USER_SNIPPET_HERE");
+ // TODO getDrawable
+ // /////////////////////////////
+ curItem.setMarker(getGroupIcon(i));
+ mOverlay.addItem(curItem);
+ hash.put(i.uid, curItem);
+ markerToInt.put(curItem, i.uid);
+ }
} else {
- 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 (isInvalidLocation(i.location)) {
+ mOverlay.removeItem(hash.get(i.uid));
+ markerToInt.remove(hash.get(i.uid));
+ hash.remove(i.uid);
+ } else {
+ curItem = hash.get(i.uid);
+ curItem.setGeoPoint(i.location);
+ mOverlay.updateItem(curItem);
+ }
}
}
if (mMapView != null) {
mMapView.refresh();
}
- preMapInfo = mapInfo;
+ checkMarkerTime();
}
+ @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);
+ Toast toast = Toast.makeText(context,"收到新路标,集合时间:" + nowMarkerHour + ":" + nowMarkerMinute, 5000);
+ toast.setGravity(Gravity.TOP, 0, 80);
+ toast.show();
+ return;
+ }
+ if (nowMarker == null) {
+ Log.d("marker", "New marker created!");
+ nowMarker = new OverlayItem(markerInfo.markerPoint, "MARKER_NAME",
+ "");
+ nowMarker.setMarker(context.getResources().getDrawable(
+ R.drawable.marker_red));
+ System.out.println(markerInfo.markerPoint.getLatitudeE6() + " "
+ + markerInfo.markerPoint.getLongitudeE6());
+ final Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(markerInfo.markerTimestamp);
+ Date date = (Date) cal.getTime();
+ nowMarkerHour = date.getHours();
+ nowMarkerMinute = date.getMinutes();
+ nowMarkerTimestamp = markerInfo.markerTimestamp;
+ nowMarkerLevel = markerInfo.level;
+
+ markerIndex = mOverlay.getAllItem().size();
+ mOverlay.addItem(nowMarker);
+ mMapView.refresh();
+ mMapController.animateTo(markerInfo.markerPoint);
+ Toast toast = Toast.makeText(context,"收到新路标,集合时间:" + nowMarkerHour + ":" + nowMarkerMinute, 5000);
+ toast.setGravity(Gravity.TOP, 0, 80);
+ toast.show();
+ return;
+ }
+ }
+
+ void sendMarker() {
+ 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);
+ Toast toast = Toast.makeText(context,"创建新路标,集合时间:" + nowMarkerHour + ":" + nowMarkerMinute, 5000);
+ toast.setGravity(Gravity.TOP, 0, 80);
+ toast.show();
}
public GeoPoint getMakerLocation() {
- if (nowMarker == null) return null;
- else return nowMarker.getPoint();
+ 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();
}
+
+ public void checkMarkerTime() {
+ if (nowMarker != null && nowMarkerTimestamp <= System.currentTimeMillis()) {
+ AlertMaker lateAlert = new AlertMaker(context, this);
+ lateAlert.showLateAlert();
+ removeMarker();
+ }
+ }
/**
* 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 +530,4 @@ public class MapMaker extends Activity {
clearOverlay(null);
mOverlay.addItem(mItems);
}
-
- @Override
- protected void onPause() {
- mMapView.onPause();
- }
-
- @Override
- protected void onResume() {
- mMapView.onResume();
- }
-
- @Override
- protected void onDestroy() {
- mMapView.destroy();
- }
-
}
diff --git a/client/Piztor/src/com/macaroon/piztor/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/Settings.java b/client/Piztor/src/com/macaroon/piztor/Settings.java
index b334cc4..14d5b3e 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,43 @@ import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
+import android.widget.RadioGroup.OnCheckedChangeListener;import android.widget.CompoundButton;
+import android.widget.RadioGroup;
+import android.widget.SeekBar;
+import android.widget.TextView;
import android.widget.Toast;
public class Settings extends PiztorAct {
- Button logout;
+
+ public final int show_by_team = 1;
+ public final int show_by_sex = 2;
+
+ Button logout, subscribe, account;
MapInfo mapInfo;
Transam transam;
+ private int currentRate;
+ OnCheckedChangeListener radioButtonListener = null;
+ RadioGroup radioGroup;
+
// Event
final static int logoutButtonPressed = 10;
final static int logoutFailed = 11;
- @SuppressLint("HandlerLeak")
- Handler handler = new Handler() {
+ static class ReCall extends Handler {
+ WeakReference<Settings> outerClass;
+
+ ReCall(Settings activity) {
+ outerClass = new WeakReference<Settings>(activity);
+ }
+
@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 +57,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 +69,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 +129,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,35 +140,139 @@ 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一次更新");
+ 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);
+ radioGroup = (RadioGroup)this.findViewById(R.id.radioGroup);
+ if (Main.colorMode == Main.show_by_sex) radioGroup.check(R.id.show_by_sex);
+ else radioGroup.check(R.id.show_by_team);
+ radioButtonListener = new OnCheckedChangeListener() {
+
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ if (checkedId == R.id.show_by_team){
+ setColorMode(show_by_team);
+ }
+ if (checkedId == R.id.show_by_sex){
+ setColorMode(show_by_sex);
+ }
+ }
+ };
+ radioGroup.setOnCheckedChangeListener(radioButtonListener);
+
}
@Override
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一次更新");
+ SeekBar bar1 = (SeekBar) Settings.this.findViewById(R.id.settings_GPSrefreshrate_bar);
+ bar1.setProgress(currentRate);
+ bar1.setOnSeekBarChangeListener(new mySeekBarListener());
+ }
+
+ private void setColorMode(int colorMode) {
+ Main.colorMode = colorMode;
+ Log.d("color", "switch to " + colorMode);
+ }
+
+ @Override
+ protected void onDestroy() {
+ setGPSrate();
+ super.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ setGPSrate();
+ super.onPause();
+ }
+
+ @Override
+ protected void onPause() {
+ setGPSrate();
+ super.onPause();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (app.isExiting || app.isLogout)
+ finish();
+ }
+
@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..ff7c00d 100644
--- a/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
+++ b/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
@@ -1,9 +1,12 @@
package com.macaroon.piztor;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.Vector;
import android.app.Activity;
@@ -11,6 +14,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 +22,296 @@ 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;
+import com.macaroon.piztor.Settings.ReCall;
-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;
- }
- }
-
- };
-
- }
+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;
+ private Set<Integer> recSubcribe;
+
+
+ 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);
+ mShowInfo = (TextView) findViewById(R.id.textView1);
+ mShowInfo.setText("若要关注整个连请将班级号留空");
+
+ listGroup = new Vector<RGroup>();
+ recSubcribe = new HashSet<Integer>();
+
+ 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) {
+ if (i.section == 255)
+ recSubcribe.add(i.company);
+ }
+ for (int i : recSubcribe) {
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("subscribe_text", i + "连");
+ mList.add(map);
+
+ RGroup listItem = new RGroup(i, 255);
+ listGroup.add(listItem);
+ simpleAdapter.notifyDataSetChanged();
+ }
+ for (RGroup i : ((myApp) getApplication()).sublist) {
+ if (i.section == 255) continue;
+ //else
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("subscribe_text", i.company + "连 " + i.section + "班");
+ mList.add(map);
+
+ RGroup listItem = new RGroup(i.company, i.section);
+ 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,ss;
+ //Log.d("sub", edit_company.getText().toString() + " " + edit_section.getText().toString());
+ if (edit_company.getText().toString().length() == 0) {
+ mShowInfo.setText("连号为空,请输入正确的连队、班级号(关注整个连,则班号留空)");
+ Log.d("sub", "连号为空");
+ return;
+ } else {
+ cc = Integer.parseInt(edit_company.getText().toString());
+ if (cc <= 0 || cc > 40) {
+ mShowInfo.setText("连号超限,请输入正确的连队、班级号(关注整个连,则班号留空)");
+ Log.d("sub", "连号超限" + cc);
+ return;
+ }
+ }
+
+ if (edit_section.getText().toString().length() == 0) {
+ ss = 255;
+ Log.d("sub", "订阅全连" + cc);
+ } else {
+ ss = Integer.parseInt(edit_section.getText().toString());
+ if (ss <= 0 || ss > 20) {
+ mShowInfo.setText("班号超限,请输入正确的连队、班级号(关注整个连,则班号留空)");
+ Log.d("sub", "班号超限" + ss);
+ return;
+ }
+ }
+
+ // TODO get real company and section number
+ if (recSubcribe.contains(cc)) return;
+
+ if (ss == 255) {
+ recSubcribe.add(cc);
+ for (int i = 0; i < listGroup.size(); i++) {
+ if (listGroup.get(i).company == cc) {
+ listGroup.remove(i);
+ mList.remove(i);
+ i--;
+ simpleAdapter.notifyDataSetChanged();
+ }
+ }
+
+ RGroup listItem = new RGroup(cc, 255);
+ listGroup.add(listItem);
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("subscribe_text", cc + "连");
+ mList.add(map);
+ simpleAdapter.notifyDataSetChanged();
+ subscribe();
+ mShowInfo.setText("已关注第" + cc + "连");
+ return;
+ }
+ RGroup listItem = new RGroup(cc, ss);
+ for (RGroup i : listGroup) {
+ if (i.company == cc && i.section == ss)
+ return;
+ }
+ listGroup.add(listItem);
+
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("subscribe_text", cc + "连 " + ss + "班");
+ mList.add(map);
+
+ subscribe();
+
+ simpleAdapter.notifyDataSetChanged();
+ mShowInfo.setText("已关注第" + cc + "连" + ss + "班");
+ }
+ });
+ }
+
+ 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_DELETE:
+ if (listGroup.get(msg.arg1).section == 255)
+ recSubcribe.remove(listGroup.get(msg.arg1).company);
+ mList.remove(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/UpdateInfo.java b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
index 0521432..66ead66 100644
--- a/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
+++ b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
@@ -1,5 +1,144 @@
package com.macaroon.piztor;
-public class UpdateInfo {
+import java.lang.ref.WeakReference;
+import java.util.Vector;
+
+import com.baidu.platform.comapi.basestruct.GeoPoint;
+import com.macaroon.piztor.Settings.ReCall;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.Menu;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class UpdateInfo extends PiztorAct {
+ TextView userName, nickName;
+ EditText oldPass, newPass;
+ Button submit;
+
+ static class ReCall extends Handler {
+ WeakReference<UpdateInfo> outerClass;
+
+ ReCall(UpdateInfo activity) {
+ outerClass = new WeakReference<UpdateInfo>(activity);
+ }
+
+ @Override
+ public void handleMessage(Message m) {
+ UpdateInfo 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.appMgr.trigger(AppMgr.logout);
+ break;
+ case Res.SendMessage:
+ Log.d(LogInfo.resquest, "send message successfully");
+ break;
+ case Res.SetPassword:
+ ResSetPassword res = (ResSetPassword) m.obj;
+ switch (res.type) {
+ case 0:
+ out.receiveMessage("修改成功,请重新登录");
+ out.appMgr.trigger(AppMgr.logout);
+ break;
+ case 1:
+ out.appMgr.trigger(AppMgr.logout);
+ break;
+ case 3:
+ out.receiveMessage("密码错误");
+ default:
+ break;
+ }
+ break;
+ case -1:
+ out.appMgr.trigger(AppMgr.logout);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ ReCall handler = new ReCall(this);
+ void receiveMessage(String msg) {
+ Log.d("recieve message", msg);
+ Toast toast = Toast.makeText(getApplicationContext(), msg,
+ Toast.LENGTH_LONG);
+ toast.show();
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ id = "updateInfo";
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_updateinfo);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ oldPass = (EditText) findViewById(R.id.password_old);
+ newPass = (EditText) findViewById(R.id.password_new);
+ submit = (Button) findViewById(R.id.btn_submit);
+ userName = (TextView) findViewById(R.id.username);
+ nickName = (TextView) findViewById(R.id.nickname);
+ userName.setText(app.username);
+ nickName.setText(app.mapInfo.myInfo.nickname);
+ submit.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ String oldpass = oldPass.getText().toString();
+ String newpass = newPass.getText().toString();
+ ReqSetPassword req = new ReqSetPassword(app.token,
+ app.username, oldpass, newpass, System
+ .currentTimeMillis(), 3000);
+ transam.send(req);
+ }
+ });
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ transam.setHandler(handler);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.update_info, menu);
+ return true;
+ }
}
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..ab38efa
--- /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;
+ boolean isExiting = false;
+ boolean isLogout = false;
+ String ip = "202.120.7.4";
+// static String ip = "69.85.86.42";
+// static String ip = "192.168.1.101";
+ int port = 2223;
+ String token = null;
+ String username = null;
+ Vector<RGroup> sublist;
+
+ AppMgr appMgr;
+
+ 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;
+ }
+
+}