List of usage examples for android.graphics.drawable Icon createWithResource
public static Icon createWithResource(String resPackage, @DrawableRes int resId)
From source file:MainActivity.java
@Deprecated public void showNotification(View view) { Intent activityIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0); Notification notification;// ww w . j a va 2 s. c om if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC) .setSmallIcon(Icon.createWithResource(this, R.mipmap.ic_launcher)) .addAction(new Notification.Action.Builder( Icon.createWithResource(this, android.R.drawable.ic_media_previous), "Previous", pendingIntent).build()) .addAction(new Notification.Action.Builder( Icon.createWithResource(this, android.R.drawable.ic_media_pause), "Pause", pendingIntent).build()) .addAction(new Notification.Action.Builder( Icon.createWithResource(this, android.R.drawable.ic_media_next), "Next", pendingIntent) .build()) .setContentTitle("Music").setContentText("Now playing...") .setLargeIcon(Icon.createWithResource(this, R.mipmap.ic_launcher)) .setStyle(new Notification.MediaStyle() //.setMediaSession(mMediaSession.getSessionToken()) .setShowActionsInCompactView(1)) .build(); } else { notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC) .setSmallIcon(R.mipmap.ic_launcher) .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_previous, "Previous", pendingIntent).build()) .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_pause, "Pause", pendingIntent).build()) .addAction( new Notification.Action.Builder(android.R.drawable.ic_media_next, "Next", pendingIntent) .build()) .setContentTitle("Music").setContentText("Now playing...") .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setStyle(new Notification.MediaStyle() //.setMediaSession(mMediaSession.getSessionToken()) .setShowActionsInCompactView(1)) .build(); } NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); }
From source file:com.android.deskclock.data.TimerNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final RemoteViews content = new RemoteViews(pname, R.layout.chronometer_notif_content); content.setChronometerCountDown(R.id.chronometer, true); content.setChronometer(R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(R.string.timer_notification_label); } else { stateText = timer.getLabel(); }/* w w w. ja v a2 s . c o m*/ // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_add_24dp); final CharSequence title2 = res.getText(R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_reset_24dp); final CharSequence title1 = res.getText(R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); } content.setTextViewText(R.id.state, stateText); // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false) .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM) .setSmallIcon(R.drawable.stat_notify_timer).setGroup(nm.getTimerNotificationGroupKey()) .setVisibility(Notification.VISIBILITY_PUBLIC).setStyle(new Notification.DecoratedCustomViewStyle()) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, R.color.default_background)).build(); }
From source file:com.android.deskclock.data.StopwatchNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) { @StringRes/*from w ww . ja v a 2 s. co m*/ final int eventLabel = R.string.label_notification; // Intent to load the app when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); // Compute some values required below. final boolean running = stopwatch.isRunning(); final String pname = context.getPackageName(); final Resources res = context.getResources(); final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime(); final RemoteViews content = new RemoteViews(pname, R.layout.chronometer_notif_content); content.setChronometer(R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); if (running) { // Left button: Pause final Intent pause = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(R.string.sw_pause_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right button: Add Lap if (DataModel.getDataModel().canAddMoreLaps()) { final Intent lap = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_sw_lap_24dp); final CharSequence title2 = res.getText(R.string.sw_lap_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, lap); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } // Show the current lap number if any laps have been recorded. final int lapCount = DataModel.getDataModel().getLaps().size(); if (lapCount > 0) { final int lapNumber = lapCount + 1; final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber); content.setTextViewText(R.id.state, lap); content.setViewVisibility(R.id.state, VISIBLE); } else { content.setViewVisibility(R.id.state, GONE); } } else { // Left button: Start final Intent start = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(R.string.sw_start_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right button: Reset (dismisses notification and resets stopwatch) final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); // Indicate the stopwatch is paused. content.setTextViewText(R.id.state, res.getString(R.string.swn_paused)); content.setViewVisibility(R.id.state, VISIBLE); } // Swipe away will reset the stopwatch without bringing forward the app. final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); return new Notification.Builder(context).setLocalOnly(true).setOngoing(running) .setCustomContentView(content).setContentIntent(pendingShowApp).setAutoCancel(stopwatch.isPaused()) .setPriority(Notification.PRIORITY_MAX).setSmallIcon(R.drawable.stat_notify_stopwatch) .setGroup(nm.getStopwatchNotificationGroupKey()) .setStyle(new Notification.DecoratedCustomViewStyle()) .setDeleteIntent(Utils.pendingServiceIntent(context, reset)) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, R.color.default_background)).build(); }
From source file:com.wizardsofm.deskclock.data.StopwatchNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) { @StringRes/*from www.j a v a2s . c om*/ final int eventLabel = com.wizardsofm.deskclock.R.string.label_notification; // Intent to load the app when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); // Compute some values required below. final boolean running = stopwatch.isRunning(); final String pname = context.getPackageName(); final Resources res = context.getResources(); final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime(); final RemoteViews content = new RemoteViews(pname, com.wizardsofm.deskclock.R.layout.chronometer_notif_content); content.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); if (running) { // Left button: Pause final Intent pause = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_pause_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right button: Add Lap if (DataModel.getDataModel().canAddMoreLaps()) { final Intent lap = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_sw_lap_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_lap_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, lap); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } // Show the current lap number if any laps have been recorded. final int lapCount = DataModel.getDataModel().getLaps().size(); if (lapCount > 0) { final int lapNumber = lapCount + 1; final String lap = res.getString(com.wizardsofm.deskclock.R.string.sw_notification_lap_number, lapNumber); content.setTextViewText(com.wizardsofm.deskclock.R.id.state, lap); content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, VISIBLE); } else { content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, GONE); } } else { // Left button: Start final Intent start = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_start_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right button: Reset (dismisses notification and resets stopwatch) final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); // Indicate the stopwatch is paused. content.setTextViewText(com.wizardsofm.deskclock.R.id.state, res.getString(com.wizardsofm.deskclock.R.string.swn_paused)); content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, VISIBLE); } // Swipe away will reset the stopwatch without bringing forward the app. final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); return new Notification.Builder(context).setLocalOnly(true).setOngoing(running) .setCustomContentView(content).setContentIntent(pendingShowApp).setAutoCancel(stopwatch.isPaused()) .setPriority(Notification.PRIORITY_MAX) .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_stopwatch) .setGroup(nm.getStopwatchNotificationGroupKey()) .setStyle(new Notification.DecoratedCustomViewStyle()) .setDeleteIntent(Utils.pendingServiceIntent(context, reset)) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background)) .build(); }
From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final RemoteViews content = new RemoteViews(pname, com.wizardsofm.deskclock.R.layout.chronometer_notif_content); content.setChronometerCountDown(com.wizardsofm.deskclock.R.id.chronometer, true); content.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_notification_label); } else { stateText = timer.getLabel(); }//from www . j a v a 2 s . co m // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_add_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); } content.setTextViewText(com.wizardsofm.deskclock.R.id.state, stateText); // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, com.wizardsofm.deskclock.R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false) .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM) .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer) .setGroup(nm.getTimerNotificationGroupKey()).setVisibility(Notification.VISIBILITY_PUBLIC) .setStyle(new Notification.DecoratedCustomViewStyle()) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background)) .build(); }
From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java
@TargetApi(Build.VERSION_CODES.N) public void updateTile(Tile tile, int id) { VolumeControl item = model.parseItem(model.getItemById(id)); if (item != null && tile != null) { tile.setIcon(Icon.createWithResource(context, model.getIconDrawable(item.icon))); tile.setLabel(item.label);/*from www .j ava2s. c om*/ tile.setState(Tile.STATE_ACTIVE); tile.updateTile(); } }
From source file:com.metinkale.prayerapp.vakit.WidgetService.java
public static void updateOngoing() { extractColors();/*from w w w. j a v a 2 s. c o m*/ NotificationManager nm = (NotificationManager) App.getContext() .getSystemService(Context.NOTIFICATION_SERVICE); for (int i = mOngoing.size() - 1; i >= 0; i--) { long id = mOngoing.get(i); Times t = Times.getTimes(id); if ((t == null) || !t.isOngoingNotificationActive()) { nm.cancel(id + "", NotIds.ONGOING); mOngoing.remove(i); } } List<Long> ids = Times.getIds(); for (long id : ids) { Times t = Times.getTimes(id); if ((t != null) && t.isOngoingNotificationActive() && !mOngoing.contains(id)) { mOngoing.add(id); } } LocalDate cal = LocalDate.now(); String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part); for (long id : mOngoing) { Times t = Times.getTimes(id); String[] dt = { t.getTime(cal, 0), t.getTime(cal, 1), t.getTime(cal, 2), t.getTime(cal, 3), t.getTime(cal, 4), t.getTime(cal, 5) }; boolean icon = Prefs.showOngoingIcon(); boolean number = Prefs.showOngoingNumber(); Crashlytics.setBool("showIcon", icon); Crashlytics.setBool("showNumber", number); Notification noti; if (Prefs.getAlternativeOngoing()) { RemoteViews views = new RemoteViews(App.getContext().getPackageName(), R.layout.notification_layout); int[] timeIds = { R.id.time0, R.id.time1, R.id.time2, R.id.time3, R.id.time4, R.id.time5 }; int[] vakitIds = { R.id.imsak, R.id.gunes, R.id.ogle, R.id.ikindi, R.id.aksam, R.id.yatsi }; int next = t.getNext(); if (Prefs.getVakitIndicator().equals("next")) next++; for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(timeIds[i], Html.fromHtml("<strong><em>" + Utils.fixTime(dt[i]) + "</em></strong>")); } else { views.setTextViewText(timeIds[i], Utils.fixTime(dt[i])); } } for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(vakitIds[i], Html.fromHtml("<strong><em>" + Vakit.getByIndex(i).getString() + "</em></strong>")); } else { views.setTextViewText(vakitIds[i], Vakit.getByIndex(i).getString()); } } views.setTextViewText(R.id.time, t.getLeft(t.getNext(), false)); views.setTextViewText(R.id.city, t.getName()); views.setTextColor(R.id.imsak, COLOR_1ST); views.setTextColor(R.id.gunes, COLOR_1ST); views.setTextColor(R.id.ogle, COLOR_1ST); views.setTextColor(R.id.ikindi, COLOR_1ST); views.setTextColor(R.id.aksam, COLOR_1ST); views.setTextColor(R.id.yatsi, COLOR_1ST); views.setTextColor(R.id.time0, COLOR_1ST); views.setTextColor(R.id.time1, COLOR_1ST); views.setTextColor(R.id.time2, COLOR_1ST); views.setTextColor(R.id.time3, COLOR_1ST); views.setTextColor(R.id.time4, COLOR_1ST); views.setTextColor(R.id.time5, COLOR_1ST); views.setTextColor(R.id.time, COLOR_1ST); views.setTextColor(R.id.city, COLOR_1ST); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setOngoing(true).build(); } else { noti = new NotificationCompat.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder).setOngoing(true) .build(); } } else { int n = t.getNext(); String sum = App.getContext().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(), left_part[n], t.getLeft().substring(0, 5)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.InboxStyle( new Notification.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)) .setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } else { noti = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } } if (Build.VERSION.SDK_INT >= 16) { noti.priority = Notification.PRIORITY_LOW; } noti.when = icon ? System.currentTimeMillis() : 0; try { nm.notify(id + "", NotIds.ONGOING, noti); } catch (Exception e) { Crashlytics.logException(e); } } }
From source file:com.oasisfeng.nevo.decorators.media.MediaPlayerDecorator.java
@Override protected void apply(final StatusBarNotificationEvo evolving) throws Exception { if (evolving.isClearable()) return; // Just sticky notification, to reduce the overhead. final INotification n = evolving.notification(); RemoteViews content_view = n.getBigContentView(); // Prefer big content view since it usually contains more actions if (content_view == null) content_view = n.getContentView(); if (content_view == null) return;/* ww w .java 2 s.co m*/ final AtomicReference<IntentSender> sender_holder = new AtomicReference<>(); final View views = content_view.apply(new ContextWrapper(this) { @Override public void startIntentSender(final IntentSender intent, final Intent fillInIntent, final int flagsMask, final int flagsValues, final int extraFlags) throws IntentSender.SendIntentException { startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, null); } @Override public void startIntentSender(final IntentSender intent, final Intent fillInIntent, final int flagsMask, final int flagsValues, final int extraFlags, final Bundle options) throws IntentSender.SendIntentException { sender_holder.set(intent); } }, null); if (!(views instanceof ViewGroup)) return; final List<NotificationCompat.Action> actions = new ArrayList<>(8); findClickable((ViewGroup) views, new Predicate<View>() { @Override public boolean apply(final View v) { sender_holder.set(null); v.performClick(); // trigger startIntentSender() above final IntentSender sender = sender_holder.get(); if (sender == null) { Log.w(TAG, v + " has OnClickListener but no PendingIntent in it."); return true; } final PendingIntent pending_intent = getPendingIntent(sender); if (v instanceof TextView) { final CharSequence text = ((TextView) v).getText(); actions.add(new NotificationCompat.Action(0, text, pending_intent)); } else if (v instanceof ImageView) { final int res = getImageViewResource((ImageView) v); CharSequence title = v.getContentDescription(); if (title == null) title = "<" + System.identityHashCode(v); actions.add(new NotificationCompat.Action(res, title, pending_intent)); } else { CharSequence title = v.getContentDescription(); if (title == null) title = "<" + System.identityHashCode(v); actions.add(new NotificationCompat.Action(0, title, pending_intent)); } return true; } }); final Notification mirror; final String pkg = evolving.getPackageName(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { final Notification.Builder b = new Notification.Builder(createPackageContext(pkg, 0)) .setContentTitle(n.extras().getCharSequence(NotificationCompat.EXTRA_TITLE)) .setLargeIcon(n.getLargeIcon()).setSmallIcon(fixIconPkg(n.getSmallIcon(), pkg)); for (final NotificationCompat.Action action : actions) b.addAction(new Action.Builder(Icon.createWithResource(pkg, action.getIcon()), action.getTitle(), action.getActionIntent()).build()); mirror = b.build(); } else { final NotificationCompat.Builder b = new NotificationCompat.Builder(createPackageContext(pkg, 0)) .setContentTitle(n.extras().getCharSequence(NotificationCompat.EXTRA_TITLE)) .setLargeIcon(n.extras().getParcelable(NotificationCompat.EXTRA_LARGE_ICON).<Bitmap>get()) .setSmallIcon(android.R.drawable.ic_media_play); for (final NotificationCompat.Action action : actions) b.addAction(action); mirror = b.build(); } final NotificationManagerCompat nm = NotificationManagerCompat.from(this); nm.notify("M<" + evolving.getPackageName() + (evolving.getTag() != null ? ">" + evolving.getTag() : ">"), evolving.getId(), mirror); }
From source file:com.android.deskclock.data.TimerNotificationBuilderN.java
@Override public Notification buildHeadsUp(Context context, List<Timer> expired) { final Timer timer = expired.get(0); // First action intent is to reset all timers. final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_stop_24dp); final Intent reset = TimerService.createResetExpiredTimersIntent(context); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); // Generate some descriptive text, a title, and an action name based on the timer count. final CharSequence stateText; final int count = expired.size(); final List<Notification.Action> actions = new ArrayList<>(2); if (count == 1) { final String label = timer.getLabel(); if (TextUtils.isEmpty(label)) { stateText = context.getString(R.string.timer_times_up); } else {//from w w w. jav a 2s. c o m stateText = label; } // Left button: Reset single timer final CharSequence title1 = context.getString(R.string.timer_stop); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right button: Add minute final Intent addTime = TimerService.createAddMinuteTimerIntent(context, timer.getId()); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addTime); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_add_24dp); final CharSequence title2 = context.getString(R.string.timer_plus_1_min); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } else { stateText = context.getString(R.string.timer_multi_times_up, count); // Left button: Reset all timers final CharSequence title1 = context.getString(R.string.timer_stop_all); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); } final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final RemoteViews contentView = new RemoteViews(pname, R.layout.chronometer_notif_content); contentView.setChronometerCountDown(R.id.chronometer, true); contentView.setChronometer(R.id.chronometer, base, null, true); contentView.setTextViewText(R.id.state, stateText); // Content intent shows the timer full screen when clicked. final Intent content = new Intent(context, ExpiredTimersActivity.class); final PendingIntent contentIntent = Utils.pendingActivityIntent(context, content); // Full screen intent has flags so it is different than the content intent. final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen); return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false) .setAutoCancel(false).setContentIntent(contentIntent).setCustomContentView(contentView) .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_timer).setFullScreenIntent(pendingFullScreen, true) .setStyle(new Notification.DecoratedCustomViewStyle()) .setActions(actions.toArray(new Notification.Action[actions.size()])).build(); }
From source file:com.abhinavjhanwar.android.egg.neko.Cat.java
public Notification.Builder buildNotification(Context context) { final Bundle extras = new Bundle(); extras.putString("android.substName", context.getString(R.string.app_name)); final Intent intent = new Intent(Intent.ACTION_MAIN).setClass(context, NekoLand.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return new Notification.Builder(context) .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon)) .setLargeIcon(createLargeIcon(context)).setColor(getBodyColor()) .setPriority(Notification.PRIORITY_DEFAULT).setContentTitle(NekoService.notificationText) .setShowWhen(true).setCategory(Notification.CATEGORY_STATUS).setContentText(getName()) .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)).setAutoCancel(true) .setVibrate(PURR).addExtras(extras); }/*from w w w . ja v a2 s.com*/ return new Notification.Builder(context).setSmallIcon(R.drawable.stat_icon) .setPriority(Notification.PRIORITY_DEFAULT).setContentTitle(OldService.notificationText) .setContentText(getName()).setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setAutoCancel(true).setVibrate(PURR); }