Skip to content

Commit

Permalink
Fix #697 - Allow users to opt out of "Location not enabled" dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
barbeau committed Apr 5, 2017
1 parent 08d3d04 commit 98135b6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@
*/
package org.onebusaway.android.map.googlemapsv2;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.LocationSource;
Expand Down Expand Up @@ -50,25 +72,6 @@
import org.onebusaway.android.util.PreferenceUtils;
import org.onebusaway.android.util.UIUtils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -618,7 +621,11 @@ public void run() {
public boolean setMyLocation(boolean useDefaultZoom, boolean animateToLocation) {
if (!LocationUtils.isLocationEnabled(getActivity()) && mRunning && UIUtils.canManageDialog(
getActivity())) {
showDialog(MapDialogFragment.NOLOCATION_DIALOG);
// If the user hasn't opted out of "Enable location" dialog, show it to them
SharedPreferences prefs = Application.getPrefs();
if (!prefs.getBoolean(getString(R.string.preference_key_never_show_location_dialog), false)) {
showDialog(MapDialogFragment.NOLOCATION_DIALOG);
}
return false;
}

Expand Down Expand Up @@ -1103,15 +1110,26 @@ public void onClick(DialogInterface dialog, int which) {

@SuppressWarnings("deprecation")
private Dialog createNoLocationDialog() {
View view = getActivity().getLayoutInflater().inflate(R.layout.no_location_dialog, null);
CheckBox neverShowDialog = (CheckBox) view.findViewById(R.id.location_never_ask_again);

neverShowDialog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
// Save the preference
PreferenceUtils.saveBoolean(getString(R.string.preference_key_never_show_location_dialog), isChecked);
}
});

Drawable icon = getResources().getDrawable(android.R.drawable.ic_dialog_map);
DrawableCompat.setTint(icon, getResources().getColor(R.color.theme_primary));

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.main_nolocation_title)
.setIcon(icon)
.setCancelable(false)
.setMessage(R.string.main_nolocation)
.setPositiveButton(android.R.string.yes,
.setView(view)
.setPositiveButton(R.string.rt_yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand All @@ -1121,7 +1139,7 @@ public void onClick(DialogInterface dialog, int which) {
}
}
)
.setNegativeButton(android.R.string.no,
.setNegativeButton(R.string.rt_no,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,9 @@ private void setupMyLocationButton() {
@Override
public void onClick(View arg0) {
if (mMapFragment != null) {
// Reset the preference to ask user to enable location
PreferenceUtils.saveBoolean(getString(R.string.preference_key_never_show_location_dialog), false);

mMapFragment.setMyLocation(true, true);
ObaAnalytics.reportEventWithCategory(
ObaAnalytics.ObaEventCategory.UI_ACTION.toString(),
Expand Down
26 changes: 26 additions & 0 deletions onebusaway-android/src/main/res/layout/no_location_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="24dp"
android:paddingRight="12dp">

<TextView
android:id="@+id/no_location_text"
style="?android:attr/textAppearance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="14dp"
android:paddingBottom="6dp"
android:text="@string/main_nolocation"
android:textSize="16sp"
android:autoLink="all"
android:linksClickable="true"></TextView>

<CheckBox
android:id="@+id/location_never_ask_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_never_ask_again" />
</LinearLayout>
1 change: 1 addition & 0 deletions onebusaway-android/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="preference_key_notifications">preference_key_notifications</string>
<string name="preference_key_trip_plan_notifications">preference_key_trip_plan_notifications</string>
<string name="preference_key_left_hand_mode">preference_key_left_hand_mode</string>
<string name="preference_key_never_show_location_dialog">never_show_location_dialog</string>

<!-- Regions API URL -->
<string name="regions_api_url">http://regions.onebusaway.org/regions-v3.json</string>
Expand Down
1 change: 1 addition & 0 deletions onebusaway-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<string name="main_nolocation">OneBusAway would like your location, do you want to enable it
now?
</string>
<string name="main_never_ask_again">Never ask again</string>
<string name="main_waiting_for_location">Trying to get a fix on your location&#8230;</string>
<string name="main_location_unavailable">Unable to get your location.</string>
<string name="main_outofrange_title">Out of range</string>
Expand Down

0 comments on commit 98135b6

Please sign in to comment.