Commit e17a7643 authored by John Taylor's avatar John Taylor

Moved the location check back to onCreate- it means we only show it once, but...

Moved the location check back to onCreate- it means we only show it once, but otherwise we end up on an onResume onPause loop.

Removed the "Pisa" default and made the default location 0,0.  It's more obvious that something is wrong.

Tried to clarify the messages a bit.  This is a stopgap until we make the location controller better.
parent 3bc09b34
......@@ -3,6 +3,18 @@
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="2" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</value>
</option>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
......
......@@ -193,6 +193,10 @@ public class DynamicStarMapActivity extends Activity
// to do it at API level 19.
//getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
// Eventually we should check at the point of use, but this will do for now. If the
// user revokes the permission later then odd things may happen.
playServicesChecker.maybeCheckForGooglePlayServices();
model = StardroidApplication.getModel();
layerManager = StardroidApplication.getLayerManager(getAssets(),
sharedPreferences,
......@@ -245,12 +249,14 @@ public class DynamicStarMapActivity extends Activity
handler.post(new Runnable() {
@Override
public void run() {
if (!sharedPreferences.getBoolean(ApplicationConstants.NO_WARN_ABOUT_MISSING_SENSORS, false)) {
if (!sharedPreferences
.getBoolean(ApplicationConstants.NO_WARN_ABOUT_MISSING_SENSORS, false)) {
Log.d(TAG, "showing no sensor dialog");
// TODO(jontayler): refactor to use dialog fragments.
showDialog(DialogFactory.DIALOG_ID_NO_SENSORS);
// First time, force manual mode.
sharedPreferences.edit().putBoolean(ApplicationConstants.AUTO_MODE_PREF_KEY, false).apply();
sharedPreferences.edit().putBoolean(ApplicationConstants.AUTO_MODE_PREF_KEY, false)
.apply();
setAutoMode(false);
} else {
Log.d(TAG, "showing no sensor toast");
......@@ -421,8 +427,7 @@ public class DynamicStarMapActivity extends Activity
Log.d(TAG, "onResume at " + System.currentTimeMillis());
super.onResume();
Log.i(TAG, "Resuming");
// We check each time because the user might have changed their location preferences.
playServicesChecker.maybeCheckForGooglePlayServices();
wakeLock.acquire();
Log.i(TAG, "Starting view");
skyView.onResume();
......@@ -469,7 +474,7 @@ public class DynamicStarMapActivity extends Activity
flashTheScreen();
controller.useRealTime();
Toast.makeText(this,
R.string.time_travel_close_message,
R.string.time_travel_close_message,
Toast.LENGTH_SHORT).show();
Log.d(TAG, "Leaving Time Travel mode.");
timePlayerUI.setVisibility(View.GONE);
......
......@@ -45,6 +45,7 @@ public class SplashScreenActivity extends Activity
@Inject Animation fadeAnimation;
@Inject EulaDialogFragment eulaDialogFragmentWithButtons;
@Inject FragmentManager fragmentManager;
private View graphic;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -54,9 +55,7 @@ public class SplashScreenActivity extends Activity
((StardroidApplication) getApplication()).getApplicationComponent().newSplashScreenSubcomponent(
new SplashScreenModule(this)).inject(this);
final View graphic = findViewById(R.id.splash);
boolean eulaShown = maybeShowEula();
graphic = findViewById(R.id.splash);
fadeAnimation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation arg0) {
......@@ -74,6 +73,12 @@ public class SplashScreenActivity extends Activity
Log.d(TAG, "SplashScreen.Animcation onAnimationStart");
}
});
}
@Override
public void onResume() {
super.onResume();
boolean eulaShown = maybeShowEula();
if (!eulaShown) {
// User has previously accepted - let's get on with it!
graphic.startAnimation(fadeAnimation);
......
......@@ -73,32 +73,45 @@ public class EulaDialogFragment extends DialogFragment {
.setNegativeButton(R.string.dialog_accept,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(TAG, "TOS Dialog closed. User accepts.");
dialog.dismiss();
analytics.trackEvent(
Analytics.APP_CATEGORY, Analytics.TOS_ACCEPT, Analytics.TOS_ACCEPTED, 1);
if (resultListener != null) {
resultListener.eulaAccepted();
}
acceptEula(dialog);
}
})
.setPositiveButton(R.string.dialog_decline,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(TAG, "TOS Dialog closed. User declines.");
dialog.dismiss();
analytics.trackEvent(
Analytics.APP_CATEGORY, Analytics.TOS_ACCEPT, Analytics.TOS_REJECTED, 0);
if (resultListener != null) {
resultListener.eulaRejected();
}
rejectEula(dialog);
}
});
}
return tosDialogBuilder.create();
}
private void acceptEula(DialogInterface dialog) {
Log.d(TAG, "TOS Dialog closed. User accepts.");
dialog.dismiss();
analytics.trackEvent(
Analytics.APP_CATEGORY, Analytics.TOS_ACCEPT, Analytics.TOS_ACCEPTED, 1);
if (resultListener != null) {
resultListener.eulaAccepted();
}
}
private void rejectEula(DialogInterface dialog) {
Log.d(TAG, "TOS Dialog closed. User declines.");
dialog.dismiss();
analytics.trackEvent(
Analytics.APP_CATEGORY, Analytics.TOS_ACCEPT, Analytics.TOS_REJECTED, 0);
if (resultListener != null) {
resultListener.eulaRejected();
}
}
private String getVersionName() {
return ((StardroidApplication) parentActivity.getApplication()).getVersionName();
}
@Override
public void onCancel(DialogInterface dialog) {
rejectEula(dialog);
}
}
......@@ -78,7 +78,7 @@ public class GooglePlayServicesChecker implements LocationPermissionRationaleFra
private void checkLocationServicesEnabled() {
if (ActivityCompat.checkSelfPermission(parent, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Location permission not enabled - prompting user");
Log.d(TAG, "Location permission not enabled - maybe prompting user");
// Check Permissions now
if (ActivityCompat.shouldShowRequestPermissionRationale(
parent, Manifest.permission.ACCESS_FINE_LOCATION)) {
......
......@@ -87,47 +87,54 @@ public class LocationController extends AbstractController implements LocationLi
return;
}
if (locationManager == null) {
// TODO(johntaylor): find out under what circumstances this can happen.
Log.e(TAG, "Location manager was null - using preferences");
setLocationFromPrefs();
return;
}
Criteria locationCriteria = new Criteria();
locationCriteria.setAccuracy(forceGps ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE);
locationCriteria.setAltitudeRequired(false);
locationCriteria.setBearingRequired(false);
locationCriteria.setCostAllowed(true);
locationCriteria.setSpeedRequired(false);
locationCriteria.setPowerRequirement(Criteria.POWER_LOW);
String locationProvider = locationManager.getBestProvider(locationCriteria, true);
if (locationProvider == null) {
Log.w(TAG, "No location provider is enabled");
String possiblelocationProvider = locationManager.getBestProvider(locationCriteria, false);
if (possiblelocationProvider == null) {
// TODO(johntaylor): should we make this a dialog?
Toast.makeText(context, R.string.location_no_auto, Toast.LENGTH_LONG).show();
try {
if (locationManager == null) {
// TODO(johntaylor): find out under what circumstances this can happen.
Log.e(TAG, "Location manager was null - using preferences");
setLocationFromPrefs();
return;
}
AlertDialog.Builder alertDialog = getSwitchOnGPSDialog();
alertDialog.show();
return;
} else {
Log.d(TAG, "Got location provider " + locationProvider);
}
Criteria locationCriteria = new Criteria();
locationCriteria.setAccuracy(forceGps ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE);
locationCriteria.setAltitudeRequired(false);
locationCriteria.setBearingRequired(false);
locationCriteria.setCostAllowed(true);
locationCriteria.setSpeedRequired(false);
locationCriteria.setPowerRequirement(Criteria.POWER_LOW);
String locationProvider = locationManager.getBestProvider(locationCriteria, true);
if (locationProvider == null) {
Log.w(TAG, "No location provider is enabled");
String possiblelocationProvider = locationManager.getBestProvider(locationCriteria, false);
if (possiblelocationProvider == null) {
Log.i(TAG, "No location provider is even available");
// TODO(johntaylor): should we make this a dialog?
Toast.makeText(context, R.string.location_no_auto, Toast.LENGTH_LONG).show();
setLocationFromPrefs();
return;
}
AlertDialog.Builder alertDialog = getSwitchOnGPSDialog();
alertDialog.show();
return;
} else {
Log.d(TAG, "Got location provider " + locationProvider);
}
locationManager.requestLocationUpdates(locationProvider, LOCATION_UPDATE_TIME_MILLISECONDS,
MINIMUM_DISTANCE_BEFORE_UPDATE_METRES,
this);
locationManager.requestLocationUpdates(locationProvider, LOCATION_UPDATE_TIME_MILLISECONDS,
MINIMUM_DISTANCE_BEFORE_UPDATE_METRES,
this);
Location location = locationManager.getLastKnownLocation(locationProvider);
if (location != null) {
LatLong myLocation = new LatLong(location.getLatitude(), location.getLongitude());
setLocationInModel(myLocation, location.getProvider());
}
Location location = locationManager.getLastKnownLocation(locationProvider);
if (location != null) {
LatLong myLocation = new LatLong(location.getLatitude(), location.getLongitude());
setLocationInModel(myLocation, location.getProvider());
} catch (SecurityException securityException) {
Log.d(TAG, "Caught " + securityException);
Log.d(TAG, "Most likely user has not enabled this permission");
}
Log.d(TAG, "LocationController -start");
......@@ -169,12 +176,13 @@ public class LocationController extends AbstractController implements LocationLi
}
private void setLocationFromPrefs() {
Log.d(TAG, "Setting location from preferences");
String longitude_s = PreferenceManager.getDefaultSharedPreferences(context)
.getString("longitude", "");
.getString("longitude", "0");
String latitude_s = PreferenceManager.getDefaultSharedPreferences(context)
.getString("latitude", "");
.getString("latitude", "0");
float longitude = -80, latitude = 40;
float longitude = 0, latitude = 0;
try {
longitude = Float.parseFloat(longitude_s);
latitude = Float.parseFloat(latitude_s);
......
......@@ -18,7 +18,7 @@
<string name="location_long_pref">Longitude</string>
<string name="degrees" translation_description="angular degrees">Degrees</string>
<string name="preferences">preferences</string>
<string name="location_no_auto">Auto-location permission is disabled on your phone. You can set the location manually in preferences.</string>
<string name="location_no_auto">Auto-location permission is disabled on your phone. You can set the location manually in preferences. Until then the map will be incorrect.</string>
<string name="location_offer_to_enable">Auto-location is disabled. Would you like to enable it?</string>
<string name="location_offer_to_enable_gps_title">Auto-location disabled</string>
<string name="location_set_auto">Location set from %1$s to %2$s</string>
......
......@@ -4,7 +4,7 @@
<![CDATA[
<h1>New in version %s</h1>
\t • Fixed gallery search <br/>
\t • Change Cassiopeia to the more popular W shape
\t • Change Cassiopeia to the more popular W shape <br/>
\t • Provide clearer guidance to Android 6 users on enabling location
]]>
</string>
......
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="stardroid.preferences">
<PreferenceCategory
android:title="@string/provider_prefs">
<PreferenceCategory android:title="@string/provider_prefs">
<!-- TODO(johntaylor): restore this once it's toggling properly CheckBoxPreference
android:key="show_sky_gradient"
android:defaultValue="true"
......@@ -60,21 +59,23 @@
android:title="@string/location_placename"
android:summary="@string/location_placename_hint"
android:dependency="no_auto_locate"
android:defaultValue="Pisa" />
android:defaultValue="" />
<EditTextPreference
android:key="latitude"
android:layout="?android:attr/preferenceLayoutChild"
android:title="@string/location_lat_pref"
android:dependency="no_auto_locate"
android:summary="@string/degrees"
android:defaultValue="43.7166667"/>
android:inputType="number"
android:defaultValue="0"/>
<EditTextPreference
android:key="longitude"
android:layout="?android:attr/preferenceLayoutChild"
android:title="@string/location_long_pref"
android:dependency="no_auto_locate"
android:summary="@string/degrees"
android:defaultValue="10.3833333"/>
android:inputType="number"
android:defaultValue="0"/>
<CheckBoxPreference
android:defaultValue="true"
android:title="@string/use_magnetic_correction"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment