From e8f306a023d44fda09fb10e5e37296ff02bbe152 Mon Sep 17 00:00:00 2001 From: Josephine Lim Date: Mon, 15 May 2017 10:11:03 +0200 Subject: [PATCH 1/6] Add Dialog if GPS not enabled --- .../nrw/commons/nearby/NearbyActivity.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java index 43966f7a4..c292dd802 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java @@ -1,10 +1,14 @@ package fr.free.nrw.commons.nearby; +import android.content.DialogInterface; +import android.content.Intent; +import android.location.LocationManager; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AlertDialog; import android.view.Menu; import android.view.MenuInflater; 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.R; +import timber.log.Timber; import java.util.List; @@ -47,6 +52,7 @@ public class NearbyActivity extends BaseActivity { if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } + checkGps(); bundle = new Bundle(); locationManager = new LocationServiceManager(this); locationManager.registerLocationManager(); @@ -83,6 +89,37 @@ 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("GPS is disabled in your device. Would you like to enable it?") + .setCancelable(false) + .setPositiveButton("Enable GPS", + new DialogInterface.OnClickListener(){ + public void onClick(DialogInterface dialog, int id){ + Intent callGPSSettingIntent = new Intent( + android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); + startActivity(callGPSSettingIntent); + } + }); + 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"); + } + } + private void showMapView() { if (!isMapViewActive) { isMapViewActive = true; From faa60dc82448827c62a5cd27545b3ef11e664d67 Mon Sep 17 00:00:00 2001 From: Josephine Lim Date: Mon, 15 May 2017 10:25:40 +0200 Subject: [PATCH 2/6] Add string resources --- .../free/nrw/commons/nearby/NearbyActivity.java | 17 ++++++++--------- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java index c292dd802..dc9769fda 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java @@ -91,24 +91,23 @@ public class NearbyActivity extends BaseActivity { protected void checkGps() { - LocationManager manager = (LocationManager) - getSystemService(LOCATION_SERVICE); - if(!manager.isProviderEnabled( LocationManager.GPS_PROVIDER )) { + 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("GPS is disabled in your device. Would you like to enable it?") + alertDialogBuilder.setMessage(R.string.gps_disabled) .setCancelable(false) - .setPositiveButton("Enable GPS", - new DialogInterface.OnClickListener(){ - public void onClick(DialogInterface dialog, int id){ + .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); startActivity(callGPSSettingIntent); } }); alertDialogBuilder.setNegativeButton("Cancel", - new DialogInterface.OnClickListener(){ - public void onClick(DialogInterface dialog, int id){ + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bad2512de..479727e0e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,6 +51,8 @@ Search categories Save Refresh + GPS is disabled in your device. Would you like to enable it? + Enable GPS No uploads yet From 0af03bb456d193fb51e23ec3bb438decef3f01cf Mon Sep 17 00:00:00 2001 From: Josephine Lim Date: Mon, 15 May 2017 10:39:56 +0200 Subject: [PATCH 3/6] Refresh view if settings changed --- .../fr/free/nrw/commons/nearby/NearbyActivity.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java index dc9769fda..6a9516a83 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java @@ -102,7 +102,7 @@ public class NearbyActivity extends BaseActivity { public void onClick(DialogInterface dialog, int id) { Intent callGPSSettingIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); - startActivity(callGPSSettingIntent); + startActivityForResult(callGPSSettingIntent, 1); } }); alertDialogBuilder.setNegativeButton("Cancel", @@ -119,6 +119,14 @@ public class NearbyActivity extends BaseActivity { } } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == 1) { + refreshView(); + } + } + private void showMapView() { if (!isMapViewActive) { isMapViewActive = true; From ad7c1cc8f5c1794a8d47114b548ff1317260b2ef Mon Sep 17 00:00:00 2001 From: Josephine Lim Date: Mon, 15 May 2017 10:47:02 +0200 Subject: [PATCH 4/6] Use requestCode instead --- .../main/java/fr/free/nrw/commons/nearby/NearbyActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java index 6a9516a83..fee1704a5 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java @@ -122,7 +122,7 @@ public class NearbyActivity extends BaseActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (resultCode == 1) { + if (requestCode == 1) { refreshView(); } } From 42e975c19cadb92d50767b9120914c398f45b78d Mon Sep 17 00:00:00 2001 From: Josephine Lim Date: Mon, 15 May 2017 10:49:45 +0200 Subject: [PATCH 5/6] Added logs --- .../main/java/fr/free/nrw/commons/nearby/NearbyActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java index fee1704a5..6532540e4 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java @@ -102,6 +102,7 @@ public class NearbyActivity extends BaseActivity { 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); } }); @@ -123,6 +124,7 @@ public class NearbyActivity extends BaseActivity { 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(); } } From 0809290a62764ce9d549dd82fdaaaa53f47db89b Mon Sep 17 00:00:00 2001 From: Josephine Lim Date: Mon, 15 May 2017 10:54:13 +0200 Subject: [PATCH 6/6] Fix whitespace --- .../main/java/fr/free/nrw/commons/nearby/NearbyActivity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java index 6532540e4..e0a65e1a5 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java @@ -89,7 +89,6 @@ public class NearbyActivity extends BaseActivity { } } - protected void checkGps() { LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { @@ -114,7 +113,6 @@ public class NearbyActivity extends BaseActivity { }); AlertDialog alert = alertDialogBuilder.create(); alert.show(); - } else { Timber.d("GPS is enabled"); }