summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com/macaroon
diff options
context:
space:
mode:
authorsjtufs <[email protected]>2013-09-01 16:14:54 +0800
committersjtufs <[email protected]>2013-09-01 16:14:54 +0800
commite7022e78a79f04b62d9ec788428b04a01420bb66 (patch)
tree7c8b786b833dec2a61d53e43ffb2faa00051c0b0 /client/Piztor/src/com/macaroon
parent99a1b057ead83443ceeb80d17581a041bf56d248 (diff)
Piztor rc1
Diffstat (limited to 'client/Piztor/src/com/macaroon')
-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
12 files changed, 220 insertions, 87 deletions
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;