From a33ed0eabe94748b7ff6604af58dd25a0024bf04 Mon Sep 17 00:00:00 2001 From: goblin911 Date: Fri, 23 Aug 2013 16:00:07 +0800 Subject: asdf --- .../Piztor/src/com/example/piztor/Controller.java | 30 ++++ .../Piztor/src/com/example/piztor/GPSTracker.java | 199 +++++++++++++++++++++ .../Piztor/src/com/example/piztor/Login.java | 18 ++ .../src/com/example/piztor/MainActivity.java | 104 +++++++++++ .../Piztor/src/com/example/piztor/MyView.java | 75 ++++++++ .../Piztor/src/com/example/piztor/Myrequest.java | 10 ++ .../Piztor/src/com/example/piztor/Myrespond.java | 12 ++ .../Piztor/src/com/example/piztor/Running.java | 42 +++++ .../src/com/example/piztor/SocketClient.java | 114 ++++++++++++ .../Piztor/src/com/example/piztor/Tracker.java | 34 ++++ .../Piztor/src/com/example/piztor/Transam.java | 124 +++++++++++++ 11 files changed, 762 insertions(+) create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Controller.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/GPSTracker.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Login.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/MyView.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Myrequest.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Myrespond.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Running.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Tracker.java create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Transam.java (limited to 'client/activity-demo/Piztor/src/com') diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Controller.java b/client/activity-demo/Piztor/src/com/example/piztor/Controller.java new file mode 100644 index 0000000..6e55581 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Controller.java @@ -0,0 +1,30 @@ +package com.example.piztor; + +import java.io.Serializable; +import android.content.Intent; + +public class Controller { + String userToken; + Running run; + + Controller() { + run = null; + userToken = null; + } + + void setRun(Running run) { + this.run = run; + } + + void recieveInfo(Myrespond r) { + if (r.wrong != null) { + System.out.println(r.wrong); + } else { + System.out.println("yeal!"); + } + } + + void recieveLocation(double x, double y) { + run.v.drawLocation(x, y); + } +} diff --git a/client/activity-demo/Piztor/src/com/example/piztor/GPSTracker.java b/client/activity-demo/Piztor/src/com/example/piztor/GPSTracker.java new file mode 100644 index 0000000..e592ba3 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/GPSTracker.java @@ -0,0 +1,199 @@ +package com.example.piztor; +import android.app.AlertDialog; +import android.app.Service; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.os.IBinder; +import android.provider.Settings; +import android.util.Log; + +public class GPSTracker extends Service implements LocationListener { + + private final Context mContext; + + // flag for GPS status + boolean isGPSEnabled = false; + + // flag for network status + boolean isNetworkEnabled = false; + + // flag for GPS status + boolean canGetLocation = false; + + Location location; // location + double latitude; // latitude + double longitude; // longitude + + // The minimum distance to change Updates in meters + private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters + + // The minimum time between updates in milliseconds + private static final long MIN_TIME_BW_UPDATES = 10 * 60 * 1; // 1 minute + + // Declaring a Location Manager + protected LocationManager locationManager; + + public GPSTracker(Context context) { + this.mContext = context; + getLocation(); + } + + public Location getLocation() { + try { + locationManager = (LocationManager) mContext + .getSystemService(LOCATION_SERVICE); + + // getting GPS status + isGPSEnabled = locationManager + .isProviderEnabled(LocationManager.GPS_PROVIDER); + + // getting network status + isNetworkEnabled = locationManager + .isProviderEnabled(LocationManager.NETWORK_PROVIDER); + + if (!isGPSEnabled && !isNetworkEnabled) { + // no network provider is enabled + } else { + this.canGetLocation = true; + if (isNetworkEnabled) { + locationManager.requestLocationUpdates( + LocationManager.NETWORK_PROVIDER, + MIN_TIME_BW_UPDATES, + MIN_DISTANCE_CHANGE_FOR_UPDATES, this); + Log.d("Network", "Network"); + if (locationManager != null) { + location = locationManager + .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + if (location != null) { + latitude = location.getLatitude(); + longitude = location.getLongitude(); + } + } + } + // if GPS Enabled get lat/long using GPS Services + if (isGPSEnabled) { + if (location == null) { + locationManager.requestLocationUpdates( + LocationManager.GPS_PROVIDER, + MIN_TIME_BW_UPDATES, + MIN_DISTANCE_CHANGE_FOR_UPDATES, this); + Log.d("GPS Enabled", "GPS Enabled"); + if (locationManager != null) { + location = locationManager + .getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (location != null) { + latitude = location.getLatitude(); + longitude = location.getLongitude(); + } + } + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return location; + } + + /** + * Stop using GPS listener + * Calling this function will stop using GPS in your app + */ + public void stopUsingGPS(){ + if(locationManager != null){ + locationManager.removeUpdates(GPSTracker.this); + } + } + + /** + * Function to get latitude + */ + public double getLatitude(){ + if(location != null){ + latitude = location.getLatitude(); + } + + // return latitude + return latitude; + } + + /** + * Function to get longitude + */ + public double getLongitude(){ + if(location != null){ + longitude = location.getLongitude(); + } + + // return longitude + return longitude; + } + + /** + * Function to check GPS/wifi enabled + * @return boolean + */ + public boolean canGetLocation() { + return this.canGetLocation; + } + + /** + * Function to show settings alert dialog + * On pressing Settings button will lauch Settings Options + */ + public void showSettingsAlert(){ + AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext); + + // Setting Dialog Title + alertDialog.setTitle("GPS is settings"); + + // Setting Dialog Message + alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?"); + + // On pressing Settings button + alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog,int which) { + Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); + mContext.startActivity(intent); + } + }); + + // on pressing cancel button + alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + + // Showing Alert Message + alertDialog.show(); + } + + @Override + public void onLocationChanged(Location location) { + } + + @Override + public void onProviderDisabled(String provider) { + } + + @Override + public void onProviderEnabled(String provider) { + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + } + + @Override + public IBinder onBind(Intent arg0) { + return null; + } +} diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Login.java b/client/activity-demo/Piztor/src/com/example/piztor/Login.java new file mode 100644 index 0000000..e7712c4 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Login.java @@ -0,0 +1,18 @@ +package com.example.piztor; + +public class Login { + MainActivity main; + + Login(MainActivity main) { + this.main = main; + } + + void success(int token) { + main.start(); + System.out.println("token!"); + } + + void failed() { + System.out.println("fuck!!"); + } +} diff --git a/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java b/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java new file mode 100644 index 0000000..333bfd4 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java @@ -0,0 +1,104 @@ +package com.example.piztor; + +import java.io.PrintStream; +import java.util.Vector; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.Menu; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +public class MainActivity extends Activity { + PrintStream cout = System.out; + Button b; + EditText username, password, ip, port; + Login login; + public final static String SER_KEY = "CONTROL"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + login = new Login(this); + b = (Button) findViewById(R.id.login); + b.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + cout.println(username.getText().toString()); + cout.println(password.getText().toString()); + cout.println(ip.getText().toString()); + cout.println(port.getText().toString()); + ip.setText("192.168.1.102"); + port.setText("9990"); + username.setText("hello"); + password.setText("world"); + Vector r = new Vector(); + r.add(0); + r.add(username.getText().toString()); + r.add(password.getText().toString()); + Transam t = new Transam(ip.getText().toString(), Integer + .parseInt(port.getText().toString()), new Myrequest(r), + login); + new Thread(t).run(); + } + }); + username = (EditText) findViewById(R.id.username); + password = (EditText) findViewById(R.id.password); + ip = (EditText) findViewById(R.id.ip); + port = (EditText) findViewById(R.id.port); + cout.println("onCreate!"); + } + + void start() { + Intent i = new Intent(); + i.setClass(MainActivity.this, Running.class); + startActivity(i); + } + + @Override + protected void onStart() { + super.onStart(); + cout.println("onStart!"); + } + + @Override + protected void onRestart() { + super.onRestart(); + cout.println("onRestart!"); + } + + @Override + protected void onResume() { + super.onResume(); + // cout.println("onResume!"); + // v.drawString("!!!!!"); + } + + @Override + protected void onPause() { + super.onPause(); + cout.println("onPause!"); + } + + @Override + protected void onStop() { + super.onStop(); + cout.println("onStop!"); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + cout.println("onDestroy!"); + } + + @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; + } + +} diff --git a/client/activity-demo/Piztor/src/com/example/piztor/MyView.java b/client/activity-demo/Piztor/src/com/example/piztor/MyView.java new file mode 100644 index 0000000..1627e4c --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/MyView.java @@ -0,0 +1,75 @@ +package com.example.piztor; + +import java.io.*; +import android.content.*; +import android.graphics.*; +import android.graphics.Paint.Style; +import android.util.*; +import android.view.*; + +public class MyView extends View { + static PrintStream cout = System.out; + private Paint mPaint; + public Canvas c = null; + public Bitmap b = null; + public double scale = 100; + public double centerX, centerY; +// Vector v; + + void setup(Canvas c, Bitmap b, double x, double y) { + this.c = c; + this.b = b; + centerX = x; + centerY = y; + } + + public MyView(Context context) { + super(context); +// v = new Vector(); + mPaint = new Paint(); + mPaint.setColor(Color.RED); + mPaint.setStyle(Style.FILL); + } + + public MyView(Context context, AttributeSet attr) { + super(context, attr); +// v = new Vector(); + mPaint = new Paint(); + mPaint.setColor(Color.RED); + mPaint.setStyle(Style.FILL); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + canvas.drawBitmap(b, 0, 0, mPaint); + // canvas.restore(); + } + + @Override + public boolean onTouchEvent(MotionEvent e) { +// v.add(new PointF(e.getX(), e.getY())); + c.drawRect(e.getX() - 1, e.getY() + 1, e.getX() + 1, e.getY() - 1, + mPaint); + invalidate(); + return true; + } + + void drawLocation(double x, double y) { + if (centerX < 0) { + centerX = x; + centerY = y; + } + int x1 = (int)(getWidth() / 2 + (x - centerX) * scale); + int y1 = (int)(getHeight() / 2 + (y - centerY) * scale); + c.drawRect(x1 - 1, y1 + 1, x1 + 1, y1 - 1, mPaint); + invalidate(); + } + + void drawString(String s) { + mPaint.setTextSize(15); + c.drawText(s, 0, getHeight() / 2, mPaint); + invalidate(); + } + +} \ No newline at end of file diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Myrequest.java b/client/activity-demo/Piztor/src/com/example/piztor/Myrequest.java new file mode 100644 index 0000000..9397e0c --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Myrequest.java @@ -0,0 +1,10 @@ +package com.example.piztor; + +import java.util.Vector; + +public class Myrequest{ + public Vector contain; + Myrequest(Vector info){ + contain = info; + } +} \ No newline at end of file diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Myrespond.java b/client/activity-demo/Piztor/src/com/example/piztor/Myrespond.java new file mode 100644 index 0000000..2398f2b --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Myrespond.java @@ -0,0 +1,12 @@ +package com.example.piztor; + +import java.util.Vector; + +public class Myrespond{ + public Vector contain; + public String wrong; + Myrespond(){ + wrong = null; + contain = new Vector(); + } +} \ No newline at end of file diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Running.java b/client/activity-demo/Piztor/src/com/example/piztor/Running.java new file mode 100644 index 0000000..4ea1526 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Running.java @@ -0,0 +1,42 @@ +package com.example.piztor; + +import java.io.PrintStream; + +import android.os.Bundle; +import android.app.Activity; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.view.Menu; + +public class Running extends Activity { + PrintStream cout = System.out; + MyView v; + Bitmap b; + Canvas c; + Controller controller; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + b = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888); + c = new Canvas(b); + controller = new Controller(); + controller.setRun(this); + setContentView(R.layout.activity_running); + cout.println("running is created!!!"); + } + + @Override + protected void onStart() { + super.onStart(); + v = (MyView) findViewById(R.id.view); + v.setup(c, b, 31, 121); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.running, menu); + return true; + } + +} diff --git a/client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java b/client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java new file mode 100644 index 0000000..e66b5bc --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java @@ -0,0 +1,114 @@ +package com.example.piztor; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.net.Socket; +import java.net.UnknownHostException; + +public class SocketClient { + static PrintStream cout = System.out; + static Socket client; + + public SocketClient(String site, int port) throws UnknownHostException, + IOException { + try { + cout.println(site + " " + port); + client = new Socket(site, port); + cout.println("connected successfully!!!"); + } catch (UnknownHostException e) { + cout.println("unknownhostexception!!"); + throw e; + } catch (IOException e) { + cout.println("IOException!!"); + throw e; + } + } + + public Myrespond sendMsg(Myrequest req) throws IOException { + try { + DataOutputStream out = new DataOutputStream( + client.getOutputStream()); + int tmp = (Integer) req.contain.get(0); + out.writeByte(tmp); + switch (tmp) { + case 0: + String id = (String) req.contain.get(1); + String pass = (String) req.contain.get(2); + out.writeUTF(id); + out.writeUTF(pass); + break; + case 1: + int tk1 = (Integer) req.contain.get(1); + int acc = (Integer) req.contain.get(2); + String mess = (String) req.contain.get(3); + out.writeInt(tk1); + out.writeInt(acc); + out.writeUTF(mess); + break; + case 2: + int tk2 = (Integer) req.contain.get(1); + double slot = (Double) req.contain.get(2); + double slat = (Double) req.contain.get(3); + out.writeInt(tk2); + out.writeDouble(slot); + out.writeDouble(slat); + break; + case 3: + int tk3 = (Integer) req.contain.get(1); + int gid = (Integer) req.contain.get(2); + out.writeInt(tk3); + out.writeInt(gid); + break; + } + out.flush(); + client.shutdownOutput(); + DataInputStream in = new DataInputStream(client.getInputStream()); + int type = in.readUnsignedByte(); + Myrespond r = new Myrespond(); + switch (type) { + case 0: + int id = in.readInt(); + int status = in.readUnsignedByte(); + r.contain.add(0); + r.contain.add(id); + r.contain.add(status); + break; + case 1: + r.contain.add(1); + // reserved + break; + case 2: + r.contain.add(2); + // reserved + break; + case 3: + int n = in.readInt(); + r.contain.add(3); + r.contain.add(n); + for (int i = 1; i <= n; i++) { + int tid = in.readInt(); + double lot = in.readDouble(); + double lat = in.readDouble(); + r.contain.add(tid); + r.contain.add(lot); + r.contain.add(lat); + } + break; + } + return r; + } catch (IOException e) { + throw e; + } + } + + public void closeSocket() { + try { + client.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Tracker.java b/client/activity-demo/Piztor/src/com/example/piztor/Tracker.java new file mode 100644 index 0000000..ceda506 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Tracker.java @@ -0,0 +1,34 @@ +package com.example.piztor; + +import java.util.Timer; +import java.util.TimerTask; + +public class Tracker implements Runnable { + + private static final long TIME_DELTA = 1000 * 60 * 5; + public final Context mContext; + + Controller controller; + + public Tracker(Controller newController) { + controller = newController; + } + + public Timer timer; + public void run() { + TimerTask task = new GPSTask(); + timer.schedule(new GPSTask(), 0, TIME_DELTA); + } + + class GPSTask extends TimerTask { + public void run() { + GPSTracker tracker; + tracker = new GPSTracker(Tracker.this); + + double latitude = tracker.getLatitude(); + double longitude = tracker.getLongitude(); + + controller.recieveLocation(latitude, longitude); + } + } +} diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Transam.java b/client/activity-demo/Piztor/src/com/example/piztor/Transam.java new file mode 100644 index 0000000..e39abd5 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Transam.java @@ -0,0 +1,124 @@ +package com.example.piztor; +import java.io.IOException; +import java.net.UnknownHostException; +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 boolean flag = true; + public boolean reqlog = false; + public int cnt = 4; + public int port; + public String ip; + Thread thread; + Myrequest req; + Myrespond res; + Controller core; + Login log; + + + Transam(String i,int p,Myrequest r,Login l){ + port = p; + ip = i; + req = r; + log = l; + reqlog = true; + } + + Transam(String i,int p,Myrequest r,Controller c){ + port = p; + ip = i; + req = r; + core = c; + } + + public void run() { + final thd t = new thd(); + flag = false; + thread = new Thread(t); + cnt = 4; + thread.start(); + timer = new Timer(); + TimerTask task = new Timertk(); + timer.schedule(task,2000,2000); + } + + class thd implements Runnable { + @Override + public void run() { + try{ + SocketClient client = new SocketClient(ip,port); + res = client.sendMsg(req); + if(!reqlog){ + core.recieveInfo(res); + } + else{ + if((Integer) res.contain.get(2)==0){ + int t = (Integer) res.contain.get(1); + log.success(t); + } + else{ + log.failed(); + } + } + Message msg = new Message(); + msg.what = 1; + handler.sendMessage(msg); + client.closeSocket(); + }catch (UnknownHostException e){ + }catch (IOException e){ + } + + } + } + + @SuppressLint("HandlerLeak") + Handler handler = new Handler(){ + public void handleMessage(Message msg) { + switch (msg.what) { + case 1: + flag = true; + break; + case 2: + if(!reqlog){ + res = new Myrespond(); + res.wrong = msg.obj.toString(); + core.recieveInfo(res); + } + else{ + log.failed(); + } + break; + case 3: + 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 = 2; + handler.sendMessage(msg); + timer.cancel(); + } + else if(flag==true){ + timer.cancel(); + } + } + }; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 589d2b52b1135e876ee4c76dd2bf11c7a7cd973a Mon Sep 17 00:00:00 2001 From: Myth Yang Date: Fri, 23 Aug 2013 20:17:23 +0800 Subject: idiot --- client/activity-demo/Piztor.rar | Bin 0 -> 7055093 bytes client/activity-demo/Piztor/.classpath | 4 +- client/activity-demo/Piztor/AndroidManifest.xml | 6 + .../activity-demo/Piztor/bin/AndroidManifest.xml | 6 + client/activity-demo/Piztor/bin/Piztor.apk | Bin 3695642 -> 3698259 bytes client/activity-demo/Piztor/bin/classes.dex | Bin 636728 -> 642964 bytes .../classes/com/example/piztor/Controller.class | Bin 1221 -> 1527 bytes .../classes/com/example/piztor/GPSTracker$1.class | Bin 1176 -> 1184 bytes .../classes/com/example/piztor/GPSTracker$2.class | Bin 854 -> 854 bytes .../classes/com/example/piztor/GPSTracker.class | Bin 4458 -> 4470 bytes .../bin/classes/com/example/piztor/Login.class | Bin 808 -> 774 bytes .../com/example/piztor/MainActivity$1.class | Bin 2226 -> 2432 bytes .../classes/com/example/piztor/MainActivity.class | Bin 2898 -> 3200 bytes .../bin/classes/com/example/piztor/MyView.class | Bin 2787 -> 3669 bytes .../bin/classes/com/example/piztor/Rmsg.class | Bin 0 -> 438 bytes .../bin/classes/com/example/piztor/Running.class | Bin 2017 -> 2264 bytes .../classes/com/example/piztor/SocketClient.class | Bin 3962 -> 4046 bytes .../com/example/piztor/Tracker$GPSTask.class | Bin 749 -> 1292 bytes .../bin/classes/com/example/piztor/Tracker.class | Bin 935 -> 1099 bytes .../bin/classes/com/example/piztor/Transam$1.class | Bin 1655 -> 1655 bytes .../com/example/piztor/Transam$Timertk.class | Bin 1102 -> 1102 bytes .../classes/com/example/piztor/Transam$thd.class | Bin 1996 -> 2127 bytes .../bin/classes/com/example/piztor/Transam.class | Bin 2082 -> 2082 bytes ...support-v4-47342e257aecfcb7fb303475c203fee3.jar | Bin 0 -> 211326 bytes client/activity-demo/Piztor/bin/resources.ap_ | Bin 3475139 -> 3475320 bytes .../Piztor/src/com/example/piztor/Controller.java | 5 +- .../Piztor/src/com/example/piztor/GPSTracker.java | 107 +++++++++--------- .../Piztor/src/com/example/piztor/Login.java | 4 +- .../src/com/example/piztor/MainActivity.java | 32 ++++-- .../Piztor/src/com/example/piztor/MyView.java | 60 +++++++--- .../Piztor/src/com/example/piztor/Rmsg.java | 12 ++ .../Piztor/src/com/example/piztor/Running.java | 4 +- .../src/com/example/piztor/SocketClient.java | 13 +-- .../Piztor/src/com/example/piztor/Tracker.java | 35 +++--- .../Piztor/src/com/example/piztor/Transam.java | 2 + .../src/com/example/piztor/Controller.java | 30 ----- .../src/com/example/piztor/Login.java | 18 --- .../src/com/example/piztor/MainActivity.java | 104 ----------------- .../src/com/example/piztor/MyView.java | 75 ------------- .../src/com/example/piztor/Myrequest.java | 10 -- .../src/com/example/piztor/Myrespond.java | 12 -- .../src/com/example/piztor/Running.java | 42 ------- .../src/com/example/piztor/SocketClient.java | 114 ------------------- .../src/com/example/piztor/Transam.java | 124 --------------------- 44 files changed, 186 insertions(+), 633 deletions(-) create mode 100644 client/activity-demo/Piztor.rar create mode 100644 client/activity-demo/Piztor/bin/classes/com/example/piztor/Rmsg.class create mode 100644 client/activity-demo/Piztor/bin/dexedLibs/android-support-v4-47342e257aecfcb7fb303475c203fee3.jar create mode 100644 client/activity-demo/Piztor/src/com/example/piztor/Rmsg.java delete mode 100644 client/activity-demo/src/com/example/piztor/Controller.java delete mode 100644 client/activity-demo/src/com/example/piztor/Login.java delete mode 100644 client/activity-demo/src/com/example/piztor/MainActivity.java delete mode 100644 client/activity-demo/src/com/example/piztor/MyView.java delete mode 100644 client/activity-demo/src/com/example/piztor/Myrequest.java delete mode 100644 client/activity-demo/src/com/example/piztor/Myrespond.java delete mode 100644 client/activity-demo/src/com/example/piztor/Running.java delete mode 100644 client/activity-demo/src/com/example/piztor/SocketClient.java delete mode 100644 client/activity-demo/src/com/example/piztor/Transam.java (limited to 'client/activity-demo/Piztor/src/com') diff --git a/client/activity-demo/Piztor.rar b/client/activity-demo/Piztor.rar new file mode 100644 index 0000000..5ebf80c Binary files /dev/null and b/client/activity-demo/Piztor.rar differ diff --git a/client/activity-demo/Piztor/.classpath b/client/activity-demo/Piztor/.classpath index 7bc01d9..5176974 100644 --- a/client/activity-demo/Piztor/.classpath +++ b/client/activity-demo/Piztor/.classpath @@ -1,9 +1,9 @@ - - + + diff --git a/client/activity-demo/Piztor/AndroidManifest.xml b/client/activity-demo/Piztor/AndroidManifest.xml index 9561604..10e170f 100644 --- a/client/activity-demo/Piztor/AndroidManifest.xml +++ b/client/activity-demo/Piztor/AndroidManifest.xml @@ -3,6 +3,12 @@ package="com.example.piztor" android:versionCode="1" android:versionName="1.0" > + + + + + + + + + + + + r = new Vector(); r.add(0); r.add(username.getText().toString()); @@ -42,6 +39,21 @@ public class MainActivity extends Activity { .parseInt(port.getText().toString()), new Myrequest(r), login); new Thread(t).run(); + flag = true; + } + else{ + Vector r = new Vector(); + r.add(2); + r.add(login.tk); + double lot = 123.456; + double lat = 654.321; + r.add(lot); + r.add(lat); + Transam t = new Transam(ip.getText().toString(), Integer + .parseInt(port.getText().toString()), new Myrequest(r), + c); + new Thread(t).run(); + } } }); username = (EditText) findViewById(R.id.username); @@ -60,6 +72,10 @@ public class MainActivity extends Activity { @Override protected void onStart() { super.onStart(); + ip.setText("192.168.1.101"); + port.setText("9990"); + username.setText("hello"); + password.setText("world"); cout.println("onStart!"); } diff --git a/client/activity-demo/Piztor/src/com/example/piztor/MyView.java b/client/activity-demo/Piztor/src/com/example/piztor/MyView.java index 1627e4c..a213013 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/MyView.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/MyView.java @@ -1,39 +1,55 @@ package com.example.piztor; -import java.io.*; -import android.content.*; -import android.graphics.*; +import java.io.PrintStream; +import java.util.Vector; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; import android.graphics.Paint.Style; -import android.util.*; -import android.view.*; +import android.graphics.Point; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; public class MyView extends View { static PrintStream cout = System.out; - private Paint mPaint; + private Paint mPaint, oPaint; public Canvas c = null; public Bitmap b = null; - public double scale = 100; + public double scale = 1; public double centerX, centerY; -// Vector v; + + + Point myLocation; + Vector Location; void setup(Canvas c, Bitmap b, double x, double y) { this.c = c; this.b = b; centerX = x; centerY = y; + myLocation = new Point(10, 10); + Location = new Vector(); + Location.add(myLocation); } public MyView(Context context) { super(context); -// v = new Vector(); + // v = new Vector(); mPaint = new Paint(); mPaint.setColor(Color.RED); mPaint.setStyle(Style.FILL); + oPaint = new Paint(); + oPaint.setColor(Color.BLUE); + oPaint.setStyle(Style.FILL); } public MyView(Context context, AttributeSet attr) { super(context, attr); -// v = new Vector(); + // v = new Vector(); mPaint = new Paint(); mPaint.setColor(Color.RED); mPaint.setStyle(Style.FILL); @@ -42,34 +58,42 @@ public class MyView extends View { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - canvas.drawBitmap(b, 0, 0, mPaint); + cout.println(myLocation.x + " -- " + myLocation.y); + canvas.drawCircle(myLocation.x, myLocation.y, 5, mPaint); + //canvas.drawBitmap(b, 0, 0, mPaint); + /*for (int i = 1; i < Location.size(); i++) { + canvas.drawCircle(Location.get(i).x, Location.get(i).y, 2, oPaint); + }*/ // canvas.restore(); } @Override public boolean onTouchEvent(MotionEvent e) { -// v.add(new PointF(e.getX(), e.getY())); + // v.add(new PointF(e.getX(), e.getY())); c.drawRect(e.getX() - 1, e.getY() + 1, e.getX() + 1, e.getY() - 1, mPaint); + invalidate(); return true; } - void drawLocation(double x, double y) { + void changMyLocation(double x, double y) { if (centerX < 0) { centerX = x; centerY = y; } - int x1 = (int)(getWidth() / 2 + (x - centerX) * scale); - int y1 = (int)(getHeight() / 2 + (y - centerY) * scale); - c.drawRect(x1 - 1, y1 + 1, x1 + 1, y1 - 1, mPaint); + int x1 = (int) (getWidth() / 2 + (x - centerX) * scale); + int y1 = (int) (getHeight() / 2 + (y - centerY) * scale); + myLocation.x = x1; + myLocation.y = y1; + cout.println(x + " " + y); invalidate(); } - + void drawString(String s) { mPaint.setTextSize(15); c.drawText(s, 0, getHeight() / 2, mPaint); invalidate(); } - + } \ No newline at end of file diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Rmsg.java b/client/activity-demo/Piztor/src/com/example/piztor/Rmsg.java new file mode 100644 index 0000000..8f4f587 --- /dev/null +++ b/client/activity-demo/Piztor/src/com/example/piztor/Rmsg.java @@ -0,0 +1,12 @@ +package com.example.piztor; + +public class Rmsg{ + int id; + double lat; + double lot; + Rmsg(int i,double l,double ll){ + id = i; + lat = l; + lot = ll; + } +} \ No newline at end of file diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Running.java b/client/activity-demo/Piztor/src/com/example/piztor/Running.java index 4ea1526..f4b6135 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/Running.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/Running.java @@ -29,7 +29,9 @@ public class Running extends Activity { protected void onStart() { super.onStart(); v = (MyView) findViewById(R.id.view); - v.setup(c, b, 31, 121); + v.setup(c, b, -1, -1); + Tracker tr = new Tracker(controller, Running.this); + new Thread(tr).run(); } @Override diff --git a/client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java b/client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java index e66b5bc..472da0d 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/SocketClient.java @@ -36,8 +36,7 @@ public class SocketClient { case 0: String id = (String) req.contain.get(1); String pass = (String) req.contain.get(2); - out.writeUTF(id); - out.writeUTF(pass); + out.writeBytes(id + "\0" + pass); break; case 1: int tk1 = (Integer) req.contain.get(1); @@ -45,7 +44,7 @@ public class SocketClient { String mess = (String) req.contain.get(3); out.writeInt(tk1); out.writeInt(acc); - out.writeUTF(mess); + out.writeBytes(mess); break; case 2: int tk2 = (Integer) req.contain.get(1); @@ -74,6 +73,7 @@ public class SocketClient { r.contain.add(0); r.contain.add(id); r.contain.add(status); + System.out.println(id); break; case 1: r.contain.add(1); @@ -89,11 +89,10 @@ public class SocketClient { r.contain.add(n); for (int i = 1; i <= n; i++) { int tid = in.readInt(); - double lot = in.readDouble(); double lat = in.readDouble(); - r.contain.add(tid); - r.contain.add(lot); - r.contain.add(lat); + double lot = in.readDouble(); + Rmsg a = new Rmsg(tid,lat,lot); + r.contain.add(a); } break; } diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Tracker.java b/client/activity-demo/Piztor/src/com/example/piztor/Tracker.java index ceda506..0222325 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/Tracker.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/Tracker.java @@ -1,34 +1,41 @@ package com.example.piztor; - import java.util.Timer; import java.util.TimerTask; +import android.content.Context; + public class Tracker implements Runnable { - private static final long TIME_DELTA = 1000 * 60 * 5; - public final Context mContext; - + private static final long TIME_DELTA = 1000 * 10; // 10 seconds + public Timer timer; + private final Context mContext; Controller controller; - public Tracker(Controller newController) { + public Tracker(Controller newController, Context context) { + timer = new Timer(); + mContext = context; controller = newController; } - public Timer timer; public void run() { - TimerTask task = new GPSTask(); - timer.schedule(new GPSTask(), 0, TIME_DELTA); + GPSTask t = new GPSTask(); + t.run(); + //timer.s +// timer.schedule(new GPSTask(), 0, TIME_DELTA); } class GPSTask extends TimerTask { + @Override public void run() { GPSTracker tracker; - tracker = new GPSTracker(Tracker.this); - - double latitude = tracker.getLatitude(); - double longitude = tracker.getLongitude(); - - controller.recieveLocation(latitude, longitude); + tracker = new GPSTracker(mContext); + System.out.println("can get location?"); + if(tracker.canGetLocation()) { + double latitude = tracker.getLatitude(); + double longitude = tracker.getLongitude(); + System.out.println("yes!"); + controller.recieveLocation(latitude, longitude); + } } } } diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Transam.java b/client/activity-demo/Piztor/src/com/example/piztor/Transam.java index e39abd5..db76d06 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/Transam.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/Transam.java @@ -71,7 +71,9 @@ public class Transam implements Runnable { handler.sendMessage(msg); client.closeSocket(); }catch (UnknownHostException e){ + e.printStackTrace(); }catch (IOException e){ + e.printStackTrace(); } } diff --git a/client/activity-demo/src/com/example/piztor/Controller.java b/client/activity-demo/src/com/example/piztor/Controller.java deleted file mode 100644 index 6e55581..0000000 --- a/client/activity-demo/src/com/example/piztor/Controller.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.example.piztor; - -import java.io.Serializable; -import android.content.Intent; - -public class Controller { - String userToken; - Running run; - - Controller() { - run = null; - userToken = null; - } - - void setRun(Running run) { - this.run = run; - } - - void recieveInfo(Myrespond r) { - if (r.wrong != null) { - System.out.println(r.wrong); - } else { - System.out.println("yeal!"); - } - } - - void recieveLocation(double x, double y) { - run.v.drawLocation(x, y); - } -} diff --git a/client/activity-demo/src/com/example/piztor/Login.java b/client/activity-demo/src/com/example/piztor/Login.java deleted file mode 100644 index e7712c4..0000000 --- a/client/activity-demo/src/com/example/piztor/Login.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.example.piztor; - -public class Login { - MainActivity main; - - Login(MainActivity main) { - this.main = main; - } - - void success(int token) { - main.start(); - System.out.println("token!"); - } - - void failed() { - System.out.println("fuck!!"); - } -} diff --git a/client/activity-demo/src/com/example/piztor/MainActivity.java b/client/activity-demo/src/com/example/piztor/MainActivity.java deleted file mode 100644 index 333bfd4..0000000 --- a/client/activity-demo/src/com/example/piztor/MainActivity.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.example.piztor; - -import java.io.PrintStream; -import java.util.Vector; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.view.Menu; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; - -public class MainActivity extends Activity { - PrintStream cout = System.out; - Button b; - EditText username, password, ip, port; - Login login; - public final static String SER_KEY = "CONTROL"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - login = new Login(this); - b = (Button) findViewById(R.id.login); - b.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - cout.println(username.getText().toString()); - cout.println(password.getText().toString()); - cout.println(ip.getText().toString()); - cout.println(port.getText().toString()); - ip.setText("192.168.1.102"); - port.setText("9990"); - username.setText("hello"); - password.setText("world"); - Vector r = new Vector(); - r.add(0); - r.add(username.getText().toString()); - r.add(password.getText().toString()); - Transam t = new Transam(ip.getText().toString(), Integer - .parseInt(port.getText().toString()), new Myrequest(r), - login); - new Thread(t).run(); - } - }); - username = (EditText) findViewById(R.id.username); - password = (EditText) findViewById(R.id.password); - ip = (EditText) findViewById(R.id.ip); - port = (EditText) findViewById(R.id.port); - cout.println("onCreate!"); - } - - void start() { - Intent i = new Intent(); - i.setClass(MainActivity.this, Running.class); - startActivity(i); - } - - @Override - protected void onStart() { - super.onStart(); - cout.println("onStart!"); - } - - @Override - protected void onRestart() { - super.onRestart(); - cout.println("onRestart!"); - } - - @Override - protected void onResume() { - super.onResume(); - // cout.println("onResume!"); - // v.drawString("!!!!!"); - } - - @Override - protected void onPause() { - super.onPause(); - cout.println("onPause!"); - } - - @Override - protected void onStop() { - super.onStop(); - cout.println("onStop!"); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - cout.println("onDestroy!"); - } - - @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; - } - -} diff --git a/client/activity-demo/src/com/example/piztor/MyView.java b/client/activity-demo/src/com/example/piztor/MyView.java deleted file mode 100644 index 1627e4c..0000000 --- a/client/activity-demo/src/com/example/piztor/MyView.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.example.piztor; - -import java.io.*; -import android.content.*; -import android.graphics.*; -import android.graphics.Paint.Style; -import android.util.*; -import android.view.*; - -public class MyView extends View { - static PrintStream cout = System.out; - private Paint mPaint; - public Canvas c = null; - public Bitmap b = null; - public double scale = 100; - public double centerX, centerY; -// Vector v; - - void setup(Canvas c, Bitmap b, double x, double y) { - this.c = c; - this.b = b; - centerX = x; - centerY = y; - } - - public MyView(Context context) { - super(context); -// v = new Vector(); - mPaint = new Paint(); - mPaint.setColor(Color.RED); - mPaint.setStyle(Style.FILL); - } - - public MyView(Context context, AttributeSet attr) { - super(context, attr); -// v = new Vector(); - mPaint = new Paint(); - mPaint.setColor(Color.RED); - mPaint.setStyle(Style.FILL); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - canvas.drawBitmap(b, 0, 0, mPaint); - // canvas.restore(); - } - - @Override - public boolean onTouchEvent(MotionEvent e) { -// v.add(new PointF(e.getX(), e.getY())); - c.drawRect(e.getX() - 1, e.getY() + 1, e.getX() + 1, e.getY() - 1, - mPaint); - invalidate(); - return true; - } - - void drawLocation(double x, double y) { - if (centerX < 0) { - centerX = x; - centerY = y; - } - int x1 = (int)(getWidth() / 2 + (x - centerX) * scale); - int y1 = (int)(getHeight() / 2 + (y - centerY) * scale); - c.drawRect(x1 - 1, y1 + 1, x1 + 1, y1 - 1, mPaint); - invalidate(); - } - - void drawString(String s) { - mPaint.setTextSize(15); - c.drawText(s, 0, getHeight() / 2, mPaint); - invalidate(); - } - -} \ No newline at end of file diff --git a/client/activity-demo/src/com/example/piztor/Myrequest.java b/client/activity-demo/src/com/example/piztor/Myrequest.java deleted file mode 100644 index 9397e0c..0000000 --- a/client/activity-demo/src/com/example/piztor/Myrequest.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.example.piztor; - -import java.util.Vector; - -public class Myrequest{ - public Vector contain; - Myrequest(Vector info){ - contain = info; - } -} \ No newline at end of file diff --git a/client/activity-demo/src/com/example/piztor/Myrespond.java b/client/activity-demo/src/com/example/piztor/Myrespond.java deleted file mode 100644 index 2398f2b..0000000 --- a/client/activity-demo/src/com/example/piztor/Myrespond.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.example.piztor; - -import java.util.Vector; - -public class Myrespond{ - public Vector contain; - public String wrong; - Myrespond(){ - wrong = null; - contain = new Vector(); - } -} \ No newline at end of file diff --git a/client/activity-demo/src/com/example/piztor/Running.java b/client/activity-demo/src/com/example/piztor/Running.java deleted file mode 100644 index 4ea1526..0000000 --- a/client/activity-demo/src/com/example/piztor/Running.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.example.piztor; - -import java.io.PrintStream; - -import android.os.Bundle; -import android.app.Activity; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.view.Menu; - -public class Running extends Activity { - PrintStream cout = System.out; - MyView v; - Bitmap b; - Canvas c; - Controller controller; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - b = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888); - c = new Canvas(b); - controller = new Controller(); - controller.setRun(this); - setContentView(R.layout.activity_running); - cout.println("running is created!!!"); - } - - @Override - protected void onStart() { - super.onStart(); - v = (MyView) findViewById(R.id.view); - v.setup(c, b, 31, 121); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.running, menu); - return true; - } - -} diff --git a/client/activity-demo/src/com/example/piztor/SocketClient.java b/client/activity-demo/src/com/example/piztor/SocketClient.java deleted file mode 100644 index e66b5bc..0000000 --- a/client/activity-demo/src/com/example/piztor/SocketClient.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.example.piztor; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.net.Socket; -import java.net.UnknownHostException; - -public class SocketClient { - static PrintStream cout = System.out; - static Socket client; - - public SocketClient(String site, int port) throws UnknownHostException, - IOException { - try { - cout.println(site + " " + port); - client = new Socket(site, port); - cout.println("connected successfully!!!"); - } catch (UnknownHostException e) { - cout.println("unknownhostexception!!"); - throw e; - } catch (IOException e) { - cout.println("IOException!!"); - throw e; - } - } - - public Myrespond sendMsg(Myrequest req) throws IOException { - try { - DataOutputStream out = new DataOutputStream( - client.getOutputStream()); - int tmp = (Integer) req.contain.get(0); - out.writeByte(tmp); - switch (tmp) { - case 0: - String id = (String) req.contain.get(1); - String pass = (String) req.contain.get(2); - out.writeUTF(id); - out.writeUTF(pass); - break; - case 1: - int tk1 = (Integer) req.contain.get(1); - int acc = (Integer) req.contain.get(2); - String mess = (String) req.contain.get(3); - out.writeInt(tk1); - out.writeInt(acc); - out.writeUTF(mess); - break; - case 2: - int tk2 = (Integer) req.contain.get(1); - double slot = (Double) req.contain.get(2); - double slat = (Double) req.contain.get(3); - out.writeInt(tk2); - out.writeDouble(slot); - out.writeDouble(slat); - break; - case 3: - int tk3 = (Integer) req.contain.get(1); - int gid = (Integer) req.contain.get(2); - out.writeInt(tk3); - out.writeInt(gid); - break; - } - out.flush(); - client.shutdownOutput(); - DataInputStream in = new DataInputStream(client.getInputStream()); - int type = in.readUnsignedByte(); - Myrespond r = new Myrespond(); - switch (type) { - case 0: - int id = in.readInt(); - int status = in.readUnsignedByte(); - r.contain.add(0); - r.contain.add(id); - r.contain.add(status); - break; - case 1: - r.contain.add(1); - // reserved - break; - case 2: - r.contain.add(2); - // reserved - break; - case 3: - int n = in.readInt(); - r.contain.add(3); - r.contain.add(n); - for (int i = 1; i <= n; i++) { - int tid = in.readInt(); - double lot = in.readDouble(); - double lat = in.readDouble(); - r.contain.add(tid); - r.contain.add(lot); - r.contain.add(lat); - } - break; - } - return r; - } catch (IOException e) { - throw e; - } - } - - public void closeSocket() { - try { - client.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} diff --git a/client/activity-demo/src/com/example/piztor/Transam.java b/client/activity-demo/src/com/example/piztor/Transam.java deleted file mode 100644 index e39abd5..0000000 --- a/client/activity-demo/src/com/example/piztor/Transam.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.example.piztor; -import java.io.IOException; -import java.net.UnknownHostException; -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 boolean flag = true; - public boolean reqlog = false; - public int cnt = 4; - public int port; - public String ip; - Thread thread; - Myrequest req; - Myrespond res; - Controller core; - Login log; - - - Transam(String i,int p,Myrequest r,Login l){ - port = p; - ip = i; - req = r; - log = l; - reqlog = true; - } - - Transam(String i,int p,Myrequest r,Controller c){ - port = p; - ip = i; - req = r; - core = c; - } - - public void run() { - final thd t = new thd(); - flag = false; - thread = new Thread(t); - cnt = 4; - thread.start(); - timer = new Timer(); - TimerTask task = new Timertk(); - timer.schedule(task,2000,2000); - } - - class thd implements Runnable { - @Override - public void run() { - try{ - SocketClient client = new SocketClient(ip,port); - res = client.sendMsg(req); - if(!reqlog){ - core.recieveInfo(res); - } - else{ - if((Integer) res.contain.get(2)==0){ - int t = (Integer) res.contain.get(1); - log.success(t); - } - else{ - log.failed(); - } - } - Message msg = new Message(); - msg.what = 1; - handler.sendMessage(msg); - client.closeSocket(); - }catch (UnknownHostException e){ - }catch (IOException e){ - } - - } - } - - @SuppressLint("HandlerLeak") - Handler handler = new Handler(){ - public void handleMessage(Message msg) { - switch (msg.what) { - case 1: - flag = true; - break; - case 2: - if(!reqlog){ - res = new Myrespond(); - res.wrong = msg.obj.toString(); - core.recieveInfo(res); - } - else{ - log.failed(); - } - break; - case 3: - 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 = 2; - handler.sendMessage(msg); - timer.cancel(); - } - else if(flag==true){ - timer.cancel(); - } - } - }; -} \ No newline at end of file -- cgit v1.2.3-70-g09d2