Skip to content

Commit

Permalink
Fix location setting off dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
barbeau committed Jun 24, 2015
1 parent 86c4722 commit a382ffe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.onebusaway.android.map.StopMapController;
import org.onebusaway.android.region.ObaRegionsTask;
import org.onebusaway.android.util.LocationHelper;
import org.onebusaway.android.util.LocationUtil;
import org.onebusaway.android.util.UIHelp;

import android.app.Dialog;
Expand Down Expand Up @@ -480,6 +481,11 @@ public void run() {
@Override
@SuppressWarnings("deprecation")
public void setMyLocation(boolean useDefaultZoom, boolean animateToLocation) {
if (!LocationUtil.isLocationEnabled(getActivity()) && mRunning && UIHelp.canDisplayDialog(getActivity())) {
showDialog(MapDialogFragment.NOLOCATION_DIALOG);
return;
}

Location lastLocation = Application.getLastKnownLocation(this.getActivity(), null);
if (lastLocation == null) {
Toast.makeText(getActivity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.onebusaway.android.map.StopMapController;
import org.onebusaway.android.region.ObaRegionsTask;
import org.onebusaway.android.util.LocationHelper;
import org.onebusaway.android.util.LocationUtil;
import org.onebusaway.android.util.UIHelp;

import android.app.Dialog;
Expand Down Expand Up @@ -469,6 +470,11 @@ public void run() {
@Override
@SuppressWarnings("deprecation")
public void setMyLocation(boolean useDefaultZoom, boolean animateToLocation) {
if (!LocationUtil.isLocationEnabled(getActivity()) && mRunning && UIHelp.canDisplayDialog(getActivity())) {
showDialog(MapDialogFragment.NOLOCATION_DIALOG);
return;
}

Location lastLocation = Application.getLastKnownLocation(this.getActivity(), null);
if (lastLocation == null) {
Toast.makeText(getActivity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -132,6 +134,35 @@ public static boolean fuzzyEquals(Location a, Location b) {
return a.distanceTo(b) <= FUZZY_EQUALS_THRESHOLD;
}

/**
* Returns true if the user has enabled location services on their device, false if they have
* not
*
* from http://stackoverflow.com/a/22980843/937715
*
* @return true if the user has enabled location services on their device, false if they have
* not
*/
public static boolean isLocationEnabled(Context context) {
int locationMode = Settings.Secure.LOCATION_MODE_OFF;
String locationProviders;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
locationMode = Settings.Secure
.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
} else {
locationProviders = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}
}

/**
* Returns the human-readable details of a Location (provider, lat/long, accuracy, timestamp)
*
Expand Down

0 comments on commit a382ffe

Please sign in to comment.