summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorsjtufs <[email protected]>2013-08-30 22:33:16 +0800
committersjtufs <[email protected]>2013-08-30 22:33:16 +0800
commit6f38860cd5907501d90eb5518ac42978d7dec834 (patch)
tree6c461b109242e8c0bb59d1f1a1a0373261e8d88a /client
parent04cd785f24d779996df8672938372467af6c9a82 (diff)
update
Diffstat (limited to 'client')
-rw-r--r--client/Piztor/res/drawable/circle_blue.pngbin0 -> 1070 bytes
-rw-r--r--client/Piztor/res/drawable/circle_glass.pngbin0 -> 1173 bytes
-rw-r--r--client/Piztor/res/drawable/circle_metal.pngbin0 -> 894 bytes
-rw-r--r--client/Piztor/res/drawable/circle_paper.pngbin0 -> 965 bytes
-rw-r--r--client/Piztor/res/drawable/circle_red.pngbin690 -> 892 bytes
-rw-r--r--client/Piztor/res/drawable/circle_tan.pngbin0 -> 916 bytes
-rw-r--r--client/Piztor/res/drawable/circle_wood.pngbin0 -> 1359 bytes
-rw-r--r--client/Piztor/res/drawable/circle_yellow.pngbin0 -> 946 bytes
-rw-r--r--client/Piztor/res/drawable/footbar_checkin.pngbin3251 -> 1639 bytes
-rw-r--r--client/Piztor/res/layout/activity_settings.xml246
-rw-r--r--client/Piztor/res/layout/activity_updateinfo.xml121
-rw-r--r--client/Piztor/res/layout/main_footbar.xml10
-rw-r--r--client/Piztor/res/layout/settings_headbar.xml4
-rw-r--r--client/Piztor/res/values/strings.xml4
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AlertMaker.java24
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AppMgr.java8
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Convert.java63
-rw-r--r--client/Piztor/src/com/macaroon/piztor/EException.java75
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Infomation.java8
-rw-r--r--client/Piztor/src/com/macaroon/piztor/InitAct.java9
-rw-r--r--client/Piztor/src/com/macaroon/piztor/LogInfo.java12
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Login.java27
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java227
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MainActivity.java133
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapInfo.java9
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java85
-rw-r--r--client/Piztor/src/com/macaroon/piztor/PushClient.java106
-rw-r--r--client/Piztor/src/com/macaroon/piztor/RGroup.java10
-rw-r--r--client/Piztor/src/com/macaroon/piztor/RUserInfo.java22
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Req.java100
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqLocation.java16
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqLogin.java16
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqLogout.java12
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java14
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqStartPush.java12
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqUpdate.java16
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java15
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java15
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Res.java141
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResLocation.java18
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResLogin.java17
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResLogout.java13
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResPushLocation.java18
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResPushMessage.java15
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResSendMessage.java13
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResStartPush.java13
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResUpdate.java13
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResUserInfo.java22
-rw-r--r--client/Piztor/src/com/macaroon/piztor/ResUserinfo.java20
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Settings.java131
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SocketClient.java373
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Transam.java219
-rw-r--r--client/Piztor/src/com/macaroon/piztor/UpdateInfo.java5
53 files changed, 1418 insertions, 1032 deletions
diff --git a/client/Piztor/res/drawable/circle_blue.png b/client/Piztor/res/drawable/circle_blue.png
new file mode 100644
index 0000000..09c3658
--- /dev/null
+++ 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
new file mode 100644
index 0000000..826b2b7
--- /dev/null
+++ b/client/Piztor/res/drawable/circle_glass.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_metal.png b/client/Piztor/res/drawable/circle_metal.png
new file mode 100644
index 0000000..d84e1ad
--- /dev/null
+++ 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
new file mode 100644
index 0000000..973787d
--- /dev/null
+++ b/client/Piztor/res/drawable/circle_paper.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_red.png b/client/Piztor/res/drawable/circle_red.png
index 034cea8..fd0efb1 100644
--- a/client/Piztor/res/drawable/circle_red.png
+++ b/client/Piztor/res/drawable/circle_red.png
Binary files differ
diff --git a/client/Piztor/res/drawable/circle_tan.png b/client/Piztor/res/drawable/circle_tan.png
new file mode 100644
index 0000000..27d10ad
--- /dev/null
+++ 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
new file mode 100644
index 0000000..ea18f7a
--- /dev/null
+++ 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
new file mode 100644
index 0000000..7c1dfc7
--- /dev/null
+++ b/client/Piztor/res/drawable/circle_yellow.png
Binary files differ
diff --git a/client/Piztor/res/drawable/footbar_checkin.png b/client/Piztor/res/drawable/footbar_checkin.png
index 0a4b148..f514613 100644
--- a/client/Piztor/res/drawable/footbar_checkin.png
+++ b/client/Piztor/res/drawable/footbar_checkin.png
Binary files differ
diff --git a/client/Piztor/res/layout/activity_settings.xml b/client/Piztor/res/layout/activity_settings.xml
index 865cbc6..3bd6fef 100644
--- a/client/Piztor/res/layout/activity_settings.xml
+++ b/client/Piztor/res/layout/activity_settings.xml
@@ -11,121 +11,157 @@
<include layout="@layout/settings_headbar"></include>
- <TextView
- android:id="@+id/settings_GPSrefreshrate_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginTop="10dip"
- android:text="GPS refresh rate"
- android:textColor="@android:color/white"
- android:textSize="20dip" />
-
+ <RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dip"
+ android:orientation="horizontal">
+ <TextView
+ android:id="@+id/settings_GPSrefreshrate_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_marginTop="10dip"
+ android:layout_marginLeft="60dip"
+ android:text="GPS refresh rate"
+ android:textColor="@android:color/white"
+ android:textSize="20dip" />
+ <TextView
+ android:id="@+id/settings_GPSrefreshrate"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="20dip"
+ android:layout_marginTop="10dip"
+ android:layout_marginLeft="20dip"
+ android:layout_gravity="center_vertical"
+ android:textColor="@android:color/white"
+ android:layout_toRightOf="@+id/settings_GPSrefreshrate_text"
+ android:text="30s"/>
+
+ </RelativeLayout>
+
<SeekBar
- android:id="@+id/settings_GPSrefreshrate"
+ android:id="@+id/settings_GPSrefreshrate_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:max="60"
+ android:progress="30"
+ android:paddingLeft="18px"
+ android:paddingRight="18px"
android:layout_marginLeft="40px"
android:layout_marginRight="40px" />
+ <RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="40dip"
+ android:layout_marginRight="40dip">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="@android:color/white"
+ android:layout_alignParentLeft="true"
+ android:text="fast"
+ android:textSize="12dip"/>
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="@android:color/white"
+ android:layout_alignParentRight="true"
+ android:text="slow"
+ android:textSize="12dip"/>
+ </RelativeLayout>
+
<View
android:layout_width="fill_parent"
android:layout_height="1.0px"
- android:layout_marginTop="40px"
- android:layout_marginBottom="40px"
- android:layout_marginLeft="20.0px"
- android:layout_marginRight="20.0px"
+ android:layout_marginTop="20dip"
+ android:layout_marginBottom="20dip"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
android:background="#ffc0c3c4" />
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Button 2" />
-
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Button 3" />
-
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Button 4" />
-
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Button 5" />
-
- <ProgressBar
- android:id="@+id/progressBar1"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- <RadioButton
- android:id="@+id/radioButton2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="RadioButton 1" />
-
- <RadioButton
- android:id="@+id/radioButton1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="RadioButton 2" />
-
- <ToggleButton
- android:id="@+id/toggleButton1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="ToggleButton" />
-
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Button 6" />
-
- <SeekBar
- android:id="@+id/seekBar1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- <Button
- android:id="@+id/button3"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Button 7" />
-
- <Button
- android:id="@+id/button4"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Button 8" />
-
- <CheckBox
- android:id="@+id/checkBox1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="CheckBox" />
-
- <Button
- android:id="@+id/button2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Button 9" />
-
- <Button
- android:id="@+id/button1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Button 10" />
-
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Button 11"
- android:id="@+id/settings_btn_logout" />
+ <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:orientation="horizontal">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="#4D4D4D"
+ android:textColor="#FFFFFF"
+ android:textSize="25dip"
+ android:text="company"
+ android:id="@+id/settings_subscribe_company"
+ />
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="#4D4D4D"
+ android:textColor="#FFFFFF"
+ android:textSize="25dip"
+ android:layout_marginLeft="20dip"
+ android:text="section"
+ android:id="@+id/settings_subscribe_section"
+ />
+
+ <Button
+ android:id="@+id/settings_btn_subscribe"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="20dip"
+ android:text="@string/change"
+ android:textSize="22dip" />
+
+ </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"
+ android:layout_marginRight="50dip"
+ android:orientation="vertical">
+ <Button
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="5dip"
+ android:paddingBottom="5dip"
+ android:text="@string/update_info"
+ android:textSize="30dip"
+ android:textColor="@android:color/white"
+ android:background="#4285F4"
+ android:id="@+id/settings_btn_updateinfo" />
+ <Button
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="5dip"
+ android:paddingBottom="5dip"
+ android:layout_marginTop="20dip"
+ android:text="@string/logout"
+ android:textSize="30dip"
+ android:textColor="@android:color/white"
+ android:background="#DB4437"
+ android:id="@+id/settings_btn_logout" />
+ </LinearLayout>
</LinearLayout>
-
</ScrollView> \ No newline at end of file
diff --git a/client/Piztor/res/layout/activity_updateinfo.xml b/client/Piztor/res/layout/activity_updateinfo.xml
new file mode 100644
index 0000000..de9ecc6
--- /dev/null
+++ b/client/Piztor/res/layout/activity_updateinfo.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+
+ <LinearLayout
+
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_marginTop="20dip"
+ android:orientation="vertical" >
+
+ <include layout="@layout/settings_headbar"></include>
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_marginTop="10dip"
+ android:gravity="center"
+ android:textSize="20dip"
+ android:textColor="#FFFFFF"
+ android:text="haha"
+ android:id="@+id/username_text" />
+ <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" />
+
+ <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" />
+
+ <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/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" />
+
+ <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>
+</ScrollView> \ No newline at end of file
diff --git a/client/Piztor/res/layout/main_footbar.xml b/client/Piztor/res/layout/main_footbar.xml
index b4659ff..287fb4f 100644
--- a/client/Piztor/res/layout/main_footbar.xml
+++ b/client/Piztor/res/layout/main_footbar.xml
@@ -6,7 +6,7 @@
android:background="@drawable/footbar_background" android:baselineAligned="false">
<LinearLayout
- android:id="@+id/footbar_btn_search_layout"
+ android:id="@+id/footbar_btn_checkin_layout"
android:layout_width="64dip"
android:layout_height="match_parent"
android:orientation="vertical"
@@ -14,21 +14,21 @@
android:layout_gravity="center_vertical"
android:layout_weight="1">
<ImageButton
- android:id="@+id/footbar_btn_search"
+ android:id="@+id/footbar_btn_checkin"
android:layout_width="90dip"
android:layout_height="30dip"
android:layout_gravity="center"
android:contentDescription="@string/desc"
- android:background="@drawable/footbar_btn_search_style"/>
+ android:background="@drawable/footbar_btn_checkin_style"/>
<TextView
- android:id="@+id/footbar_btn_search_text"
+ android:id="@+id/footbar_btn_checkin_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="10dip"
android:textColor="@android:color/white"
android:layout_gravity="center"
- android:text="@string/search"/>
+ android:text="@string/checkin"/>
</LinearLayout>
<LinearLayout
diff --git a/client/Piztor/res/layout/settings_headbar.xml b/client/Piztor/res/layout/settings_headbar.xml
index 606c172..3063b66 100644
--- a/client/Piztor/res/layout/settings_headbar.xml
+++ b/client/Piztor/res/layout/settings_headbar.xml
@@ -5,14 +5,14 @@
android:background="@drawable/topbar_background"
android:id="@+id/settings_headbar_layout" >
- <ImageButton
+ <!-- ImageButton
android:id="@+id/settings_btn_back"
android:layout_width="110dip"
android:layout_height="40dip"
android:layout_marginLeft="0dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
- android:background="@drawable/navigation_back"/>
+ android:background="@drawable/navigation_back"/-->
<TextView
android:id="@+id/settings_headbar_text"
diff --git a/client/Piztor/res/values/strings.xml b/client/Piztor/res/values/strings.xml
index 192d392..6ff1392 100644
--- a/client/Piztor/res/values/strings.xml
+++ b/client/Piztor/res/values/strings.xml
@@ -21,5 +21,9 @@
<string name="username">username</string>
<string name="login">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">更改</string>
</resources>
diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
index 839813a..cc70e62 100644
--- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
@@ -96,7 +96,7 @@ public class AlertMaker {
mapMaker.DrawMarker(markerPoint);
else {
Toast toast = Toast.makeText(context,
- "Too early!Give me more time!", Toast.LENGTH_LONG);
+ "Too early! Give me at least 2 minutes!", Toast.LENGTH_LONG);
toast.show();
closeBoard(context);
showMarkerAlert(markerPoint);
@@ -108,26 +108,4 @@ public class AlertMaker {
markerDialog.show();
}
- public void showQuitAlert() {
-
- AlertDialog.Builder quitDialog = new AlertDialog.Builder(context);
- closeBoard(context);
- quitDialog.setTitle("Quit");
- quitDialog.setMessage("Do you want to logout and quit?");
- quitDialog.setPositiveButton("Quit",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- AppMgr.exit();
- }
- });
- quitDialog.setNegativeButton("Cancel",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- closeBoard(context);
- }
- });
- quitDialog.show();
- }
-
}
diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
index e322745..933d2db 100644
--- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java
+++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
@@ -68,21 +68,15 @@ public class AppMgr {
static void trigger(int event) {
Intent i = new Intent();
- System.out.println(nowAct.id + " : " + event);
- if (mp.get(nowAct.getClass()) == null)
- System.out.println("first");
- else if (mp.get(nowAct.getClass()) == null)
- System.out.println("second");
i.setClass(nowAct, mp.get(nowAct.getClass()).get(event));
if (event == errorToken)
Infomation.token = null;
if (event == loginSuccess) {
mBMapManager.start();
- transam.startPush(Infomation.token, Infomation.username);
+ mapInfo.clear();
}
if (event == logout) {
mBMapManager.stop();
- transam.stopPush();
}
nowAct.startActivity(i);
}
diff --git a/client/Piztor/src/com/macaroon/piztor/Convert.java b/client/Piztor/src/com/macaroon/piztor/Convert.java
new file mode 100644
index 0000000..af7359c
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/Convert.java
@@ -0,0 +1,63 @@
+package com.macaroon.piztor;
+
+import android.annotation.SuppressLint;
+
+public class Convert {
+
+ @SuppressLint("DefaultLocale")
+ public static byte[] hexStringToBytes(String hexString) {
+ if (hexString == null || hexString.equals("")) {
+ return null;
+ }
+ hexString = hexString.toUpperCase();
+ int length = hexString.length() / 2;
+ char[] hexChars = hexString.toCharArray();
+ byte[] d = new byte[length];
+ for (int i = 0; i < length; i++) {
+ int pos = i * 2;
+ d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+ }
+ return d;
+ }
+
+ public static byte charToByte(char c) {
+ return (byte) "0123456789ABCDEF".indexOf(c);
+ }
+
+ public static byte[] intToBytes(int i) {
+ byte[] d = new byte[4];
+ d[0] = (byte)((i >> 24) & 0xFF);
+ d[1] = (byte)((i >> 16) & 0xFF);
+ d[2] = (byte)((i >> 8) & 0xFF);
+ d[3] = (byte)(i & 0xFF);
+ return d;
+ }
+
+ public static byte[] doubleToBytes(double d){
+ byte[] b=new byte[8];
+ long l=Double.doubleToLongBits(d);
+ for(int i=0;i<8;i++){
+ b[i] = (byte)(l >>> 8*(7-i));
+ }
+ return b;
+ }
+
+ public static void write(byte[] s,byte[] w,int l) {
+
+ for(int i=0;i<w.length;i++){
+ s[i+l] = w[i];
+ }
+ }
+
+ public static String byteToHexString(byte[] buffer){
+ String p ="";
+ for (int i = 0; i < buffer.length; i++) {
+ String hex = Integer.toHexString(buffer[i] & 0xFF);
+ if (hex.length() == 1) {
+ hex = '0' + hex;
+ }
+ p += hex;
+ }
+ return p;
+ }
+} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/EException.java b/client/Piztor/src/com/macaroon/piztor/EException.java
new file mode 100644
index 0000000..5ce1fdb
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/EException.java
@@ -0,0 +1,75 @@
+package com.macaroon.piztor;
+
+
+
+public class EException extends Exception {
+
+ static final int EConnectedFailedException =101;
+ static final int ETimeOutException =102;
+ static final int EJavaHostException =103;
+ static final int EPushFailedException =104;
+ static final int EIOException =105;
+ static final int EUnknownHostException =106;
+ static final int EStatusFailedException =107;
+
+
+ private static final long serialVersionUID = 100L;
+ int Rtype;
+ int Etype;
+ long time;
+ public EException(int e,int r,long timep) {
+ super();
+ Rtype = r;
+ Etype = e;
+ time = timep;
+ }
+ }
+
+ class EConnectFailedException extends EException{
+ private static final long serialVersionUID = 101L;
+ public EConnectFailedException(int t,long timep) {
+ super(101,t,timep);
+ }
+ }
+
+ class ETimeOutException extends EException{
+ private static final long serialVersionUID = 102L;
+ public ETimeOutException(int t,long timep) {
+ super(102,t,timep);
+ }
+ }
+
+ class EJavaHostException extends EException{
+ private static final long serialVersionUID = 103L;
+ public EJavaHostException(int t,long timep) {
+ super(103,t,timep);
+ }
+ }
+
+ class EPushFailedException extends EException{
+ private static final long serialVersionUID = 104L;
+ public EPushFailedException(int t,long timep) {
+ super(104,t,timep);
+ }
+ }
+
+ class EIOException extends EException{
+ private static final long serialVersionUID = 105L;
+ public EIOException(int t,long timep) {
+ super(105,t,timep);
+ }
+ }
+
+ class EUnknownHostException extends EException{
+ private static final long serialVersionUID = 106L;
+ public EUnknownHostException(int t,long timep) {
+ super(106,t,timep);
+ }
+ }
+
+ class EStatusFailedException extends EException{
+ private static final long serialVersionUID = 107L;
+ public EStatusFailedException(int t,long timep) {
+ super(107,t,timep);
+ }
+ } \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/Infomation.java b/client/Piztor/src/com/macaroon/piztor/Infomation.java
index 603819e..60eb03f 100644
--- a/client/Piztor/src/com/macaroon/piztor/Infomation.java
+++ b/client/Piztor/src/com/macaroon/piztor/Infomation.java
@@ -1,11 +1,15 @@
package com.macaroon.piztor;
+import java.util.Vector;
+
public class Infomation {
- static String ip = "192.168.1.171";
+ 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 = 2222;
+ 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 272afe7..8145935 100644
--- a/client/Piztor/src/com/macaroon/piztor/InitAct.java
+++ b/client/Piztor/src/com/macaroon/piztor/InitAct.java
@@ -2,23 +2,16 @@ package com.macaroon.piztor;
import android.os.Bundle;
import android.view.Menu;
-import android.content.Context;
public class InitAct extends PiztorAct {
- private CopyMap copyMap;
- private String assetDir;
- private String dir;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
id = "initAct";
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_init);
- copyMap = new CopyMap();
- copyMap.testCopy(InitAct.this);
AppMgr.init(getApplicationContext());
AppMgr.transam.setTimeOutTime(5000);
+ setContentView(R.layout.activity_init);
}
@Override
diff --git a/client/Piztor/src/com/macaroon/piztor/LogInfo.java b/client/Piztor/src/com/macaroon/piztor/LogInfo.java
new file mode 100644
index 0000000..2fd93ac
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/LogInfo.java
@@ -0,0 +1,12 @@
+package com.macaroon.piztor;
+
+public class LogInfo {
+ static String login = "login";
+ static String logout = "logout";
+ static String update = "update";
+ static String resquest = "resquest";
+ static String push = "push";
+ static String exception = "exception";
+ static String s = "successfull";
+ static String f = "failed";
+}
diff --git a/client/Piztor/src/com/macaroon/piztor/Login.java b/client/Piztor/src/com/macaroon/piztor/Login.java
index a1a6d0d..533eeac 100644
--- a/client/Piztor/src/com/macaroon/piztor/Login.java
+++ b/client/Piztor/src/com/macaroon/piztor/Login.java
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
@@ -30,20 +31,19 @@ public class Login extends PiztorAct {
}
if (m.what == 0) {
ResLogin res = (ResLogin) m.obj;
- if (res.status == 1) {
- actMgr.trigger(loginFailed);
- return;
- }
+ Log.d(LogInfo.login, LogInfo.s);
Infomation.token = res.t;
- Infomation.myInfo.uid = res.uid;
- Infomation.username = edtUser.getText().toString();
- System.out.println(res.status + " :!!! " + res.type);
+ Infomation.sublist = res.sublist;
+ Infomation.username = res.uinfo.username;
+ Infomation.myInfo = new UserInfo(res.uinfo.uid);
+ Infomation.myInfo.setInfo(res.uinfo.gid.company,
+ res.uinfo.gid.section, res.uinfo.sex,
+ res.uinfo.nickname);
+ System.out.println("login !!!!" + res.sublist.size());
actMgr.trigger(AppMgr.loginSuccess);
- System.out.println("............");
} else {
- System.out.println("reveive other info ~~~~~~~~~~~~~~" + m.what);
-// System.out.println("login de " + m.what);
-// actMgr.trigger(loginFailed);
+ System.out.println("login handler reveive other info : "
+ + m.what);
}
}
};
@@ -113,7 +113,10 @@ public class Login extends PiztorAct {
@Override
protected void onResume() {
super.onResume();
- AppMgr.transam.setHandler(handler);
+ if (AppMgr.transam == null)
+ Log.d(LogInfo.exception, "transam = null");
+ AppMgr.transam.setHandler(handler);
+
}
@Override
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java
index 1e46003..623595b 100644
--- a/client/Piztor/src/com/macaroon/piztor/Main.java
+++ b/client/Piztor/src/com/macaroon/piztor/Main.java
@@ -1,8 +1,6 @@
package com.macaroon.piztor;
import java.util.Calendar;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.Vector;
import android.annotation.SuppressLint;
@@ -39,14 +37,13 @@ public class Main extends PiztorAct {
final static int FailedFetch = 5;
final static int mapViewtouched = 7;
-
MapMaker mapMaker = null;
MapView mMapView;
AlertMaker alertMaker;
private Calendar calendar;
GeoPoint markerPoint = null;
private MKMapTouchListener mapTouchListener;
-
+
/**
* Locating component
*/
@@ -56,100 +53,67 @@ public class Main extends PiztorAct {
LocationData locData = null;
public MyLocationListener myListener = new MyLocationListener();
boolean isFirstLocation = true;
+ public static int GPSrefreshrate = 5;
ImageButton btnSearch, btnFetch, btnFocus, btnSettings;
MapInfo mapInfo;
+ Transam transam;
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message m) {
switch (m.what) {
- case 1:// 上传自己信息成功or失败
- ResUpdate update = (ResUpdate) m.obj;
- if (update.status == 0)
- System.out.println("update success");
- else {
- System.out.println("update failed");
- actMgr.trigger(AppMgr.errorToken);
- }
+ case Res.Login:// 上传自己信息成功or失败
+ Log.d("update location", "successfull");
break;
- case 2:// 得到别人的信息
- ResLocation location = (ResLocation) m.obj;
- if (location.status == 0) {
- mapInfo.clear();
- for (RLocation i : location.l) {
- System.out.println(i.id + " : " + i.latitude + " "
- + i.longitude);
- UserInfo info = new UserInfo(i.id);
- info.setLocation(i.latitude, i.longitude);
- mapInfo.addUserInfo(info);
- }
-// actMgr.trigger(SuccessFetch);
- flushMap();
- } else {
- System.out.println("resquest for location failed!");
- actMgr.trigger(AppMgr.errorToken);
- }
- break;
- case 3:// 得到用户信息
- ResUserInfo r = (ResUserInfo) m.obj;
- if (r.status == 0) {
- System.out.println("id : " + r.uid + " sex : " + r.sex
- + " group : " + r.section);
- if (r.uid == Infomation.myInfo.uid) {
- System.out.println("flush myself info!!!");
- Infomation.myInfo.section = r.section;
- Infomation.myInfo.company = r.company;
- Infomation.myInfo.sex = r.sex;
+ 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 = 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 {
- UserInfo user = mapInfo.getUserInfo(r.uid);
- if (user != null)
- user.setInfo(r.company, r.section, r.sex);
- else
- System.out.println("fuck!!!!");
+ r = new UserInfo(info.uid);
+ r.setInfo(info.gid.company, info.gid.section, info.sex,
+ info.nickname);
+ r.setLocation(info.latitude, info.longitude);
+ mapInfo.addUserInfo(r);
}
- flushMap();
- } else {
- System.out.println("reqest for userInfo must be wrong!!!");
- actMgr.trigger(AppMgr.errorToken);
- }
- break;
- case 4:// 登出
- ResLogout logout = (ResLogout) m.obj;
- if (logout.status == 0) {
- actMgr.trigger(AppMgr.logout);
- } else {
- Toast toast = Toast.makeText(getApplicationContext(),
- "logout failed", Toast.LENGTH_LONG);
- toast.show();
}
+ System.out.println("now has info number : " + mapInfo.allUsers.size());
+ flushMap();
break;
- case Transam.StartPush:
- ResStartPush startpush = (ResStartPush) m.obj;
- if (startpush.status == 1) {
- System.out.println("!!!!!!!!!!!!!jian gui le!!!!!!!!!!!!!");
- }
+ case Res.Logout:// 登出
+ actMgr.trigger(AppMgr.logout);
break;
- case Transam.PushMessage:
+ case Res.PushMessage:
ResPushMessage pushMessage = (ResPushMessage) m.obj;
receiveMessage(pushMessage.message);
break;
- case Transam.SendMessage:
- ResSendMessage resMessage = (ResSendMessage) m.obj;
- System.out.println("res message " + resMessage.status);
+ case Res.SendMessage:
+ Log.d(LogInfo.resquest, "send message successfully");
break;
- case Transam.PushLocation:
+ case Res.PushLocation:
ResPushLocation pushLocation = (ResPushLocation) m.obj;
- upDateInfo(pushLocation.l);
+ upMapInfo(pushLocation.l);
+ flushMap();
break;
+ case -1:
+ actMgr.trigger(AppMgr.logout);
default:
break;
}
}
- void upDateInfo(Vector<RLocation> l) {
- // TODO
+ 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) {
@@ -184,18 +148,16 @@ public class Main extends PiztorAct {
if (mapMaker != null)
mapMaker.UpdateMap(AppMgr.mapInfo);
else
- System.out
- .println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ 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 toast = Toast.makeText(getApplicationContext(), msg,
+ Toast.LENGTH_LONG);
toast.show();
}
-
public class MyLocationListener implements BDLocationListener {
int cnt = 0;
@@ -229,7 +191,17 @@ public class Main extends PiztorAct {
hasAnimation = true;
isFirstLocation = false;
}
+ int TMP = location.getLocType();
+ if (TMP == 61) Toast.makeText(Main.this, "Piztor : Update from GPS result (" + GPSrefreshrate + "s)", 3000).show();
+ if (TMP == 161) Toast.makeText(Main.this, "Piztor : Update from Network (" + GPSrefreshrate + "s)" , 3000).show();
+ if (TMP == 65) Toast.makeText(Main.this, "Piztor : Update from Cache (" + GPSrefreshrate + "s)", 3000).show();
mapMaker.UpdateLocationOverlay(locData, hasAnimation);
+
+ LocationClientOption option = new LocationClientOption();
+ option.setOpenGps(true);
+ option.setCoorType("bd09ll");
+ option.setScanSpan(GPSrefreshrate * 1000);
+ mLocClient.setLocOption(option);
}
@Override
@@ -248,9 +220,6 @@ public class Main extends PiztorAct {
if (e == ActMgr.Create) {
System.out.println(Infomation.token + " "
+ Infomation.username + " " + Infomation.myInfo.uid);
- AppMgr.transam.send(new ReqUserInfo(Infomation.token,
- Infomation.username, Infomation.myInfo.uid, System
- .currentTimeMillis(), 5000));
}
if (e == SuccessFetch)
flushMap();
@@ -263,74 +232,76 @@ public class Main extends PiztorAct {
}
-
- void requesLocation(int company, int section) {
- ReqLocation r = new ReqLocation(Infomation.token, Infomation.username,
- company, section, System.currentTimeMillis(), 2000);
- AppMgr.transam
- .send(new ReqSendMessage(Infomation.token, Infomation.username,
- "hahaha", System.currentTimeMillis(), 5000));
+ void requestUserInfo() {
+ for (RGroup i : Infomation.sublist) {
+ ReqUserInfo r = new ReqUserInfo(Infomation.token,
+ Infomation.username, i, System.currentTimeMillis(), 2000);
+ transam.send(r);
+ }
System.out.println("get others infomation!!!");
- AppMgr.transam.send(r);
}
void focusOn() {
mapMaker.mMapController.animateTo(Infomation.myInfo.location);
}
-
+
public void InitTouchListenr() {
mapTouchListener = new MKMapTouchListener() {
-
+
@Override
public void onMapLongClick(GeoPoint arg0) {
closeBoard(Main.this);
alertMaker.showMarkerAlert(arg0);
}
-
+
@Override
public void onMapDoubleClick(GeoPoint arg0) {
// TODO Auto-generated method stub
-
+
}
-
+
@Override
public void onMapClick(GeoPoint arg0) {
// TODO Auto-generated method stub
-
+
}
};
mMapView.regMapTouchListner(mapTouchListener);
}
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
id = "Main";
super.onCreate(savedInstanceState);
-
- locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);
- isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER);
-
+
+ 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();
-// ActStatus fetchStatus = r[1] = new FetchStatus();
-// ActStatus focusStatus = r[2] = new FocusStatus();
- AppMgr.transam.setHandler(handler);
+ // ActStatus fetchStatus = r[1] = new FetchStatus();
+ // ActStatus focusStatus = r[2] = new FocusStatus();
+ if (transam == null)
+ Log.d(LogInfo.exception, "transam = null");
+ transam.setHandler(handler);
actMgr = new ActMgr(this, startStatus, r);
-// actMgr.add(startStatus, FocuseButtonPress, focusStatus);
-// actMgr.add(startStatus, Fetch, fetchStatus);
-// actMgr.add(startStatus, SuccessFetch, startStatus);
-// actMgr.add(startStatus, Fetch, startStatus);
-// actMgr.add(fetchStatus, Fetch, startStatus);
-// actMgr.add(fetchStatus, FailedFetch, startStatus);
-// actMgr.add(fetchStatus, SuccessFetch, startStatus);
-// actMgr.add(focusStatus, FocuseButtonPress, startStatus);
-// actMgr.add(focusStatus, mapViewtouched, startStatus);
-// actMgr.add(focusStatus, SuccessFetch, focusStatus);
-// actMgr.add(focusStatus, Fetch, focusStatus);
+ // actMgr.add(startStatus, FocuseButtonPress, focusStatus);
+ // actMgr.add(startStatus, Fetch, fetchStatus);
+ // actMgr.add(startStatus, SuccessFetch, startStatus);
+ // actMgr.add(startStatus, Fetch, startStatus);
+ // actMgr.add(fetchStatus, Fetch, startStatus);
+ // actMgr.add(fetchStatus, FailedFetch, startStatus);
+ // actMgr.add(fetchStatus, SuccessFetch, startStatus);
+ // actMgr.add(focusStatus, FocuseButtonPress, startStatus);
+ // actMgr.add(focusStatus, mapViewtouched, startStatus);
+ // actMgr.add(focusStatus, SuccessFetch, focusStatus);
+ // actMgr.add(focusStatus, Fetch, focusStatus);
setContentView(R.layout.activity_main);
-
+
mMapView = (MapView) findViewById(R.id.bmapView);
mapMaker = new MapMaker(mMapView, getApplicationContext());
alertMaker = new AlertMaker(Main.this, mapMaker);
@@ -345,7 +316,7 @@ public class Main extends PiztorAct {
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);
option.setCoorType("bd09ll");
- option.setScanSpan(5000);
+ option.setScanSpan(GPSrefreshrate * 1000);
mLocClient.setLocOption(option);
mLocClient.start();
mapMaker.UpdateLocationOverlay(locData, false);
@@ -354,11 +325,11 @@ public class Main extends PiztorAct {
public static void closeBoard(Context cc) {
InputMethodManager imm = (InputMethodManager) cc
.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm.isActive())
- imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
- InputMethodManager.HIDE_NOT_ALWAYS);
- }
-
+ if (imm.isActive())
+ imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
+ InputMethodManager.HIDE_NOT_ALWAYS);
+ }
+
/*
* public boolean onTap(int index) { OverlayItem item = getItem(index);
* mCurItem = item; if () }
@@ -373,17 +344,17 @@ public class Main extends PiztorAct {
btnFetch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
- requesLocation(Infomation.myInfo.company, Infomation.myInfo.section);
+
}
});
-
+
btnFocus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
focusOn();
}
});
-
+
btnSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
@@ -396,15 +367,15 @@ public class Main extends PiztorAct {
@Override
protected void onRestart() {
super.onRestart();
- AppMgr.transam.setHandler(handler);
+ transam.setHandler(handler);
}
-
+
@Override
protected void onResume() {
isFirstLocation = true;
+ requestUserInfo();
mapMaker.onResume();
flushMap();
- requesLocation(Infomation.myInfo.company, Infomation.myInfo.section);
super.onResume();
}
@@ -431,7 +402,7 @@ public class Main extends PiztorAct {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
- alertMaker.showQuitAlert();
+ AppMgr.exit();
return true;
}
return super.onKeyDown(keyCode, event);
diff --git a/client/Piztor/src/com/macaroon/piztor/MainActivity.java b/client/Piztor/src/com/macaroon/piztor/MainActivity.java
new file mode 100644
index 0000000..483112d
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/MainActivity.java
@@ -0,0 +1,133 @@
+package com.macaroon.piztor;
+
+import java.util.Vector;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.view.Menu;
+import android.view.View;
+
+public class MainActivity extends Activity {
+ public String token = "";
+ public String uname = "";
+ public int com;
+ public int sec;
+ public int step = 0;
+ Transam t;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ t = new Transam("192.168.1.171",2223,handler);
+ Thread thread = new Thread(t);
+ thread.start();
+
+ }
+
+ Handler handler = new Handler() {
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case 0:
+ token = ((ResLogin) msg.obj ).t;
+ uname = ((ResLogin) msg.obj ).uinfo.username;
+ com = ((ResLogin) msg.obj ).uinfo.gid.company;
+ sec = ((ResLogin) msg.obj ).uinfo.gid.section;
+ System.out.println(com);
+ System.out.println(sec);
+ System.out.println(((ResLogin) msg.obj ).uinfo.sex);
+ for(int i=0;i<((ResLogin) msg.obj ).subscribeNumber;i++){
+ System.out.println(((ResLogin) msg.obj ).sublist.get(i).company);
+ System.out.println(((ResLogin) msg.obj ).sublist.get(i).section);
+ }
+ System.out.println(token);
+ break;
+ case 2:
+ ResUserInfo r = (ResUserInfo) msg.obj ;
+ System.out.println(r.number);
+ for(int i=0;i<r.number;i++){
+ System.out.println(r.uinfo.get(i).nickname);
+ System.out.println(r.uinfo.get(i).latitude);
+ System.out.println(r.uinfo.get(i).longitude);
+ }
+ break;
+ case 100:
+ System.out.println(((ResPushMessage) msg.obj).message);
+ break;
+ case 101:
+ int nn = ((ResPushLocation)msg.obj).n;
+ Vector<RLocation> ll = ((ResPushLocation)msg.obj).l;
+ for(int i=0;i<nn;i++){
+ System.out.println(ll.get(i).latitude + " " + ll.get(i).longitude);
+ }
+ break;
+ case -1:
+ System.out.println(-1);
+ }
+ super.handleMessage(msg);
+ }
+ };
+
+
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+
+
+
+
+ public void sendMessage(View view) {
+
+ if(step == 0){
+ long time = System.currentTimeMillis();
+ ReqLogin r = new ReqLogin("hello","world",time,2000);
+ t.send(r);
+ step++;
+ }
+ else if(step == 1){
+ long time = System.currentTimeMillis();
+ ReqUpdate r = new ReqUpdate (token,uname,123.456,654.321,time,2000);
+ t.send(r);
+ step++;
+ }
+ else if(step == 2){
+ long time = System.currentTimeMillis();
+ ReqSendMessage r = new ReqSendMessage (token,uname,"wurusai",time,2000);
+ t.send(r);
+ step++;
+ }
+ else if(step == 3){
+ long time = System.currentTimeMillis();
+ ReqLogout r = new ReqLogout(token,uname,time,2000);
+ t.send(r);
+ step++;
+ }
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+}
+
+
+
+
+
+
diff --git a/client/Piztor/src/com/macaroon/piztor/MapInfo.java b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
index 52e168b..d49ac1e 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapInfo.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
@@ -14,7 +14,6 @@ public class MapInfo {
HashMap<Integer, UserInfo> mp;
Vector<UserInfo> allUsers;
UserInfo myInfo;
- Style layout;
@SuppressLint("UseSparseArrays")
MapInfo() {
@@ -32,10 +31,6 @@ public class MapInfo {
mp.put(userInfo.uid, userInfo);
}
- void setStyle(Style layout) {
- this.layout = layout;
- }
-
UserInfo getUserInfo(int uid) {
if (mp.containsKey(uid))
return mp.get(uid);
@@ -57,7 +52,7 @@ class UserInfo {
int company; //group id
int section;
GeoPoint location;
-
+ String nickname;
UserInfo(int uid) {
this.uid = uid;
}
@@ -66,7 +61,7 @@ class UserInfo {
location = new GeoPoint((int)(lat * 1e6), (int)(lot * 1e6));
}
- void setInfo(int company, int section, int sex) {
+ void setInfo(int company, int section, int sex, String nickName) {
this.company = company;
this.section = section;
this.sex = sex;
diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
index 0469702..ef79f73 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
@@ -5,6 +5,8 @@ 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;
@@ -28,6 +30,7 @@ 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;
@@ -100,6 +103,9 @@ public class MapMaker extends Activity {
private Context context;
private LocationManager locationManager = null;
boolean isGPSEnabled;
+ private int[] myIcons;
+ private Drawable[] myBM;
+ private final int iconNum = 4;
/**
* Constructor
@@ -171,7 +177,7 @@ public class MapMaker extends Activity {
return false;
}
}
-
+
/**
* Initialize offline map
*/
@@ -265,7 +271,6 @@ public class MapMaker extends Activity {
popLay = new PopupOverlay(mMapView, popListener);
}
-
/**
* Initialize touch listener
@@ -281,9 +286,24 @@ public class MapMaker extends Activity {
InitMyOverLay();
InitPopup();
InitOfflineMap();
+ myBM = new Drawable[20];
+ initMyIcons();
//InitTouchListenr();
}
+ public void initMyIcons() {
+ myBM[0] = context.getResources().getDrawable(R.drawable.circle_red);
+ myBM[1] = context.getResources().getDrawable(R.drawable.circle_green);
+ myBM[2] = context.getResources().getDrawable(R.drawable.circle_glass);
+ myBM[3] = context.getResources().getDrawable(R.drawable.circle_yellow);
+ myBM[4] = context.getResources().getDrawable(R.drawable.circle_wood);
+ }
+
+ public Drawable getGroupIcon(int gid) {
+ if (gid == Infomation.myInfo.section) return myBM[0];
+ else return myBM[gid % iconNum];
+ }
+
/**
* Update location layer when new location is received
*/
@@ -296,48 +316,10 @@ public class MapMaker extends Activity {
, (int)(locationData.longitude * 1E6)));
}
}
-
+
/**
* Update to draw other users
*/
- /*
- public void UpdateMap(MapInfo mapInfo) {
-
- if (mapInfo != null) {
- preMapInfo = mapInfo;
- if (mOverlay != null && mOverlay.getAllItem().size() != 0) {
- mOverlay.removeAll();
- }
- mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView);
- GeoPoint p;
- Vector<UserInfo> allUsers = mapInfo.getVector();
- if (nowMarker != null) {
- mOverlay.addItem(nowMarker);
- }
- for (int i =1; i < allUsers.size(); i++) {
- // it's me!
- if (allUsers.get(i).uid == Infomation.myInfo.uid) continue;
- p = new GeoPoint((int)(allUsers.get(i).getLatitude() * 1E6),
- (int)(allUsers.get(i).getLongitude()*1E6));
- curItem = new OverlayItem(p, "USERNAME HERE!!!!!", "");
- //TODO
- ////////////////////////////////////////////////////////////
- curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red));
- mOverlay.addItem(curItem);
- }
- mItems = new ArrayList<OverlayItem>();
- mItems.addAll(mOverlay.getAllItem());
- }
-
- if (mMapView != null) {
- if (mMapView.getOverlays() != null) {
- //mMapView.getOverlays().add(mOverlay);
- mMapView.refresh();
- }
- }
- }
- */
-
public void UpdateMap(MapInfo mapInfo) {
if (mapInfo == null) {
@@ -367,7 +349,7 @@ public class MapMaker extends Activity {
curItem = new OverlayItem(p, "USERNAME_HERE", "USER_SNIPPET_HERE");
//TODO getDrawable
///////////////////////////////
- curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red));
+ curItem.setMarker(getGroupIcon(i.section));
mOverlay.addItem(curItem);
hash.put(i.uid, curItem);
//if (mMapView != null)
@@ -387,28 +369,35 @@ public class MapMaker extends Activity {
preMapInfo = mapInfo;
}
-
/**
* Update marker
- */
+ *
public void UpdateMarker() {
-
mOverlay.addItem(nowMarker);
if (mMapView != null) {
mMapView.getOverlays().add(mOverlay);
mMapView.refresh();
}
}
+ */
/**
* Draw a marker
*/
public void DrawMarker(GeoPoint markerPoint) {
- nowMarker = new OverlayItem(markerPoint, "THIS IS A MARKER", "");
+ if (nowMarker != null) {
+ nowMarker.setGeoPoint(markerPoint);
+ mOverlay.updateItem(nowMarker);
+ mMapView.refresh();
+ mMapController.animateTo(markerPoint);
+ return;
+ }
+ nowMarker = new OverlayItem(markerPoint, "MARKER_NAME", "");
nowMarker.setMarker(context.getResources().getDrawable(R.drawable.marker_red));
- Log.d("marker", "new marker created");
- UpdateMap(preMapInfo);
+ Log.d("marker", "new marker created");
+ mOverlay.addItem(nowMarker);
+ mMapView.refresh();
mMapController.animateTo(markerPoint);
}
diff --git a/client/Piztor/src/com/macaroon/piztor/PushClient.java b/client/Piztor/src/com/macaroon/piztor/PushClient.java
index ea32ad6..fff39fe 100644
--- a/client/Piztor/src/com/macaroon/piztor/PushClient.java
+++ b/client/Piztor/src/com/macaroon/piztor/PushClient.java
@@ -9,7 +9,6 @@ import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Vector;
-import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
@@ -25,18 +24,18 @@ public class PushClient {
static final int TokenLength = 32;
static final int FingerPrintLength = 32;
- public final static int StartPush =5;
+ static final int StartPush =5;
- public final static int Message = 0;
- public final static int Location = 1;
- public final static int PushMessage =100;
- public final static int PushLocation =101;
+ static final int Message = 0;
+ static final int Location = 1;
+ static final int PushMessage =100;
+ static final int PushLocation =101;
- public final static int Reconnect =-2;
+ static final int Reconnect =-2;
- public final static int Failed = 2;
- public final static int TimeOut = 1;
- public final static int Success = 0;
+ static final int StatusFailed = 2;
+ static final int TimeOut = 1;
+ static final int Success = 0;
private String LastPrint = "";
@@ -45,8 +44,8 @@ public class PushClient {
IOException {
try {
client = new Socket();
- client.connect(new InetSocketAddress(site,port), 5000);
- client.setSoTimeout(5000);
+ client.connect(new InetSocketAddress(site,port), retime);
+ client.setSoTimeout(2000);
} catch (UnknownHostException e) {
e.printStackTrace();
throw e;
@@ -68,13 +67,13 @@ public class PushClient {
len = IntLength+ByteLength+TokenLength+(r.uname).length()+ByteLength;
byte[] b = new byte[len];
int pos = 0;
- write(b,intToBytes(len),pos);
+ Convert.write(b,Convert.intToBytes(len),pos);
pos+=IntLength;
b[pos] = (byte) 5;
pos+=ByteLength;
- write(b,hexStringToBytes(r.token),pos);
+ Convert.write(b,Convert.hexStringToBytes(r.token),pos);
pos+=TokenLength;
- write(b,r.uname.getBytes(),pos);
+ Convert.write(b,r.uname.getBytes(),pos);
pos+=r.uname.length();
b[pos] = 0;
pos+=ByteLength;
@@ -84,13 +83,11 @@ public class PushClient {
in.readInt();
in.readUnsignedByte();
int status = in.readUnsignedByte();
- ResStartPush rchk = new ResStartPush(status);
+ if(status == 1) return StatusFailed;
+ ResStartPush rchk = new ResStartPush();
msg.obj = rchk;
msg.what = StartPush;
recall.sendMessage(msg);
- if(status == 1) {
- return Failed;
- }
return Success;
} catch (SocketTimeoutException e){
e.printStackTrace();
@@ -105,7 +102,7 @@ public class PushClient {
return client.isClosed();
}
- public void listen(Handler recall,Handler h) throws IOException{
+ public void listen(Handler recall) throws IOException{
client.setSoTimeout(0);
DataInputStream in = new DataInputStream(client.getInputStream());
DataOutputStream out = new DataOutputStream(client.getOutputStream());
@@ -117,7 +114,7 @@ public class PushClient {
int tmp = in.readUnsignedByte();
byte[] buffer = new byte[32];
in.read(buffer);
- String p = byteToHexString(buffer);
+ String p = Convert.byteToHexString(buffer);
int outlen;
int pos=0;
byte[] o = new byte[IntLength+ByteLength+FingerPrintLength];;
@@ -135,11 +132,11 @@ public class PushClient {
recall.sendMessage(msg);
LastPrint = p;
}
- write(o,intToBytes(outlen),pos); //can be folded!
+ Convert.write(o,Convert.intToBytes(outlen),pos); //can be folded!
pos+=IntLength;
o[pos]=(byte) Message;
pos+=ByteLength;
- write(o,hexStringToBytes(p),pos);
+ Convert.write(o,Convert.hexStringToBytes(p),pos);
pos+=FingerPrintLength;
out.write(o);
out.flush();
@@ -163,11 +160,11 @@ public class PushClient {
recall.sendMessage(msg);
LastPrint = p;
}
- write(o,intToBytes(outlen),pos);
+ Convert.write(o,Convert.intToBytes(outlen),pos);
pos+=IntLength;
o[pos]=(byte) Location;
pos+=ByteLength;
- write(o,hexStringToBytes(p),pos);
+ Convert.write(o,Convert.hexStringToBytes(p),pos);
pos+=FingerPrintLength;
out.write(o);
out.flush();
@@ -189,64 +186,5 @@ public class PushClient {
throw e;
}
}
-
- @SuppressLint("DefaultLocale")
- private static byte[] hexStringToBytes(String hexString) {
- if (hexString == null || hexString.equals("")) {
- return null;
- }
- hexString = hexString.toUpperCase();
- int length = hexString.length() / 2;
- char[] hexChars = hexString.toCharArray();
- byte[] d = new byte[length];
- for (int i = 0; i < length; i++) {
- int pos = i * 2;
- d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
- }
- return d;
- }
-
- private static byte charToByte(char c) {
- return (byte) "0123456789ABCDEF".indexOf(c);
- }
-
- private static byte[] intToBytes(int i) {
- byte[] d = new byte[4];
- d[0] = (byte)((i >> 24) & 0xFF);
- d[1] = (byte)((i >> 16) & 0xFF);
- d[2] = (byte)((i >> 8) & 0xFF);
- d[3] = (byte)(i & 0xFF);
- return d;
- }
-
- @SuppressLint("UseValueOf")
- public static byte[] doubleToBytes(double d){
- byte[] b=new byte[8];
- long l=Double.doubleToLongBits(d);
- for(int i=0;i < 8;i++){
- b[i]=new Long(l).byteValue();
- l=l>>8;
- }
- return b;
- }
-
- private static void write(byte[] s,byte[] w,int l) {
-
- for(int i=0;i<w.length;i++){
- s[i+l] = w[i];
- }
- }
-
- private static String byteToHexString(byte[] buffer){
- String p ="";
- for (int i = 0; i < buffer.length; i++) {
- String hex = Integer.toHexString(buffer[i] & 0xFF);
- if (hex.length() == 1) {
- hex = '0' + hex;
- }
- p += hex;
- }
- return p;
- }
}
diff --git a/client/Piztor/src/com/macaroon/piztor/RGroup.java b/client/Piztor/src/com/macaroon/piztor/RGroup.java
new file mode 100644
index 0000000..95beca7
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/RGroup.java
@@ -0,0 +1,10 @@
+package com.macaroon.piztor;
+
+public class RGroup {
+ int company; //group id
+ int section;
+ RGroup(int com,int sec){
+ company = com;
+ section = sec;
+ }
+} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/RUserInfo.java b/client/Piztor/src/com/macaroon/piztor/RUserInfo.java
new file mode 100644
index 0000000..3b24aa2
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/RUserInfo.java
@@ -0,0 +1,22 @@
+package com.macaroon.piztor;
+
+public class RUserInfo {
+ int uid; //userid
+ String username; //username
+ String nickname; //nickname
+ double latitude; //latitude
+ double longitude; //longitude
+ RGroup gid; //gid
+ int sex; //type 0 for female,type 1 for male
+
+
+ RUserInfo(int u,String user,String nick,double lat,double lot,RGroup g,int s){
+ uid = u;
+ username = user;
+ nickname = nick;
+ latitude = lat;
+ longitude = lot;
+ gid = g;
+ sex =s;
+ }
+} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/Req.java b/client/Piztor/src/com/macaroon/piztor/Req.java
index ad84922..f4c3a1f 100644
--- a/client/Piztor/src/com/macaroon/piztor/Req.java
+++ b/client/Piztor/src/com/macaroon/piztor/Req.java
@@ -1,5 +1,7 @@
package com.macaroon.piztor;
+import java.util.Vector;
+
public class Req{
int type; //request type
String token; //authentciation
@@ -13,4 +15,100 @@ public class Req{
time = tm;
alive = av;
}
-} \ No newline at end of file
+}
+
+//--------------------------------------//
+// authentication //
+//--------------------------------------//
+
+class ReqLogin extends Req{
+ String user; //username
+ String pass; //password
+
+ ReqLogin(String u,String p,long time,long alive){
+ super(0,"","",time,alive); //for type 0
+ user = u;
+ pass = p;
+ }
+}
+
+//--------------------------------------//
+// Update Location //
+//--------------------------------------//
+
+class ReqUpdate extends Req{
+ double latitude; //latitude
+ double longitude; //longitude
+
+ ReqUpdate(String token,String name,double lat,double lot,long time,long alive){
+ super(1,token,name,time,alive); //for type 1
+ latitude = lat;
+ longitude = lot;
+ }
+}
+
+//--------------------------------------//
+// Ask user info //
+//--------------------------------------//
+
+class ReqUserInfo extends Req{
+ RGroup gid; //group id
+
+
+ ReqUserInfo(String token,String name,RGroup id,long time,long alive){
+ super(2,token,name,time,alive); //for type 2
+ gid = id;
+ }
+}
+
+//--------------------------------------//
+// Subscription //
+//--------------------------------------//
+
+class ReqSubscription extends Req{
+ int n; //number of users you want to subscirbe
+ Vector<RGroup> slist; //list of users' group id
+
+
+ ReqSubscription(String token,String name,int number,Vector<RGroup> sublist,long time,long alive){
+ super(3,token,name,time,alive); //for type 3
+ n = number;
+ slist = sublist;
+ }
+}
+
+//--------------------------------------//
+// Log out //
+//--------------------------------------//
+
+class ReqLogout extends Req{
+
+ ReqLogout(String token,String name,long time,long alive){
+ super(4,token,name,time,alive); //for type 4
+ }
+}
+
+//--------------------------------------//
+// Start push //
+//--------------------------------------//
+
+class ReqStartPush extends Req{
+
+ ReqStartPush(String token,String name){
+ super(5,token,name,(long) 0,(long) 0); //for type 5
+ }
+}
+
+//--------------------------------------//
+// Send Message //
+//--------------------------------------//
+
+class ReqSendMessage extends Req{
+ String msg;
+
+ ReqSendMessage(String token,String name,String message,long time,long alive){
+ super(6,token,name,time,alive); //for type 6
+ msg = message;
+ }
+}
+
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqLocation.java b/client/Piztor/src/com/macaroon/piztor/ReqLocation.java
deleted file mode 100644
index 4ed1ffc..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqLocation.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// Ask Location //
-//--------------------------------------//
-
-public class ReqLocation extends Req{
- int company; //group id;
- int section;
-
- ReqLocation(String token,String name,int com,int sec,long time,long alive){
- super(2,token,name,time,alive); //for type 2
- company = com;
- section = sec;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqLogin.java b/client/Piztor/src/com/macaroon/piztor/ReqLogin.java
deleted file mode 100644
index 23aba93..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqLogin.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// authentication //
-//--------------------------------------//
-
-public class ReqLogin extends Req{
- String user; //username
- String pass; //password
-
- ReqLogin(String u,String p,long time,long alive){
- super(0,"","",time,alive); //for type 0
- user = u;
- pass = p;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqLogout.java b/client/Piztor/src/com/macaroon/piztor/ReqLogout.java
deleted file mode 100644
index 22bddfa..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqLogout.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// Log out //
-//--------------------------------------//
-
-public class ReqLogout extends Req{
-
- ReqLogout(String token,String name,long time,long alive){
- super(4,token,name,time,alive); //for type 4
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java b/client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java
deleted file mode 100644
index d5bcef4..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqSendMessage.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// Send Message //
-//--------------------------------------//
-
-public class ReqSendMessage extends Req{
- String msg;
-
- ReqSendMessage(String token,String name,String message,long time,long alive){
- super(6,token,name,time,alive); //for type 6
- msg = message;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqStartPush.java b/client/Piztor/src/com/macaroon/piztor/ReqStartPush.java
deleted file mode 100644
index 91d8c0f..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqStartPush.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// Start push //
-//--------------------------------------//
-
-public class ReqStartPush extends Req{
-
- ReqStartPush(String token,String name){
- super(5,token,name,(long) 0,(long) 0); //for type 5
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqUpdate.java b/client/Piztor/src/com/macaroon/piztor/ReqUpdate.java
deleted file mode 100644
index 234114a..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqUpdate.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// Update Location //
-//--------------------------------------//
-
-public class ReqUpdate extends Req{
- double latitude; //latitude
- double longitude; //longitude
-
- ReqUpdate(String token,String name,double lat,double lot,long time,long alive){
- super(1,token,name,time,alive); //for type 1
- latitude = lat;
- longitude = lot;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java b/client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java
deleted file mode 100644
index 89c20ee..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqUserInfo.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// Ask user info //
-//--------------------------------------//
-
-public class ReqUserInfo extends Req{
- int uid; //user id
-
-
- ReqUserInfo(String token,String name,int id,long time,long alive){
- super(3,token,name,time,alive); //for type 3
- uid = id;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java b/client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java
deleted file mode 100644
index 77bcf84..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ReqUserinfo.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.macaroon.piztor;
-
-//--------------------------------------//
-// Ask user info //
-//--------------------------------------//
-
-public class ReqUserinfo extends Req{
- int uid; //user id
-
-
- ReqUserinfo(String token,String name,int id,long time,long alive){
- super(3,token,name,time,alive); //for type 3
- uid = id;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/Res.java b/client/Piztor/src/com/macaroon/piztor/Res.java
index a225080..699de45 100644
--- a/client/Piztor/src/com/macaroon/piztor/Res.java
+++ b/client/Piztor/src/com/macaroon/piztor/Res.java
@@ -1,11 +1,146 @@
package com.macaroon.piztor;
+import java.util.Vector;
+
public class Res{
+
+ static final int Login =0;
+ static final int Update =1;
+ static final int UserInfo =2;
+ static final int Subscription =3;
+ static final int Logout =4;
+ static final int StartPush =5;
+ static final int SendMessage =6;
+ static final int PushMessage =100;
+ static final int PushLocation =101;
+
int type;
- int status;
- Res(int t,int s){
+ Res(int t){
type = t;
- status = s;
}
}
+//--------------------------------------//
+// Respond to login //
+//--------------------------------------//
+
+class ResLogin extends Res{
+ String t; //user token
+ RUserInfo uinfo; //userinfo
+ Vector<RGroup> sublist; //list of users subscribed
+ int subscribeNumber; //number of users subscribed
+
+ ResLogin(String token,RUserInfo rui,Vector<RGroup> slist,int subn){
+ super(0); //for type 0
+ t = token;
+ uinfo = rui;
+ sublist = slist;
+ subscribeNumber = subn;
+ }
+}
+
+//--------------------------------------//
+// Respond to update location //
+//--------------------------------------//
+
+class ResUpdate extends Res{
+
+ ResUpdate(){
+ super(1); //for type 1
+ }
+}
+
+//--------------------------------------//
+// Respond to User Info //
+//--------------------------------------//
+
+class ResUserInfo extends Res{
+ int number; //number of users
+ Vector<RUserInfo> uinfo;
+
+ ResUserInfo(int n,Vector<RUserInfo> rui){
+ super(2); //for type 2
+ number = n;
+ uinfo = rui;
+ }
+}
+
+//--------------------------------------//
+// Respond to Update Subscription //
+//--------------------------------------//
+
+class ResSubscription extends Res{
+
+ ResSubscription(){
+ super(3); //for type 3
+ }
+}
+
+//--------------------------------------//
+// Respond to logout //
+//--------------------------------------//
+
+class ResLogout extends Res{
+
+ ResLogout(){
+ super(4); //for type 4
+ }
+}
+
+//--------------------------------------//
+// Respond to start push //
+//--------------------------------------//
+
+class ResStartPush extends Res{
+
+ ResStartPush(){
+ super(5); //for type 5
+ }
+}
+
+//--------------------------------------//
+// Respond to send Message //
+//--------------------------------------//
+
+class ResSendMessage extends Res{
+
+ ResSendMessage(){
+ super(6); //for type 6
+ }
+}
+
+//---------------------------------------------------------------------------------------------------//
+
+
+
+//---------------------------------------------------------------------------------------------------//
+
+
+
+//--------------------------------------//
+// Push Message //
+//--------------------------------------//
+
+class ResPushMessage extends Res{
+ String message;
+
+ ResPushMessage(String s){
+ super(100); //for type 100
+ message = s;
+ }
+}
+
+//--------------------------------------//
+// Push Location //
+//--------------------------------------//
+
+class ResPushLocation extends Res{
+ Vector<RLocation> l; //vector for location info
+ int n; //number of location info
+
+ ResPushLocation(int num,Vector<RLocation> locationvec){
+ super(101); //for type 101
+ l = locationvec;
+ n = num;
+ }
+} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResLocation.java b/client/Piztor/src/com/macaroon/piztor/ResLocation.java
deleted file mode 100644
index a4f2622..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResLocation.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.macaroon.piztor;
-
-import java.util.Vector;
-
-//--------------------------------------//
-// Location Info //
-//--------------------------------------//
-
-public class ResLocation extends Res{
- Vector<RLocation> l; //vector for location info
- int n; //number of location info
-
- ResLocation(int num,int status,Vector<RLocation> locationvec){
- super(2,status); //for type 2
- l = locationvec;
- n = num;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResLogin.java b/client/Piztor/src/com/macaroon/piztor/ResLogin.java
deleted file mode 100644
index e2f138c..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResLogin.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Respond to login //
-//--------------------------------------//
-
-public class ResLogin extends Res{
- String t; //user token
- int uid; //userid
-
- ResLogin(int id,String token,int status){
- super(0,status); //for type 0
- t = token;
- uid = id;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResLogout.java b/client/Piztor/src/com/macaroon/piztor/ResLogout.java
deleted file mode 100644
index 4b2a8d1..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResLogout.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Respond to logout //
-//--------------------------------------//
-
-public class ResLogout extends Res{
-
- ResLogout(int status){
- super(4,status); //for type 4
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResPushLocation.java b/client/Piztor/src/com/macaroon/piztor/ResPushLocation.java
deleted file mode 100644
index c3e2b64..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResPushLocation.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.macaroon.piztor;
-
-import java.util.Vector;
-
-//--------------------------------------//
-// Push Location //
-//--------------------------------------//
-
-public class ResPushLocation extends Res{
- Vector<RLocation> l; //vector for location info
- int n; //number of location info
-
- ResPushLocation(int num,Vector<RLocation> locationvec){
- super(101,0); //for type 101
- l = locationvec;
- n = num;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResPushMessage.java b/client/Piztor/src/com/macaroon/piztor/ResPushMessage.java
deleted file mode 100644
index ff61ee0..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResPushMessage.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Push Message //
-//--------------------------------------//
-
-public class ResPushMessage extends Res{
- String message;
-
- ResPushMessage(String s){
- super(100,0); //for type 100
- message = s;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResSendMessage.java b/client/Piztor/src/com/macaroon/piztor/ResSendMessage.java
deleted file mode 100644
index 09f3ffa..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResSendMessage.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Respond to send Message //
-//--------------------------------------//
-
-public class ResSendMessage extends Res{
-
- ResSendMessage(int status){
- super(6,status); //for type 6
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResStartPush.java b/client/Piztor/src/com/macaroon/piztor/ResStartPush.java
deleted file mode 100644
index 33343d7..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResStartPush.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Respond to start push //
-//--------------------------------------//
-
-public class ResStartPush extends Res{
-
- ResStartPush(int status){
- super(5,status); //for type 5
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResUpdate.java b/client/Piztor/src/com/macaroon/piztor/ResUpdate.java
deleted file mode 100644
index dd0d29b..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResUpdate.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Respond to update location //
-//--------------------------------------//
-
-public class ResUpdate extends Res{
-
- ResUpdate(int status){
- super(1,status); //for type 1
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResUserInfo.java b/client/Piztor/src/com/macaroon/piztor/ResUserInfo.java
deleted file mode 100644
index 2556c68..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResUserInfo.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Respond to User Info //
-//--------------------------------------//
-
-public class ResUserInfo extends Res{
- int uid; //userid
- int company; //group id
- int section;
- int sex; //type 0 for female,type 1 for male
-
-
- ResUserInfo(int status,int u,int com,int sec,int s){
- super(3,status); //for type 3
- uid = u;
- company = com;
- section = sec;
- sex =s;
- }
-} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/ResUserinfo.java b/client/Piztor/src/com/macaroon/piztor/ResUserinfo.java
deleted file mode 100644
index ed981b4..0000000
--- a/client/Piztor/src/com/macaroon/piztor/ResUserinfo.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.macaroon.piztor;
-
-
-//--------------------------------------//
-// Respond to User Info //
-//--------------------------------------//
-
-public class ResUserinfo extends Res{
- int uid; //userid
- int gid; //groupid
- int sex; //type 0 for female,type 1 for male
-
-
- ResUserinfo(int status,int u,int g,int s){
- super(3,status); //for type 3
- uid = u;
- gid = g;
- sex =s;
- }
-} \ 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 c0ca901..b334cc4 100644
--- a/client/Piztor/src/com/macaroon/piztor/Settings.java
+++ b/client/Piztor/src/com/macaroon/piztor/Settings.java
@@ -1,9 +1,12 @@
package com.macaroon.piztor;
+import java.util.Vector;
+
import android.annotation.SuppressLint;
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;
@@ -12,87 +15,78 @@ import android.widget.Toast;
public class Settings extends PiztorAct {
Button logout;
MapInfo mapInfo;
-
+ Transam transam;
// Event
final static int logoutButtonPressed = 10;
final static int logoutFailed = 11;
-
-
+
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message m) {
- System.out.println("!!!!!!!!!!!!!!!!!!!!!settings" + m.what);
switch (m.what) {
- case 1:// 上传自己信息成功or失败
- ResUpdate update = (ResUpdate) m.obj;
- if (update.status == 0)
- System.out.println("update success");
- else {
- System.out.println("update failed");
- actMgr.trigger(AppMgr.errorToken);
- }
+ case Res.Update:// 上传自己信息成功or失败
+ Log.d("update location", "successfull");
break;
- case 2:// 得到别人的信息
- ResLocation location = (ResLocation) m.obj;
- if (location.status == 0) {
- mapInfo.clear();
- for (RLocation i : location.l) {
- System.out.println(i.id + " : " + i.latitude + " " + i.longitude);
- UserInfo info = new UserInfo(i.id);
- info.setLocation(i.latitude, i.longitude);
- mapInfo.addUserInfo(info);
+ 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 = 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);
+ mapInfo.addUserInfo(r);
}
- } else {
- System.out.println("resquest for location failed!");
- actMgr.trigger(AppMgr.errorToken);
}
break;
- case 3:// 得到用户信息
- ResUserInfo r = (ResUserInfo) m.obj;
- if (r.status == 0) {
- System.out.println("id : " + r.uid + " sex : " + r.sex
- + " group : " + r.section);
- UserInfo user = mapInfo.getUserInfo(r.uid);
- user.setInfo(r.company, r.section, r.sex);
- } else {
- System.out.println("reqest for userInfo must be wrong!!!");
- actMgr.trigger(AppMgr.errorToken);
- }
+ case Res.Logout:// 登出
+ actMgr.trigger(AppMgr.logout);
break;
- case 4:// 登出
- ResLogout logout = (ResLogout) m.obj;
- System.out.println("logout status" + logout.status);
- if (logout.status == 0) {
- Infomation.token = null;
- Infomation.myInfo.company = -1;
- Infomation.myInfo.section = -1;
- Infomation.myInfo.uid = -1;
- Infomation.username = null;
- actMgr.trigger(AppMgr.logout);
- break;
- } else {
- Toast toast = Toast.makeText(getApplicationContext(),
- "logout failed", Toast.LENGTH_LONG);
- toast.show();
- actMgr.trigger(logoutFailed);
- }
+ case Res.PushMessage:
+ ResPushMessage pushMessage = (ResPushMessage) m.obj;
+ 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);
break;
default:
break;
}
}
};
-
- class StartStatus extends ActStatus {
-
- @Override
- void enter(int e) {
+
+ void upMapInfo(Vector<RLocation> l) {
+ 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);
+ }
}
+ }
- @Override
- void leave(int e) {
- }
+ void receiveMessage(String msg) {
+ Log.d("recieve message", msg);
+ Toast toast = Toast.makeText(getApplicationContext(), msg,
+ Toast.LENGTH_LONG);
+ toast.show();
}
class LogoutStatus extends ActStatus {
@@ -100,28 +94,31 @@ public class Settings extends PiztorAct {
@Override
void enter(int e) {
System.out.println("!!!!!!!logout info send!!!!!!!!");
- AppMgr.transam.send(new ReqLogout(Infomation.token,
- Infomation.username, System.currentTimeMillis(), 2000));
+ transam.send(new ReqLogout(Infomation.token, Infomation.username,
+ System.currentTimeMillis(), 2000));
}
@Override
void leave(int e) {
- // TODO Auto-generated method stub
}
+
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ mapInfo = AppMgr.mapInfo;
+ transam = AppMgr.transam;
+ if (transam == null)
+ Log.d(LogInfo.exception, "transam = null");
+ transam.setHandler(handler);
ActStatus[] r = new ActStatus[3];
- ActStatus start = r[0] = new StartStatus();
+ ActStatus start = r[0] = new EmptyStatus();
ActStatus logout = r[2] = new LogoutStatus();
actMgr = new ActMgr(this, start, r);
actMgr.add(start, logoutButtonPressed, logout);
actMgr.add(logout, logoutFailed, start);
- AppMgr.transam.setHandler(handler);
- mapInfo = AppMgr.mapInfo;
setContentView(R.layout.activity_settings);
}
@@ -132,7 +129,7 @@ public class Settings extends PiztorAct {
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- actMgr.trigger(logoutButtonPressed);
+ actMgr.trigger(logoutButtonPressed);
}
});
}
diff --git a/client/Piztor/src/com/macaroon/piztor/SocketClient.java b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
index 622c581..58b20c7 100644
--- a/client/Piztor/src/com/macaroon/piztor/SocketClient.java
+++ b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
@@ -9,7 +9,6 @@ import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Vector;
-import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
@@ -23,21 +22,33 @@ public class SocketClient {
static final int DoubleLength = 8;
static final int TokenLength = 32;
- public final static int Login =0;
- public final static int Update =1;
- public final static int Location =2;
- public final static int UserInfo =3;
- public final static int Logout =4;
- public final static int SendMessage =6;
+ static final int Login =0;
+ static final int Update =1;
+ static final int UserInfo =2;
+ static final int Subscription =3;
+ static final int Logout =4;
+ static final int StartPush =5;
+ static final int SendMessage =6;
- public final static int GroupID =0;
- public final static int Gender =1;
+ static final int ClosePush =-5;
+
+ static final int UID =1;
+ static final int Uname =2;
+ static final int Nname =3;
+ static final int Gender =4;
+ static final int GroupID =5;
+ static final int Latitude =6;
+ static final int Longitude =7;
+
+ static final int StatusFailed = 2;
+ static final int TimeOut = 1;
+ static final int Success = 0;
public SocketClient(String site, int port, int retime) throws UnknownHostException,
IOException {
try {
client = new Socket();
- client.connect(new InetSocketAddress(site,port), 5000);
+ client.connect(new InetSocketAddress(site,port), retime);
client.setSoTimeout(retime);
} catch (UnknownHostException e) {
e.printStackTrace();
@@ -48,7 +59,7 @@ public class SocketClient {
}
}
- public int sendMsg(Req req,Handler recall) throws IOException,SocketTimeoutException {
+ public int sendMsg(Req req,Handler recall,Handler h) throws IOException,SocketTimeoutException {
try {
DataOutputStream out = new DataOutputStream(
client.getOutputStream());
@@ -61,15 +72,15 @@ public class SocketClient {
ReqLogin rau = (ReqLogin) req;
len = IntLength+ByteLength+rau.user.length()+ByteLength+rau.pass.length()+ByteLength;
b = new byte[len];
- write(b,intToBytes(len),pos);
+ Convert.write(b,Convert.intToBytes(len),pos);
pos+=IntLength;
b[pos] = (byte) tmp;
pos+=ByteLength;
- write(b,rau.user.getBytes(),pos);
+ Convert.write(b,rau.user.getBytes(),pos);
pos+=rau.user.length();
b[pos] = 0;
pos+=ByteLength;
- write(b, rau.pass.getBytes(),pos);
+ Convert.write(b, rau.pass.getBytes(),pos);
pos+= rau.pass.length();
b[pos] = 0;
pos+=ByteLength;
@@ -79,71 +90,78 @@ public class SocketClient {
ReqUpdate rup = (ReqUpdate) req;
len = IntLength+ByteLength+TokenLength+(rup.uname).length()+ByteLength+DoubleLength+DoubleLength;
b = new byte[len];
- write(b,intToBytes(len),pos);
+ Convert.write(b,Convert.intToBytes(len),pos);
pos+=IntLength;
b[pos] = (byte) tmp;
pos+=ByteLength;
- write(b,hexStringToBytes(rup.token),pos);
+ Convert.write(b,Convert.hexStringToBytes(rup.token),pos);
pos+=TokenLength;
- write(b,(rup.uname).getBytes(),pos);
+ Convert.write(b,(rup.uname).getBytes(),pos);
pos+=(rup.uname).length();
b[pos] = 0;
pos+=ByteLength;
- write(b,doubleToBytes(rup.latitude),pos);
+ Convert.write(b,Convert.doubleToBytes(rup.latitude),pos);
pos+=DoubleLength;
- write(b,doubleToBytes(rup.longitude),pos);
+ Convert.write(b,Convert.doubleToBytes(rup.longitude),pos);
pos+=DoubleLength;
out.write(b);
break;
- case Location:
- ReqLocation ras = (ReqLocation) req;
- len = IntLength+ByteLength+TokenLength+ras.uname.length()+ByteLength+ByteLength+ByteLength;
+ case UserInfo:
+ ReqUserInfo rus = (ReqUserInfo) req;
+ len = IntLength+ByteLength+TokenLength+rus.uname.length()+ByteLength+ByteLength+ByteLength;
b = new byte[len];
- write(b,intToBytes(len),pos);
+ Convert.write(b,Convert.intToBytes(len),pos);
pos+=IntLength;
b[pos] = (byte) tmp;
pos+=ByteLength;
- write(b,hexStringToBytes(ras.token),pos);
+ Convert.write(b,Convert.hexStringToBytes(rus.token),pos);
pos+=TokenLength;
- write(b,(ras.uname).getBytes(),pos);
- pos+=(ras.uname).length();
+ Convert.write(b,(rus.uname).getBytes(),pos);
+ pos+=(rus.uname).length();
b[pos] = 0;
pos+=ByteLength;
- b[pos] = (byte) ras.company;
+ b[pos] = (byte) rus.gid.company;
+ pos+=ByteLength;
+ b[pos] = (byte) rus.gid.section;
pos+=ByteLength;
- b[pos] = (byte) ras.section;
- pos+=ByteLength;
out.write(b);
break;
- case UserInfo:
- ReqUserInfo rus = (ReqUserInfo) req;
- len = IntLength+ByteLength+TokenLength+rus.uname.length()+ByteLength+IntLength;
+ case Subscription:
+ ReqSubscription rsu = (ReqSubscription) req;
+ int number = rsu.n;
+ len = IntLength+ByteLength+TokenLength+rsu.uname.length()+ByteLength+2*ByteLength*number+ByteLength;
b = new byte[len];
- write(b,intToBytes(len),pos);
+ Convert.write(b,Convert.intToBytes(len),pos);
pos+=IntLength;
b[pos] = (byte) tmp;
pos+=ByteLength;
- write(b,hexStringToBytes(rus.token),pos);
+ Convert.write(b,Convert.hexStringToBytes(rsu.token),pos);
pos+=TokenLength;
- write(b,(rus.uname).getBytes(),pos);
- pos+=(rus.uname).length();
+ Convert.write(b,(rsu.uname).getBytes(),pos);
+ pos+=(rsu.uname).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ for(int i=0;i<number;i++) {
+ b[pos] = (byte) rsu.slist.get(i).company;
+ pos+=ByteLength;
+ b[pos] = (byte) rsu.slist.get(i).section;
+ pos+=ByteLength;
+ }
b[pos] = 0;
pos+=ByteLength;
- write(b,intToBytes(rus.uid),pos);
- pos+=IntLength;
out.write(b);
break;
case Logout:
ReqLogout rlo = (ReqLogout) req;
len = IntLength+ByteLength+TokenLength+rlo.uname.length()+ByteLength;
b = new byte[len];
- write(b,intToBytes(len),pos);
+ Convert.write(b,Convert.intToBytes(len),pos);
pos+=IntLength;
b[pos] = (byte) tmp;
pos+=ByteLength;
- write(b,hexStringToBytes(rlo.token),pos);
+ Convert.write(b,Convert.hexStringToBytes(rlo.token),pos);
pos+=TokenLength;
- write(b,(rlo.uname).getBytes(),pos);
+ Convert.write(b,(rlo.uname).getBytes(),pos);
pos+=(rlo.uname).length();
b[pos] = 0;
pos+=ByteLength;
@@ -153,17 +171,17 @@ public class SocketClient {
ReqSendMessage rem = (ReqSendMessage) req;
len = IntLength+ByteLength+TokenLength+rem.uname.length()+ByteLength+rem.msg.length()+ByteLength;
b = new byte[len];
- write(b,intToBytes(len),pos);
+ Convert.write(b,Convert.intToBytes(len),pos);
pos+=IntLength;
b[pos] = (byte) tmp;
pos+=ByteLength;
- write(b,hexStringToBytes(rem.token),pos);
+ Convert.write(b,Convert.hexStringToBytes(rem.token),pos);
pos+=TokenLength;
- write(b,(rem.uname).getBytes(),pos);
+ Convert.write(b,(rem.uname).getBytes(),pos);
pos+=(rem.uname).length();
b[pos] = 0;
pos+=ByteLength;
- write(b,rem.msg.getBytes(),pos);
+ Convert.write(b,rem.msg.getBytes(),pos);
pos+=rem.msg.length();
b[pos] = 0;
pos+=ByteLength;
@@ -176,85 +194,211 @@ public class SocketClient {
int outlen = in.readInt();
int type = in.readUnsignedByte();
int status = in.readUnsignedByte();
+ if(status == 1) return StatusFailed;
switch (type) {
case Login:
- int id = in.readInt();
byte[] buffer = new byte[32];
in.read(buffer);
- String tk = "";
- for (int i = 0; i < buffer.length; i++) {
- String hex = Integer.toHexString(buffer[i] & 0xFF);
- if (hex.length() == 1) {
- hex = '0' + hex;
- }
- tk += hex;
+ String tk = Convert.byteToHexString(buffer);
+ outlen-=(IntLength+ByteLength+TokenLength+ByteLength);
+ int cnt = 0;
+ int uid =0,s =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) {
+ int typ = in.readUnsignedByte();
+ outlen-=ByteLength;
+ switch(typ){
+ case UID:
+ uid = in.readInt();
+ outlen-=IntLength;
+ break;
+ case Uname:
+ i = 0;
+ while(true) {
+ bu[i] = in.readByte();
+ if(bu[i] == 0)break;
+ i++;
+ }
+ byte[] wr = new byte[i];
+ for(int j=0;j<i;j++){
+ wr[j] = bu[j];
+ }
+ uname = new String(wr);
+ outlen-=ByteLength*(i+1);
+ break;
+ case Nname:
+ i = 0;
+ while(true) {
+ bu[i] = in.readByte();
+ if(bu[i] == 0)break;
+ i++;
+ }
+ byte[] wt = new byte[i];
+ for(int j=0;j<i;j++){
+ wt[j] = bu[j];
+ }
+ nname = new String(wt);
+ outlen-=ByteLength*(i+1);
+ break;
+ case Gender:
+ s = in.readUnsignedByte();
+ outlen-=ByteLength;
+ break;
+ case GroupID:
+ int com = in.readUnsignedByte();
+ int sec = in.readUnsignedByte();
+ rg = new RGroup(com,sec);
+ outlen-=ByteLength*2;
+ break;
+ case Latitude:
+ lat = in.readDouble();
+ outlen-=DoubleLength;
+ break;
+ case Longitude:
+ lot = in.readDouble();
+ outlen-=DoubleLength;
+ break;
+ }
+ cnt++;
}
- ResLogin rchklogin = new ResLogin(id,tk,status);
- msg.obj = rchklogin;
+ RUserInfo r = new RUserInfo(uid,uname,nname,lat,lot,rg,s);
+ 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();
+ int sec = in.readUnsignedByte();
+ vrg.add(new RGroup(com,sec));
+ outlen-=ByteLength*2;
+ number++;
+ }
+ in.readUnsignedByte();
+ msg.obj = new ResLogin(tk, r, vrg, number);
msg.what = Login;
recall.sendMessage(msg);
+ Vector<String> vs = new Vector<String>();
+ vs.add(uname);
+ vs.add(tk);
+ Message m = new Message();
+ m.obj = vs;
+ m.what = StartPush;
+ h.sendMessage(m);
break;
case Update:
- msg.obj = new ResUpdate(status);
+ msg.obj = new ResUpdate();
msg.what = Update;
recall.sendMessage(msg);
break;
- case Location:
- int n = 0;
- outlen-=(IntLength+ByteLength+ByteLength);
- Vector<RLocation> tmpv = new Vector<RLocation>();
- while(outlen > 0) {
- int tid = in.readInt();
- double lat = in.readDouble();
- double lot = in.readDouble();
- tmpv.add(new RLocation(tid,lat,lot));
- outlen -= (IntLength+DoubleLength+DoubleLength);
- n++;
- }
- msg.obj = new ResLocation(n,status,tmpv);
- msg.what = Location;
- recall.sendMessage(msg);
- break;
case UserInfo:
outlen-=(IntLength+ByteLength+ByteLength);
- ReqUserInfo rus = (ReqUserInfo) req;
- int u = rus.uid;
- int com = 0,sec = 0,s = 0;
+ int uid1 =0,s1 =0;
+ String uname1 ="",nname1 ="";
+ double lat1 =0.0,lot1 =0.0;
+ RGroup rg1 = null;
+ int k = 0;
+ byte[] bn = new byte[200];
+ Vector<RUserInfo> v = new Vector<RUserInfo>();
+ int n = 0;
while(outlen > 0) {
- int typ = in.readUnsignedByte();
- outlen-=ByteLength;
- switch(typ){
- case GroupID:
- com = in.readUnsignedByte();
- sec = in.readUnsignedByte();
- outlen-=(ByteLength+ByteLength);
- break;
- case Gender:
- s = in.readUnsignedByte();
+ int tmpcnt =0;
+ while(tmpcnt < 7) {
+ int typ = in.readUnsignedByte();
outlen-=ByteLength;
- break;
+ switch(typ){
+ case UID:
+ uid1 = in.readInt();
+ outlen-=IntLength;
+ break;
+ case Uname:
+ k = 0;
+ while(true) {
+ bn[k] = in.readByte();
+ if(bn[k] == 0)break;
+ k++;
+ }
+ byte[] wr = new byte[k];
+ for(int j=0;j<k;j++){
+ wr[j] = bn[j];
+ }
+ uname1 = new String(wr);
+ outlen-=ByteLength*(k+1);
+ break;
+ case Nname:
+ k = 0;
+ while(true) {
+ bn[k] = in.readByte();
+ if(bn[k] == 0)break;
+ k++;
+ }
+ byte[] wt = new byte[k];
+ for(int j=0;j<k;j++){
+ wt[j] = bn[j];
+ }
+ nname1 = new String(wt);
+ outlen-=ByteLength*(k+1);
+ break;
+ case Gender:
+ s1 = in.readUnsignedByte();
+ outlen-=ByteLength;
+ break;
+ case GroupID:
+ int com = in.readUnsignedByte();
+ int sec = in.readUnsignedByte();
+ rg1 = new RGroup(com,sec);
+ outlen-=ByteLength*2;
+ break;
+ case Latitude:
+ lat1 = in.readDouble();
+ outlen-=DoubleLength;
+ break;
+ case Longitude:
+ lot1 = in.readDouble();
+ outlen-=DoubleLength;
+ break;
+ }
+ tmpcnt++;
}
+ in.readUnsignedByte();
+ outlen-=ByteLength;
+ v.add(new RUserInfo(uid1,uname1,nname1,lat1,lot1,rg1,s1));
+ n++;
}
- msg.obj = new ResUserInfo(status,u,com,sec,s);
+ msg.obj = new ResUserInfo(n,v);
msg.what = UserInfo;
recall.sendMessage(msg);
break;
+ case Subscription:
+ msg.obj = new ResSubscription();
+ msg.what = Subscription;
+ recall.sendMessage(msg);
+ break;
case Logout:
- msg.obj = new ResLogout(status);
+ msg.obj = new ResLogout();
msg.what = Logout;
recall.sendMessage(msg);
+ Message ms = new Message();
+ ms.what = ClosePush;
+ h.sendMessage(ms);
break;
case SendMessage:
- msg.obj = new ResSendMessage(status);
+ msg.obj = new ResSendMessage();
msg.what = SendMessage;
recall.sendMessage(msg);
break;
}
- return 0;
+ return Success;
} catch (SocketTimeoutException e){
- return 1;
+ e.printStackTrace();
+ return TimeOut;
} catch (IOException e) {
+ e.printStackTrace();
throw e;
}
}
@@ -267,50 +411,7 @@ public class SocketClient {
throw e;
}
}
-
- @SuppressLint("DefaultLocale")
- private static byte[] hexStringToBytes(String hexString) {
- if (hexString == null || hexString.equals("")) {
- return null;
- }
- hexString = hexString.toUpperCase();
- int length = hexString.length() / 2;
- char[] hexChars = hexString.toCharArray();
- byte[] d = new byte[length];
- for (int i = 0; i < length; i++) {
- int pos = i * 2;
- d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
- }
- return d;
- }
-
- private static byte charToByte(char c) {
- return (byte) "0123456789ABCDEF".indexOf(c);
- }
-
- private static byte[] intToBytes(int i) {
- byte[] d = new byte[4];
- d[0] = (byte)((i >> 24) & 0xFF);
- d[1] = (byte)((i >> 16) & 0xFF);
- d[2] = (byte)((i >> 8) & 0xFF);
- d[3] = (byte)(i & 0xFF);
- return d;
- }
-
- public static byte[] doubleToBytes(double d){
- byte[] b=new byte[8];
- long l=Double.doubleToLongBits(d);
- for(int i=0;i<8;i++){
- b[i] = (byte)(l >>> 8*(7-i));
- }
- return b;
- }
-
- private static void write(byte[] s,byte[] w,int l) {
-
- for(int i=0;i<w.length;i++){
- s[i+l] = w[i];
- }
- }
+
+
}
diff --git a/client/Piztor/src/com/macaroon/piztor/Transam.java b/client/Piztor/src/com/macaroon/piztor/Transam.java
index 7902fde..ea5790d 100644
--- a/client/Piztor/src/com/macaroon/piztor/Transam.java
+++ b/client/Piztor/src/com/macaroon/piztor/Transam.java
@@ -5,12 +5,14 @@ import java.net.UnknownHostException;
import java.util.LinkedList;
import java.util.Queue;
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 v0.4a //
+// Piztor Transmission Protocol v2.0 beta //
//------------------------------------------------//
// //
@@ -24,11 +26,12 @@ import android.os.Message;
// 6 for sendmessage //
// //
// 100 for pushmessage //
+// 101 for pushlocation //
// //
// ----------I'm the division line-------- //
// //
// -1 for Exceptions //
-// Exception (req type , exception type) //
+// Exception (req type,ex type,exception type) //
// //
// ----------I'm the division line-------- //
// //
@@ -56,7 +59,6 @@ import android.os.Message;
// status -- 0 for success //
// 1 for failed/invalid //
// //
-// push message -- message //
// //
//------------------------------------------------//
@@ -64,53 +66,47 @@ import android.os.Message;
public class Transam implements Runnable {
- public final static int Login =0;
- public final static int Update =1;
- public final static int Location =2;
- public final static int UserInfo =3;
- public final static int Logout =4;
- public final static int StartPush =5;
- public final static int SendMessage =6;
+ static final int Login =0;
+ static final int Update =1;
+ static final int UserInfo =2;
+ static final int Subscription =3;
+ static final int Logout =4;
+ static final int StartPush =5;
+ static final int SendMessage =6;
- public final static int PushMessage =100;
- public final static int PushLocation =101;
+ static final int ClosePush = -5;
- public final static int GroupID =0;
- public final static int Gender =1;
+ static final int EConnectedFailedException =101;
+ static final int ETimeOutException =102;
+ static final int EJavaHostException =103;
+ static final int EPushFailedException =104;
+ static final int EIOException =105;
+ static final int EUnknownHostException =106;
+ static final int EStatusFailedException =107;
- public final static int EConnectedFailedException =101;
- public final static int ETimeOutException =102;
- public final static int EJavaHostException =103;
- public final static int EPushFailedException =104;
- public final static int EIOException =105;
- public final static int EUnknownHostException =106;
+ static final int Reconnect =-2;
+ static final int Exception =-1;
+ static final int TimeOut =0;
- public Timer timer;
- public boolean running = false;
- public boolean flag = true;
- public int cnt = 4; //retry times
- public int tcnt; //current remain retry times
- public int rcnt; //current remain retry times (push)
- public int retime = 2000; //timeout time
- Res res;
- Req req;
- public int p; //port
- public String i; //ip
- Thread thread;
- Handler core;
- Handler recall; //recall
- Queue<Req> reqtask ; //request task
+ 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
- public String itoken;
- public String iname;
+ private String itoken;
+ private String iname;
- Thread Pushthread;
- PushClient push;
-
-
- public final static int Reconnect =-2;
- public final static int Exception =-1;
- public final static int TimeOut =0;
+ private Thread Pushthread;
+ private PushClient push;
Transam(String ip, int port,Handler Recall) {
p = port;
@@ -124,14 +120,14 @@ public class Transam implements Runnable {
}
- public void startPush(String token,String name) {
+ private void startPush(String token,String name) {
itoken = token;
iname = name;
rcnt = cnt;
connectpush();
}
- public void stopPush() {
+ private void stopPush() {
try{
if(push.isClosed() == false) {
push.closeSocket();
@@ -181,7 +177,7 @@ public class Transam implements Runnable {
}
else{ //run the request
running = true;
- tcnt = cnt;
+ tcnt = cnt;
connect();
}
}
@@ -201,7 +197,19 @@ public class Transam implements Runnable {
Pushthread.start();
}
- class reqpush implements Runnable {
+ class tmain extends TimerTask {
+ public void run() {
+ connect();
+ }
+ };
+
+ class pmain extends TimerTask {
+ public void run() {
+ connectpush();
+ }
+ };
+
+ private class reqpush implements Runnable {
public void run() {
try {
if(itoken == null || iname == null) return;
@@ -217,9 +225,14 @@ public class Transam implements Runnable {
}
else if (out == 2){
stopPush();
+ Message msg = new Message();
+ msg.what = Exception;
+ msg.obj = new EStatusFailedException(5,0);
+ recall.sendMessage(msg);
}
else {
- push.listen(recall,handler);
+ rcnt = cnt;
+ push.listen(recall);
}
} catch (UnknownHostException e) {
e.printStackTrace();
@@ -238,23 +251,30 @@ public class Transam implements Runnable {
}
}
- class thd implements Runnable {
+ private class thd implements Runnable {
public void run() {
try {
SocketClient client = new SocketClient(i,p,retime);
- int out = client.sendMsg(req,recall);
+ int out = client.sendMsg(req,recall,handler);
if(out == 0){
client.closeSocket();
running = false;
}
- else {
+ else if (out == 1){
client.closeSocket();
- Message m = new Message();
- EConnectFailedException c = new EConnectFailedException(req.type,req.time);
- m.obj = c;
- m.what = Exception;
+ Message m = new Message();
+ m.obj = new ETimeOutException(req.type,req.time);
+ m.what = TimeOut;
handler.sendMessage(m);
- }
+ }
+ else {
+ client.closeSocket();
+ Message msg = new Message();
+ msg.what = Exception;
+ msg.obj = new EStatusFailedException(5,0);
+ recall.sendMessage(msg);
+ running = false;
+ }
} catch (UnknownHostException e) {
e.printStackTrace();
Message msg = new Message();
@@ -272,15 +292,18 @@ public class Transam implements Runnable {
}
}
+
@SuppressLint("HandlerLeak")
- Handler handler = new Handler() {
+ private Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case Exception:
if (tcnt > 0) {
tcnt--;
System.out.println(tcnt);
- connect();
+ timer = new Timer();
+ TimerTask task = new tmain();
+ timer.schedule(task,retime);
} else if (tcnt == 0) {
Message m = new Message();
m.obj = msg.obj;
@@ -292,7 +315,10 @@ public class Transam implements Runnable {
case TimeOut:
if (tcnt > 0) {
tcnt--;
- connect();
+ System.out.println(tcnt);
+ timer = new Timer();
+ TimerTask task = new tmain();
+ timer.schedule(task,retime);
} else if (tcnt == 0) {
Message m = new Message();
EConnectFailedException c = new EConnectFailedException(req.type,req.time);
@@ -305,72 +331,33 @@ public class Transam implements Runnable {
case Reconnect:
if (rcnt > 0) {
rcnt--;
- connectpush();
+ System.out.println(rcnt);
+ pushtimer = new Timer();
+ TimerTask task = new pmain();
+ pushtimer.schedule(task,retime);
} else if (rcnt == 0) {
Message m = new Message();
- //EPushFailedException c = new EPushFailedException(req.type);
- m.obj = msg.obj;
+ EPushFailedException c = new EPushFailedException(5,0);
+ //m.obj = msg.obj;
+ m.obj = c;
m.what = Exception;
recall.sendMessage(m);
}
break;
+ case StartPush:
+ @SuppressWarnings("unchecked")
+ Vector<String> s = (Vector<String>) msg.obj;
+ startPush(s.get(1),s.get(0));
+ System.out.println("startpush");
+ break;
+ case ClosePush:
+ stopPush();
+ System.out.println("closepush");
+ break;
}
super.handleMessage(msg);
}
};
- class EException extends Exception {
- private static final long serialVersionUID = 100L;
- int Rtype;
- int Etype;
- long time;
- public EException(int e,int r,long timep) {
- super();
- Rtype = r;
- Etype = e;
- time = timep;
- }
- }
-
- class EConnectFailedException extends EException{
- private static final long serialVersionUID = 101L;
- public EConnectFailedException(int t,long timep) {
- super(101,t,timep);
- }
- }
-
- class ETimeOutException extends EException{
- private static final long serialVersionUID = 102L;
- public ETimeOutException(int t,long timep) {
- super(102,t,timep);
- }
- }
-
- class EJavaHostException extends EException{
- private static final long serialVersionUID = 103L;
- public EJavaHostException(int t,long timep) {
- super(103,t,timep);
- }
- }
-
- class EPushFailedException extends EException{
- private static final long serialVersionUID = 104L;
- public EPushFailedException(int t,long timep) {
- super(104,t,timep);
- }
- }
-
- class EIOException extends EException{
- private static final long serialVersionUID = 105L;
- public EIOException(int t,long timep) {
- super(105,t,timep);
- }
- }
- class EUnknownHostException extends EException{
- private static final long serialVersionUID = 106L;
- public EUnknownHostException(int t,long timep) {
- super(106,t,timep);
- }
- }
} \ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
new file mode 100644
index 0000000..0521432
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
@@ -0,0 +1,5 @@
+package com.macaroon.piztor;
+
+public class UpdateInfo {
+
+}