/* * Logout button click action */ public void logOut(View v) { PlaceItDb instance = PlaceItDb.getInstance(); List<PlaceIt> placeIts = PlaceItList.all(); for (PlaceIt placeIt : placeIts) { // disable all trackLocations placeIt.trackLocation(this, false); // disable all alarms placeIt.setAlarm(this, false); // drop the current table // instance.delete(placeIt); } // disable the current user SyncClient.logOut(); // stop checking for Categorical stopService(checker); // stop syncing stopService(syncing); // return to login window Intent returnSignUp = new Intent(this, MainActivity.class); startActivity(returnSignUp); finish(); }
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); int pID; if ((pID = bundle.getInt(MainActivity.PLACEIT_ID, -1)) == -1) throw new RuntimeException("Notification not used correctly: pID not found"); PlaceItNotification.cancel(context, pID); PlaceIt placeIt = PlaceItList.find(pID); if (bundle.get(BUTTON_TAG).equals(R.string.notification_discard)) { placeIt.discard(context); Toast.makeText(context, "Place-it discarded.", Toast.LENGTH_LONG).show(); } else if (bundle.get(BUTTON_TAG).equals(R.string.notification_repost)) { placeIt.repost(context); Toast.makeText(context, "Place-it reposted.", Toast.LENGTH_LONG).show(); } else throw new RuntimeException("Notification not used correctly"); }
/** * Shows the notification with repost and discard options. Multiple Place-its listed as separate * notifications. */ public static void notify(final Context context, final int pID) { final Resources res = context.getResources(); PlaceIt placeIt = PlaceItList.find(pID); final String title = placeIt.getTitle(); // address for Categorical, Location cordinate for regular String address = placeIt.getDescription(); if (placeIt.getClass() == CategoricalPlaceIt.class) { address = ((CategoricalPlaceIt) placeIt).getAddress(); } else { address = "" + ((LocationPlaceIt) placeIt).getLocation().getLatitude() + ((LocationPlaceIt) placeIt).getLocation().getLongitude(); } final String fullTitle = res.getString(R.string.place_it_notification_title_template, title); final String fullAddress = res.getString(R.string.place_it_notification_text_template, address); final NotificationCompat.Builder notification = new NotificationCompat.Builder(context); // Set appropriate defaults for the notification light, sound, // and vibration. notification.setDefaults(Notification.DEFAULT_ALL); // required values notification.setSmallIcon(R.drawable.ic_launcher); notification.setContentTitle(fullTitle); notification.setContentText(fullAddress); // Set preview information for this notification. notification.setTicker(title); // On click action go to DescriptionActivity Intent descriptionIntent = new Intent(context, DescriptionActivity.class).putExtra(MainActivity.PLACEIT_ID, pID); notification.setContentIntent( PendingIntent.getActivity( context, pID, descriptionIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Repost action Intent repostIntent = new Intent(context, PlaceItNotification.class) .putExtra(BUTTON_TAG, R.string.notification_repost) .putExtra(MainActivity.PLACEIT_ID, pID); notification.addAction( R.drawable.ic_stat_repost, res.getString(R.string.notification_repost), PendingIntent.getBroadcast(context, 0, repostIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Discard action Intent discardIntent = new Intent(context, PlaceItNotification.class) .putExtra(BUTTON_TAG, R.string.notification_discard) .putExtra(MainActivity.PLACEIT_ID, pID); notification.addAction( R.drawable.ic_stat_discard, res.getString(R.string.notification_discard), PendingIntent.getBroadcast(context, 0, discardIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Automatically dismiss the notification when it is touched. notification.setAutoCancel(true); notify(context, notification.build(), pID); }