use of android.support.v4.app.NotificationCompat.Builder in project android by cSploit.
the class MultiAttackService method setupNotification.
private void setupNotification() {
// get notification manager
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// get notification builder
mBuilder = new NotificationCompat.Builder(this);
// create a broadcast receiver to get actions
// performed on the notification by the user
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Logger.debug("received action: " + action);
if (action == null)
return;
// user cancelled our notification
if (action.equals(NOTIFICATION_CANCELLED)) {
mRunning = false;
stopSelf();
}
}
};
mContentIntent = null;
// register our receiver
registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED));
// set common notification actions
mBuilder.setDeleteIntent(PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0));
mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
}
use of android.support.v4.app.NotificationCompat.Builder in project android by cSploit.
the class UpdateService method setupNotification.
/**
* connect to the notification manager and create a notification builder.
* it also setup the cancellation Intent for get notified when our notification got cancelled.
*/
private void setupNotification() {
// get notification manager
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// get notification builder
mBuilder = new NotificationCompat.Builder(this);
// create a broadcast receiver to get actions
// performed on the notification by the user
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action == null)
return;
// user cancelled our notification
if (action.equals(NOTIFICATION_CANCELLED)) {
mRunning = false;
}
}
};
// register our receiver
registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED));
// set common notification actions
mBuilder.setDeleteIntent(PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0));
mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
}
use of android.support.v4.app.NotificationCompat.Builder in project cw-omnibus by commonsguy.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, VoiceReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteInput remoteInput = new RemoteInput.Builder(VoiceReceiver.EXTRA_SPEECH).setLabel(getString(R.string.talk)).setChoices(getResources().getStringArray(R.array.replies)).build();
NotificationCompat.Action wearAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput).build();
NotificationCompat.WearableExtender wearExtender = new NotificationCompat.WearableExtender().addAction(wearAction);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(android.R.drawable.stat_sys_download_done).setContentTitle(getString(R.string.title)).setContentText(getString(R.string.talk)).extend(wearExtender);
NotificationManagerCompat.from(this).notify(NOTIFY_ID, builder.build());
finish();
}
use of android.support.v4.app.NotificationCompat.Builder in project cw-omnibus by commonsguy.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, RemoteInputReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteInput remoteInput = new RemoteInput.Builder(RemoteInputReceiver.EXTRA_INPUT).setLabel(getString(R.string.talk)).build();
NotificationCompat.Action remoteAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput).build();
NotificationCompat.Builder builder = RemoteInputReceiver.buildNotificationBase(this).addAction(remoteAction);
NotificationManagerCompat.from(this).notify(RemoteInputReceiver.NOTIFY_ID, builder.build());
finish();
}
use of android.support.v4.app.NotificationCompat.Builder in project SeriesGuide by UweTrottmann.
the class ListWidgetProvider method buildRemoteViews.
public static RemoteViews buildRemoteViews(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
// setup intent pointing to RemoteViewsService providing the views for the collection
Intent intent = new Intent(context, ListWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
// When intents are compared, the extras are ignored, so we need to
// embed the extras into the data so that the extras will not be
// ignored.
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
// determine layout (current size) and theme (user pref)
final boolean isCompactLayout = isCompactLayout(appWidgetManager, appWidgetId);
final boolean isLightTheme = WidgetSettings.isLightTheme(context, appWidgetId);
int layoutResId;
if (isLightTheme) {
layoutResId = isCompactLayout ? R.layout.appwidget_v11_light_compact : R.layout.appwidget_v11_light;
} else {
layoutResId = isCompactLayout ? R.layout.appwidget_v11_compact : R.layout.appwidget_v11;
}
// build widget views
RemoteViews rv = new RemoteViews(context.getPackageName(), layoutResId);
rv.setRemoteAdapter(R.id.list_view, intent);
// The empty view is displayed when the collection has no items. It
// should be a sibling of the collection view.
rv.setEmptyView(R.id.list_view, R.id.empty_view);
// set the background colors of...
// ...the header
boolean isDarkTheme = WidgetSettings.isDarkTheme(context, appWidgetId);
rv.setInt(R.id.containerWidgetHeader, "setBackgroundColor", isDarkTheme ? Color.TRANSPARENT : ContextCompat.getColor(context, R.color.accent_primary));
// ...the whole widget
int bgColor = WidgetSettings.getWidgetBackgroundColor(context, appWidgetId, isLightTheme);
rv.setInt(R.id.container, "setBackgroundColor", bgColor);
// determine type specific values
final int widgetType = WidgetSettings.getWidgetListType(context, appWidgetId);
int showsTabIndex;
int titleResId;
int emptyResId;
if (widgetType == WidgetSettings.Type.UPCOMING) {
// upcoming
showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_UPCOMING;
titleResId = R.string.upcoming;
emptyResId = R.string.noupcoming;
} else if (widgetType == WidgetSettings.Type.RECENT) {
// recent
showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_RECENT;
titleResId = R.string.recent;
emptyResId = R.string.norecent;
} else {
// shows
showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_SHOWS;
titleResId = R.string.shows;
emptyResId = R.string.no_nextepisode;
}
// change title and empty view based on type
rv.setTextViewText(R.id.empty_view, context.getString(emptyResId));
if (!isCompactLayout) {
// only regular layout has text title
rv.setTextViewText(R.id.widgetTitle, context.getString(titleResId));
}
// app launch button
final Intent appLaunchIntent = new Intent(context, ShowsActivity.class).putExtra(ShowsActivity.InitBundle.SELECTED_TAB, showsTabIndex);
PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(appLaunchIntent).getPendingIntent(appWidgetId, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.widget_title, pendingIntent);
// item intent template, launches episode detail view
TaskStackBuilder builder = TaskStackBuilder.create(context);
builder.addNextIntent(appLaunchIntent);
builder.addNextIntent(new Intent(context, EpisodesActivity.class));
rv.setPendingIntentTemplate(R.id.list_view, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT));
// settings button
Intent settingsIntent = new Intent(context, ListWidgetConfigure.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
rv.setOnClickPendingIntent(R.id.widget_settings, PendingIntent.getActivity(context, appWidgetId, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT));
return rv;
}
Aggregations