From d93ca602849f1d94500f2b9e21f794048095186d Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Wed, 15 Mar 2017 07:11:19 -0400 Subject: [PATCH 01/27] Returned to development settings --- .../keithirwin/tracman/LocationService.java | 92 ++++++++----------- .../us/keithirwin/tracman/LoginActivity.java | 38 ++++---- .../keithirwin/tracman/SettingsActivity.java | 10 +- 3 files changed, 59 insertions(+), 81 deletions(-) diff --git a/app/src/main/java/us/keithirwin/tracman/LocationService.java b/app/src/main/java/us/keithirwin/tracman/LocationService.java index f486331..2ab96f5 100644 --- a/app/src/main/java/us/keithirwin/tracman/LocationService.java +++ b/app/src/main/java/us/keithirwin/tracman/LocationService.java @@ -41,8 +41,8 @@ import java.net.URISyntaxException; public class LocationService extends Service implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener { public LocationService() {} - //private String TAG = "LocationService"; - final String SERVER_ADDRESS = "https://tracman.org"; + private String TAG = "LocationService"; + final String SERVER_ADDRESS = "https://dev.tracman.org"; private Socket socket; private String mUserID; @@ -74,11 +74,9 @@ public class LocationService extends Service implements GoogleApiClient.Connecti mNotificationBuilder .setPriority(-1) .setSmallIcon(R.drawable.logo_white) -// .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo_by)) .setCategory(NotificationCompat.CATEGORY_SERVICE) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentTitle(getText(R.string.app_name)) -// .setWhen(System.currentTimeMillis()) .setContentIntent(notificationIntent) .setOngoing(persist); } @@ -100,45 +98,31 @@ public class LocationService extends Service implements GoogleApiClient.Connecti @Override public void onReceive(Context context, Intent intent) { connectLocationUpdates(300, LocationRequest.PRIORITY_NO_POWER); - //Log.d(TAG, "Priority and interval lowered due to low power"); + Log.d(TAG, "Priority and interval lowered due to low power"); } }; -// private TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { -// public java.security.cert.X509Certificate[] getAcceptedIssuers() { -// return new java.security.cert.X509Certificate[] {}; -// } -// -// public void checkClientTrusted(X509Certificate[] chain, -// String authType) throws CertificateException { -// } -// -// public void checkServerTrusted(X509Certificate[] chain, -// String authType) throws CertificateException { -// } -// } }; - @Override public void onCreate() { super.onCreate(); - //Log.d(TAG, "onCreate called"); + Log.d(TAG, "onCreate called"); // Get preferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); setupNotifications(true); showNotification(getText(R.string.connecting), false); - //Log.d(TAG, "Notification set up"); + Log.d(TAG, "Notification set up"); buildGoogleApiClient(); - //Log.d(TAG, "Google API Client built"); + Log.d(TAG, "Google API Client built"); mGoogleApiClient.connect(); - //Log.d(TAG, "Connected to Google API Client"); + Log.d(TAG, "Connected to Google API Client"); IntentFilter lowPowerFilter = new IntentFilter(); lowPowerFilter.addAction("android.intent.action.BATTERY_LOW"); registerReceiver(LowPowerReceiver, lowPowerFilter); - //Log.d(TAG, "LowPowerReceiver activated"); + Log.d(TAG, "LowPowerReceiver activated"); mUserID = sharedPref.getString("loggedInUserId", null); mUserSK = sharedPref.getString("loggedInUserSk", null); @@ -153,21 +137,21 @@ public class LocationService extends Service implements GoogleApiClient.Connecti showNotification(getText(R.string.connected), false); // Log errors -// socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() { -// @Override -// public void call(Object... args) { -// Transport transport = (Transport) args[0]; -// transport.on(Transport.EVENT_ERROR, new Emitter.Listener() { -// @Override -// public void call(Object... args) { -// Exception e = (Exception) args[0]; -// Log.e(TAG, "Transport error " + e); -// e.printStackTrace(); -// e.getCause().printStackTrace(); -// } -// }); -// } -// }); + socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() { + @Override + public void call(Object... args) { + Transport transport = (Transport) args[0]; + transport.on(Transport.EVENT_ERROR, new Emitter.Listener() { + @Override + public void call(Object... args) { + Exception e = (Exception) args[0]; + Log.e(TAG, "Transport error " + e); + e.printStackTrace(); + e.getCause().printStackTrace(); + } + }); + } + }); socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { @Override @@ -183,7 +167,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti } catch (URISyntaxException e) { showNotification(getText(R.string.server_connection_error), false); - //Log.e(TAG, "Failed to connect to sockets server " + SERVER_ADDRESS, e); + Log.e(TAG, "Failed to connect to sockets server " + SERVER_ADDRESS, e); } } @@ -214,11 +198,11 @@ public class LocationService extends Service implements GoogleApiClient.Connecti // Get permission if (!checkLocationPermission(this)) { - //Log.d(TAG, "Location permission denied"); + Log.d(TAG, "Location permission denied"); //TODO: Turn off location updates } else { - //Log.d(TAG, "Location permission granted"); + Log.d(TAG, "Location permission granted"); // Request location updates if (mGoogleApiClient.isConnected()) { @@ -244,7 +228,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti @Override public void onConnected(Bundle bundle) { - //Log.d(TAG, "onConnected called"); + Log.d(TAG, "onConnected called"); mLocationRequest = LocationRequest.create(); connectLocationUpdates(getIntervalSetting(), getPrioritySetting()); @@ -258,7 +242,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti @Override public void onConnectionFailed(ConnectionResult connectionResult) { - //Log.e(TAG, "onConnectionFailed: " + connectionResult); + Log.e(TAG, "onConnectionFailed: " + connectionResult); showNotification(getText(R.string.google_connection_error), false); buildGoogleApiClient(); } @@ -267,11 +251,11 @@ public class LocationService extends Service implements GoogleApiClient.Connecti @Override public void call(final Object... args) { if (args[0].toString().equals("true")) { - //Log.d(TAG, "Activating realtime updates"); + Log.d(TAG, "Activating realtime updates"); connectLocationUpdates(getIntervalSetting(), getPrioritySetting()); showNotification(getString(R.string.realtime_updates), true); } else { - //Log.d(TAG, "Deactivating realtime updates"); + Log.d(TAG, "Deactivating realtime updates"); connectLocationUpdates(300, LocationRequest.PRIORITY_NO_POWER); showNotification(getString(R.string.occasional_updates), false); } @@ -290,36 +274,36 @@ public class LocationService extends Service implements GoogleApiClient.Connecti mLocationView.put("dir", String.valueOf(location.getBearing())); mLocationView.put("spd", String.valueOf(location.getSpeed())); } catch (JSONException e) { - //Log.e(TAG, "Failed to put JSON data"); + Log.e(TAG, "Failed to put JSON data"); } socket.emit("set", mLocationView); - //Log.v(TAG, "Location updated: " + mLocationView.toString()); + Log.v(TAG, "Location updated: " + mLocationView.toString()); } @Override public void onConnectionSuspended(int i) { - //Log.d(TAG, "onConnectionSuspended called"); + Log.d(TAG, "onConnectionSuspended called"); showNotification(getText(R.string.google_connection_error), false); } @Override public void onDestroy() { super.onDestroy(); - //Log.d(TAG, "onDestroy executed"); + Log.d(TAG, "onDestroy executed"); socket.disconnect(); socket.off("activate", onActivate); - //Log.d(TAG, "Disconnected from sockets"); + Log.d(TAG, "Disconnected from sockets"); mGoogleApiClient.disconnect(); - //Log.d(TAG, "Google API disconnected"); + Log.d(TAG, "Google API disconnected"); unregisterReceiver(LowPowerReceiver); - //Log.d(TAG, "LowPowerReceiver deactivated"); + Log.d(TAG, "LowPowerReceiver deactivated"); setupNotifications(false); showNotification(getText(R.string.disconnected), false); - //Log.d(TAG, "Notification changed"); + Log.d(TAG, "Notification changed"); } } \ No newline at end of file diff --git a/app/src/main/java/us/keithirwin/tracman/LoginActivity.java b/app/src/main/java/us/keithirwin/tracman/LoginActivity.java index abe0761..53c8170 100644 --- a/app/src/main/java/us/keithirwin/tracman/LoginActivity.java +++ b/app/src/main/java/us/keithirwin/tracman/LoginActivity.java @@ -27,35 +27,29 @@ import org.json.JSONObject; import java.io.IOException; import java.security.KeyStore; import java.util.Arrays; -import java.util.Collections; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; import okhttp3.Call; -import okhttp3.CipherSuite; -import okhttp3.ConnectionSpec; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Callback; import okhttp3.Response; -import okhttp3.TlsVersion; public class LoginActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener, View.OnClickListener { -// private static final String TAG = "LoginActivity"; + private static final String TAG = "LoginActivity"; private static final int RC_SIGN_IN = 9001; // Development - //private final String SERVER_ADDRESS = "https://dev.tracman.org/"; - //private static final String GOOGLE_WEB_CLIENT_ID = "483494341936-hps4p2pcu3ctshjvqm3pqdbg0t0q281o.apps.googleusercontent.com"; + private final String SERVER_ADDRESS = "https://dev.tracman.org/"; + private static final String GOOGLE_WEB_CLIENT_ID = "483494341936-hps4p2pcu3ctshjvqm3pqdbg0t0q281o.apps.googleusercontent.com"; // Production - private final String SERVER_ADDRESS = "https://tracman.org/"; - private static final String GOOGLE_WEB_CLIENT_ID = "483494341936-hrn0ms1tebgdtfs5f4i6ebmkt3qmo16o.apps.googleusercontent.com"; +// private final String SERVER_ADDRESS = "https://tracman.org/"; +// private static final String GOOGLE_WEB_CLIENT_ID = "483494341936-hrn0ms1tebgdtfs5f4i6ebmkt3qmo16o.apps.googleusercontent.com"; private GoogleApiClient mGoogleApiClient; private ProgressDialog mProgressDialog; @@ -63,7 +57,7 @@ public class LoginActivity extends AppCompatActivity implements @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); -// Log.v(TAG, "Created..."); + Log.v(TAG, "Created..."); // Set up layout setContentView(R.layout.activity_login); @@ -95,20 +89,20 @@ public class LoginActivity extends AppCompatActivity implements @Override public void onStart() { super.onStart(); -// Log.v(TAG, "Started. Checking for intent method"); + Log.v(TAG, "Started. Checking for intent method"); if (getIntent().hasExtra("method")) { -// Log.v(TAG, "Intent has method extra"); + Log.v(TAG, "Intent has method extra"); if (getIntent().getStringExtra("method").equals("signOut")) { -// Log.d(TAG, "Got intent to sign out"); + Log.d(TAG, "Got intent to sign out"); } } else { // Try to sign in -// Log.v(TAG, "Trying to sign in..."); + Log.v(TAG, "Trying to sign in..."); OptionalPendingResult opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient); if (opr.isDone()) { // If the user's cached credentials are valid, the OptionalPendingResult will be "done" // and the GoogleSignInResult will be available instantly. -// Log.d(TAG, "Got cached sign-in"); + Log.d(TAG, "Got cached sign-in"); GoogleSignInResult result = opr.get(); handleSignInResult(result); } else { @@ -163,7 +157,7 @@ public class LoginActivity extends AppCompatActivity implements client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { -// Log.e(TAG, "Failed to connect to server: " + SERVER_ADDRESS + "auth/google/idtoken?id_token=" + token); + Log.e(TAG, "Failed to connect to server: " + SERVER_ADDRESS + "auth/google/idtoken?id_token=" + token); showError(R.string.server_connection_error); e.printStackTrace(); } @@ -175,7 +169,7 @@ public class LoginActivity extends AppCompatActivity implements res.body().close(); throw new IOException("Unexpected code: " + res); } else { -// Log.d(TAG, "Response code: " + res.code()); + Log.d(TAG, "Response code: " + res.code()); String userString = res.body().string(); System.out.println("Full response: " + userString); @@ -185,10 +179,10 @@ public class LoginActivity extends AppCompatActivity implements userID = user.getString("_id"); userName = user.getString("name"); userSK = user.getString("sk32"); -// Log.v(TAG, "User retrieved with ID: " + userID); + Log.v(TAG, "User retrieved with ID: " + userID); } catch (JSONException e) { -// Log.e(TAG, "Unable to parse user JSON: ", e); -// Log.e(TAG, "JSON String used: " + userString); + Log.e(TAG, "Unable to parse user JSON: ", e); + Log.e(TAG, "JSON String used: " + userString); userID = null; userName = null; userSK = null; diff --git a/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java b/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java index 02dfbea..b1c20fa 100644 --- a/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java +++ b/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java @@ -34,7 +34,7 @@ import java.util.List; * API Guide for more information on developing a Settings UI. */ public class SettingsActivity extends AppCompatPreferenceActivity { - //private static final String TAG = "SettingsActivity"; + private static final String TAG = "SettingsActivity"; private static final int MY_FINE_LOCATION_PERMISSION = 425; /** @@ -88,7 +88,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { MY_FINE_LOCATION_PERMISSION); } -// Log.d(TAG, "Starting LocationService"); + Log.d(TAG, "Starting LocationService"); startService(new Intent(SettingsActivity.this, LocationService.class)); } @@ -130,7 +130,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupActionBar(); -// Log.d(TAG, "activity onCreate called"); + Log.d(TAG, "activity onCreate called"); // Restart LocationService when any related preference is changed // findPreference("gps_switch").setOnPreferenceChangeListener(sRestartLocationServiceOnChangeListener); @@ -145,7 +145,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { @Override protected void onStop() { - //Log.d(TAG, "onStop called"); + Log.d(TAG, "onStop called"); super.onStop(); // Restart service so settings can take effect @@ -162,7 +162,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } // Start location tracking service -// Log.d(TAG, "Starting LocationService"); + Log.d(TAG, "Starting LocationService"); startService(new Intent(this, LocationService.class)); } From 1b4c9dfc339baf7c3e06fac1175cecd505435a0d Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 6 Apr 2017 18:42:40 -0400 Subject: [PATCH 02/27] Attempt to fix loading on boot --- .../us/keithirwin/tracman/SettingsActivity.java | 13 +++++++++---- build.gradle | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java b/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java index b1c20fa..7d6acb8 100644 --- a/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java +++ b/app/src/main/java/us/keithirwin/tracman/SettingsActivity.java @@ -147,10 +147,16 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected void onStop() { Log.d(TAG, "onStop called"); super.onStop(); + // Get updated preferences + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + + // Save updated preferences + SharedPreferences.Editor editor = sharedPref.edit(); +// editor.putBoolean("pref_start_boot", ); + editor.apply(); // Restart service so settings can take effect stopService(new Intent(this, LocationService.class)); - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPref.getBoolean("gps_switch", false)) { // Ask for location permissions (can't be done in service, only activity) @@ -219,8 +225,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName); -// || MapPreferenceFragment.class.getName().equals(fragmentName) -// || NotificationPreferenceFragment.class.getName().equals(fragmentName); } /** @@ -242,7 +246,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // Bind the summary of preferences to their value bindPreferenceSummaryToValue(findPreference("broadcast_frequency")); bindPreferenceSummaryToValue(findPreference("broadcast_priority")); - } + + } } /** diff --git a/build.gradle b/build.gradle index 3afcd7f..4f5127c 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.1' classpath 'com.google.gms:google-services:3.0.0' // NOTE: Do not place your application dependencies here; they belong From abb4fa34722a086b28d55ccfac8b972261208b96 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Mon, 17 Apr 2017 14:32:35 -0400 Subject: [PATCH 03/27] Created new login page --- app/src/main/res/layout/activity_login.xml | 141 +++++++++++++++------ app/src/main/res/values-de/strings.xml | 9 +- app/src/main/res/values-es/strings.xml | 11 +- app/src/main/res/values/strings.xml | 7 +- 4 files changed, 117 insertions(+), 51 deletions(-) diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 5fdb88d..a767e2d 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -7,6 +7,7 @@ android:weightSum="6" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="#080808" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" @@ -14,74 +15,130 @@ tools:context="us.keithirwin.tracman.LoginActivity" android:clickable="true"> - + + + + + android:src="@drawable/logo_by" /> + + + android:textColor="@color/Yellow"/> + - + + android:layout_height="wrap_content" > - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +