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(-) 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