notification can resume tracking

This commit is contained in:
y20k 2018-03-20 15:15:57 +01:00
parent 00a291ac04
commit 4e4c6ae2bd
15 changed files with 113 additions and 23 deletions

View file

@ -39,7 +39,7 @@ import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -141,7 +141,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
mTrackingStoppedReceiver = createTrackingStoppedReceiver(); mTrackingStoppedReceiver = createTrackingStoppedReceiver();
IntentFilter trackingStoppedIntentFilter = new IntentFilter(ACTION_TRACKING_STOPPED); IntentFilter trackingStoppedIntentFilter = new IntentFilter(ACTION_TRACKING_STOPPED);
LocalBroadcastManager.getInstance(this).registerReceiver(mTrackingStoppedReceiver, trackingStoppedIntentFilter); LocalBroadcastManager.getInstance(this).registerReceiver(mTrackingStoppedReceiver, trackingStoppedIntentFilter);
} }
@ -642,6 +641,18 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
break; break;
case ACTION_CLEAR:
// show map fragment
mBottomNavigationView.setSelectedItemId(R.id.navigation_map);
// show clear dialog
handleClearButtonClick();
// clear intent
intent.setAction(ACTION_DEFAULT);
break;
default: default:
break; break;
} }
@ -715,12 +726,43 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
} }
// public class SectionsPagerAdapter extends FragmentPagerAdapter {
//
// public SectionsPagerAdapter(FragmentManager fm) {
// super(fm);
// }
//
// @Override
// public Fragment getItem(int position) {
// // getItem is called to instantiate the fragment for the given page.
// switch (position) {
// case FRAGMENT_ID_MAP:
// return new MainActivityMapFragment();
// case FRAGMENT_ID_TRACKS:
// return new MainActivityTrackFragment();
// }
// return null;
// }
//
// @Override
// public int getCount() {
// return 2;
// }
//
// public Fragment getFragment(int pos) {
// return getItem(pos);
// }
//
// }
/** /**
* Inner class: SectionsPagerAdapter that returns a fragment corresponding to one of the tabs. * Inner class: SectionsPagerAdapter that returns a fragment corresponding to one of the tabs.
* see also: https://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html * see also: https://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
* and: http://www.truiton.com/2015/12/android-activity-fragment-communication/ * and: http://www.truiton.com/2015/12/android-activity-fragment-communication/
*/ */
public class SectionsPagerAdapter extends FragmentPagerAdapter { public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
private final SparseArray<WeakReference<Fragment>> instantiatedFragments = new SparseArray<>(); private final SparseArray<WeakReference<Fragment>> instantiatedFragments = new SparseArray<>();
@ -742,7 +784,7 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
@Override @Override
public int getCount() { public int getCount() {
// Show 2 total pages. // show 2 total pages.
return 2; return 2;
} }

View file

@ -54,7 +54,7 @@ public final class NotificationHelper implements TrackbookKeys {
// build context text for notification builder // build context text for notification builder
String contentText = getContextString(context, track); String contentText = getContextString(context, track);
// ACTION: NOTIFICATION TAP // ACTION: NOTIFICATION TAP & BUTTON SHOW
Intent tapActionIntent = new Intent(context, MainActivity.class); Intent tapActionIntent = new Intent(context, MainActivity.class);
tapActionIntent.setAction(ACTION_SHOW_MAP); tapActionIntent.setAction(ACTION_SHOW_MAP);
tapActionIntent.putExtra(EXTRA_TRACK, track); tapActionIntent.putExtra(EXTRA_TRACK, track);
@ -70,7 +70,13 @@ public final class NotificationHelper implements TrackbookKeys {
Intent stopActionIntent = new Intent(context, TrackerService.class); Intent stopActionIntent = new Intent(context, TrackerService.class);
stopActionIntent.setAction(ACTION_STOP); stopActionIntent.setAction(ACTION_STOP);
// pending intent wrapper for notification stop action // pending intent wrapper for notification stop action
PendingIntent stopActionPendingIntent = PendingIntent.getService(context, 12, stopActionIntent, 0); PendingIntent stopActionPendingIntent = PendingIntent.getService(context, 14, stopActionIntent, 0);
// ACTION: NOTIFICATION BUTTON RESUME
Intent resumeActionIntent = new Intent(context, TrackerService.class);
resumeActionIntent.setAction(ACTION_RESUME);
// pending intent wrapper for notification resume action
PendingIntent resuneActionPendingIntent = PendingIntent.getService(context, 16, resumeActionIntent, 0);
// construct notification in builder // construct notification in builder
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
@ -79,10 +85,12 @@ public final class NotificationHelper implements TrackbookKeys {
builder.setSmallIcon(R.drawable.ic_notification_small_24dp); builder.setSmallIcon(R.drawable.ic_notification_small_24dp);
builder.setLargeIcon(getNotificationIconLarge(context, tracking)); builder.setLargeIcon(getNotificationIconLarge(context, tracking));
if (tracking) { if (tracking) {
builder.addAction(R.drawable.ic_stop_white_36dp, context.getString(R.string.notification_stop), stopActionPendingIntent); builder.addAction(R.drawable.ic_stop_white_24dp, context.getString(R.string.notification_stop), stopActionPendingIntent);
builder.setContentTitle(context.getString(R.string.notification_title_trackbook_running)); builder.setContentTitle(context.getString(R.string.notification_title_trackbook_running));
builder.setContentText(getContextString(context, track)); builder.setContentText(getContextString(context, track));
} else { } else {
builder.addAction(R.drawable.ic_fiber_manual_record_white_24dp, context.getString(R.string.notification_resume), resuneActionPendingIntent);
builder.addAction(R.drawable.ic_compass_needle_white_24dp, context.getString(R.string.notification_show), tapActionPendingIntent);
builder.setContentTitle(context.getString(R.string.notification_title_trackbook_not_running)); builder.setContentTitle(context.getString(R.string.notification_title_trackbook_not_running));
builder.setContentText(getContextString(context, track)); builder.setContentText(getContextString(context, track));
} }

View file

@ -27,6 +27,8 @@ public interface TrackbookKeys {
String ACTION_STOP = "org.y20k.trackbook.action.STOP"; String ACTION_STOP = "org.y20k.trackbook.action.STOP";
String ACTION_DISMISS = "org.y20k.transistor.action.DISMISS"; String ACTION_DISMISS = "org.y20k.transistor.action.DISMISS";
String ACTION_RESUME = "org.y20k.transistor.action.RESUME"; String ACTION_RESUME = "org.y20k.transistor.action.RESUME";
String ACTION_CLEAR = "org.y20k.transistor.action.CLEAR";
String ACTION_SAVE = "org.y20k.transistor.action.SAVE";
String ACTION_DEFAULT = "DEFAULT"; String ACTION_DEFAULT = "DEFAULT";
String ACTION_SHOW_MAP = "SHOW_MAP"; String ACTION_SHOW_MAP = "SHOW_MAP";
String ACTION_TRACK_UPDATED = "TRACK_UPDATED"; String ACTION_TRACK_UPDATED = "TRACK_UPDATED";

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/trackbook_white"
android:pathData="M21,3L3,10.53v0.98l6.84,2.65L12.48,21h0.98L21,3z"/>
</vector>

View file

@ -1,9 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="36dp" android:width="24dp"
android:viewportHeight="24.0" android:height="24dp"
android:viewportWidth="24.0" android:viewportWidth="24.0"
android:width="36dp"> android:viewportHeight="24.0">
<path <path
android:fillColor="@color/trackbook_white" android:fillColor="@color/trackbook_white"
android:pathData="M6,6h12v12H6z"/> android:pathData="M6,6h12v12H6z"/>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/onboarding" > android:id="@+id/onboarding" >
@ -30,13 +31,13 @@
android:layout_marginTop="@dimen/activity_vertical_margin" > android:layout_marginTop="@dimen/activity_vertical_margin" >
<ImageView <ImageView
android:id="@+id/trackbook_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/trackbook_icon" android:layout_gravity="center_vertical"
android:background="@mipmap/ic_launcher"
android:contentDescription="@string/layout_onboarding_description_app_icon"
android:layout_marginEnd="@dimen/activity_horizontal_margin" android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_gravity="center_vertical" /> android:contentDescription="@string/layout_onboarding_description_app_icon"
app:srcCompat="@mipmap/ic_launcher" />
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"

View file

@ -26,7 +26,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:background="@color/trackbook_transparent" android:backgroundTint="@color/trackbook_transparent"
android:contentDescription="@string/descr_export_button" android:contentDescription="@string/descr_export_button"
app:layout_constraintBottom_toBottomOf="@+id/track_selector" app:layout_constraintBottom_toBottomOf="@+id/track_selector"
app:layout_constraintEnd_toStartOf="@+id/delete_button" app:layout_constraintEnd_toStartOf="@+id/delete_button"
@ -38,7 +38,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/activity_horizontal_margin" android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:background="@color/trackbook_transparent" android:backgroundTint="@color/trackbook_transparent"
android:contentDescription="@string/descr_delete_button" android:contentDescription="@string/descr_delete_button"
app:layout_constraintBottom_toBottomOf="@+id/export_button" app:layout_constraintBottom_toBottomOf="@+id/export_button"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:gravity="center" android:gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -16,11 +17,11 @@
android:text="@string/track_tab_onboarding_h1_part_1" /> android:text="@string/track_tab_onboarding_h1_part_1" />
<ImageView <ImageView
android:id="@+id/trackbook_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/trackbook_icon" android:contentDescription="@string/layout_onboarding_description_app_icon"
android:background="@mipmap/ic_launcher" app:srcCompat="@mipmap/ic_launcher" />
android:contentDescription="@string/layout_onboarding_description_app_icon" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -11,6 +11,10 @@
<string name="notification_title_trackbook_not_running">Trackbook ist inaktiv</string> <string name="notification_title_trackbook_not_running">Trackbook ist inaktiv</string>
<string name="notification_title_trackbook_running">Trackbook wird ausgeführt</string> <string name="notification_title_trackbook_running">Trackbook wird ausgeführt</string>
<string name="notification_stop">Stopp</string> <string name="notification_stop">Stopp</string>
<string name="notification_clear">Zurücksetzen</string>
<string name="notification_save">Speichernn</string>
<string name="notification_resume">Fortsetzen</string>
<string name="notification_show">Show</string>
<string name="notification_content_duration">Dauer</string> <string name="notification_content_duration">Dauer</string>
<string name="notification_content_distance">Entfernung</string> <string name="notification_content_distance">Entfernung</string>
<string name="notification_channel_recording_name">Status der Aufzeichnung</string> <string name="notification_channel_recording_name">Status der Aufzeichnung</string>

View file

@ -11,6 +11,10 @@
<string name="notification_title_trackbook_running">Trackbook aktif</string> <string name="notification_title_trackbook_running">Trackbook aktif</string>
<string name="notification_title_trackbook_not_running">Trackbook tidak aktif</string> <string name="notification_title_trackbook_not_running">Trackbook tidak aktif</string>
<string name="notification_stop">Berhenti</string> <string name="notification_stop">Berhenti</string>
<string name="notification_clear">Clear</string>
<string name="notification_save">Save</string>
<string name="notification_resume">Resume</string>
<string name="notification_show">Show</string>
<string name="notification_content_duration">Durasi</string> <string name="notification_content_duration">Durasi</string>
<string name="notification_content_distance">Jarak</string> <string name="notification_content_distance">Jarak</string>
<string name="notification_channel_recording_name">Movement Recording State</string> <string name="notification_channel_recording_name">Movement Recording State</string>
@ -24,7 +28,7 @@
<!-- fab sub menu --> <!-- fab sub menu -->
<string name="fab_sub_menu_clear">Clear</string> <string name="fab_sub_menu_clear">Clear</string>
<string name="fab_sub_menu_save">Save and Clear</string> <string name="fab_sub_menu_save">Save</string>
<string name="fab_sub_menu_resume">Resume</string> <string name="fab_sub_menu_resume">Resume</string>
<!-- dialogs --> <!-- dialogs -->

View file

@ -11,6 +11,10 @@
<string name="notification_title_trackbook_running">Trackbook in esecuzione</string> <string name="notification_title_trackbook_running">Trackbook in esecuzione</string>
<string name="notification_title_trackbook_not_running">Trackbook non in esecuzione</string> <string name="notification_title_trackbook_not_running">Trackbook non in esecuzione</string>
<string name="notification_stop">Stop</string> <string name="notification_stop">Stop</string>
<string name="notification_clear">Cancella</string>
<string name="notification_save">Salva e ripristina la mappa</string>
<string name="notification_resume">Resume</string>
<string name="notification_show">Show</string>
<string name="notification_content_duration">Durata</string> <string name="notification_content_duration">Durata</string>
<string name="notification_content_distance">Distanza</string> <string name="notification_content_distance">Distanza</string>
<string name="notification_channel_recording_name">Stato registrazione</string> <string name="notification_channel_recording_name">Stato registrazione</string>

View file

@ -11,6 +11,10 @@
<string name="notification_title_trackbook_running">Trackbook 実行中</string> <string name="notification_title_trackbook_running">Trackbook 実行中</string>
<string name="notification_title_trackbook_not_running">Trackbook は実行していません</string> <string name="notification_title_trackbook_not_running">Trackbook は実行していません</string>
<string name="notification_stop">停止</string> <string name="notification_stop">停止</string>
<string name="notification_clear">クリア</string>
<string name="notification_save">保存してクリア</string>
<string name="notification_esume">Resume</string>
<string name="notification_show">Show</string>
<string name="notification_content_duration">期間</string> <string name="notification_content_duration">期間</string>
<string name="notification_content_distance">距離</string> <string name="notification_content_distance">距離</string>
<string name="notification_channel_recording_name">移動記録状態</string> <string name="notification_channel_recording_name">移動記録状態</string>

View file

@ -11,6 +11,10 @@
<string name="notification_title_trackbook_running">Trackbook kjører</string> <string name="notification_title_trackbook_running">Trackbook kjører</string>
<string name="notification_title_trackbook_not_running">Trackbook kjører ikke</string> <string name="notification_title_trackbook_not_running">Trackbook kjører ikke</string>
<string name="notification_stop">Stopp</string> <string name="notification_stop">Stopp</string>
<string name="notification_clear">Tøm</string>
<string name="notification_save">Lagre og tøm</string>
<string name="notification_resume">Fortsett</string>
<string name="notification_show">Show</string>
<string name="notification_content_duration">Varighet</string> <string name="notification_content_duration">Varighet</string>
<string name="notification_content_distance">Distanse</string> <string name="notification_content_distance">Distanse</string>
<string name="notification_channel_recording_name">Bevegelsesopptakstilstand</string> <string name="notification_channel_recording_name">Bevegelsesopptakstilstand</string>

View file

@ -11,6 +11,10 @@
<string name="notification_title_trackbook_running">Trackbook is actief</string> <string name="notification_title_trackbook_running">Trackbook is actief</string>
<string name="notification_title_trackbook_not_running">Trackbook is niet actief</string> <string name="notification_title_trackbook_not_running">Trackbook is niet actief</string>
<string name="notification_stop">Stoppen</string> <string name="notification_stop">Stoppen</string>
<string name="notification_clear">Wissen</string>
<string name="notification_save">Opslaan en wissen</string>
<string name="notification_resume">Resume</string>
<string name="notification_show">Show</string>
<string name="notification_content_duration">Duur</string> <string name="notification_content_duration">Duur</string>
<string name="notification_content_distance">Afstand</string> <string name="notification_content_distance">Afstand</string>
<string name="notification_channel_recording_name">Movement Recording State</string> <string name="notification_channel_recording_name">Movement Recording State</string>

View file

@ -11,6 +11,10 @@
<string name="notification_title_trackbook_running">Trackbook running</string> <string name="notification_title_trackbook_running">Trackbook running</string>
<string name="notification_title_trackbook_not_running">Trackbook not running</string> <string name="notification_title_trackbook_not_running">Trackbook not running</string>
<string name="notification_stop">Stop</string> <string name="notification_stop">Stop</string>
<string name="notification_clear">Clear</string>
<string name="notification_save">Save</string>
<string name="notification_resume">Resume</string>
<string name="notification_show">Show</string>
<string name="notification_content_duration">Duration</string> <string name="notification_content_duration">Duration</string>
<string name="notification_content_distance">Distance</string> <string name="notification_content_distance">Distance</string>
<string name="notification_channel_recording_name">Movement Recording State</string> <string name="notification_channel_recording_name">Movement Recording State</string>