diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 5ad24305..002ab083 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -43,6 +43,8 @@
android:screenOrientation="portrait"/>
+
diff --git a/src/main/java/org/medicmobile/webapp/mobile/RequestPermissionActivity.java b/src/main/java/org/medicmobile/webapp/mobile/RequestPermissionActivity.java
new file mode 100644
index 00000000..cfce8b36
--- /dev/null
+++ b/src/main/java/org/medicmobile/webapp/mobile/RequestPermissionActivity.java
@@ -0,0 +1,43 @@
+package org.medicmobile.webapp.mobile;
+
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.widget.TextView;
+
+import static org.medicmobile.webapp.mobile.MedicLog.trace;
+
+/**
+ * Shows a confirmation view that displays a "prominent" disclosure about how
+ * the user geolocation data is used, asking to confirm whether to allow the app to
+ * access the location or not.
+ *
+ * If the user accepts, a request to the API to access the location is made by the main activity,
+ * but Android will show another confirmation dialog. If the user decline the first
+ * confirmation, the request to the API is omitted and the decision recorded to avoid
+ * requesting the same next time.
+ */
+public class RequestPermissionActivity extends LockableActivity {
+
+ @Override public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ setContentView(R.layout.request_permission);
+ String message = getResources().getString(R.string.locRequest_message);
+ String appName = getResources().getString(R.string.app_name);
+ TextView field = (TextView) findViewById(R.id.locMessageText);
+ field.setText(String.format(message, appName));
+ }
+
+ public void onClickOk(View view) {
+ trace(this, "onClickOk() :: user accepted to share the location");
+ setResult(RESULT_OK);
+ finish();
+ }
+
+ public void onClickNegative(View view) {
+ trace(this, ":: onClickNegative() :: user denied to share the location");
+ setResult(RESULT_CANCELED);
+ finish();
+ }
+}
diff --git a/src/main/java/org/medicmobile/webapp/mobile/RequestPermissionDialog.java b/src/main/java/org/medicmobile/webapp/mobile/RequestPermissionDialog.java
deleted file mode 100644
index c276b20f..00000000
--- a/src/main/java/org/medicmobile/webapp/mobile/RequestPermissionDialog.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.medicmobile.webapp.mobile;
-
-import android.Manifest;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.support.v4.app.ActivityCompat;
-
-import static org.medicmobile.webapp.mobile.MedicLog.error;
-import static org.medicmobile.webapp.mobile.MedicLog.trace;
-
-/**
- * Shows a confirmation dialog that displays a "prominent" disclosure about how
- * the user geolocation data is used, asking to confirm whether to allow the app to
- * access the location or not.
- *
- * If the user accepts, a request to the API to access the location is made,
- * but Android will show another confirmation dialog. If the user decline the first
- * confirmation, the request to the API is omitted and the decision recorded to avoid
- * requesting the same next time.
- */
-public abstract class RequestPermissionDialog {
-
- private static final String[] LOCATION_PERMISSIONS = { Manifest.permission.ACCESS_FINE_LOCATION };
-
- /**
- * Show the confirmation dialog unless the user has previously denied
- * to share the location from this same dialog.
- */
- public static void show(final EmbeddedBrowserActivity activity, final int requestCode) {
- final SettingsStore settings = SettingsStore.in(activity);
- if (settings.hasUserDeniedGeolocation()) {
- trace(activity, "RequestPermissionDialog.show() :: " +
- "user has previously denied to share location");
- activity.locationRequestResolved();
- return;
- }
- String message = activity.getResources().getString(R.string.locRequest_message);
- String appName = activity.getResources().getString(R.string.app_name);
- AlertDialog.Builder builder = new AlertDialog.Builder(activity);
- AlertDialog alert = builder
- .setTitle(R.string.locRequest_title)
- .setIcon(android.R.drawable.ic_menu_mylocation)
- .setMessage(String.format(message, appName))
- .setCancelable(true)
- .setPositiveButton(R.string.locRequest_okButton, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- trace(activity, "RequestPermissionDialog.show() :: " +
- "user accepted to share the location");
- ActivityCompat.requestPermissions(activity, LOCATION_PERMISSIONS, requestCode);
- }
- })
- .setNegativeButton(R.string.locRequest_denyButton, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- trace(activity, "RequestPermissionDialog.show() :: " +
- "user denied to share the location");
- activity.locationRequestResolved();
- try {
- settings.setUserDeniedGeolocation();
- } catch (SettingsException e) {
- error(e, "Error recording negative to access location");
- }
- }
- })
- .create();
- alert.show();
- }
-}
diff --git a/src/main/java/org/medicmobile/webapp/mobile/SettingsStore.java b/src/main/java/org/medicmobile/webapp/mobile/SettingsStore.java
index a60565fa..41ac9ea3 100644
--- a/src/main/java/org/medicmobile/webapp/mobile/SettingsStore.java
+++ b/src/main/java/org/medicmobile/webapp/mobile/SettingsStore.java
@@ -54,10 +54,8 @@ String get(String key) {
/**
* Returns true if the user has denied to provide its geolocation data.
- * The rejection is taken from the first dialog with the "prominent" disclosure
+ * The rejection is taken from the first view with the "prominent" disclosure
* about the location data, not from the native dialog displayed by Android.
- *
- * @see RequestPermissionDialog
*/
boolean hasUserDeniedGeolocation() {
return prefs.getBoolean("denied-geolocation", false);
diff --git a/src/main/res/drawable-anydpi/location_pin.xml b/src/main/res/drawable-anydpi/location_pin.xml
new file mode 100644
index 00000000..de72ef4a
--- /dev/null
+++ b/src/main/res/drawable-anydpi/location_pin.xml
@@ -0,0 +1,11 @@
+
+
+
diff --git a/src/main/res/drawable-hdpi/location_pin.png b/src/main/res/drawable-hdpi/location_pin.png
new file mode 100644
index 00000000..0d1fd948
Binary files /dev/null and b/src/main/res/drawable-hdpi/location_pin.png differ
diff --git a/src/main/res/drawable-mdpi/location_pin.png b/src/main/res/drawable-mdpi/location_pin.png
new file mode 100644
index 00000000..94a038c8
Binary files /dev/null and b/src/main/res/drawable-mdpi/location_pin.png differ
diff --git a/src/main/res/drawable-xhdpi/location_pin.png b/src/main/res/drawable-xhdpi/location_pin.png
new file mode 100644
index 00000000..6dc7fd09
Binary files /dev/null and b/src/main/res/drawable-xhdpi/location_pin.png differ
diff --git a/src/main/res/drawable-xxhdpi/location_pin.png b/src/main/res/drawable-xxhdpi/location_pin.png
new file mode 100644
index 00000000..b74b4585
Binary files /dev/null and b/src/main/res/drawable-xxhdpi/location_pin.png differ
diff --git a/src/main/res/layout/request_permission.xml b/src/main/res/layout/request_permission.xml
new file mode 100644
index 00000000..d11e5739
--- /dev/null
+++ b/src/main/res/layout/request_permission.xml
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index ed9cf313..3827ea69 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -48,6 +48,8 @@
Location Access
%s collects location data when you submit a form to analyze and improve health outcomes in your area. Select \"Allow while using the app\" on the next screen to turn on your location access.
- OK
+ Turn on
No thanks
+ My location icon
+ Location in map icon
diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml
index b19f582b..6c58cfd0 100644
--- a/src/main/res/values/styles.xml
+++ b/src/main/res/values/styles.xml
@@ -10,4 +10,8 @@
- 32dp
- 32dp
+
diff --git a/src/webview/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java b/src/webview/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java
index 8de675e7..7661476d 100644
--- a/src/webview/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java
+++ b/src/webview/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java
@@ -8,6 +8,7 @@
import android.net.Uri;
import android.net.ConnectivityManager;
import android.os.Bundle;
+import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
@@ -43,8 +44,11 @@ public class EmbeddedBrowserActivity extends LockableActivity {
private static final int NON_SIMPRINTS_FLAGS = 0x7;
static final int GRAB_PHOTO = (0 << 3) | NON_SIMPRINTS_FLAGS;
static final int GRAB_MRDT_PHOTO = (1 << 3) | NON_SIMPRINTS_FLAGS;
+ private static final int ACCESS_FINE_LOCATION_PERMISSION_REQUEST = (int)(Math.random() * 1000);
- private final static int ACCESS_FINE_LOCATION_PERMISSION_REQUEST = (int)(Math.random() * 1000);
+ private static final int DISCLOSURE_LOCATION_PERMISSION_REQUEST = 1122331;
+
+ private static final String[] LOCATION_PERMISSIONS = { Manifest.permission.ACCESS_FINE_LOCATION };
private static final ValueCallback IGNORE_RESULT = new ValueCallback() {
public void onReceiveValue(String result) { /* ignore */ }
@@ -179,6 +183,25 @@ protected void onStart() {
default:
trace(this, "onActivityResult() :: no handling for requestCode=%s", requestCode);
}
+ } else if(requestCode == DISCLOSURE_LOCATION_PERMISSION_REQUEST) {
+ // User accepted or denied to allow the app to access
+ // location data in RequestPermissionActivity
+ if (resultCode == RESULT_OK) { // user accepted
+ // Request to Android location data access
+ ActivityCompat.requestPermissions(
+ this,
+ LOCATION_PERMISSIONS,
+ ACCESS_FINE_LOCATION_PERMISSION_REQUEST);
+ } else if (resultCode == RESULT_CANCELED) { // user rejected
+ try {
+ this.locationRequestResolved();
+ settings.setUserDeniedGeolocation();
+ } catch (SettingsException e) {
+ error(e, "Error recording negative to access location");
+ } catch (Exception e) {
+ error(e, "Unknown Error recording negative to access location");
+ }
+ }
} else {
String js = simprints.process(requestCode, i);
trace(this, "Execing JS: %s", js);
@@ -308,7 +331,14 @@ public boolean getLocationPermissions() {
trace(this, "getLocationPermissions() :: already granted");
return true;
}
- RequestPermissionDialog.show(this, ACCESS_FINE_LOCATION_PERMISSION_REQUEST);
+ if (settings.hasUserDeniedGeolocation()) {
+ trace(this, "getLocationPermissions() :: user has previously denied to share location");
+ return false;
+ }
+ trace(this, "getLocationPermissions() :: location never granted, requesting access...");
+ startActivityForResult(
+ new Intent(this, RequestPermissionActivity.class),
+ DISCLOSURE_LOCATION_PERMISSION_REQUEST);
return false;
}
diff --git a/src/xwalk/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java b/src/xwalk/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java
index 114a93cf..25230acf 100644
--- a/src/xwalk/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java
+++ b/src/xwalk/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java
@@ -8,6 +8,7 @@
import android.net.Uri;
import android.net.ConnectivityManager;
import android.os.Bundle;
+import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.KeyEvent;
import android.view.Menu;
@@ -50,6 +51,10 @@ public class EmbeddedBrowserActivity extends LockableActivity {
private final static int ACCESS_FINE_LOCATION_PERMISSION_REQUEST = (int)Math.random();
+ private static final int DISCLOSURE_LOCATION_PERMISSION_REQUEST = 1122331;
+
+ private static final String[] LOCATION_PERMISSIONS = { Manifest.permission.ACCESS_FINE_LOCATION };
+
private static final ValueCallback IGNORE_RESULT = new ValueCallback() {
public void onReceiveValue(String result) { /* ignore */ }
};
@@ -185,6 +190,25 @@ public void onReceiveValue(String result) {
default:
trace(this, "onActivityResult() :: no handling for requestCode=%s", requestCode);
}
+ } else if(requestCode == DISCLOSURE_LOCATION_PERMISSION_REQUEST) {
+ // User accepted or denied to allow the app to access
+ // location data in RequestPermissionActivity
+ if (resultCode == RESULT_OK) { // user accepted
+ // Request to Android location data access
+ ActivityCompat.requestPermissions(
+ this,
+ LOCATION_PERMISSIONS,
+ ACCESS_FINE_LOCATION_PERMISSION_REQUEST);
+ } else if (resultCode == RESULT_CANCELED) { // user rejected
+ try {
+ this.locationRequestResolved();
+ settings.setUserDeniedGeolocation();
+ } catch (SettingsException e) {
+ error(e, "Error recording negative to access location");
+ } catch (Exception e) {
+ error(e, "Unknown Error recording negative to access location");
+ }
+ }
} else {
String js = simprints.process(requestCode, i);
trace(this, "Execing JS: %s", js);
@@ -326,7 +350,14 @@ public boolean getLocationPermissions() {
trace(this, "getLocationPermissions() :: already granted");
return true;
}
- RequestPermissionDialog.show(this, ACCESS_FINE_LOCATION_PERMISSION_REQUEST);
+ if (settings.hasUserDeniedGeolocation()) {
+ trace(this, "getLocationPermissions() :: user has previously denied to share location");
+ return false;
+ }
+ trace(this, "getLocationPermissions() :: location never granted, requesting access...");
+ startActivityForResult(
+ new Intent(this, RequestPermissionActivity.class),
+ DISCLOSURE_LOCATION_PERMISSION_REQUEST);
return false;
}