forked from upstream-mirrors/OpenTracks
Code refactor of GoogleLocationUtils
This commit is contained in:
@@ -65,7 +65,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
@@ -496,10 +495,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
||||||
this, Looper.myLooper(), false);
|
this, Looper.myLooper(), false);
|
||||||
if (!myTracksLocationManager.isGpsProviderEnabled()) {
|
if (!myTracksLocationManager.isGpsProviderEnabled()) {
|
||||||
intent = GoogleLocationUtils.isAvailable(TrackListActivity.this) ? new Intent(
|
intent = GoogleLocationUtils.newLocationSettingsIntent(TrackListActivity.this);
|
||||||
GoogleLocationUtils.ACTION_GOOGLE_LOCATION_SETTINGS)
|
|
||||||
: new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
startGps = !TrackRecordingServiceConnectionUtils.isRecordingServiceRunning(
|
startGps = !TrackRecordingServiceConnectionUtils.isRecordingServiceRunning(
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import android.content.Intent;
|
|||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -165,12 +164,9 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
final MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
final MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
||||||
getActivity(), Looper.myLooper(), true);
|
getActivity(), Looper.myLooper(), true);
|
||||||
if (!myTracksLocationManager.isAllowed()) {
|
if (!myTracksLocationManager.isAllowed()) {
|
||||||
String setting = getString(
|
String message = getString(R.string.my_location_no_gps,
|
||||||
GoogleLocationUtils.isAvailable(getActivity()) ? R.string.gps_google_location_settings
|
GoogleLocationUtils.getLocationSettingsName(getActivity()));
|
||||||
: R.string.gps_location_access);
|
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
|
||||||
Toast.makeText(
|
|
||||||
getActivity(), getString(R.string.my_location_no_gps, setting), Toast.LENGTH_LONG)
|
|
||||||
.show();
|
|
||||||
myTracksLocationManager.close();
|
myTracksLocationManager.close();
|
||||||
} else {
|
} else {
|
||||||
myTracksLocationManager.requestLastLocation(new LocationListener() {
|
myTracksLocationManager.requestLastLocation(new LocationListener() {
|
||||||
@@ -727,10 +723,8 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
message = null;
|
message = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String setting = getString(
|
message = getString(
|
||||||
GoogleLocationUtils.isAvailable(getActivity()) ? R.string.gps_google_location_settings
|
R.string.gps_disabled, GoogleLocationUtils.getLocationSettingsName(getActivity()));
|
||||||
: R.string.gps_location_access);
|
|
||||||
message = getString(R.string.gps_disabled, setting);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,11 +744,7 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = GoogleLocationUtils.isAvailable(getActivity()) ? new Intent(
|
startActivity(GoogleLocationUtils.newLocationSettingsIntent(getActivity()));
|
||||||
GoogleLocationUtils.ACTION_GOOGLE_LOCATION_SETTINGS)
|
|
||||||
: new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.util;
|
package com.google.android.apps.mytracks.util;
|
||||||
|
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for Google location settings
|
* Utilities for Google location settings
|
||||||
@@ -28,7 +31,7 @@ import android.content.pm.ResolveInfo;
|
|||||||
*/
|
*/
|
||||||
public class GoogleLocationUtils {
|
public class GoogleLocationUtils {
|
||||||
|
|
||||||
public static final String
|
private static final String
|
||||||
ACTION_GOOGLE_LOCATION_SETTINGS = "com.google.android.gsf.GOOGLE_LOCATION_SETTINGS";
|
ACTION_GOOGLE_LOCATION_SETTINGS = "com.google.android.gsf.GOOGLE_LOCATION_SETTINGS";
|
||||||
private static final String
|
private static final String
|
||||||
ACTION_GOOGLE_APPS_LOCATION_SETTINGS = "com.google.android.gsf.GOOGLE_APPS_LOCATION_SETTINGS";
|
ACTION_GOOGLE_APPS_LOCATION_SETTINGS = "com.google.android.gsf.GOOGLE_APPS_LOCATION_SETTINGS";
|
||||||
@@ -44,4 +47,27 @@ public class GoogleLocationUtils {
|
|||||||
.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
return resolveInfo != null;
|
return resolveInfo != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the location settings name.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
*/
|
||||||
|
public static String getLocationSettingsName(Context context) {
|
||||||
|
return context.getString(isAvailable(context) ? R.string.gps_google_location_settings
|
||||||
|
: R.string.gps_location_access);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new location settings intent.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
*/
|
||||||
|
public static Intent newLocationSettingsIntent(Context context) {
|
||||||
|
Intent intent = isAvailable(context) ? new Intent(
|
||||||
|
GoogleLocationUtils.ACTION_GOOGLE_LOCATION_SETTINGS)
|
||||||
|
: new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user