package com.macaroon.piztor;
import java.util.Timer;
import java.util.TimerTask;
import android.annotation.SuppressLint;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
public class Main extends PiztorAct {
final static int SearchButtonPress = 1;
final static int FetchButtonPress = 2;
final static int FocuseButtonPress = 3;
final static int SuccessFetch = 4;
final static int FailedFetch = 5;
final static int TimerFlush = 6;
ActMgr actMgr;
ImageButton btnSearch, btnFetch, btnFocus, btnSettings;
Timer autodate;
@SuppressLint("HandlerLeak")
Handler fromGPS = new Handler() {
@Override
public void handleMessage(Message m) {
if (m.what != 0) {
Location l = (Location) m.obj;
if (l == null)
System.out.println("fuck!!!");
else {
ReqUpdate r = new ReqUpdate(UserInfo.token,
UserInfo.username, l.getLatitude(),
l.getLongitude(), System.currentTimeMillis(), 1000);
AppMgr.transam.send(r);
}
}
}
};
@SuppressLint("HandlerLeak")
Handler fromTransam = new Handler() {
@Override
public void handleMessage(Message m) {
switch (m.what) {
case 1:
ResUpdate update = (ResUpdate) m.obj;
if (update.s == 0)
System.out.println("update success");
else {
System.out.println("update failed");
actMgr.trigger(AppMgr.errorToken);
}
break;
case 2:
ResLocation location = (ResLocation) m.obj;
if (location.s == 0) {
for (int i = 0; i < location.n; i++) {
System.out.println(location.l.get(i).i + " : "
+ location.l.get(i).lat + " "
+ location.l.get(i).lot);
}
actMgr.trigger(SuccessFetch);
} else {
System.out
.println("resquest for location must be wrong!!!");
actMgr.trigger(AppMgr.errorToken);
}
break;
case 3:
ResUserinfo r = (ResUserinfo) m.obj;
if (r.s == 0) {
System.out.println("id : " + r.uid + " sex : " + r.sex
+ " group : " + r.gid);
} else {
System.out.println("reqest for userInfo must be wrong!!!");
actMgr.trigger(AppMgr.errorToken);
}
break;
default:
break;
}
}
};
String cause(int t) {
switch (t) {
case SearchButtonPress:
return "Search Button Press";
case FetchButtonPress:
return "Fetch Button Press";
case FocuseButtonPress:
return "Focuse Button Press";
case SuccessFetch:
return "Success Fetch";
case FailedFetch:
return "Failed Fetch";
case TimerFlush:
return "TimerFlush";
default:
return "Fuck!!!";
}
}
// TODO flush map view
void flushMap() {
}
class StartStatus extends ActStatus {
@Override
void enter(int e) {
System.out.println("enter start status!!!!");
if (e == ActMgr.Create) {
AppMgr.transam.send(new ReqUserinfo(UserInfo.token,
UserInfo.username, UserInfo.id, System
.currentTimeMillis(), 5000));
}
if (e == TimerFlush) {
ReqLocation r = new ReqLocation(UserInfo.token,
UserInfo.username, 1, System.currentTimeMillis(), 1000);
AppMgr.transam.send(r);
}
if (e == SuccessFetch)
flushMap();
}
@Override
void leave(int e) {
System.out.println("leave start status!!!! because" + cause(e));
}
}
class FetchStatus extends ActStatus {
@Override
void enter(int e) {
System.out.println("enter Fetch status!!!!");
if (e == FetchButtonPress) {
ReqLocation r = new ReqLocation(UserInfo.token,
UserInfo.username, 1, System.currentTimeMillis(), 1000);
AppMgr.transam.send(r);
}
}
@Override
void leave(int e) {
System.out.println("leave fetch status!!!! because" + cause(e));
}
}
class FocusStatus extends ActStatus {
@Override