Loading app/src/main/java/net/fabiszewski/ulogger/BootCompletedReceiver.java +8 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; /** * Receiver for boot completed broadcast Loading @@ -34,8 +35,14 @@ public class BootCompletedReceiver extends BroadcastReceiver { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean autoStart = prefs.getBoolean("prefAutoStart", false); if (autoStart && Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { DbAccess db = DbAccess.getInstance(); db.open(context); if (db.getTrackName() == null) { db.newAutoTrack(); } db.close(); Intent i = new Intent(context, LoggerService.class); context.startService(i); ContextCompat.startForegroundService(context, i); } } } app/src/main/java/net/fabiszewski/ulogger/DbAccess.java +23 −0 Original line number Diff line number Diff line Loading @@ -15,10 +15,12 @@ import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.location.Location; import android.support.annotation.NonNull; import android.util.Log; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; import java.util.TimeZone; Loading Loading @@ -288,6 +290,19 @@ class DbAccess { return trackName; } /** * Get auto-generated track name (Auto_[yyyy.MM.dd_HH.mm.ss]). * * @return Track name */ @NonNull static String getAutoTrackName() { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getDefault()); final String dateSuffix = sdf.format(Calendar.getInstance().getTime()); return "Auto_" + dateSuffix; } /** * Update current track, set id. * Loading Loading @@ -315,6 +330,14 @@ class DbAccess { db.insert(DbContract.Track.TABLE_NAME, null, values); } /** * Start new track with auto-generated name. * @see DbAccess#newTrack(String) */ void newAutoTrack() { newTrack(getAutoTrackName()); } /** * Get track summary * Loading app/src/main/java/net/fabiszewski/ulogger/LoggerService.java +5 −5 Original line number Diff line number Diff line Loading @@ -136,14 +136,14 @@ public class LoggerService extends Service { final boolean prefsUpdated = (intent != null) && intent.getBooleanExtra(MainActivity.UPDATED_PREFS, false); if (prefsUpdated) { handlePrefsUpdated(); } else if (isRunning) { // first start } else { final Notification notification = showNotification(NOTIFICATION_ID); startForeground(NOTIFICATION_ID, notification); } else { if (!isRunning) { // onCreate failed to start updates stopSelf(); } } return START_STICKY; } Loading app/src/main/java/net/fabiszewski/ulogger/MainActivity.java +1 −5 Original line number Diff line number Diff line Loading @@ -486,11 +486,7 @@ public class MainActivity extends AppCompatActivity { if (editText == null) { return; } final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getDefault()); final String dateSuffix = sdf.format(Calendar.getInstance().getTime()); final String autoName = "Auto_" + dateSuffix; editText.setText(autoName); editText.setText(DbAccess.getAutoTrackName()); editText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Loading Loading
app/src/main/java/net/fabiszewski/ulogger/BootCompletedReceiver.java +8 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; /** * Receiver for boot completed broadcast Loading @@ -34,8 +35,14 @@ public class BootCompletedReceiver extends BroadcastReceiver { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean autoStart = prefs.getBoolean("prefAutoStart", false); if (autoStart && Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { DbAccess db = DbAccess.getInstance(); db.open(context); if (db.getTrackName() == null) { db.newAutoTrack(); } db.close(); Intent i = new Intent(context, LoggerService.class); context.startService(i); ContextCompat.startForegroundService(context, i); } } }
app/src/main/java/net/fabiszewski/ulogger/DbAccess.java +23 −0 Original line number Diff line number Diff line Loading @@ -15,10 +15,12 @@ import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.location.Location; import android.support.annotation.NonNull; import android.util.Log; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; import java.util.TimeZone; Loading Loading @@ -288,6 +290,19 @@ class DbAccess { return trackName; } /** * Get auto-generated track name (Auto_[yyyy.MM.dd_HH.mm.ss]). * * @return Track name */ @NonNull static String getAutoTrackName() { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getDefault()); final String dateSuffix = sdf.format(Calendar.getInstance().getTime()); return "Auto_" + dateSuffix; } /** * Update current track, set id. * Loading Loading @@ -315,6 +330,14 @@ class DbAccess { db.insert(DbContract.Track.TABLE_NAME, null, values); } /** * Start new track with auto-generated name. * @see DbAccess#newTrack(String) */ void newAutoTrack() { newTrack(getAutoTrackName()); } /** * Get track summary * Loading
app/src/main/java/net/fabiszewski/ulogger/LoggerService.java +5 −5 Original line number Diff line number Diff line Loading @@ -136,14 +136,14 @@ public class LoggerService extends Service { final boolean prefsUpdated = (intent != null) && intent.getBooleanExtra(MainActivity.UPDATED_PREFS, false); if (prefsUpdated) { handlePrefsUpdated(); } else if (isRunning) { // first start } else { final Notification notification = showNotification(NOTIFICATION_ID); startForeground(NOTIFICATION_ID, notification); } else { if (!isRunning) { // onCreate failed to start updates stopSelf(); } } return START_STICKY; } Loading
app/src/main/java/net/fabiszewski/ulogger/MainActivity.java +1 −5 Original line number Diff line number Diff line Loading @@ -486,11 +486,7 @@ public class MainActivity extends AppCompatActivity { if (editText == null) { return; } final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getDefault()); final String dateSuffix = sdf.format(Calendar.getInstance().getTime()); final String autoName = "Auto_" + dateSuffix; editText.setText(autoName); editText.setText(DbAccess.getAutoTrackName()); editText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Loading