Commit 3989c6b8 authored by John Taylor's avatar John Taylor

Checkpoint. Start to move the EULA to the splash page since it interferes...

Checkpoint.  Start to move the EULA to the splash page since it interferes with the barrage of messages and permission-seeking dialogs.
parent 914cb84f
This diff is collapsed.
......@@ -51,6 +51,7 @@ dependencies {
compile 'com.android.support:support-annotations:23.1.0'
compile 'com.google.guava:guava:19.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.dagger:dagger:2.0.2'
provided 'javax.annotation:jsr250-api:1.0' // For annotations not in Android but needed by Dagger
apt 'com.google.dagger:dagger-compiler:2.0.2'
......
......@@ -5,7 +5,8 @@ import com.google.android.stardroid.activities.DynamicStarMapSubcomponent;
import com.google.android.stardroid.activities.EditSettingsActivity;
import com.google.android.stardroid.activities.ImageDisplayActivity;
import com.google.android.stardroid.activities.ImageGalleryActivity;
import com.google.android.stardroid.activities.SplashScreenActivity;
import com.google.android.stardroid.activities.SplashScreenModule;
import com.google.android.stardroid.activities.SplashScreenSubcomponent;
import javax.inject.Singleton;
......@@ -19,9 +20,9 @@ import dagger.Component;
@Component(modules={ApplicationModule.class})
public interface ApplicationComponent {
void inject(StardroidApplication app);
void inject(SplashScreenActivity activity);
void inject(EditSettingsActivity activity);
void inject(ImageDisplayActivity activity);
void inject(ImageGalleryActivity activity);
DynamicStarMapSubcomponent newDynamicStarMapSubcomponent(DynamicStarMapModule activityModule);
SplashScreenSubcomponent newSplashScreenSubcomponent(SplashScreenModule activityModule);
}
......@@ -27,4 +27,18 @@ public class ApplicationConstants {
/** Default value for 'down' in phone coords when the app starts */
public static final Vector3 INITIAL_DOWN = new Vector3(0, -1, -9);
// Preference keys
public static final String AUTO_MODE_PREF_KEY = "auto_mode";
public static final String NO_WARN_ABOUT_MISSING_SENSORS = "no warn about missing sensors";
public static final String BUNDLE_TARGET_NAME = "target_name";
public static final String BUNDLE_NIGHT_MODE = "night_mode";
public static final String BUNDLE_X_TARGET = "bundle_x_target";
public static final String BUNDLE_Y_TARGET = "bundle_y_target";
public static final String BUNDLE_Z_TARGET = "bundle_z_target";
public static final String BUNDLE_SEARCH_MODE = "bundle_search";
public static final String SOUND_EFFECTS = "sound_effects";
// Preference that keeps track of whether or not the user accepted the ToS for this version
public static final String READ_TOS_PREF_VERSION = "read_tos_version";
// End Preference Keys
}
......@@ -6,6 +6,7 @@ import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.stardroid.util.MiscUtil;
import java.util.concurrent.ExecutorService;
......@@ -55,4 +56,14 @@ public class ApplicationModule {
Resources provideResources() {
return app.getResources();
}
@Provides @Singleton
GoogleApiAvailability providePlayServicesApiAvailability() {
return GoogleApiAvailability.getInstance();
}
/*@Provides @Singleton
GoogleApiAvailability providePlayServicesApiAvailability() {
return GoogleApiAvailability.getInstance();
}*/
}
......@@ -14,6 +14,7 @@
package com.google.android.stardroid.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
......@@ -28,6 +29,7 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import com.google.android.stardroid.ApplicationConstants;
import com.google.android.stardroid.R;
import com.google.android.stardroid.R.layout;
import com.google.android.stardroid.R.string;
......@@ -60,7 +62,7 @@ public class DialogFactory {
static final int DIALOG_ID_EULA_WITH_BUTTONS = 6;
static final int DIALOG_ID_NO_SENSORS = 7;
private DynamicStarMapActivity parentActivity;
private Activity parentActivity;
private ArrayAdapter<SearchResult> multipleSearchResultsAdaptor;
private SharedPreferences preferences;
private Analytics analytics;
......@@ -83,7 +85,7 @@ public class DialogFactory {
/**
* Creates dialogs on demand. Delegated to by the parentActivity.
*/
public Dialog onCreateDialog(int id) {
private Dialog onCreateDialog(int id) {
switch (id) {
case (DialogFactory.DIALOG_ID_HELP):
return createHelpDialog();
......@@ -113,7 +115,7 @@ public class DialogFactory {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(TAG, "No Sensor Dialog closed");
preferences.edit().putBoolean(
DynamicStarMapActivity.NO_WARN_ABOUT_MISSING_SENSORS,
ApplicationConstants.NO_WARN_ABOUT_MISSING_SENSORS,
((CheckBox) view.findViewById(R.id.no_show_dialog_again)).isChecked()).commit();
dialog.dismiss();
}
......@@ -213,7 +215,7 @@ public class DialogFactory {
* Display the Terms of Service and privacy policy to the user.
*/
private Dialog createTermsOfServiceDialog(boolean hideButtons) {
AlertDialog tosDialog = null;
AlertDialog tosDialog;
LayoutInflater inflater = parentActivity.getLayoutInflater();
View view = inflater.inflate(layout.tos_view, null);
......
package com.google.android.stardroid.activities;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Handler;
......@@ -32,7 +33,13 @@ public class DynamicStarMapModule {
@Provides
@Singleton
DynamicStarMapActivity provideActivity() {
DynamicStarMapActivity provideDynamicStarMapActivity() {
return activity;
}
@Provides
@Singleton
Activity provideActivity() {
return activity;
}
......
......@@ -35,7 +35,6 @@ import com.google.android.stardroid.util.Analytics;
import com.google.android.stardroid.util.MiscUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
......@@ -107,7 +106,7 @@ public class EditSettingsActivity extends PreferenceActivity {
}
protected boolean setLatLongFromPlace(String place) {
List<Address> addresses = new ArrayList<Address>();
List<Address> addresses;
try {
addresses = geocoder.getFromLocationName(place, 1);
} catch (IOException e) {
......
......@@ -16,13 +16,14 @@ package com.google.android.stardroid.activities;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import com.google.android.stardroid.ApplicationConstants;
import com.google.android.stardroid.R;
import com.google.android.stardroid.StardroidApplication;
import com.google.android.stardroid.util.Analytics;
......@@ -37,17 +38,21 @@ public class SplashScreenActivity extends Activity {
private final static String TAG = MiscUtil.getTag(SplashScreenActivity.class);
@Inject Analytics analytics;
@Inject SharedPreferences sharedPreferences;
@Inject Animation fadeAnimation;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "SplashScreen onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
((StardroidApplication) getApplication()).getApplicationComponent().inject(this);
((StardroidApplication) getApplication()).getApplicationComponent().newSplashScreenSubcomponent(
new SplashScreenModule(this)).inject(this);
final View graphic = findViewById(R.id.splash);
Animation fadeAnimation = AnimationUtils.loadAnimation(this, R.anim.fadeout);
maybeShowEula();
fadeAnimation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation arg0) {
Log.d(TAG, "SplashScreen.Animation onAnimationEnd");
......@@ -90,4 +95,20 @@ public class SplashScreenActivity extends Activity {
startActivity(intent);
super.finish();
}
private void maybeShowEula() {
int versionCode = ((StardroidApplication) getApplication()).getVersion();
boolean eulaConfirmed = (sharedPreferences.getInt(
ApplicationConstants.READ_TOS_PREF_VERSION, -1) == versionCode);
if (!eulaConfirmed) {
showDialog(DialogFactory.DIALOG_ID_EULA_WITH_BUTTONS);
}
}
public void recordEulaAccepted() {
int versionCode = ((StardroidApplication) getApplication()).getVersion();
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(ApplicationConstants.READ_TOS_PREF_VERSION, versionCode);
editor.commit();
}
}
package com.google.android.stardroid.activities;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import com.google.android.stardroid.R;
import javax.inject.Singleton;
import dagger.Provides;
/**
* Created by johntaylor on 4/2/16.
*/
public class SplashScreenModule {
private SplashScreenActivity activity;
public SplashScreenModule(SplashScreenActivity activity) {
this.activity = activity;
}
@Provides
@Singleton
Animation provideTimeTravelFlashAnimation() {
return AnimationUtils.loadAnimation(activity, R.anim.fadeout);
}
}
package com.google.android.stardroid.activities;
import javax.inject.Singleton;
import dagger.Subcomponent;
/**
* Created by johntaylor on 4/2/16.
*/
@Singleton
@Subcomponent(modules={SplashScreenModule.class})
public interface SplashScreenSubcomponent {
void inject(SplashScreenActivity activity);
}
package com.google.android.stardroid.activities.util;
import android.Manifest;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.stardroid.activities.DynamicStarMapActivity;
import com.google.android.stardroid.control.LocationController;
import com.google.android.stardroid.util.MiscUtil;
import javax.inject.Inject;
/**
* Created by johntaylor on 4/2/16.
*/
public class GooglePlayServicesChecker {
private static final String TAG = MiscUtil.getTag(GooglePlayServicesChecker.class);
private final Activity parent;
private final SharedPreferences preferences;
//private final GoogleApiClient apiClient;
private final GoogleApiAvailability apiAvailability;
@Inject
GooglePlayServicesChecker(Activity parent, SharedPreferences preferences,
/*GoogleApiClient apiClient, */GoogleApiAvailability apiAvailability) {
this.parent = parent;
this.preferences = preferences;
//this.apiClient = apiClient;
this.apiAvailability = apiAvailability;
}
/**
* Checks whether play services is available and up to date and prompts the user
* if necessary.
* <p/>
* Note that at present we only need it for location services so if the user is setting
* their location manually we don't do the check.
*/
public void maybeCheckForGooglePlayServices() {
Log.d(TAG, "Google Play Services check");
if (preferences.getBoolean(LocationController.NO_AUTO_LOCATE, false)) {
Log.d(TAG, "Auto location disabled - not checking for GMS");
return;
}
int googlePlayServicesAvailability = apiAvailability.isGooglePlayServicesAvailable(parent);
if (googlePlayServicesAvailability == ConnectionResult.SUCCESS) {
Log.d(TAG, "Google Play Services is available and up to date");
} else {
Log.d(TAG, "Google Play Status availability: " + googlePlayServicesAvailability);
if (apiAvailability.isUserResolvableError(googlePlayServicesAvailability)) {
Log.d(TAG, "...but we can fix it");
apiAvailability.getErrorDialog(parent, googlePlayServicesAvailability,
DynamicStarMapActivity.GOOGLE_PLAY_SERVICES_REQUEST_CODE).show();
} else {
Log.d(TAG, "...and we can't fix it");
// For now just warn the user, though we may need to do something like disable
// auto location.
Toast.makeText(parent, "Warning: Google Play Services error - Automatic location might not work", Toast.LENGTH_LONG);
}
}
checkLocationServicesEnabled();
}
private void checkLocationServicesEnabled() {
if (ActivityCompat.checkSelfPermission(parent, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Location permission not enabled - prompting user");
// Check Permissions Now
ActivityCompat.requestPermissions(parent,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
DynamicStarMapActivity.GOOGLE_PLAY_SERVICES_REQUEST_LOCATION_PERMISSION_CODE);
} else {
Log.d(TAG, "Location permission is granted");
}
}
/**
* Called after a request to check permissions.
*/
public void runAfterPermissionsCheck(int requestCode,
String[] permissions,
int[] grantResults) {
if(grantResults.length == 1
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "User granted permission");
} else {
Log.i(TAG, "User denied permission");
// Send them to the location dialog;
}
}
/**
* Called after the user is prompted to resolve any issues.
*/
public void runAfterDialog() {
// Just log for now.
Log.d(TAG, "Play Services Dialog has been shown");
}
}
......@@ -50,7 +50,7 @@ import java.util.List;
*/
public class LocationController extends AbstractController implements LocationListener {
// Must match the key in the preferences file.
private static final String NO_AUTO_LOCATE = "no_auto_locate";
public static final String NO_AUTO_LOCATE = "no_auto_locate";
// Must match the key in the preferences file.
private static final String FORCE_GPS = "force_gps";
private static final int MINIMUM_DISTANCE_BEFORE_UPDATE_METRES = 2000;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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