From d3684b3bfd46c3a36e994d12193ebab1d2913c93 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Thu, 29 Aug 2013 10:23:02 +0800 Subject: fix #6 --- client/Piztor/src/com/macaroon/piztor/Main.java | 45 ++++++++++++++++++++++ .../Piztor/src/com/macaroon/piztor/MapMaker.java | 15 ++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'client/Piztor/src') diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java index 03e7ebc..63d4cd5 100644 --- a/client/Piztor/src/com/macaroon/piztor/Main.java +++ b/client/Piztor/src/com/macaroon/piztor/Main.java @@ -4,13 +4,20 @@ import java.util.Timer; import java.util.TimerTask; import android.annotation.SuppressLint; +import android.app.AlertDialog; +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.ImageButton; import android.widget.TextView; import android.widget.Toast; @@ -52,6 +59,8 @@ public class Main extends PiztorAct { /** * Locating component */ + LocationManager locationManager; + boolean isGPSEnabled; LocationClient mLocClient; LocationData locData = null; public MyLocationListener myListener = new MyLocationListener(); @@ -285,10 +294,45 @@ public class Main extends PiztorAct { } } + 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(); + } + + 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"; super.onCreate(savedInstanceState); + + locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE); + isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER); + if (isGPSEnabled == false) showSettingsAlert(); + mapInfo = AppMgr.mapInfo; ActStatus[] r = new ActStatus[3]; ActStatus startStatus = r[0] = new StartStatus(); @@ -358,6 +402,7 @@ public class Main extends PiztorAct { @Override protected void onResume() { + isFirstLocation = true; mapMaker.onResume(); flushMap(); super.onResume(); diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java index 4e30df6..9b422fc 100644 --- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java @@ -8,6 +8,7 @@ import android.util.Log; import android.util.AttributeSet; import android.annotation.SuppressLint; import android.location.Location; +import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -20,7 +21,10 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; @@ -29,6 +33,7 @@ import android.widget.Toast; import android.view.View.OnClickListener; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; +import android.provider.Settings; import com.baidu.location.BDLocation; import com.baidu.location.BDLocationListener; @@ -72,9 +77,7 @@ public class MapMaker extends Activity { private MyOverlay markerOverlay; private OverlayItem nowMarker = null; - // - private Context context; - + // map touch listener private MKMapTouchListener mapTouchListener; // Popup component @@ -83,6 +86,11 @@ public class MapMaker extends Activity { private View viewCache = null; private View popupInfo = null; + //misc + private Context context; + private LocationManager locationManager = null; + boolean isGPSEnabled; + /** * Constructor */ @@ -234,6 +242,7 @@ public class MapMaker extends Activity { InitPopup(); InitTouchListenr(); } + /** * Update location layer when new location is received */ -- cgit v1.2.3-70-g09d2 From 6de595800a491a7bea84bc1ae3623baba2d3f933 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Thu, 29 Aug 2013 12:13:09 +0800 Subject: added AlterMaker and marker with time picker --- .../Piztor/src/com/macaroon/piztor/AlertMaker.java | 111 +++++++++++++++++++++ client/Piztor/src/com/macaroon/piztor/Main.java | 97 ++++++++++-------- .../Piztor/src/com/macaroon/piztor/MapMaker.java | 37 +------ 3 files changed, 170 insertions(+), 75 deletions(-) create mode 100644 client/Piztor/src/com/macaroon/piztor/AlertMaker.java (limited to 'client/Piztor/src') 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); } /** -- cgit v1.2.3-70-g09d2 From 757f12574ee1e10a59af5ab25b0dce2ba4bdc1dc Mon Sep 17 00:00:00 2001 From: sjtufs Date: Thu, 29 Aug 2013 12:34:34 +0800 Subject: fixed a bug --- client/Piztor/src/com/macaroon/piztor/AlertMaker.java | 4 ++-- client/Piztor/src/com/macaroon/piztor/Main.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'client/Piztor/src') diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java index 3233beb..cc70e62 100644 --- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java +++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java @@ -70,7 +70,7 @@ public class AlertMaker { context.startActivity(intent); } }); - gpsDialog.setNegativeButton("Cancel", + gpsDialog.setNegativeButton("Go without GPS", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); @@ -91,7 +91,7 @@ public class AlertMaker { @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)) + if ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute >= calendar.get(Calendar.MINUTE)) || hourOfDay > calendar.get(Calendar.HOUR_OF_DAY)) mapMaker.DrawMarker(markerPoint); else { diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java index 09aa02f..cfa77c5 100644 --- a/client/Piztor/src/com/macaroon/piztor/Main.java +++ b/client/Piztor/src/com/macaroon/piztor/Main.java @@ -332,7 +332,6 @@ public class Main extends PiztorAct { locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE); isGPSEnabled = locationManager.isProviderEnabled(locationManager.GPS_PROVIDER); - if (isGPSEnabled == false) alertMaker.showSettingsAlert(); mapInfo = AppMgr.mapInfo; ActStatus[] r = new ActStatus[3]; @@ -356,6 +355,7 @@ public class Main extends PiztorAct { mMapView = (MapView) findViewById(R.id.bmapView); mapMaker = new MapMaker(mMapView, getApplicationContext()); alertMaker = new AlertMaker(Main.this, mapMaker); + if (isGPSEnabled == false) alertMaker.showSettingsAlert(); mapMaker.clearOverlay(mMapView); mapMaker.InitMap(); InitTouchListenr(); -- cgit v1.2.3-70-g09d2