enabled swipe action on notification

master
y20k 2016-09-07 15:48:12 +02:00
parent 87636e9a64
commit c5a85abb3b
4 changed files with 47 additions and 18 deletions

View File

@ -38,6 +38,7 @@ import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import org.y20k.trackbook.helpers.NotificationHelper;
import org.y20k.trackbook.helpers.TrackbookKeys;
import java.util.ArrayList;
@ -148,6 +149,10 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
mMainActivityFragment.setTrackingState(mTrackerServiceRunning);
}
if (intent.hasExtra(EXTRA_CLEAR_MAP)) {
clearMap();
}
// if not in onboarding mode: set state of FloatingActionButton
if (mFloatingActionButton != null) {
setFloatingActionButtonState();
@ -218,6 +223,18 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
handleFloatingActionButtonClick(view);
}
});
mFloatingActionButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (mTrackerServiceRunning) {
return false;
} else {
clearMap();
NotificationHelper.stop();
return true;
}
}
});
} else {
// point to the on main onboarding layout
@ -289,6 +306,13 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
}
/* Removes track crumbs from map */
private void clearMap() {
Toast.makeText(this, "Clearing map", Toast.LENGTH_LONG).show(); // TODO remove
}
/* Check which permissions have been granted */
private List<String> checkPermissions() {
List<String> permissions = new ArrayList<>();

View File

@ -94,27 +94,30 @@ public class NotificationHelper implements TrackbookKeys {
String contentText = mService.getString(R.string.notification_content_distance) + ": " + track.getTrackDistance() + " | " +
mService.getString(R.string.notification_content_duration) + " : " + track.getTrackDuration();
// explicit intent for notification tap
// CASE: NOTIFICATION TAP
Intent tapActionIntent = new Intent(mService, MainActivity.class);
tapActionIntent.setAction(Intent.ACTION_MAIN);
tapActionIntent.addCategory(Intent.CATEGORY_LAUNCHER);
tapActionIntent.putExtra(EXTRA_TRACK, track);
tapActionIntent.putExtra(EXTRA_TRACKING_STATE, true);
tapActionIntent.putExtra(EXTRA_TRACKING_STATE, tracking);
// artificial back stack for started Activity (https://developer.android.com/training/notify-user/navigation.html#DirectEntry)
TaskStackBuilder tapActionIntentBuilder = TaskStackBuilder.create(mService);
tapActionIntentBuilder.addParentStack(MainActivity.class);
tapActionIntentBuilder.addNextIntent(tapActionIntent);
// pending intent wrapper for notification tap
PendingIntent tapActionPendingIntent = tapActionIntentBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// explicit intent for stopping playback
// CASE: NOTIFICATION SWIPE
Intent swipeActionIntent = new Intent(mService, MainActivity.class);
swipeActionIntent.putExtra(EXTRA_CLEAR_MAP, tracking);
// artificial back stack for started Activity (https://developer.android.com/training/notify-user/navigation.html#DirectEntry)
TaskStackBuilder swipeActionIntentBuilder = TaskStackBuilder.create(mService);
swipeActionIntentBuilder.addParentStack(MainActivity.class);
swipeActionIntentBuilder.addNextIntent(swipeActionIntent);
// pending intent wrapper for notification tap
PendingIntent swipeActionPendingIntent = swipeActionIntentBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// CASE: NOTIFICATION BUTTON STOP
Intent stopActionIntent = new Intent(mService, TrackerService.class);
stopActionIntent.setAction(ACTION_STOP);
// artificial back stack for started Activity.
// -> navigating backward from the Activity leads to Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mService);
// // backstack: adds back stack for Intent (but not the Intent itself)
// stackBuilder.addParentStack(MainActivity.class);
// backstack: add explicit intent for notification tap
stackBuilder.addNextIntent(tapActionIntent);
// pending intent wrapper for notification tap
PendingIntent tapActionPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// pending intent wrapper for notification stop action
PendingIntent stopActionPendingIntent = PendingIntent.getService(mService, 0, stopActionIntent, 0);
@ -133,10 +136,10 @@ public class NotificationHelper implements TrackbookKeys {
// third line of text - only appears in expanded view
// builder.setSubText();
} else {
builder.setDeleteIntent(swipeActionPendingIntent);
builder.setContentTitle(mService.getString(R.string.notification_title_trackbook_not_running));
builder.setContentText(contentText);
// third line of text - only appears in expanded view
// builder.setSubText();
builder.setSubText(mService.getString(R.string.notification_swipe_to_clear_map));
}
return builder;

View File

@ -32,6 +32,7 @@ public interface TrackbookKeys {
public static final String EXTRA_TRACK = "TRACK";
public static final String EXTRA_LAST_LOCATION = "LAST_LOCATION";
public static final String EXTRA_TRACKING_STATE = "TRACKING_STATE";
public static final String EXTRA_CLEAR_MAP = "CLEAR_MAP";
public static final String EXTRA_INFOSHEET_TITLE = "EXTRA_INFOSHEET_TITLE";
public static final String EXTRA_INFOSHEET_CONTENT = "INFOSHEET_CONTENT";

View File

@ -14,6 +14,7 @@
<string name="notification_title_trackbook_running">Trackbook running</string>
<string name="notification_title_trackbook_not_running">Trackbook not running</string>
<string name="notification_stop">Stop</string>
<string name="notification_swipe_to_clear_map">&#8230; swipe to clear map.</string>
<string name="notification_content_duration">Duration</string>
<string name="notification_content_distance">Distance</string>