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 @@ + + + + + + + + + + + +