Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #198 from rilling/group6_C2
Browse files Browse the repository at this point in the history
Added resume and finish button in pause mode
  • Loading branch information
pranjalesh authored Nov 27, 2023
2 parents 7e7acfa + af9a981 commit de57c29
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 141 deletions.
29 changes: 14 additions & 15 deletions src/main/java/de/dennisguse/opentracks/TrackListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
};
Expand Down Expand Up @@ -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) -> {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
});
Expand Down Expand Up @@ -363,7 +363,7 @@ protected void onResume() {
LoaderManager.getInstance(this).restartLoader(0, null, loaderCallbacks);

// Float button
setFloatButton();
// setFloatButton();
}

@Override
Expand Down Expand Up @@ -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
Expand Down
116 changes: 23 additions & 93 deletions src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,89 +112,45 @@ 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)
.putExtra(TrackStoppedActivity.EXTRA_TRACK_ID, trackId);
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();
Expand Down Expand Up @@ -253,10 +208,7 @@ protected void onStart() {

PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

if (trackRecordingServiceConnection != null) {
trackRecordingServiceConnection.startConnection(this);
}

trackRecordingServiceConnection.startConnection(this);
trackDataHub.start();
}

Expand All @@ -273,10 +225,7 @@ protected void onResume() {
trackDataHub.setRecordingStatus(recordingStatus);
}

if (trackRecordingServiceConnection != null) {
trackRecordingServiceConnection.startAndBindWithCallback(this);
}

trackRecordingServiceConnection.startAndBindWithCallback(this);
}

@Override
Expand All @@ -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();
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 12 additions & 8 deletions src/main/res/layout/track_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ limitations under the License.
</com.google.android.material.appbar.AppBarLayout>

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
Expand Down Expand Up @@ -133,13 +134,16 @@ limitations under the License.

</com.google.android.material.bottomappbar.BottomAppBar>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/track_list_fab_action"
android:tint="@android:color/white"
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/image_record"
android:src="@drawable/ic_baseline_record_24"
app:layout_anchor="@id/bottom_app_bar" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
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" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
18 changes: 12 additions & 6 deletions src/main/res/layout/track_recording.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="709dp"
android:orientation="vertical"
Expand Down Expand Up @@ -53,12 +54,17 @@
app:menu="@menu/track_record"
app:navigationIcon="@drawable/ic_logo_color_24dp" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/track_recording_fab_action"
<Button
android:id="@+id/hold_to_stop_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/image_stop"
android:src="@drawable/ic_baseline_record_24"
app:layout_anchor="@id/bottom_app_bar" />
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" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading

0 comments on commit de57c29

Please sign in to comment.