Skip to content

Commit b911b47

Browse files
committed
make location request more user intuitive
1 parent 8444575 commit b911b47

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

app/src/main/java/com/lcl/lclmeasurementtool/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
3737
mCellularManager = CellularManager.getManager(this);
3838
mLocationManager = LocationServiceManager.getManager(this);
3939

40-
locationServiceListener = new LocationServiceListener(this);
40+
locationServiceListener = new LocationServiceListener(this, getLifecycle());
4141
getLifecycle().addObserver(locationServiceListener);
4242

4343
TextView tv = (TextView) findViewById(R.id.signalStrengthStatus);

app/src/main/java/com/lcl/lclmeasurementtool/Managers/LocationServiceListener.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ public class LocationServiceListener implements LifecycleObserver {
2828
// the context of the Application
2929
private final Context context;
3030

31+
// the life cycle object
32+
private final Lifecycle lifecycle;
33+
34+
// the lock that controls the check on location mode
35+
private boolean checkLocationModeLock = false;
36+
3137
/**
3238
* Initialize a LocationService Listener using the current context of the Application
3339
*
3440
* @param context the context of the application
3541
*/
36-
public LocationServiceListener(@NonNull Context context) {
42+
public LocationServiceListener(@NonNull Context context, Lifecycle lifecycle) {
3743
this.context = context;
3844
this.mLocationManager = LocationServiceManager.getManager(context);
45+
this.lifecycle = lifecycle;
3946
}
4047

4148

@@ -54,12 +61,16 @@ void checkLocationPermission() {
5461
*/
5562
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
5663
void checkLocationMode() {
57-
if (!mLocationManager.isLocationModeOn()) {
58-
64+
if (!mLocationManager.isLocationModeOn() && lifecycle.getCurrentState().equals(Lifecycle.State.RESUMED) && !checkLocationModeLock) {
65+
System.out.println(1);
66+
checkLocationModeLock = true;
5967
// TODO turn off start FAB if canceled
6068
UIUtils.showDialog(context, R.string.location_message_title, R.string.enable_location_message,
6169
R.string.go_to_setting,
62-
(paramDialogInterface, paramInt) -> context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)),
70+
(paramDialogInterface, paramInt) -> {
71+
context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
72+
checkLocationModeLock = false;
73+
},
6374
android.R.string.cancel,
6475
null);
6576
}

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
<string name="hello_first_fragment">Hello first fragment</string>
1111
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
12-
<string name="permission_rationale">Location Service should be enabled for core functionality</string>
13-
<string name="permission_denied_explanation">Permission was denied, but is needed for core functionality</string>
12+
<string name="permission_rationale">"We use Location Service to provide more accurate core network measurement and other related service. Granting the permission of the location service will help us improve our service. We will upload anonymized and fused location data to our encrypted server for post-analysis to better network experience."</string>
1413
<string name="settings">Settings</string>
1514
<string name="no_location_detected">No location detected</string>
16-
<string name="enable_location_message">Enable Location</string>
15+
<string name="enable_location_message">The core functionality relies on location to provide better cellular network experience. Disabling the location service will result in missing in functionality.</string>
1716
<string name="go_to_setting">Settings</string>
1817
<string name="location_message_title">Using Location Service</string>
18+
<string name="permission_denied_explanation">"We use Location Service to provide core functionalities in this measurement tool. Disabling location service will result in missing in functionality."</string>
1919
</resources>

0 commit comments

Comments
 (0)