summaryrefslogtreecommitdiff
path: root/client/.metadata/.plugins/org.eclipse.core.resources/.history/65
diff options
context:
space:
mode:
authorgoblin911 <goblinliu@gmail.com>2013-08-25 21:18:19 +0800
committergoblin911 <goblinliu@gmail.com>2013-08-25 21:18:19 +0800
commit0e687f12bd2653adb55ea002b39292678366c525 (patch)
tree0ad073ec8ff2ed2716adf23a679184c38df582a1 /client/.metadata/.plugins/org.eclipse.core.resources/.history/65
parent2efdc2f20f0306791ced5ec78a1acddfaf086f42 (diff)
...
Diffstat (limited to 'client/.metadata/.plugins/org.eclipse.core.resources/.history/65')
-rw-r--r--client/.metadata/.plugins/org.eclipse.core.resources/.history/65/10afe9c2560d00131719b896d543f08c68
-rw-r--r--client/.metadata/.plugins/org.eclipse.core.resources/.history/65/7015966a370d00131249f322b63acde883
-rw-r--r--client/.metadata/.plugins/org.eclipse.core.resources/.history/65/c008735d330d00131249f322b63acde8134
3 files changed, 285 insertions, 0 deletions
diff --git a/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/10afe9c2560d00131719b896d543f08c b/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/10afe9c2560d00131719b896d543f08c
new file mode 100644
index 0000000..d2c7c5f
--- /dev/null
+++ b/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/10afe9c2560d00131719b896d543f08c
@@ -0,0 +1,68 @@
+package com.macaroon.piztor;
+
+import android.content.Context;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import android.location.Location;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.os.SystemClock;
+
+
+public class Tracker implements Runnable {
+
+ private static final long TIME_DELTA = 1000 * 3; // 3 second
+ public Timer timer;
+ private final Context mContext;
+ GPSTracker myTracker;
+ Handler mHandler;
+ Message message;
+
+ public Tracker(Context context, Handler yHandler) {
+ timer = new Timer();
+ mContext = context;
+ myTracker = new GPSTracker(mContext);
+ mHandler = yHandler;
+ }
+
+ void setHandler(Handler hand) {
+ mHandler = hand;
+ }
+
+
+ public void run() {
+ GPSTask myTask = new GPSTask();
+ timer.schedule(myTask, 0, TIME_DELTA);
+ }
+
+ class GPSTask extends TimerTask {
+ @Override
+ public void run() {
+ Location location = myTracker.getLocation();
+ Log.d("Location", "Fetching location.....");
+ if (myTracker.canGetLocation()) {
+
+ Log.d("TTTTTTTTTTTTTTTTTTTTTTTime","TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTime");
+ System.out.println("GPSTIME" + myTracker.location.getTime());
+ System.out.println("SYSTIME" + SystemClock.elapsedRealtime());
+
+ message = new Message();
+ message.what = 0;
+ message.obj = location;
+ if(myTracker.isGPSFix()) {
+ message.what = 1;
+ } else {
+ message.what = 2;
+ }
+ mHandler.sendMessage(message);
+ } else {
+ message = new Message();
+ message.what = 0;
+ mHandler.sendMessage(message);
+ }
+ }
+ }
+}
diff --git a/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/7015966a370d00131249f322b63acde8 b/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/7015966a370d00131249f322b63acde8
new file mode 100644
index 0000000..5254e91
--- /dev/null
+++ b/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/7015966a370d00131249f322b63acde8
@@ -0,0 +1,83 @@
+package com.macaroon.piztor;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.view.Menu;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+
+public class Login extends PiztorAct {
+
+
+ ActMgr actMgr;
+ Button btnLogin;
+ EditText edtUser, edtPass;
+
+ int loginButtonClick = 1, retryButtonClick = 2, loginFailed = 3;
+
+ Handler hand = new Handler() {
+ @Override
+ public void handleMessage(Message m) {
+ if (m.what == 0) {
+ ResLogin res = (ResLogin) m.obj;
+ UserInfo.token = res.t;
+ actMgr.trigger(AppMgr.loginSuccess);
+ } else if (m.what == 101) {
+ actMgr.trigger(loginFailed);
+ }
+ }
+ };
+
+ class StartStatus extends ActStatus {
+
+ @Override
+ void enter(int e) {
+ }
+
+ @Override
+ void leave(int e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ id = "login";
+ super.onCreate(savedInstanceState);
+ btnLogin = (Button) findViewById(R.id.login_btn_login);
+ edtUser = (EditText) findViewById(R.id.user_id);
+ edtPass = (EditText) findViewById(R.id.user_pass);
+ EmptyStatus[] r = new EmptyStatus[1];
+ r[0] = new EmptyStatus();
+ actMgr = new ActMgr(this, r[0], r);
+ setContentView(R.layout.activity_login);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ btnLogin.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ //AppMgr.transam.send(new ReqLogin(u, p, time, alive))
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.login, menu);
+ return true;
+ }
+
+}
diff --git a/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/c008735d330d00131249f322b63acde8 b/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/c008735d330d00131249f322b63acde8
new file mode 100644
index 0000000..4660356
--- /dev/null
+++ b/client/.metadata/.plugins/org.eclipse.core.resources/.history/65/c008735d330d00131249f322b63acde8
@@ -0,0 +1,134 @@
+package com.macaroon.piztor;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import android.annotation.SuppressLint;
+import android.os.Handler;
+import android.os.Message;
+
+public class Transam implements Runnable {
+
+ public Timer timer;
+ public Timer mtimer;
+ public boolean running = false;
+ public boolean flag = true;
+ public int cnt = 4;
+ Res res;
+ Req req;
+ public int p; // port
+ public String i; // ip
+ Thread thread;
+ Handler core;
+ Handler recall; // recall
+ Queue<Req> reqtask; // request task
+
+ Transam(String ip, int port, Handler Recall) {
+ p = port;
+ i = ip;
+ recall = Recall;
+ reqtask = new LinkedList<Req>();
+ }
+
+ public void send(Req r) {
+ reqtask.offer(r);
+
+ }
+
+ public void run() { // start the main timer
+ // TimerTask tmain = new Timertk();
+ // mtimer = new Timer();
+ // mtimer.schedule(tmain, 100, 100); //check the queue for every 100
+ // msec
+
+ while (true) {
+ if (running == false) {
+
+ if (!reqtask.isEmpty()) { // poll the head request
+ req = reqtask.poll();
+ if (req.time + req.alive < System.currentTimeMillis()) { // time
+ // out!
+ Message ret = new Message();
+ ret.obj = "Time out!";
+ ret.what = 100;
+ recall.sendMessage(ret);
+ } else { // run the request
+ final thd t = new thd();
+ flag = false;
+ thread = new Thread(t);
+ cnt = 4;
+ running = true;
+ thread.start();
+ timer = new Timer();
+ TimerTask task = new Timertk();
+ timer.schedule(task, 2000, 2000);
+ }
+ }
+ }
+ }
+ }
+
+ class tmain extends TimerTask {
+ public void run() {
+
+ }
+ };
+
+ class thd implements Runnable {
+ public void run() {
+ try {
+ SocketClient client = new SocketClient(i, p);
+ client.sendMsg(req, recall);
+ Message msg = new Message();
+ msg.what = 1;
+ handler.sendMessage(msg);
+ client.closeSocket();
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ System.out.println("UnknownHostException");
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.out.println("IOException");
+ }
+
+ }
+ }
+
+ @SuppressLint("HandlerLeak")
+ Handler handler = new Handler() {
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case 1:
+ flag = true;
+ break;
+ case 2:
+ final thd t = new thd();
+ thread = new Thread(t);
+ thread.start();
+ break;
+ }
+ super.handleMessage(msg);
+ }
+ };
+
+ class Timertk extends TimerTask {
+ public void run() {
+ if (flag == false && cnt > 0) {
+ cnt--;
+ } else if (cnt == 0) {
+ Message msg = new Message();
+ msg.obj = "connecting failed";
+ msg.what = 101;
+ recall.sendMessage(msg);
+ timer.cancel();
+ } else if (flag == true) {
+ timer.cancel();
+ running = false;
+ }
+ }
+ };
+} \ No newline at end of file