diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index b5c63aa0a..841ce9527 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -277,8 +277,35 @@ public void bindView(View view, Context context, Cursor cursor) { return; } - // Show the notification dialog to select type of the metric to show in starting new track - showNotificationOptionsDialog(); + + // Not Recording -> Recording + try { + runOnUiThread(() -> { + for (int i = selectedDelayInSeconds; i >= 0; i--) { + + final int secondsLeft = i; + Toast toast = Toast.makeText(TrackListActivity.this,"Recording starts in " + secondsLeft + " seconds", Toast.LENGTH_SHORT); + toast.show(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + toast.cancel(); + }}); + + } catch (Exception e) { + throw new RuntimeException(e); + } + updateGpsMenuItem(false, true); + new TrackRecordingServiceConnection((service, connection) -> { + // Track.Id trackId = service.startNewTrack(); + Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackRecordingActivity.class); + //newIntent.putExtra(TrackRecordingActivity.EXTRA_TRACK_ID, trackId); + startActivity(newIntent); + + connection.unbind(this); + }).startAndBind(this, true); }); viewBinding.trackListFabAction.setOnLongClickListener((view) -> { if (!recordingStatus.isRecording()) { @@ -289,14 +316,29 @@ public void bindView(View view, Context context, Cursor cursor) { ActivityUtils.vibrate(this, 1000); updateGpsMenuItem(false, false); trackRecordingServiceConnection.stopRecording(TrackListActivity.this); - viewBinding.trackListFabAction.setImageResource(R.drawable.ic_baseline_record_24); + viewBinding.trackListFabAction.setImageResource(R.drawable.start); viewBinding.trackListFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.red_dark)); selectedDelayInSeconds=0; return true; }); setSupportActionBar(viewBinding.trackListToolbar); + if (recordingStatus.isRecording()) { + Toast.makeText(TrackListActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show(); + return; + } + + // Not Recording -> Recording + updateGpsMenuItem(false, true); + new TrackRecordingServiceConnection((service, connection) -> { + //Track.Id trackId = service.startNewTrack(); + + Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackRecordingActivity.class); +// newIntent.putExtra(TrackRecordingActivity.EXTRA_TRACK_ID, trackId); + startActivity(newIntent); + connection.unbind(this); + }).startAndBind(this, true); loadData(getIntent()); } @@ -656,7 +698,9 @@ public void onGpsStatusChanged(GpsStatusValue newStatus) { } private void setFloatButton() { - viewBinding.trackListFabAction.setImageResource(recordingStatus.isRecording() ? R.drawable.ic_baseline_stop_24 : R.drawable.ic_baseline_record_24); + viewBinding.trackListFabAction.setImageResource(recordingStatus.isRecording() ? R.drawable.stop : R.drawable.start); +// viewBinding.trackListFabAction.setTex + viewBinding.trackListFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, recordingStatus.isRecording() ? R.color.opentracks : R.color.red_dark)); } diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index d6e686008..4a384d745 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -5,14 +5,15 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Build; import android.os.Bundle; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; +import android.widget.Button; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.appcompat.widget.SearchView; import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; @@ -112,30 +113,40 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); contentProviderUtils = new ContentProviderUtils(this); - trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID); - if (trackId == null) { - throw new RuntimeException("TrackId is mandatory"); - } - if (contentProviderUtils.getTrack(trackId) == null) { - Log.w(TAG, "TrackId does not exists."); - finish(); + if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){ + trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID); + trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); } - trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); + +// if (trackId == null) { +// throw new RuntimeException("TrackId is mandatory"); +// } +// if (contentProviderUtils.getTrack(trackId) == null) { +// Log.w(TAG, "TrackId does not exists."); +// finish(); +// } + + trackDataHub = new TrackDataHub(this); CustomFragmentPagerAdapter pagerAdapter = new CustomFragmentPagerAdapter(this); viewBinding.trackDetailActivityViewPager.setAdapter(pagerAdapter); - new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager, - (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach(); - if (savedInstanceState != null) { - viewBinding.trackDetailActivityViewPager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY)); +// new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager, +// (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach(); +// if (savedInstanceState != null) { +// viewBinding.trackDetailActivityViewPager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY)); +// } + + if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){ + viewBinding.trackRecordingFabAction.setImageResource(R.drawable.stop); + }else{ + viewBinding.trackRecordingFabAction.setImageResource(R.drawable.start); } - viewBinding.trackRecordingFabAction.setImageResource(R.drawable.ic_baseline_stop_24); viewBinding.trackRecordingFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); viewBinding.trackRecordingFabAction.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); - viewBinding.trackRecordingFabAction.setOnLongClickListener((view) -> { + viewBinding.trackRecordingFabAction.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 1000); trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) @@ -143,14 +154,48 @@ protected void onCreate(Bundle savedInstanceState) { startActivity(newIntent); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); finish(); - return true; }); + viewBinding.trackRecordingFabAction.setOnClickListener((view) -> Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show()); viewBinding.bottomAppBar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24); setSupportActionBar(viewBinding.bottomAppBar); + setSupportActionBar(viewBinding.trackListToolbar); + viewBinding.trackRecordingFabAction.setOnClickListener(v -> startRecording(pagerAdapter)); + + viewBinding.trackRecordingFabAction.setOnLongClickListener((view) -> { + ActivityUtils.vibrate(this, 1000); + trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); + Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) + .putExtra(TrackStoppedActivity.EXTRA_TRACK_ID, trackId); + startActivity(newIntent); + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); + finish(); + return true; + }); + } + void startRecording(CustomFragmentPagerAdapter pagerAdapter) { + if (recordingStatus.isRecording()) { + Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show(); + return; + } + // Not Recording -> Recording + // updateGpsMenuItem(false, true); + new TrackRecordingServiceConnection((service, connection) -> { + trackId = service.startNewTrack(); + trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); + trackRecordingServiceConnection.startConnection(this); + }).startAndBind(this, true); + + new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager, + (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach(); + viewBinding.bottomAppBar.setVisibility(View.VISIBLE); + + viewBinding.trackRecordingFabAction.setImageResource(R.drawable.stop); + + } @Override public void onAttachedToWindow() { setLockscreenPolicy(); @@ -208,7 +253,10 @@ protected void onStart() { PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); - trackRecordingServiceConnection.startConnection(this); + if (trackRecordingServiceConnection != null) { + trackRecordingServiceConnection.startConnection(this); + } + trackDataHub.start(); } @@ -225,7 +273,10 @@ protected void onResume() { trackDataHub.setRecordingStatus(recordingStatus); } - trackRecordingServiceConnection.startAndBindWithCallback(this); + if (trackRecordingServiceConnection != null) { + trackRecordingServiceConnection.startAndBindWithCallback(this); + } + } @Override @@ -234,11 +285,19 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { outState.putInt(CURRENT_TAB_TAG_KEY, viewBinding.trackDetailActivityViewPager.getCurrentItem()); } + @Override + protected void onPause() { + super.onPause(); + if (trackRecordingServiceConnection != null) { + trackRecordingServiceConnection.unbind(this); + } + } + @Override protected void onStop() { super.onStop(); PreferencesUtils.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); - trackRecordingServiceConnection.unbind(this); + trackDataHub.stop(); } @@ -257,7 +316,7 @@ protected View getRootView() { @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.track_record, menu); + getMenuInflater().inflate(R.menu.track_menu_custom, menu); return super.onCreateOptionsMenu(menu); } @@ -305,6 +364,17 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } + if (item.getItemId() == R.id.track_list_settings) { + startActivity(IntentUtils.newIntent(this, SettingsActivity.class)); + return true; + } + + + if (item.getItemId() == R.id.track_list_help) { + startActivity(IntentUtils.newIntent(this, HelpActivity.class)); + return true; + } + return super.onOptionsItemSelected(item); } diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 03ddd5fc4..668f46996 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -5,6 +5,7 @@ import android.util.Log; import android.util.Pair; import android.view.View; +import android.widget.Button; import android.widget.ArrayAdapter; import de.dennisguse.opentracks.data.ContentProviderUtils; @@ -96,7 +97,10 @@ protected void onCreate(Bundle savedInstanceState) { finish(); }); - viewBinding.resumeButton.setOnClickListener(v -> { + + Button resumeButton = findViewById(R.id.resume_button); + resumeButton.setText("RESUME"); + resumeButton.setOnClickListener(v -> { storeTrackMetaData(contentProviderUtils, track); resumeTrackAndFinish(); }); diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index 814109143..9036eaa86 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -119,7 +119,7 @@ public void onCreate() { @Override public void onDestroy() { Log.d(TAG, "Destroying"); - if (isRecording()) { + if (recordingStatus.isRecording()) { endCurrentTrack(); } diff --git a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java index 34b8c4991..59964ea98 100644 --- a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java +++ b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java @@ -183,6 +183,8 @@ public void announce(@NonNull Track track) { } } + + if (Arrays.asList(AudioManager.MODE_IN_CALL, AudioManager.MODE_IN_COMMUNICATION) .contains(audioManager.getMode())) { Log.i(TAG, "Announcement is not allowed at this time."); @@ -200,6 +202,8 @@ public void announce(@NonNull Track track) { return; } + + Distance currentIntervalDistance = PreferencesUtils.getVoiceAnnouncementDistance(); if (currentIntervalDistance != intervalDistance) { intervalStatistics = new IntervalStatistics(currentIntervalDistance); @@ -215,7 +219,10 @@ public void announce(@NonNull Track track) { sensorStatistics = contentProviderUtils.getSensorStats(track.getId()); } - Spannable announcement = VoiceAnnouncementUtils.getAnnouncement(context, track.getTrackStatistics(), PreferencesUtils.getUnitSystem(), PreferencesUtils.isReportSpeed(track), lastInterval, sensorStatistics); +// Spannable announcement = VoiceAnnouncementUtils.getAnnouncement(context, track.getTrackStatistics(), PreferencesUtils.getUnitSystem(), PreferencesUtils.isReportSpeed(track), lastInterval, sensorStatistics); + // SpannableStringBuilder announcement = new SpannableStringBuilder(); + Spannable announcement = VoiceAnnouncementUtils.getMotivationalAnnouncements(); + // announcement.append("good job"); if (announcement.length() > 0) { // We don't care about the utterance id. It is supplied here to force onUtteranceCompleted to be called. diff --git a/src/main/res/drawable/ic_baseline_play_arrow_24.xml b/src/main/res/drawable/ic_baseline_play_arrow_24.xml new file mode 100644 index 000000000..88a06e5d4 --- /dev/null +++ b/src/main/res/drawable/ic_baseline_play_arrow_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/main/res/drawable/start.xml b/src/main/res/drawable/start.xml new file mode 100644 index 000000000..c2604bd10 --- /dev/null +++ b/src/main/res/drawable/start.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/src/main/res/drawable/stop.xml b/src/main/res/drawable/stop.xml new file mode 100644 index 000000000..7df5edba9 --- /dev/null +++ b/src/main/res/drawable/stop.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/src/main/res/layout/interval_list_view.xml b/src/main/res/layout/interval_list_view.xml index aaf36bd8b..f518f9f8c 100644 --- a/src/main/res/layout/interval_list_view.xml +++ b/src/main/res/layout/interval_list_view.xml @@ -14,7 +14,7 @@ android:layout_marginBottom="8dp" android:hint="@string/stats_split_interval"> - + tools:text="100" + /> + android:layout_height="match_parent"> + + + + + + app:menu="@menu/track_record" + app:navigationIcon="@drawable/ic_logo_color_24dp" /> \ No newline at end of file diff --git a/src/main/res/layout/track_stopped.xml b/src/main/res/layout/track_stopped.xml index 4aca4c419..f98467dc6 100644 --- a/src/main/res/layout/track_stopped.xml +++ b/src/main/res/layout/track_stopped.xml @@ -197,10 +197,11 @@ app:tint="?attr/colorOnBackground" app:srcCompat="@drawable/ic_delete_forever_24dp" /> - + + + + + + + \ No newline at end of file