implemented basic resume functionlity (see #33) - needs testing
This commit is contained in:
parent
77479aa60d
commit
b737408090
4 changed files with 45 additions and 28 deletions
|
@ -308,13 +308,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
}
|
||||
|
||||
|
||||
/* Loads state of Floating Action Button from preferences */
|
||||
private void loadFloatingActionButtonState(Context context) {
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
mFloatingActionButtonState = settings.getInt(PREFS_FAB_STATE, FAB_STATE_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
/* Handles tap on the button "save" */
|
||||
private void handleSaveButtonClick() {
|
||||
// save button click is handled by onActivityResult in MainActivityMapFragment
|
||||
|
@ -340,18 +333,26 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
|
||||
|
||||
/* Handles tap on the button "resume" */
|
||||
private void handleResumeButtonClick() {
|
||||
// todo implement
|
||||
private void handleResumeButtonClick(View view) {
|
||||
// change state
|
||||
mTrackerServiceRunning = true;
|
||||
mFloatingActionButtonState = FAB_STATE_RECORDING;
|
||||
setFloatingActionButtonState();
|
||||
showFloatingActionButtonMenu(false);
|
||||
|
||||
// show snackbar
|
||||
Snackbar.make(view, R.string.snackbar_message_tracking_resumed, Snackbar.LENGTH_SHORT).setAction("Action", null).show();
|
||||
|
||||
// resume tracking
|
||||
startTrackerService(ACTION_RESUME, null);
|
||||
}
|
||||
|
||||
|
||||
// /* Saves state of Floating Action Button */ // not needed tracker service saves state
|
||||
// private void saveFloatingActionButtonState(Context context) {
|
||||
// SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// SharedPreferences.Editor editor = settings.edit();
|
||||
// editor.putInt(PREFS_FAB_STATE, mFloatingActionButtonState);
|
||||
// editor.apply();
|
||||
// }
|
||||
/* Loads state of Floating Action Button from preferences */
|
||||
private void loadFloatingActionButtonState(Context context) {
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
mFloatingActionButtonState = settings.getInt(PREFS_FAB_STATE, FAB_STATE_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
/* Set up main layout */
|
||||
|
@ -455,13 +456,13 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
mFloatingActionButtonSubResume.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
handleResumeButtonClick();
|
||||
handleResumeButtonClick(view);
|
||||
}
|
||||
});
|
||||
mFloatingActionButtonSubResumeLabel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
handleResumeButtonClick();
|
||||
handleResumeButtonClick(view);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -116,12 +116,7 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
// RESTART CHECK: checking for empty intent - try to get saved track
|
||||
if (intent == null || intent.getAction() == null) {
|
||||
LogHelper.w(LOG_TAG, "Null-Intent received. Trying to restart tracking.");
|
||||
StorageHelper storageHelper = new StorageHelper(this);
|
||||
if (storageHelper.tempFileExists()) {
|
||||
mTrack = storageHelper.loadTrack(FILE_TEMP_TRACK);
|
||||
// restart tracking
|
||||
startTracking(intent, false);
|
||||
}
|
||||
startTracking(intent, false);
|
||||
}
|
||||
|
||||
// ACTION START
|
||||
|
@ -129,6 +124,11 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
startTracking(intent, true);
|
||||
}
|
||||
|
||||
// ACTION START
|
||||
else if (intent.getAction().equals(ACTION_RESUME) && mLocationSystemSetting) {
|
||||
startTracking(intent, false);
|
||||
}
|
||||
|
||||
// ACTION STOP
|
||||
else if (intent.getAction().equals(ACTION_STOP) || !mLocationSystemSetting) {
|
||||
mTrackerServiceRunning = false;
|
||||
|
@ -210,12 +210,27 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
// create a new track -- if necessary
|
||||
if (createNewTrack) {
|
||||
mTrack = new Track();
|
||||
} else {
|
||||
StorageHelper storageHelper = new StorageHelper(this);
|
||||
if (storageHelper.tempFileExists()) {
|
||||
// load temp track file
|
||||
mTrack = storageHelper.loadTrack(FILE_TEMP_TRACK);
|
||||
} else {
|
||||
// fallback, if temfile did not exist
|
||||
LogHelper.e(LOG_TAG, "Unable to find previously saved track temp file.");
|
||||
mTrack = new Track();
|
||||
}
|
||||
}
|
||||
|
||||
// get last location
|
||||
if (intent != null && intent.hasExtra(EXTRA_LAST_LOCATION)) {
|
||||
if (intent != null && ACTION_START.equals(intent.getAction()) && intent.hasExtra(EXTRA_LAST_LOCATION)) {
|
||||
// received START intent and last location - unpack last location
|
||||
mCurrentBestLocation = intent.getParcelableExtra(EXTRA_LAST_LOCATION);
|
||||
} else if (ACTION_RESUME.equals(intent.getAction()) && mTrack.getSize() > 0) {
|
||||
// received RESUME intent - use last waypoint
|
||||
mCurrentBestLocation = mTrack.getWayPointLocation(mTrack.getSize() -1);
|
||||
}
|
||||
|
||||
// get last location - fallback
|
||||
if (mCurrentBestLocation == null) {
|
||||
mCurrentBestLocation = LocationHelper.determineLastKnownLocation(mLocationManager);
|
||||
|
@ -229,14 +244,14 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
mNotification = NotificationHelper.getNotification(this, mNotificationBuilder, mTrack, true);
|
||||
mNotificationManager.notify(TRACKER_SERVICE_NOTIFICATION_ID, mNotification); // todo check if necessary in pre Android O
|
||||
|
||||
// get duration of previously recorded track - in case this service has been restarted
|
||||
// get duration of previously recorded track - in case this service has been restarted / resumed
|
||||
final long previouslyRecordedDuration = mTrack.getTrackDuration();
|
||||
|
||||
// set timer to retrieve new locations and to prevent endless tracking
|
||||
mTimer = new CountDownTimer(EIGHT_HOURS_IN_MILLISECONDS, FIFTEEN_SECONDS_IN_MILLISECONDS) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
// update track duration - and add duration from previously interrupted session
|
||||
// update track duration - and add duration from previously interrupted / paused session
|
||||
long duration = EIGHT_HOURS_IN_MILLISECONDS - millisUntilFinished + previouslyRecordedDuration;
|
||||
mTrack.setDuration(duration);
|
||||
// try to add WayPoint to Track
|
||||
|
|
|
@ -26,6 +26,7 @@ public interface TrackbookKeys {
|
|||
String ACTION_START = "org.y20k.trackbook.action.START";
|
||||
String ACTION_STOP = "org.y20k.trackbook.action.STOP";
|
||||
String ACTION_DISMISS = "org.y20k.transistor.action.DISMISS";
|
||||
String ACTION_RESUME = "org.y20k.transistor.action.RESUME";
|
||||
String ACTION_DEFAULT = "DEFAULT";
|
||||
String ACTION_SHOW_MAP = "SHOW_MAP";
|
||||
String ACTION_TRACK_UPDATED = "TRACK_UPDATED";
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/descr_fab_sub_menu_label_save"
|
||||
android:focusable="true"
|
||||
|
@ -90,7 +91,6 @@
|
|||
app:fabSize="mini"
|
||||
app:layout_constraintBottom_toTopOf="@+id/fabSubMenuButtonResume"
|
||||
app:layout_constraintEnd_toEndOf="@+id/fabSubMenuButtonResume"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="@+id/fabSubMenuButtonResume"
|
||||
app:srcCompat="@drawable/ic_clear_white_24dp" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue