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 #300 from rilling/183-change-initial-start-screen
Browse files Browse the repository at this point in the history
183 change initial start screen
  • Loading branch information
denzz312 authored Nov 27, 2023
2 parents 61cc5fe + b0c1e58 commit 8b247a3
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 38 deletions.
52 changes: 48 additions & 4 deletions src/main/java/de/dennisguse/opentracks/TrackListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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());
}

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

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

PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

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

trackDataHub.start();
}

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

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

}

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void onCreate() {
@Override
public void onDestroy() {
Log.d(TAG, "Destroying");
if (isRecording()) {
if (recordingStatus.isRecording()) {
endCurrentTrack();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -200,6 +202,8 @@ public void announce(@NonNull Track track) {
return;
}



Distance currentIntervalDistance = PreferencesUtils.getVoiceAnnouncementDistance();
if (currentIntervalDistance != intervalDistance) {
intervalStatistics = new IntervalStatistics(currentIntervalDistance);
Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/main/res/drawable/ic_baseline_play_arrow_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M8,5v14l11,-7z"/>
</vector>
Loading

0 comments on commit 8b247a3

Please sign in to comment.