List of usage examples for android.widget RemoteViews setOnClickPendingIntent
public void setOnClickPendingIntent(int viewId, PendingIntent pendingIntent)
From source file:com.devbrackets.android.playlistcore.helper.NotificationHelper.java
/** * Creates the RemoteViews used for the custom (standard) notification * * @return The resulting RemoteViews/*from ww w.j a va 2 s .c om*/ */ @NonNull protected RemoteViews getCustomNotification(@NonNull Class<? extends Service> serviceClass) { RemoteViews customNotification = new RemoteViews(context.getPackageName(), R.layout.playlistcore_notification_content); customNotification.setOnClickPendingIntent(R.id.playlistcore_notification_playpause, createPendingIntent(RemoteActions.ACTION_PLAY_PAUSE, serviceClass)); customNotification.setOnClickPendingIntent(R.id.playlistcore_notification_next, createPendingIntent(RemoteActions.ACTION_NEXT, serviceClass)); customNotification.setOnClickPendingIntent(R.id.playlistcore_notification_prev, createPendingIntent(RemoteActions.ACTION_PREVIOUS, serviceClass)); customNotification.setTextViewText(R.id.playlistcore_notification_title, notificationInfo.getTitle()); customNotification.setTextViewText(R.id.playlistcore_notification_album, notificationInfo.getAlbum()); customNotification.setTextViewText(R.id.playlistcore_notification_artist, notificationInfo.getArtist()); if (notificationInfo.getLargeImage() != null) { customNotification.setBitmap(R.id.playlistcore_notification_large_image, "setImageBitmap", notificationInfo.getLargeImage()); } if (notificationInfo.getMediaState() != null) { updateCustomNotificationMediaState(customNotification); } return customNotification; }
From source file:org.opensilk.fuzzyclock.FuzzyWidgetService.java
/** * Updates single appwidget, will schedule next update based on current logic * @param id/* w ww . jav a 2s . c om*/ */ @DebugLog private void updateWidget(int id) { FuzzyPrefs settings = sWidgetSettings.get((Integer) id); if (settings == null) { return; // Once setup is done we will be called again. } if (LOGV) Log.v(TAG, "Updating widget id=" + id + " " + settings.toString()); mFuzzyClock.loadPreferences(settings); mFuzzyClock.setDateFormat(); mFuzzyClock.updateTime(); Bitmap bitmap = mFuzzyClock.createBitmap(); if (bitmap == null) { return; } // build onClick intent Intent intent = new Intent(mContext, FuzzyWidgetSettings.class); intent.setAction(String.format(Locale.US, "dummy_%d", id)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id); PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // send bitmap to remote view RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.fuzzy_widget); views.setImageViewBitmap(R.id.fuzzy_clock_image, bitmap); views.setContentDescription(R.id.fuzzy_clock_image, mFuzzyClock.getContentDescription()); views.setOnClickPendingIntent(R.id.fuzzy_clock_image, pi); mWidgetManager.updateAppWidget(id, views); scheduleUpdate(mFuzzyClock.getLogic().getCalendar().getTimeInMillis(), mFuzzyClock.getLogic().getNextIntervalMilli(), id); }
From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java
public void setListeners(RemoteViews view) { try {/* ww w .ja v a2 s.co m*/ PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_previous, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_close, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_pause, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_next, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_play, pendingIntent); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.pmarks.chromadoze.NoiseService.java
private void addButtonToNotification(Notification n) { // Create a new RV with a Stop button. RemoteViews rv = new RemoteViews(getPackageName(), R.layout.notification_with_stop_button); PendingIntent pendingIntent = PendingIntent.getService(this, 0, newStopIntent(this, R.string.stop_reason_notification), PendingIntent.FLAG_CANCEL_CURRENT); rv.setOnClickPendingIntent(R.id.stop_button, pendingIntent); // Pre-render the original RV, and copy some of the colors. final View inflated = n.contentView.apply(this, new FrameLayout(this)); final TextView titleText = findTextView(inflated, getString(R.string.app_name)); final TextView defaultText = findTextView(inflated, getString(R.string.notification_text)); rv.setInt(R.id.divider, "setBackgroundColor", defaultText.getTextColors().getDefaultColor()); rv.setInt(R.id.stop_button_square, "setBackgroundColor", titleText.getTextColors().getDefaultColor()); // Insert a copy of the original RV into the new one. rv.addView(R.id.notification_insert, n.contentView.clone()); // Splice everything back into the original's root view. int id = Resources.getSystem().getIdentifier("status_bar_latest_event_content", "id", "android"); n.contentView.removeAllViews(id);/* w w w. jav a2 s .c om*/ n.contentView.addView(id, rv); }
From source file:com.audiokernel.euphonyrmt.service.NotificationHandler.java
/** * This method builds upon the base notification resources to create * the resources necessary for the expanded notification RemoteViews. *//* w w w . j av a2s. c om*/ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void buildExpandedNotification() { final PendingIntent previousAction = buildPendingIntent(MPDControl.ACTION_PREVIOUS); final RemoteViews resultView = new RemoteViews(mServiceContext.getPackageName(), R.layout.notification_big); buildBaseNotification(resultView); resultView.setOnClickPendingIntent(R.id.notificationPrev, previousAction); mNotification.bigContentView = resultView; }
From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java
private RemoteViews getCustomContentView() { RemoteViews view = new RemoteViews(_package, R.layout.view_layout_notification); int style = settings.getResources().getIdentifier("style_" + settings.getTheme(), "style", _package); int backgroundColor; int iconColor; if (style != 0) { backgroundColor = settings.getStyleAttributeColor(style, android.R.attr.colorBackground); iconColor = settings.getStyleAttributeColor(style, android.R.attr.colorForeground); } else {/*ww w.ja v a 2s . com*/ backgroundColor = settings.getColor(settings.getCustomThemeBackgroundColor()); iconColor = settings.getColor(settings.getCustomThemeIconColor()); } if (settings.getTranslucent()) { backgroundColor = android.R.color.transparent; } view.setInt(R.id.notification_layout, "setBackgroundColor", backgroundColor); view.removeAllViews(R.id.volume_control_wrapper); for (int pos = 0; pos < items.size(); pos++) { VolumeControl item = model.parseItem(items.get(pos)); if (item.status == 0) { continue; } RemoteViews btn = new RemoteViews(_package, R.layout.view_widget_volume_control); PendingIntent event = PendingIntent.getBroadcast(context.getApplicationContext(), item.id, new Intent(context, SetVolumeReceiver.class).putExtra(EXTRA_ITEM_ID, item.id), PendingIntent.FLAG_UPDATE_CURRENT); btn.setOnClickPendingIntent(R.id.btn_volume_control, event); btn.setInt(R.id.btn_volume_control, "setImageResource", model.getIconDrawable(item.icon)); btn.setInt(R.id.btn_volume_control, "setColorFilter", iconColor); view.addView(R.id.volume_control_wrapper, btn); } return view; }
From source file:org.namelessrom.devicecontrol.widgets.RebootWidget.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] ids) { final ComponentName widget = new ComponentName(context, RebootWidget.class); final int[] allWidgetInstancesIds = appWidgetManager.getAppWidgetIds(widget); for (int widgetId : allWidgetInstancesIds) { final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_reboot); final Intent intent = new Intent(context, RebootWidget.class); intent.setAction(SHOW_POPUP_DIALOG_REBOOT_ACTION); final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_reboot_image, pendingIntent); appWidgetManager.updateAppWidget(widgetId, remoteViews); }/*from ww w . ja va 2s. co m*/ super.onUpdate(context, appWidgetManager, ids); }
From source file:org.fdroid.enigtext.service.KeyCachingService.java
private void foregroundServiceModern() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.key_caching_notification); Intent intent = new Intent(this, KeyCachingService.class); intent.setAction(PASSPHRASE_EXPIRED_EVENT); PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); remoteViews.setOnClickPendingIntent(R.id.lock_cache_icon, pendingIntent); builder.setSmallIcon(R.drawable.icon_cached); builder.setContent(remoteViews);/*from w w w.jav a 2 s . com*/ stopForeground(true); startForeground(SERVICE_RUNNING_ID, builder.build()); }
From source file:net.hyx.app.volumenotification.NotificationFactory.java
private RemoteViews getCustomContentView() { RemoteViews view = new RemoteViews(_package, R.layout.view_layout_notification); List<Integer> buttons = new ArrayList<>(); int theme = resources.getIdentifier("style_" + settings.getTheme(), "style", _package); int background_color; int icon_color; if (theme != 0) { TypedArray attrs = context.obtainStyledAttributes(theme, R.styleable.styleable); background_color = attrs.getColor(R.styleable.styleable_background_color, 0); icon_color = attrs.getColor(R.styleable.styleable_icon_color, 0); attrs.recycle();//from www.ja v a 2s.c om } else { background_color = settings.getColor(settings.getCustomThemeBackgroundColor()); icon_color = settings.getColor(settings.getCustomThemeIconColor()); } if (settings.getTransparent()) { background_color = android.R.color.transparent; } view.setInt(R.id.layout_background, "setBackgroundColor", background_color); view.removeAllViews(R.id.layout_buttons); for (int pos = 1; pos <= BUTTONS_SELECTION_SIZE; pos++) { int sel = settings.getButtonSelection(pos); if (!settings.getButtonChecked(pos) || buttons.contains(sel) || sel >= BUTTONS_SELECTION_SIZE) { continue; } buttons.add(sel); int btn_sel = sel + 1; int btn_id = resources.getIdentifier("btn_sel_" + btn_sel, "id", _package); RemoteViews btn = new RemoteViews(_package, resources.getIdentifier("view_btn_sel_" + btn_sel, "layout", _package)); Intent intent = new Intent(context, ReceiverSetVolume.class).putExtra("position", pos); PendingIntent event = PendingIntent.getBroadcast(context, btn_id, intent, PendingIntent.FLAG_UPDATE_CURRENT); btn.setOnClickPendingIntent(btn_id, event); //btn.setInt(btn_id, "setImageResource", settings.getDrawable(context, R.array.pref_buttons_icons_entries, settings.getButtonIcon(pos))); btn.setInt(btn_id, "setColorFilter", icon_color); view.addView(R.id.layout_buttons, btn); } return view; }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static void linkButtons(Context context, RemoteViews views, boolean playerActive) { Intent intent = new Intent(context, playerActive ? DownloadActivity.class : MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent); views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent); // Emulate media button clicks. intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_play, pendingIntent); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_next, pendingIntent); intent = new Intent("3"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_previous, pendingIntent); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_stop, pendingIntent); }