mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Code refactor of GoogleLocationUtils
This commit is contained in:
@@ -65,7 +65,6 @@ import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcelable;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
@@ -496,10 +495,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
||||
this, Looper.myLooper(), false);
|
||||
if (!myTracksLocationManager.isGpsProviderEnabled()) {
|
||||
intent = GoogleLocationUtils.isAvailable(TrackListActivity.this) ? new Intent(
|
||||
GoogleLocationUtils.ACTION_GOOGLE_LOCATION_SETTINGS)
|
||||
: new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent = GoogleLocationUtils.newLocationSettingsIntent(TrackListActivity.this);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
startGps = !TrackRecordingServiceConnectionUtils.isRecordingServiceRunning(
|
||||
|
||||
@@ -55,7 +55,6 @@ import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -165,12 +164,9 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
||||
final MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
||||
getActivity(), Looper.myLooper(), true);
|
||||
if (!myTracksLocationManager.isAllowed()) {
|
||||
String setting = getString(
|
||||
GoogleLocationUtils.isAvailable(getActivity()) ? R.string.gps_google_location_settings
|
||||
: R.string.gps_location_access);
|
||||
Toast.makeText(
|
||||
getActivity(), getString(R.string.my_location_no_gps, setting), Toast.LENGTH_LONG)
|
||||
.show();
|
||||
String message = getString(R.string.my_location_no_gps,
|
||||
GoogleLocationUtils.getLocationSettingsName(getActivity()));
|
||||
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
|
||||
myTracksLocationManager.close();
|
||||
} else {
|
||||
myTracksLocationManager.requestLastLocation(new LocationListener() {
|
||||
@@ -727,10 +723,8 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
||||
message = null;
|
||||
}
|
||||
} else {
|
||||
String setting = getString(
|
||||
GoogleLocationUtils.isAvailable(getActivity()) ? R.string.gps_google_location_settings
|
||||
: R.string.gps_location_access);
|
||||
message = getString(R.string.gps_disabled, setting);
|
||||
message = getString(
|
||||
R.string.gps_disabled, GoogleLocationUtils.getLocationSettingsName(getActivity()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,11 +744,7 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = GoogleLocationUtils.isAvailable(getActivity()) ? new Intent(
|
||||
GoogleLocationUtils.ACTION_GOOGLE_LOCATION_SETTINGS)
|
||||
: new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
startActivity(GoogleLocationUtils.newLocationSettingsIntent(getActivity()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.Settings;
|
||||
|
||||
/**
|
||||
* Utilities for Google location settings
|
||||
@@ -28,7 +31,7 @@ import android.content.pm.ResolveInfo;
|
||||
*/
|
||||
public class GoogleLocationUtils {
|
||||
|
||||
public static final String
|
||||
private static final String
|
||||
ACTION_GOOGLE_LOCATION_SETTINGS = "com.google.android.gsf.GOOGLE_LOCATION_SETTINGS";
|
||||
private static final String
|
||||
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);
|
||||
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