Merge pull request #579 from misaochan/check-gps-2

Check for GPS when Nearby is loaded
This commit is contained in:
Josephine Lim 2017-05-15 11:05:25 +02:00 committed by GitHub
commit b71fd5c960
2 changed files with 46 additions and 0 deletions

View file

@ -1,10 +1,14 @@
package fr.free.nrw.commons.nearby; package fr.free.nrw.commons.nearby;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -23,6 +27,7 @@ import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.UriSerializer; import fr.free.nrw.commons.utils.UriSerializer;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import timber.log.Timber;
import java.util.List; import java.util.List;
@ -47,6 +52,7 @@ public class NearbyActivity extends BaseActivity {
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
checkGps();
bundle = new Bundle(); bundle = new Bundle();
locationManager = new LocationServiceManager(this); locationManager = new LocationServiceManager(this);
locationManager.registerLocationManager(); locationManager.registerLocationManager();
@ -83,6 +89,44 @@ public class NearbyActivity extends BaseActivity {
} }
} }
protected void checkGps() {
LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Timber.d("GPS is not enabled");
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage(R.string.gps_disabled)
.setCancelable(false)
.setPositiveButton(R.string.enable_gps,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Timber.d("Loaded settings page");
startActivityForResult(callGPSSettingIntent, 1);
}
});
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
} else {
Timber.d("GPS is enabled");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
Timber.d("User is back from Settings page");
refreshView();
}
}
private void showMapView() { private void showMapView() {
if (!isMapViewActive) { if (!isMapViewActive) {
isMapViewActive = true; isMapViewActive = true;

View file

@ -51,6 +51,8 @@
<string name="categories_search_text_hint">Search categories</string> <string name="categories_search_text_hint">Search categories</string>
<string name="menu_save_categories">Save</string> <string name="menu_save_categories">Save</string>
<string name="refresh_button">Refresh</string> <string name="refresh_button">Refresh</string>
<string name="gps_disabled">GPS is disabled in your device. Would you like to enable it?</string>
<string name="enable_gps">Enable GPS</string>
<string name="contributions_subtitle_zero">No uploads yet</string> <string name="contributions_subtitle_zero">No uploads yet</string>
<plurals name="contributions_subtitle"> <plurals name="contributions_subtitle">
<!--zero is not used in english. Category mentioned here for easy reference in future--> <!--zero is not used in english. Category mentioned here for easy reference in future-->