summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/Piztor/res/drawable/footbar_fetch.pngbin4849 -> 742 bytes
-rw-r--r--client/Piztor/res/drawable/footbar_fetch_1.pngbin3300 -> 319 bytes
-rw-r--r--client/Piztor/res/drawable/footbar_settings.pngbin4340 -> 1051 bytes
-rw-r--r--client/Piztor/res/drawable/footbar_settings0.pngbin0 -> 4340 bytes
-rw-r--r--client/Piztor/res/drawable/footbar_settings_1.pngbin3205 -> 383 bytes
-rw-r--r--client/Piztor/res/layout/activity_login.xml26
-rw-r--r--client/Piztor/res/layout/activity_settings.xml56
-rw-r--r--client/Piztor/res/values/strings.xml5
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AlertMaker.java28
-rw-r--r--client/Piztor/src/com/macaroon/piztor/EException.java9
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Login.java5
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java42
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapInfo.java1
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java55
-rw-r--r--client/Piztor/src/com/macaroon/piztor/PushClient.java24
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Settings.java1
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SocketClient.java3
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java69
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Transam.java48
-rw-r--r--client/Piztor/src/com/macaroon/piztor/UpdateInfo.java22
20 files changed, 270 insertions, 124 deletions
diff --git a/client/Piztor/res/drawable/footbar_fetch.png b/client/Piztor/res/drawable/footbar_fetch.png
index 138ef6a..71d1a20 100644
--- a/client/Piztor/res/drawable/footbar_fetch.png
+++ b/client/Piztor/res/drawable/footbar_fetch.png
Binary files differ
diff --git a/client/Piztor/res/drawable/footbar_fetch_1.png b/client/Piztor/res/drawable/footbar_fetch_1.png
index 0d098ab..564b1da 100644
--- a/client/Piztor/res/drawable/footbar_fetch_1.png
+++ b/client/Piztor/res/drawable/footbar_fetch_1.png
Binary files differ
diff --git a/client/Piztor/res/drawable/footbar_settings.png b/client/Piztor/res/drawable/footbar_settings.png
index a6987f8..7879ceb 100644
--- a/client/Piztor/res/drawable/footbar_settings.png
+++ b/client/Piztor/res/drawable/footbar_settings.png
Binary files differ
diff --git a/client/Piztor/res/drawable/footbar_settings0.png b/client/Piztor/res/drawable/footbar_settings0.png
new file mode 100644
index 0000000..a6987f8
--- /dev/null
+++ b/client/Piztor/res/drawable/footbar_settings0.png
Binary files differ
diff --git a/client/Piztor/res/drawable/footbar_settings_1.png b/client/Piztor/res/drawable/footbar_settings_1.png
index 8b61042..b76fe9f 100644
--- a/client/Piztor/res/drawable/footbar_settings_1.png
+++ b/client/Piztor/res/drawable/footbar_settings_1.png
Binary files differ
diff --git a/client/Piztor/res/layout/activity_login.xml b/client/Piztor/res/layout/activity_login.xml
index c408a1d..cb27495 100644
--- a/client/Piztor/res/layout/activity_login.xml
+++ b/client/Piztor/res/layout/activity_login.xml
@@ -1,10 +1,12 @@
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
<RelativeLayout
android:orientation="vertical"
android:id="@+id/login_layout"
android:background="@android:color/black"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- xmlns:android="http://schemas.android.com/apk/res/android">
+ android:layout_height="fill_parent">
<LinearLayout
@@ -12,14 +14,23 @@
android:layout_height="wrap_content"
android:background="@android:color/black"
android:gravity="center_horizontal"
- android:orientation="vertical" >
+ android:orientation="vertical"
+ android:layout_marginTop="16dip">
<ImageView
android:id="@+id/main_headbar_img"
android:layout_width="180dp"
- android:layout_height="190dp"
+ android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/title_logo" />
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:text="@string/app_name"
+ android:textSize="30dip"
+ android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
@@ -27,7 +38,7 @@
android:id="@+id/user_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_marginTop="200.0dip"
+ android:layout_marginTop="260.0dip"
android:layout_marginLeft="28.0dip"
android:layout_marginRight="28.0dip">
<EditText
@@ -75,8 +86,9 @@
android:layout_height="wrap_content"
android:layout_marginLeft="70.0dip"
android:layout_marginRight="70.0dip"
- android:layout_marginTop="12.0dip"
+ android:layout_marginTop="40.0dip"
android:text="@string/login"
android:layout_below="@id/user_layout" />
-</RelativeLayout> \ No newline at end of file
+</RelativeLayout>
+</ScrollView> \ No newline at end of file
diff --git a/client/Piztor/res/layout/activity_settings.xml b/client/Piztor/res/layout/activity_settings.xml
index 36bacf3..ba67683 100644
--- a/client/Piztor/res/layout/activity_settings.xml
+++ b/client/Piztor/res/layout/activity_settings.xml
@@ -30,16 +30,18 @@
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="10dip"
+ android:layout_marginBottom="2dip"
android:text="@string/GPSrefreshrate"
android:textColor="@android:color/white"
- android:textSize="20dip" />
+ android:textSize="17dip" />
<TextView
android:id="@+id/settings_GPSrefreshrate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:textSize="20dip"
+ android:textSize="17dip"
android:layout_marginTop="10dip"
- android:layout_marginLeft="10dip"
+ android:layout_marginLeft="4dip"
+ android:layout_marginBottom="2dip"
android:layout_gravity="center_vertical"
android:textColor="@android:color/white"
android:layout_toRightOf="@+id/settings_GPSrefreshrate_text"
@@ -87,31 +89,26 @@
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:background="#ffc0c3c4" />
+
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- android:layout_marginTop="10dip"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- android:textSize="30dip"
- android:textColor="@android:color/white"
- android:text="@string/subscribe_info"/>
-
- <Button
- android:id="@+id/settings_btn_subscribe"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="20dip"
- android:text="@string/change"
- android:textSize="22dip" />
-
- </LinearLayout>
+ 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:layout_marginTop="20dip"
+ android:text="@string/change"
+ android:textSize="20dip"
+ android:textColor="@android:color/white"
+ android:background="#0F9D58"
+ android:id="@+id/settings_btn_subscribe" />
+ </LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1.0px"
@@ -141,13 +138,16 @@
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:id="@+id/show_by_team"
+ android:id="@+id/show_by_team"
+ android:textSize="18dip"
android:text="@string/show_team"
android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
android:id="@+id/show_by_sex"
+ android:textSize="18dip"
android:text="@string/show_sex"/>
</RadioGroup>
</LinearLayout>
@@ -171,7 +171,7 @@
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:text="@string/update_info"
- android:textSize="30dip"
+ android:textSize="20dip"
android:textColor="@android:color/white"
android:background="#4285F4"
android:id="@+id/settings_btn_updateinfo" />
@@ -182,7 +182,7 @@
android:paddingBottom="5dip"
android:layout_marginTop="20dip"
android:text="@string/logout"
- android:textSize="30dip"
+ android:textSize="20dip"
android:textColor="@android:color/white"
android:background="#DB4437"
android:id="@+id/settings_btn_logout" />
diff --git a/client/Piztor/res/values/strings.xml b/client/Piztor/res/values/strings.xml
index 82132ed..25e980a 100644
--- a/client/Piztor/res/values/strings.xml
+++ b/client/Piztor/res/values/strings.xml
@@ -6,7 +6,7 @@
<string name="hello_world">Hello world!</string>
<string name="settings">设置</string>
<string name="search">搜索</string>
- <string name="fetch">获取</string>
+ <string name="fetch">上传</string>
<string name="checkin">签到</string>
<string name="focus">聚焦</string>
<string name="show_sex">按性别</string>
@@ -25,7 +25,7 @@
<string name="logout">注销</string>
<string name="update_info">修改密码</string>
<string name="subscribe_info">关注信息</string>
- <string name="change">查看及修改</string>
+ <string name="change">关注信息</string>
<string name="title_activity_subscribesettings">SubscribeSettings</string>
<string name="title_activity_subscribe_settings">SubscribeSettings</string>
<string name="title_activity_update_info">UpdateInfo</string>
@@ -39,5 +39,6 @@
<string name="new_password">新密码</string>
<string name="submit">提交</string>
<string name="colormode">着色方式</string>
+ <string name="save">保存</string>
</resources>
diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
index b1087a2..eec01f5 100644
--- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
@@ -105,6 +105,32 @@ public class AlertMaker {
closeBoard(context);
}
+public void showRemoveMarkerAlert() {
+
+ closeBoard(context);
+ AlertDialog.Builder removeDialog = new AlertDialog.Builder(context);
+ removeDialog.setTitle("取消路标");
+ removeDialog.setMessage("是否取消路标?");
+ removeDialog.setPositiveButton("确定",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ mapMaker.mOverlay.removeItem(mapMaker.nowMarker);
+ mapMaker.nowMarker = null;
+ mapMaker.mMapView.refresh();
+ mapMaker.popLay.hidePop();
+ }
+ });
+ removeDialog.setNegativeButton("取消",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ mapMaker.popLay.hidePop();
+ dialog.cancel();
+ }
+ });
+ removeDialog.show();
+ closeBoard(context);
+ }
+
public long toTimestamp(int hour, int minute) {
calendar = Calendar.getInstance();
@@ -112,7 +138,7 @@ public class AlertMaker {
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
hour,minute);
- return calendar.getTimeInMillis();
+ return calendar.getTimeInMillis()/1000;
}
//TODO
diff --git a/client/Piztor/src/com/macaroon/piztor/EException.java b/client/Piztor/src/com/macaroon/piztor/EException.java
index 39d53c8..92f2ab7 100644
--- a/client/Piztor/src/com/macaroon/piztor/EException.java
+++ b/client/Piztor/src/com/macaroon/piztor/EException.java
@@ -13,7 +13,7 @@ public class EException extends Exception {
static final int EStatusFailedException =107;
static final int ELevelFailedException =108;
static final int EPasswordFailedException =109;
-
+ static final int ESubscribeFailedException =110;
private static final long serialVersionUID = 100L;
int Rtype;
@@ -90,4 +90,11 @@ public class EException extends Exception {
}
}
+ class ESubscribeFailedException extends EException{
+ private static final long serialVersionUID = 110L;
+ public ESubscribeFailedException(int t,long timep) {
+ super(110,t,timep);
+ }
+ }
+
\ No newline at end of file
diff --git a/client/Piztor/src/com/macaroon/piztor/Login.java b/client/Piztor/src/com/macaroon/piztor/Login.java
index 3b9cbc2..22c8c91 100644
--- a/client/Piztor/src/com/macaroon/piztor/Login.java
+++ b/client/Piztor/src/com/macaroon/piztor/Login.java
@@ -8,6 +8,7 @@ import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
+import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@@ -86,7 +87,11 @@ public class Login extends PiztorAct {
protected void onCreate(Bundle savedInstanceState) {
id = "login";
super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+ requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_login);
+ setProgressBarIndeterminateVisibility(true);
+ setProgressBarVisibility(true);
}
@Override
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java
index 052e267..97d2f7b 100644
--- a/client/Piztor/src/com/macaroon/piztor/Main.java
+++ b/client/Piztor/src/com/macaroon/piztor/Main.java
@@ -14,6 +14,7 @@ import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
+import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageButton;
import android.widget.Toast;
@@ -53,13 +54,14 @@ public class Main extends PiztorAct {
LocationData locData = null;
public MyLocationListener myListener = new MyLocationListener();
boolean isFirstLocation = true;
- public static int GPSrefreshrate = 5;
+ public static int GPSrefreshrate = 20;
private final int checkinRadius = 10;
ImageButton btnCheckin, btnFetch, btnFocus, btnSettings;
static class ReCall extends Handler {
WeakReference<Main> outerClass;
+ String id = "main";
ReCall(Main activity) {
outerClass = new WeakReference<Main>(activity);
@@ -71,6 +73,7 @@ public class Main extends PiztorAct {
if (out == null) {
System.out.println("act被回收了");
}
+ Log.d("marker", "what is " + m.what);
switch (m.what) {
case Res.Login:// 上传自己信息成功or失败
Log.d("update location", "successfull");
@@ -122,6 +125,7 @@ public class Main extends PiztorAct {
(int) (pushMarker.latitude * 1e6),
(int) (pushMarker.longitude * 1e6));
markerInfo.markerTimestamp = pushMarker.deadline;
+ Log.d("marker", "Marker received! " + pushMarker.deadline);
out.mapMaker.receiveMarker(markerInfo);
break;
case -1:
@@ -175,6 +179,15 @@ public class Main extends PiztorAct {
toast.show();
}
+ public void updateMyLocation() {
+ if (app.token != null) {
+ app.mapInfo.myInfo.setLocation(locData.latitude, locData.longitude);
+ transam.send(new ReqUpdate(app.token, app.username,
+ locData.latitude, locData.longitude,
+ System.currentTimeMillis(), 2000));
+ }
+ }
+
public class MyLocationListener implements BDLocationListener {
int cnt = 0;
GeoPoint lastPoint = null;
@@ -196,11 +209,7 @@ public class Main extends PiztorAct {
if (lastPoint == null || cnt > 5
|| DistanceUtil.getDistance(point, lastPoint) > 10) {
if (app.token != null) {
- app.mapInfo.myInfo.setLocation(locData.latitude,
- locData.longitude);
- transam.send(new ReqUpdate(app.token, app.username,
- locData.latitude, locData.longitude, System
- .currentTimeMillis(), 2000));
+ updateMyLocation();
lastPoint = point;
cnt = 0;
}
@@ -259,7 +268,7 @@ public class Main extends PiztorAct {
+ app.mapInfo.myInfo.uid);
}
if (e == SuccessFetch)
- flushMap();
+ { }
}
@Override
@@ -293,6 +302,7 @@ public class Main extends PiztorAct {
closeBoard(Main.this);
if (app.mapInfo.myInfo.level != 0) {
alertMaker.showMarkerAlert(arg0);
+ closeBoard(Main.this);
}
}
@@ -343,7 +353,13 @@ public class Main extends PiztorAct {
.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager
.isProviderEnabled(locationManager.GPS_PROVIDER);
+
+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+ requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
+ setProgressBarIndeterminateVisibility(true);
+ setProgressBarVisibility(true);
+
app.mBMapManager.start();
mMapView = (MapView) findViewById(R.id.bmapView);
@@ -402,7 +418,17 @@ public class Main extends PiztorAct {
actMgr.trigger(AppMgr.toSettings);
}
});
-
+
+ btnFetch.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ Toast.makeText(Main.this, "正在定位...", Toast.LENGTH_LONG).show();
+ mLocClient.requestLocation();
+ updateMyLocation();
+ focusOn();
+ }
+ });
}
@Override
diff --git a/client/Piztor/src/com/macaroon/piztor/MapInfo.java b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
index 857ea66..10cb52b 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapInfo.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapInfo.java
@@ -103,6 +103,7 @@ class UserInfo {
this.company = company;
this.section = section;
this.sex = sex;
+ this.nickname = nickName;
}
public GeoPoint getLocation(){
diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
index 967a34d..837df2b 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
@@ -34,7 +34,7 @@ import com.baidu.platform.comapi.basestruct.GeoPoint;
public class MapMaker {
// MapView controlling component
- private MapView mMapView = null;
+ MapView mMapView = null;
MapController mMapController = null;
MKOfflineMap mOffline = null;
@@ -43,7 +43,7 @@ public class MapMaker {
(int) (31.032247 * 1E6), (int) (121.445937 * 1E6));
// Map layers and items
- private MyOverlay mOverlay = null;
+ MyOverlay mOverlay = null;
private OverlayItem curItem = null;
private LocationOverlay mLocationOverlay;
private ArrayList<OverlayItem> mItems = null;
@@ -56,7 +56,7 @@ public class MapMaker {
private HashMap<OverlayItem, Integer> markerToInt = null;
// marker layer
- private OverlayItem nowMarker = null;
+ OverlayItem nowMarker = null;
static int nowMarkerHour;
static int nowMarkerMinute;
static long nowMarkerTimestamp;
@@ -67,7 +67,7 @@ public class MapMaker {
private int nowMarkerLevel;
// Popup component
- private PopupOverlay popLay = null;
+ PopupOverlay popLay = null;
private TextView popupText = null;
private TextView leftText = null;
private View viewCache = null;
@@ -127,8 +127,6 @@ public class MapMaker {
if (nowMarker != null && index == markerIndex) {
OverlayItem item = getItem(index);
- // TODO
- // ///////////////////////////////////////////////////////
leftText.setText(nowMarkerHour + "点");
popupText.setText(nowMarkerMinute + "分");
Bitmap bitmap[] = { BMapUtil.getBitmapFromView(popupLeft),
@@ -137,8 +135,7 @@ public class MapMaker {
popLay.showPopup(bitmap, item.getPoint(), 32);
} else {
OverlayItem item = getItem(index);
- UserInfo tmpInfo = preMapInfo
- .getUserInfo(markerToInt.get(item));
+ UserInfo tmpInfo = app.mapInfo.getUserInfo(markerToInt.get(item));
String itemInfo = tmpInfo.company + "连" + tmpInfo.section + "班 " + tmpInfo.nickname;
popupText.setText(itemInfo);
Bitmap bitmap = BMapUtil.getBitmapFromView(popupInfo);
@@ -243,11 +240,13 @@ public class MapMaker {
// do nothing
}
if (index == 2) {
- // remove current marker
- mOverlay.removeItem(nowMarker);
- nowMarker = null;
- mMapView.refresh();
- popLay.hidePop();
+ // remove current marker if is higher or equal level
+ if (app.mapInfo.myInfo.level >= nowMarkerLevel) {
+ AlertMaker removeAlert = new AlertMaker(context, MapMaker.this);
+ removeAlert.showRemoveMarkerAlert();
+ } else {
+ Toast.makeText(context, "权限不足", Toast.LENGTH_SHORT).show();
+ }
}
}
};
@@ -288,12 +287,13 @@ public class MapMaker {
public Drawable getGroupIcon(UserInfo userInfo) {
if (Main.colorMode == Main.show_by_team) {
- if (userInfo.section == preMapInfo.myInfo.section)
+ if (userInfo.section == app.mapInfo.myInfo.section)
return myBM[0];
else
return myBM[userInfo.section % iconNum + 1];
} else {
- return myBM[userInfo.sex ^ preMapInfo.myInfo.sex];
+ if (userInfo.sex == app.mapInfo.myInfo.sex) return myBM[0];
+ else return myBM[1];
}
}
@@ -334,7 +334,7 @@ public class MapMaker {
// first remove all old users that are not here now
if (preMapInfo != null) {
for (UserInfo i : preMapInfo.getVector()) {
- if (i.uid == preMapInfo.myInfo.uid)
+ if (i.uid == app.mapInfo.myInfo.uid)
continue;
if (mapInfo.getUserInfo(i.uid) == null) {
mOverlay.removeItem(hash.get(i.uid));
@@ -353,7 +353,7 @@ public class MapMaker {
// then update and add items
for (UserInfo i : mapInfo.getVector()) {
- if (i.uid == preMapInfo.myInfo.uid)
+ if (i.uid == app.mapInfo.myInfo.uid)
continue;
if (hash.containsKey(i.uid) == false) {
if (isInvalidLocation(i.location)) {
@@ -386,15 +386,13 @@ public class MapMaker {
checkMarkerTime();
}
- @SuppressWarnings("deprecation")
public void receiveMarker(MarkerInfo markerInfo) {
- Log.d("marker", "Marker received!");
if (nowMarker != null && markerInfo.level >= nowMarkerLevel) {
Log.d("marker", "Old marker replaced by marker with higher level!");
nowMarker.setGeoPoint(markerInfo.markerPoint);
final Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(markerInfo.markerTimestamp);
+ cal.setTimeInMillis(markerInfo.markerTimestamp * 1000);
Date date = (Date) cal.getTime();
nowMarkerHour = date.getHours();
nowMarkerMinute = date.getMinutes();
@@ -418,7 +416,7 @@ public class MapMaker {
System.out.println(markerInfo.markerPoint.getLatitudeE6() + " "
+ markerInfo.markerPoint.getLongitudeE6());
final Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(markerInfo.markerTimestamp);
+ cal.setTimeInMillis(markerInfo.markerTimestamp * 1000);
Date date = (Date) cal.getTime();
nowMarkerHour = date.getHours();
nowMarkerMinute = date.getMinutes();
@@ -437,12 +435,13 @@ public class MapMaker {
}
void sendMarker() {
+ Log.d("marker", "Marker prepare! " + nowMarkerTimestamp);
ReqSetMarker req = new ReqSetMarker(app.token, app.username, nowMarker
.getPoint().getLatitudeE6() / 1e6, nowMarker.getPoint()
.getLongitudeE6() / 1e6, (int)nowMarkerTimestamp,
System.currentTimeMillis(), 3000l);
- Log.d("marker", "Sent marker" + nowMarker.getPoint().getLatitudeE6() + " " +
- nowMarker.getPoint().getLongitudeE6());
+
+ Log.d("marker", "Marker sent! " + req.deadline);
app.transam.send(req);
}
@@ -451,14 +450,12 @@ public class MapMaker {
*/
public void DrawMarker(GeoPoint markerPoint) {
- if (preMapInfo == null) return;
-
- if (nowMarker != null && preMapInfo.myInfo.level >= nowMarkerLevel) {
+ if (nowMarker != null && app.mapInfo.myInfo.level >= nowMarkerLevel) {
nowMarker.setGeoPoint(markerPoint);
nowMarkerHour = newMarkerHour;
nowMarkerMinute = newMarkerMinute;
nowMarkerTimestamp = newMarkerTimestamp;
- nowMarkerLevel = preMapInfo.myInfo.level;
+ nowMarkerLevel = app.mapInfo.myInfo.level;
sendMarker();
Log.d("marker", "Sent and replace");
@@ -473,7 +470,7 @@ public class MapMaker {
nowMarkerHour = newMarkerHour;
nowMarkerMinute = newMarkerMinute;
nowMarkerTimestamp = newMarkerTimestamp;
- nowMarkerLevel = preMapInfo.myInfo.level;
+ nowMarkerLevel = app.mapInfo.myInfo.level;
sendMarker();
Log.d("marker", "Send and new");
@@ -504,7 +501,7 @@ public class MapMaker {
}
public void checkMarkerTime() {
- if (nowMarker != null && nowMarkerTimestamp <= System.currentTimeMillis()) {
+ if (nowMarker != null && nowMarkerTimestamp <= System.currentTimeMillis() / 1000) {
AlertMaker lateAlert = new AlertMaker(context, this);
lateAlert.showLateAlert();
removeMarker();
diff --git a/client/Piztor/src/com/macaroon/piztor/PushClient.java b/client/Piztor/src/com/macaroon/piztor/PushClient.java
index 7cecfba..7bd82a6 100644
--- a/client/Piztor/src/com/macaroon/piztor/PushClient.java
+++ b/client/Piztor/src/com/macaroon/piztor/PushClient.java
@@ -5,12 +5,14 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
+import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Vector;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
@@ -42,12 +44,13 @@ public class PushClient {
private String LastPrint = "";
- public PushClient(String site, int port,int retime) throws UnknownHostException,
+ public PushClient(String site, int port,int retime, Handler handler) throws UnknownHostException,
IOException {
try {
client = new Socket();
client.connect(new InetSocketAddress(site,port), retime);
client.setSoTimeout(2000);
+ recall = handler;
//client.setTcpNoDelay(true);
} catch (UnknownHostException e) {
e.printStackTrace();
@@ -105,15 +108,13 @@ public class PushClient {
return client.isClosed();
}
- public void listen(Handler recall) throws IOException{
+ public void listen() throws IOException{
client.setSoTimeout(0);
DataInputStream in = new DataInputStream(client.getInputStream());
DataOutputStream out = new DataOutputStream(client.getOutputStream());
-
- while(true){
- try {
+ try {
+ while(true){
int len = in.readInt();
- System.out.println(len);
int tmp = in.readUnsignedByte();
byte[] buffer = new byte[32];
in.read(buffer);
@@ -129,6 +130,7 @@ public class PushClient {
String m = new String(b);
in.readUnsignedByte();
if(LastPrint != p) {
+ System.out.println(p);
Message msg = new Message();
msg.what = PushMessage;
msg.obj = new ResPushMessage(m);
@@ -157,6 +159,7 @@ public class PushClient {
n++;
}
if(LastPrint != p) {
+ System.out.println(p);
Message msg = new Message();
msg.obj = new ResPushLocation(n,tmpv);
msg.what = PushLocation;
@@ -178,6 +181,7 @@ public class PushClient {
double lot = in.readDouble();
int dtime = in.readInt();
if(LastPrint != p) {
+
Message msg = new Message();
msg.what = PushMarker;
msg.obj = new ResPushMarker(lat,lot,dtime,lv);
@@ -194,11 +198,13 @@ public class PushClient {
out.flush();
break;
}
-
- } catch (IOException e) {
+ }
+ } catch (SocketException e){
+ System.out.println("Socket closed!");
+ return;
+ } catch (IOException e) {
e.printStackTrace();
throw e;
- }
}
}
diff --git a/client/Piztor/src/com/macaroon/piztor/Settings.java b/client/Piztor/src/com/macaroon/piztor/Settings.java
index 14d5b3e..276d4f6 100644
--- a/client/Piztor/src/com/macaroon/piztor/Settings.java
+++ b/client/Piztor/src/com/macaroon/piztor/Settings.java
@@ -195,6 +195,7 @@ public class Settings extends PiztorAct {
}
if (checkedId == R.id.show_by_sex){
setColorMode(show_by_sex);
+ Toast.makeText(Settings.this, "蓝色表示同性,红色表示异性", Toast.LENGTH_LONG).show();
}
}
};
diff --git a/client/Piztor/src/com/macaroon/piztor/SocketClient.java b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
index befe7fa..de26b63 100644
--- a/client/Piztor/src/com/macaroon/piztor/SocketClient.java
+++ b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
@@ -12,6 +12,7 @@ import java.util.Vector;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
@@ -44,6 +45,7 @@ public class SocketClient {
static final int Longitude =7;
static final int Level =8;
+ static final int SubscribeFailed =6;
static final int PasswordFailed =5;
static final int ServerFetchFailed =4;
static final int LevelFailed =3;
@@ -251,6 +253,7 @@ public class SocketClient {
if(status == 1) return StatusFailed;
if(status == 2) return LevelFailed;
if(status == 3) return PasswordFailed;
+ if(status == 4) return SubscribeFailed;
switch (type) {
case Login:
byte[] buffer = new byte[32];
diff --git a/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java b/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
index ff7c00d..4fdaa8a 100644
--- a/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
+++ b/client/Piztor/src/com/macaroon/piztor/SubscribeSettings.java
@@ -15,6 +15,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
+import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@@ -71,7 +72,7 @@ public class SubscribeSettings extends PiztorAct {
}
break;
case Res.Logout:// 登出
- out.actMgr.trigger(AppMgr.logout);
+ out.appMgr.trigger(AppMgr.logout);
break;
case Res.PushMessage:
ResPushMessage pushMessage = (ResPushMessage) m.obj;
@@ -93,10 +94,23 @@ public class SubscribeSettings extends PiztorAct {
out.mapInfo.markerInfo = markerInfo;
break;
case Res.Subscription:
- out.app.sublist = out.listGroup;
+ out.reDraw(out.listGroup);
+ out.app.sublist =(Vector<RGroup>) out.listGroup.clone();
break;
case -1:
- out.actMgr.trigger(AppMgr.logout);
+ EException eException = (EException) m.obj;
+ /////////////////TODO
+ if (eException.Etype == EException.ESubscribeFailedException) {
+ out.receiveMessage("关注信息无效");
+ for (RGroup i : out.listGroup) {
+ Log.d("sub", i.company + " " + i.section);
+ }
+ for(RGroup i : out.app.sublist) {
+ Log.d("sub", "***" + i.company + " " + i.section);
+ }
+ out.reDraw(out.app.sublist);
+ }
+ else out.appMgr.trigger(AppMgr.logout);
default:
break;
}
@@ -111,7 +125,35 @@ public class SubscribeSettings extends PiztorAct {
private EditText edit_section;
private Vector<RGroup> listGroup;
private Set<Integer> recSubcribe;
+ MySimpleAdapter simpleAdapter;
+ public void reDraw(Vector<RGroup> list) {
+ recSubcribe = new HashSet<Integer>();
+ listGroup = new Vector<RGroup>();
+ for (RGroup i : list) {
+ if (i.section == 255) {
+ recSubcribe.add(i.company);
+ }
+ }
+ mList.clear();
+ simpleAdapter.notifyDataSetChanged();
+ for (int i : recSubcribe) {
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("subscribe_text", i + "连");
+ mList.add(map);
+ RGroup listItem = new RGroup(i, 255);
+ listGroup.add(listItem);
+ simpleAdapter.notifyDataSetChanged();
+ }
+ for (RGroup i : list) {
+ if (recSubcribe.contains(i.company)) continue;
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("subscribe_text", i.company + "连 " + i.section + "班");
+ mList.add(map);
+ listGroup.add(i);
+ simpleAdapter.notifyDataSetChanged();
+ }
+ }
void upMapInfo(Vector<RLocation> l) {
for (RLocation i : l) {
@@ -128,9 +170,9 @@ public class SubscribeSettings extends PiztorAct {
void receiveMessage(String msg) {
Log.d("recieve message", msg);
- Toast toast = Toast.makeText(getApplicationContext(), msg,
- Toast.LENGTH_LONG);
- toast.show();
+ Toast toast = Toast.makeText(getApplicationContext(),msg, 2000);
+ toast.setGravity(Gravity.TOP, 0, 120);
+ toast.show();
}
void subscribe() {
@@ -157,7 +199,7 @@ public class SubscribeSettings extends PiztorAct {
edit_section = (EditText) findViewById(R.id.subscribe_section);
mList = new ArrayList<HashMap<String, Object>>();
- final MySimpleAdapter simpleAdapter = new MySimpleAdapter(this, mList,
+ simpleAdapter = new MySimpleAdapter(this, mList,
R.layout.subscribe_item, new String[] { "subscribe_text",
"btnadd" },
new int[] { R.id.textView1, R.id.button_add });
@@ -228,12 +270,13 @@ public class SubscribeSettings extends PiztorAct {
if (ss == 255) {
recSubcribe.add(cc);
for (int i = 0; i < listGroup.size(); i++) {
- if (listGroup.get(i).company == cc) {
- listGroup.remove(i);
- mList.remove(i);
- i--;
- simpleAdapter.notifyDataSetChanged();
- }
+ if (listGroup.size() > 0)
+ if (listGroup.get(i).company == cc) {
+ listGroup.remove(i);
+ mList.remove(i);
+ i--;
+ simpleAdapter.notifyDataSetChanged();
+ }
}
RGroup listItem = new RGroup(cc, 255);
diff --git a/client/Piztor/src/com/macaroon/piztor/Transam.java b/client/Piztor/src/com/macaroon/piztor/Transam.java
index bbded99..6660899 100644
--- a/client/Piztor/src/com/macaroon/piztor/Transam.java
+++ b/client/Piztor/src/com/macaroon/piztor/Transam.java
@@ -24,6 +24,7 @@ public class Transam implements Runnable {
static final int StartPush =5;
static final int SendMessage =6;
static final int SetMarker =7;
+ static final int SetPassword =8;
static final int ClosePush = -5;
@@ -35,11 +36,14 @@ public class Transam implements Runnable {
static final int EUnknownHostException =106;
static final int EStatusFailedException =107;
static final int ELevelFailedException =108;
+ static final int EPasswordFailedException =109;
+ static final int ESubscribeFailedException =110;
static final int Reconnect =-2;
static final int Exception =-1;
static final int TimeOut =0;
+ static final int RSubscribeFailed =6;
static final int RPasswordFailed =5;
static final int RServerFetchFailed =4;
static final int RLevelFailed =3;
@@ -50,10 +54,11 @@ public class Transam implements Runnable {
Timer timer;
Timer pushtimer;
boolean running = false;
+ boolean pushing = false;
int cnt = 5; //retry times
int tcnt; //current remain retry times
int rcnt; //current remain retry times (push)
- int retime = 2000; //timeout time
+ int retime = 5000; //timeout time
Req req;
int p; //port
String i; //ip
@@ -62,8 +67,8 @@ public class Transam implements Runnable {
Handler handler; //manager
Queue<Req> reqtask ; //request task
- String itoken;
- String iname;
+ String itoken = "";
+ String iname = "";
Thread Pushthread;
PushClient push;
@@ -76,15 +81,24 @@ public class Transam implements Runnable {
handler = new Manager(this);
}
- public void send(Req r){
+ public synchronized void send(Req r){
+ if(r.type == Login){
+ if(pushing == true) {
+ stopPush();
+ }
+ }
reqtask.offer(r);
}
private void startPush(String token,String name) {
- itoken = token;
- iname = name;
- rcnt = cnt;
- connectpush();
+ if(pushing == false) {
+ itoken = token;
+ iname = name;
+ rcnt = cnt;
+ pushing = true;
+ System.out.println("startpush");
+ connectpush();
+ }
}
private void stopPush() {
@@ -93,6 +107,8 @@ public class Transam implements Runnable {
push.closeSocket();
itoken = null;
iname = null;
+ pushing = false;
+ System.out.println("closepush");
}
} catch (IOException e) {
e.printStackTrace();
@@ -173,7 +189,7 @@ public class Transam implements Runnable {
public void run() {
try {
if(itoken == null || iname == null) return;
- push = new PushClient(i,p,retime);
+ push = new PushClient(i,p,retime,recall);
push.setPushHandler(recall);
int out = push.start(new ReqStartPush(itoken,iname));
if(out == RTimeOut) {
@@ -184,6 +200,7 @@ public class Transam implements Runnable {
handler.sendMessage(msg);
}
else if (out == RStatusFailed){
+ pushing = false;
stopPush();
Message msg = new Message();
msg.what = Exception;
@@ -192,7 +209,7 @@ public class Transam implements Runnable {
}
else if (out == RSuccess){
rcnt = cnt;
- push.listen(recall);
+ push.listen();
}
} catch (UnknownHostException e) {
e.printStackTrace();
@@ -251,6 +268,14 @@ public class Transam implements Runnable {
recall.sendMessage(msg);
running = false;
}
+ else if (out == RSubscribeFailed){
+ client.closeSocket();
+ Message msg = new Message();
+ msg.what = Exception;
+ msg.obj = new ESubscribeFailedException(req.type,req.time);
+ recall.sendMessage(msg);
+ running = false;
+ }
} catch (UnknownHostException e) {
e.printStackTrace();
Message msg = new Message();
@@ -317,6 +342,7 @@ public class Transam implements Runnable {
TimerTask task = out.new pmain();
out.pushtimer.schedule(task,out.retime);
} else if (out.rcnt == 0) {
+ out.pushing = false;
Message m = new Message();
EPushFailedException c = new EPushFailedException(5,0);
//m.obj = msg.obj;
@@ -329,11 +355,9 @@ public class Transam implements Runnable {
@SuppressWarnings("unchecked")
Vector<String> s = (Vector<String>) msg.obj;
out.startPush(s.get(1),s.get(0));
- System.out.println("startpush");
break;
case ClosePush:
out.stopPush();
- System.out.println("closepush");
break;
}
super.handleMessage(msg);
diff --git a/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
index 66ead66..cd428f7 100644
--- a/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
+++ b/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
@@ -68,22 +68,16 @@ public class UpdateInfo extends PiztorAct {
break;
case Res.SetPassword:
ResSetPassword res = (ResSetPassword) m.obj;
- switch (res.type) {
- case 0:
- out.receiveMessage("修改成功,请重新登录");
- out.appMgr.trigger(AppMgr.logout);
- break;
- case 1:
- out.appMgr.trigger(AppMgr.logout);
- break;
- case 3:
- out.receiveMessage("密码错误");
- default:
- break;
- }
+ out.receiveMessage("修改成功,请重新登录");
+ out.appMgr.trigger(AppMgr.logout);
break;
case -1:
- out.appMgr.trigger(AppMgr.logout);
+ EException eException = (EException) m.obj;
+ if (eException.Etype == EException.EPasswordFailedException)
+ out.receiveMessage("密码错误");
+ else {
+ out.appMgr.trigger(AppMgr.logout);
+ }
break;
default:
break;