summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsjtufs <[email protected]>2013-08-29 12:13:09 +0800
committersjtufs <[email protected]>2013-08-29 12:13:09 +0800
commit6de595800a491a7bea84bc1ae3623baba2d3f933 (patch)
treeb4f1dd26aa32f4ffb3bf3085ca58bc359b4d8b94
parentea27433e20f447cd03ebcd6732b8dc31a23d7b2b (diff)
added AlterMaker and marker with time picker
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AlertMaker.java111
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java97
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java37
3 files changed, 170 insertions, 75 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
new file mode 100644
index 0000000..3233beb
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
@@ -0,0 +1,111 @@
+package com.macaroon.piztor;
+
+import java.util.Calendar;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import android.annotation.SuppressLint;
+import android.app.AlertDialog;
+import android.app.TimePickerDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.provider.Settings;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.TextView;
+import android.widget.TimePicker;
+import android.widget.Toast;
+
+import com.baidu.location.BDLocation;
+import com.baidu.location.BDLocationListener;
+import com.baidu.location.LocationClient;
+import com.baidu.location.LocationClientOption;
+import com.baidu.mapapi.map.LocationData;
+import com.baidu.mapapi.map.MKMapTouchListener;
+import com.baidu.mapapi.map.MapView;
+import com.baidu.mapapi.map.OverlayItem;
+import com.baidu.mapapi.map.PopupOverlay;
+import com.baidu.platform.comapi.basestruct.GeoPoint;
+
+public class AlertMaker {
+
+ private Calendar calendar;
+ private Context context;
+ private GeoPoint markerPoint;
+ private MapMaker mapMaker;
+
+ public AlertMaker(Context cc, MapMaker mm) {
+ context =cc;
+ mapMaker = mm;
+ }
+
+ public static void closeBoard(Context cc) {
+ InputMethodManager imm = (InputMethodManager) cc
+ .getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm.isActive())
+ imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
+ InputMethodManager.HIDE_NOT_ALWAYS);
+ }
+
+ public void showSettingsAlert() {
+
+ closeBoard(context);
+ AlertDialog.Builder gpsDialog = new AlertDialog.Builder(context);
+ gpsDialog.setTitle("GPS settings");
+ gpsDialog.setMessage("GPS is not enabled. Please turn it on.");
+ gpsDialog.setPositiveButton("Settings",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+ context.startActivity(intent);
+ }
+ });
+ gpsDialog.setNegativeButton("Cancel",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
+ gpsDialog.show();
+ }
+
+ public void showMarkerAlert(GeoPoint point) {
+
+ closeBoard(context);
+ if (point == null) return;
+ markerPoint = point;
+ calendar = Calendar.getInstance();
+ TimePickerDialog markerDialog = new TimePickerDialog(context
+ , new TimePickerDialog.OnTimeSetListener() {
+
+ @Override
+ public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
+ ////// at least 2 minutes
+ if ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute-2 >= calendar.get(Calendar.MINUTE))
+ || hourOfDay > calendar.get(Calendar.HOUR_OF_DAY))
+ mapMaker.DrawMarker(markerPoint);
+ else {
+ Toast toast = Toast.makeText(context,
+ "Too early! Give me at least 2 minutes!", Toast.LENGTH_LONG);
+ toast.show();
+ closeBoard(context);
+ showMarkerAlert(markerPoint);
+ }
+ }
+ }
+ , calendar.get(Calendar.HOUR_OF_DAY)
+ , calendar.get(Calendar.MINUTE), false);
+ markerDialog.show();
+ }
+
+}
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java
index 63d4cd5..09aa02f 100644
--- a/client/Piztor/src/com/macaroon/piztor/Main.java
+++ b/client/Piztor/src/com/macaroon/piztor/Main.java
@@ -1,10 +1,12 @@
package com.macaroon.piztor;
+import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
+import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -18,8 +20,10 @@ import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
+import android.widget.TimePicker;
import android.widget.Toast;
import com.baidu.location.BDLocation;
@@ -27,32 +31,29 @@ import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.LocationData;
+import com.baidu.mapapi.map.MKMapTouchListener;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.mapapi.map.PopupOverlay;
+import com.baidu.platform.comapi.basestruct.GeoPoint;
public class Main extends PiztorAct {
+
final static int SearchButtonPress = 1;
final static int FocuseButtonPress = 3;
final static int SuccessFetch = 4;
final static int FailedFetch = 5;
final static int Fetch = 6;
final static int mapViewtouched = 7;
-
- /**
- * popups
- */
- private PopupOverlay pop = null;
- private TextView popupText = null;
- private View viewCache = null;
- private View popupInfo = null;
- private View popupLeft = null;
- private View popupRight = null;
- private MapView.LayoutParams layoutParam = null;
- private OverlayItem mCurItem = null;
-
+
MapMaker mapMaker = null;
MapView mMapView;
+ AlertMaker alertMaker;
+ private Calendar calendar;
+ GeoPoint markerPoint = null;
+
+ // map touch listener
+ private MKMapTouchListener mapTouchListener;
boolean isFirstLocation = true;
@@ -293,37 +294,37 @@ public class Main extends PiztorAct {
actMgr.trigger(Main.Fetch);
}
}
+
+ public void InitTouchListenr() {
- public void showSettingsAlert() {
-
- closeBoard(Main.this);
- AlertDialog.Builder gpsDialog = new AlertDialog.Builder(this);
- gpsDialog.setTitle("GPS settings");
- gpsDialog.setMessage("GPS is not enabled. Please turn it on.");
- gpsDialog.setPositiveButton("Settings",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
- Main.this.startActivity(intent);
- }
- });
- gpsDialog.setNegativeButton("Cancel",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- gpsDialog.show();
+ mapTouchListener = new MKMapTouchListener() {
+
+ @Override
+ public void onMapLongClick(GeoPoint arg0) {
+ closeBoard(Main.this);
+ alertMaker.showMarkerAlert(arg0);
+ /*
+ if (mapMaker != null)
+ mapMaker.DrawMarker(arg0);
+ Log.d("marker", "draw a new marker");
+ */
+ }
+
+ @Override
+ public void onMapDoubleClick(GeoPoint arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onMapClick(GeoPoint arg0) {
+ // TODO Auto-generated method stub
+
+ }
+ };
+ mMapView.regMapTouchListner(mapTouchListener);
}
- public static void closeBoard(Context mcontext) {
- InputMethodManager imm = (InputMethodManager) mcontext
- .getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm.isActive())
- imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
- InputMethodManager.HIDE_NOT_ALWAYS);
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
id = "Main";
@@ -331,7 +332,7 @@ public class Main extends PiztorAct {
locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER);
- if (isGPSEnabled == false) showSettingsAlert();
+ if (isGPSEnabled == false) alertMaker.showSettingsAlert();
mapInfo = AppMgr.mapInfo;
ActStatus[] r = new ActStatus[3];
@@ -354,8 +355,10 @@ public class Main extends PiztorAct {
setContentView(R.layout.activity_main);
mMapView = (MapView) findViewById(R.id.bmapView);
mapMaker = new MapMaker(mMapView, getApplicationContext());
+ alertMaker = new AlertMaker(Main.this, mapMaker);
mapMaker.clearOverlay(mMapView);
mapMaker.InitMap();
+ InitTouchListenr();
mLocClient = new LocationClient(this);
locData = new LocationData();
mLocClient.registerLocationListener(myListener);
@@ -367,6 +370,14 @@ public class Main extends PiztorAct {
mLocClient.start();
mapMaker.UpdateLocationOverlay(locData, false);
}
+
+ public static void closeBoard(Context cc) {
+ InputMethodManager imm = (InputMethodManager) cc
+ .getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm.isActive())
+ imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
+ InputMethodManager.HIDE_NOT_ALWAYS);
+ }
/*
* public boolean onTap(int index) { OverlayItem item = getItem(index);
@@ -457,4 +468,4 @@ public class Main extends PiztorAct {
mMapView.onRestoreInstanceState(savedInstanceState);
}
-} \ No newline at end of file
+}
diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
index 9b422fc..d11fe5c 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
@@ -77,9 +77,6 @@ public class MapMaker extends Activity {
private MyOverlay markerOverlay;
private OverlayItem nowMarker = null;
- // map touch listener
- private MKMapTouchListener mapTouchListener;
-
// Popup component
private PopupOverlay popLay = null;
private TextView popupText = null;
@@ -207,30 +204,7 @@ public class MapMaker extends Activity {
/**
* Initialize touch listener
*/
- public void InitTouchListenr() {
-
- mapTouchListener = new MKMapTouchListener() {
-
- @Override
- public void onMapLongClick(GeoPoint arg0) {
- DrawMarker(arg0);
- Log.d("marker", "draw a new marker");
- }
-
- @Override
- public void onMapDoubleClick(GeoPoint arg0) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onMapClick(GeoPoint arg0) {
- // TODO Auto-generated method stub
-
- }
- };
- mMapView.regMapTouchListner(mapTouchListener);
- }
+ // moved to main
/**
* Initialize map
@@ -240,7 +214,7 @@ public class MapMaker extends Activity {
InitLocationOverlay();
InitMyOverLay();
InitPopup();
- InitTouchListenr();
+ //InitTouchListenr();
}
/**
@@ -320,11 +294,10 @@ public class MapMaker extends Activity {
public void DrawMarker(GeoPoint markerPoint) {
nowMarker = new OverlayItem(markerPoint, "THIS IS A MARKER", "");
- nowMarker.setMarker(context.getResources().getDrawable(R.drawable.marker1));
- Log.d("marker", "new marker created");
- System.out.println("mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm " + markerPoint.getLatitudeE6() + " " + markerPoint.getLongitudeE6());
-
+ nowMarker.setMarker(context.getResources().getDrawable(R.drawable.marker_red));
+ Log.d("marker", "new marker created");
UpdateMap(preMapInfo);
+ mMapController.animateTo(markerPoint);
}
/**