diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index 841ce9527..ddb649616 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -122,7 +122,7 @@ public void onPrepare(Menu menu, int[] positions, long[] trackIds, boolean showS boolean isSingleSelection = trackIds.length == 1; viewBinding.bottomAppBar.performHide(true); - viewBinding.trackListFabAction.setVisibility(View.INVISIBLE); + viewBinding.button.setVisibility(View.INVISIBLE); menu.findItem(R.id.list_context_menu_edit).setVisible(isSingleSelection); menu.findItem(R.id.list_context_menu_select_all).setVisible(showSelectAll); @@ -135,7 +135,7 @@ public boolean onClick(int itemId, int[] positions, long[] trackIds) { @Override public void onDestroy() { - viewBinding.trackListFabAction.setVisibility(View.VISIBLE); + viewBinding.button.setVisibility(View.VISIBLE); viewBinding.bottomAppBar.performShow(true); } }; @@ -211,7 +211,7 @@ public void onClick(View v) { LoaderManager.getInstance(this).restartLoader(0, null, loaderCallbacks); // Float button - setFloatButton(); +// setFloatButton(); viewBinding.trackList.setEmptyView(viewBinding.trackListEmptyView); viewBinding.trackList.setOnItemClickListener((parent, view, position, trackIdId) -> { @@ -271,7 +271,7 @@ public void bindView(View view, Context context, Cursor cursor) { viewBinding.trackList.setAdapter(resourceCursorAdapter); ActivityUtils.configureListViewContextualMenu(viewBinding.trackList, contextualActionModeCallback); - viewBinding.trackListFabAction.setOnClickListener((view) -> { + viewBinding.button.setOnClickListener((view) -> { if (recordingStatus.isRecording()) { Toast.makeText(TrackListActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show(); return; @@ -307,7 +307,7 @@ public void bindView(View view, Context context, Cursor cursor) { connection.unbind(this); }).startAndBind(this, true); }); - viewBinding.trackListFabAction.setOnLongClickListener((view) -> { + viewBinding.button.setOnLongClickListener((view) -> { if (!recordingStatus.isRecording()) { return false; } @@ -316,8 +316,8 @@ 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.start); - viewBinding.trackListFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.red_dark)); + // viewBinding.button.setImageResource(R.drawable.ic_baseline_record_24); + viewBinding.button.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.red_dark)); selectedDelayInSeconds=0; return true; }); @@ -363,7 +363,7 @@ protected void onResume() { LoaderManager.getInstance(this).restartLoader(0, null, loaderCallbacks); // Float button - setFloatButton(); +// setFloatButton(); } @Override @@ -697,18 +697,17 @@ public void onGpsStatusChanged(GpsStatusValue newStatus) { updateGpsMenuItem(true, recordingStatus.isRecording()); } - private void setFloatButton() { - 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)); - } + // private void setFloatButton() { + // viewBinding.button.setImageResource(recordingStatus.isRecording() ? R.drawable.ic_baseline_stop_24 : R.drawable.ic_baseline_record_24); + // viewBinding.button.setBackgroundTintList(ContextCompat.getColorStateList(this, recordingStatus.isRecording() ? R.color.opentracks : R.color.red_dark)); + // } private void onRecordingStatusChanged(RecordingStatus status) { recordingStatus = status; - setFloatButton(); + // setFloatButton(); } + // Add a new method for handling the start recording action private void startRecording() { // Not Recording -> Recording diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index 4a384d745..754eebce3 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -5,15 +5,14 @@ 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; @@ -113,40 +112,30 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); contentProviderUtils = new ContentProviderUtils(this); - if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){ - trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID); - trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); + 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 (trackId == null) { -// throw new RuntimeException("TrackId is mandatory"); -// } -// if (contentProviderUtils.getTrack(trackId) == null) { -// Log.w(TAG, "TrackId does not exists."); -// finish(); -// } - - + trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); 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)); -// } - - if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){ - viewBinding.trackRecordingFabAction.setImageResource(R.drawable.stop); - }else{ - viewBinding.trackRecordingFabAction.setImageResource(R.drawable.start); + 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)); } - viewBinding.trackRecordingFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); - viewBinding.trackRecordingFabAction.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); - viewBinding.trackRecordingFabAction.setOnClickListener((view) -> { +// viewBinding.holdToStopButton.setImageResource(R.drawable.ic_baseline_stop_24); +// viewBinding.holdToStopButton.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); +// viewBinding.holdToStopButton.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); + viewBinding.holdToStopButton.setOnLongClickListener((view) -> { ActivityUtils.vibrate(this, 1000); trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) @@ -154,48 +143,14 @@ 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.holdToStopButton.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(); @@ -253,10 +208,7 @@ protected void onStart() { PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); - if (trackRecordingServiceConnection != null) { - trackRecordingServiceConnection.startConnection(this); - } - + trackRecordingServiceConnection.startConnection(this); trackDataHub.start(); } @@ -273,10 +225,7 @@ protected void onResume() { trackDataHub.setRecordingStatus(recordingStatus); } - if (trackRecordingServiceConnection != null) { - trackRecordingServiceConnection.startAndBindWithCallback(this); - } - + trackRecordingServiceConnection.startAndBindWithCallback(this); } @Override @@ -285,19 +234,11 @@ 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(); } @@ -316,7 +257,7 @@ protected View getRootView() { @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.track_menu_custom, menu); + getMenuInflater().inflate(R.menu.track_record, menu); return super.onCreateOptionsMenu(menu); } @@ -364,17 +305,6 @@ 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/res/layout/track_list.xml b/src/main/res/layout/track_list.xml index 5b14e2249..e4c66f854 100644 --- a/src/main/res/layout/track_list.xml +++ b/src/main/res/layout/track_list.xml @@ -32,6 +32,7 @@ limitations under the License. - - - \ No newline at end of file + android:layout_weight="1" + android:backgroundTint="#0B0A0A" + android:fontFamily="monospace" + android:text="START WORKOUT" + android:textStyle="bold" + app:layout_anchor="@+id/bottom_app_bar" + app:layout_anchorGravity="center" /> + + diff --git a/src/main/res/layout/track_recording.xml b/src/main/res/layout/track_recording.xml index b479ae259..a79743373 100644 --- a/src/main/res/layout/track_recording.xml +++ b/src/main/res/layout/track_recording.xml @@ -6,6 +6,7 @@ android:layout_height="match_parent"> - + android:backgroundTint="#020202" + android:fontFamily="monospace" + android:text="HOLD TO PAUSE" + android:textStyle="bold" + android:translationX="-20dp" + app:layout_anchor="@+id/bottom_app_bar" + app:layout_anchorGravity="end|center" /> + + - \ 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 f98467dc6..c2f4a1867 100644 --- a/src/main/res/layout/track_stopped.xml +++ b/src/main/res/layout/track_stopped.xml @@ -199,27 +199,31 @@