diff options
author | Myth Yang <[email protected]> | 2013-08-23 20:17:23 +0800 |
---|---|---|
committer | Myth Yang <[email protected]> | 2013-08-23 20:17:23 +0800 |
commit | 589d2b52b1135e876ee4c76dd2bf11c7a7cd973a (patch) | |
tree | f475e3f965dab88983c2c0ae4b3abd71081ad182 /client/activity-demo/Piztor/src/com | |
parent | a33ed0eabe94748b7ff6604af58dd25a0024bf04 (diff) |
idiot
Diffstat (limited to 'client/activity-demo/Piztor/src/com')
10 files changed, 172 insertions, 102 deletions
diff --git a/client/activity-demo/Piztor/src/com/example/piztor/Controller.java b/client/activity-demo/Piztor/src/com/example/piztor/Controller.java index 6e55581..d6e75d7 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/Controller.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/Controller.java @@ -1,7 +1,5 @@ package com.example.piztor; -import java.io.Serializable; -import android.content.Intent; public class Controller { String userToken; @@ -25,6 +23,7 @@ public class Controller { } void recieveLocation(double x, double y) { - run.v.drawLocation(x, y); + System.out.println(x + " xxxx " + y); + run.v.changMyLocation(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 index e592ba3..13cb868 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/GPSTracker.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/GPSTracker.java @@ -1,4 +1,5 @@ package com.example.piztor;
+
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
@@ -33,7 +34,7 @@ public class GPSTracker extends Service implements LocationListener { 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
+ private static final long MIN_TIME_BW_UPDATES = 1000 * 10; // 10 seconds
// Declaring a Location Manager
protected LocationManager locationManager;
@@ -56,7 +57,7 @@ public class GPSTracker extends Service implements LocationListener { isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
- if (!isGPSEnabled && !isNetworkEnabled) {
+ if (!isGPSEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
@@ -101,79 +102,84 @@ public class GPSTracker extends Service implements LocationListener { return location;
}
-
+
/**
- * Stop using GPS listener
- * Calling this function will stop using GPS in your app
- */
- public void stopUsingGPS(){
- if(locationManager != null){
+ * 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){
+ * */
+ public double getLatitude() {
+ if (location != null) {
latitude = location.getLatitude();
}
-
+
// return latitude
return latitude;
}
-
+
/**
* Function to get longitude
- */
- public double getLongitude(){
- if(location != null){
+ * */
+ 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(){
+ * 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();
+
+ // 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
@@ -196,4 +202,5 @@ public class GPSTracker extends Service implements LocationListener { 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 index e7712c4..de5cded 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/Login.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/Login.java @@ -2,13 +2,15 @@ package com.example.piztor; public class Login { MainActivity main; + int tk; Login(MainActivity main) { this.main = main; } void success(int token) { - main.start(); + //main.start(); + tk = token; System.out.println("token!"); } diff --git a/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java b/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java index 333bfd4..bf8d755 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java @@ -16,6 +16,8 @@ public class MainActivity extends Activity { Button b; EditText username, password, ip, port; Login login; + Controller c; + boolean flag = false; public final static String SER_KEY = "CONTROL"; @Override @@ -23,17 +25,12 @@ public class MainActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); login = new Login(this); + c = new Controller(); 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"); + if(flag==false){ Vector<Object> r = new Vector<Object>(); 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<Object> r = new Vector<Object>(); + 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<PointF> v; + + + Point myLocation; + Vector<Point> 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<Point>(); + Location.add(myLocation); } public MyView(Context context) { super(context); -// v = new Vector<PointF>(); + // v = new Vector<PointF>(); 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<PointF>(); + // v = new Vector<PointF>(); 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(); } } |