forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -166,7 +166,6 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||||
private SearchEngine searchEngine;
|
private SearchEngine searchEngine;
|
||||||
private SearchRecentSuggestions searchRecentSuggestions;
|
private SearchRecentSuggestions searchRecentSuggestions;
|
||||||
private MyTracksLocationManager myTracksLocationManager;
|
|
||||||
private ArrayAdapter<Map<String, Object>> arrayAdapter;
|
private ArrayAdapter<Map<String, Object>> arrayAdapter;
|
||||||
|
|
||||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
||||||
@@ -388,7 +387,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
final String textQuery = intent.getStringExtra(SearchManager.QUERY);
|
final String textQuery = intent.getStringExtra(SearchManager.QUERY);
|
||||||
setTitle(textQuery);
|
setTitle(textQuery);
|
||||||
|
|
||||||
myTracksLocationManager = new MyTracksLocationManager(this, Looper.myLooper());
|
final MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
||||||
|
this, Looper.myLooper());
|
||||||
LocationListener locationListener = new LocationListener() {
|
LocationListener locationListener = new LocationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final Location location) {
|
public void onLocationChanged(final Location location) {
|
||||||
|
|||||||
+22
-22
@@ -39,16 +39,33 @@ import android.util.Log;
|
|||||||
/**
|
/**
|
||||||
* My Tracks Location Manager. Applies Google location settings before allowing
|
* My Tracks Location Manager. Applies Google location settings before allowing
|
||||||
* access to {@link LocationManager}.
|
* access to {@link LocationManager}.
|
||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public class MyTracksLocationManager {
|
public class MyTracksLocationManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observer for Google location settings.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
private class GoogleSettingsObserver extends ContentObserver {
|
||||||
|
|
||||||
|
public GoogleSettingsObserver() {
|
||||||
|
super(new Handler());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
isAllowed = isUseLocationForServicesOn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final String TAG = MyTracksLocationManager.class.getSimpleName();
|
private static final String TAG = MyTracksLocationManager.class.getSimpleName();
|
||||||
|
|
||||||
private static final String GOOGLE_SETTINGS_CONTENT_URI = "content://com.google.settings/partner";
|
private static final String GOOGLE_SETTINGS_CONTENT_URI = "content://com.google.settings/partner";
|
||||||
private static final String USE_LOCATION_FOR_SERVICES = "use_location_for_services";
|
private static final String USE_LOCATION_FOR_SERVICES = "use_location_for_services";
|
||||||
|
|
||||||
// User has agreed to use location for Google services.
|
// User has agreed to use location for Google services.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String USE_LOCATION_FOR_SERVICES_ON = "1";
|
static final String USE_LOCATION_FOR_SERVICES_ON = "1";
|
||||||
@@ -100,13 +117,13 @@ public class MyTracksLocationManager {
|
|||||||
private LocationListener requestLocationUpdates;
|
private LocationListener requestLocationUpdates;
|
||||||
private float requestLocationUpdatesDistance;
|
private float requestLocationUpdatesDistance;
|
||||||
private long requestLocationUpdatesTime;
|
private long requestLocationUpdatesTime;
|
||||||
|
|
||||||
public MyTracksLocationManager(Context context, Looper looper) {
|
public MyTracksLocationManager(Context context, Looper looper) {
|
||||||
this.looper = looper;
|
this.looper = looper;
|
||||||
handler = new Handler(looper);
|
handler = new Handler(looper);
|
||||||
locationClient = new LocationClient(context, connectionCallbacks, onConnectionFailedListener);
|
locationClient = new LocationClient(context, connectionCallbacks, onConnectionFailedListener);
|
||||||
locationClient.connect();
|
locationClient.connect();
|
||||||
|
|
||||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
contentResolver = context.getContentResolver();
|
contentResolver = context.getContentResolver();
|
||||||
observer = new GoogleSettingsObserver();
|
observer = new GoogleSettingsObserver();
|
||||||
@@ -125,23 +142,6 @@ public class MyTracksLocationManager {
|
|||||||
contentResolver.unregisterContentObserver(observer);
|
contentResolver.unregisterContentObserver(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Observer for Google location settings.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
private class GoogleSettingsObserver extends ContentObserver {
|
|
||||||
|
|
||||||
public GoogleSettingsObserver() {
|
|
||||||
super(new Handler());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChange(boolean selfChange) {
|
|
||||||
isAllowed = isUseLocationForServicesOn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if allowed to access the location manager. Returns true if
|
* Returns true if allowed to access the location manager. Returns true if
|
||||||
* there is no Google location settings or the Google location settings allows
|
* there is no Google location settings or the Google location settings allows
|
||||||
@@ -174,7 +174,7 @@ public class MyTracksLocationManager {
|
|||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!isAllowed) {
|
if (!isAllowed) {
|
||||||
requestLastLocation = null;
|
requestLastLocation = null;
|
||||||
locationListener.onLocationChanged(null);
|
locationListener.onLocationChanged(null);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user