List of usage examples for android.widget RemoteViews setOnClickPendingIntent
public void setOnClickPendingIntent(int viewId, PendingIntent pendingIntent)
From source file:com.karma.konnect.PwoDiscoveryService.java
/** * Create the big view for the summary notification. *///from www . j a va 2s. c o m private RemoteViews updateSummaryNotificationRemoteViews(List<PwoMetadata> pwoMetadataList) { RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_big_view); // Fill in the data for the top two beacon views updateSummaryNotificationRemoteViewsFirstBeacon(pwoMetadataList.get(0), remoteViews); updateSummaryNotificationRemoteViewsSecondBeacon(pwoMetadataList.get(1), remoteViews); // Create a pending intent that will open the physical web app // TODO(cco3): Use a clickListener on the VIEW MORE button to do this PendingIntent pendingIntent = createReturnToAppPendingIntent(); remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent); return remoteViews; }
From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java
/** * Updates the record button./*from w ww . ja v a 2 s .com*/ * * @param context the context * @param remoteViews the remote views * @param isRecording true if recording * @param recordingTrackPaused true if recording track is paused */ private void updateRecordButton(Context context, RemoteViews remoteViews, boolean isRecording, boolean recordingTrackPaused) { remoteViews.setImageViewResource(R.id.track_widget_record_button, isRecording && !recordingTrackPaused ? R.drawable.ic_pause : R.drawable.ic_record); int recordActionId; if (isRecording) { recordActionId = recordingTrackPaused ? R.string.track_action_resume : R.string.track_action_pause; } else { recordActionId = R.string.track_action_start; } Intent intent = new Intent(context, ControlRecordingService.class) .setAction(context.getString(recordActionId)); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.track_widget_record_button, pendingIntent); }
From source file:com.perm.DoomPlay.DownloadNotifBuilder.java
private Notification createStartingNew() { Notification notification = new Notification(); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notif_download); views.setProgressBar(R.id.progressDownload, 100, 0, true); views.setTextViewText(R.id.notifTitle, context.getResources().getString(R.string.Downloading)); views.setTextViewText(R.id.notifArtist, track.getArtist() + "-" + track.getTitle()); views.setImageViewResource(R.id.notifPause, R.drawable.widget_pause); ComponentName componentName = new ComponentName(context, DownloadingService.class); Intent intentClose = new Intent(PlayingService.actionClose); intentClose.putExtra("aid", track.getAid()); intentClose.setComponent(componentName); Intent intentPause = new Intent(PlayingService.actionIconPause); intentPause.putExtra("aid", track.getAid()); intentPause.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(context, notificationId, intentClose, PendingIntent.FLAG_UPDATE_CURRENT)); views.setOnClickPendingIntent(R.id.notifPause, PendingIntent.getService(context, notificationId, intentPause, PendingIntent.FLAG_UPDATE_CURRENT)); notification.contentView = views;//from w ww. j a v a 2s .com notification.flags = Notification.FLAG_ONGOING_EVENT; notification.icon = R.drawable.download_icon; return notification; }
From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java
private void updateWidget(@Nonnull Context context, @Nonnull AppWidgetManager manager, @Nonnull int[] widgetIds, boolean partially) { final EditorState editorState = editor.getState(); final DisplayState displayState = display.getState(); final Resources resources = context.getResources(); final SimpleTheme theme = App.getWidgetTheme().resolveThemeFor(App.getTheme()); for (int widgetId : widgetIds) { final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout(manager, widgetId, resources, theme)); if (!partially || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { for (CppButton button : CppButton.values()) { final PendingIntent intent = intents.get(context, button); if (intent != null) { final int buttonId; if (button == CppButton.settings_widget) { // overriding default settings button behavior buttonId = CppButton.settings.id; } else { buttonId = button.id; }//from w w w . j ava 2 s .c o m views.setOnClickPendingIntent(buttonId, intent); } } } updateEditorState(context, views, editorState, theme); updateDisplayState(context, views, displayState, theme); views.setTextViewText(R.id.cpp_button_multiplication, engine.getMultiplicationSign()); if (partially && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { manager.partiallyUpdateAppWidget(widgetId, views); } else { manager.updateAppWidget(widgetId, views); } } }
From source file:com.devbrackets.android.playlistcore.helper.NotificationHelper.java
/** * Returns a fully constructed notification to use when moving a service to the * foreground. This should be called after the notification information is set with * {@link #setNotificationBaseInformation(int, int)} and {@link #updateNotificationInformation(String, String, String, Bitmap, Bitmap)}. * * @param pendingIntent The pending intent to use when the notification itself is clicked * @return The constructed notification//w ww . ja v a2 s . com */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public Notification getNotification(@Nullable PendingIntent pendingIntent, @NonNull Class<? extends Service> serviceClass) { setClickPendingIntent(pendingIntent); RemoteViews customNotificationViews = getCustomNotification(serviceClass); boolean allowSwipe = notificationInfo.getMediaState() == null || !notificationInfo.getMediaState().isPlaying(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContent(customNotificationViews); builder.setContentIntent(pendingIntent); builder.setDeleteIntent(createPendingIntent(RemoteActions.ACTION_STOP, serviceClass)); builder.setSmallIcon(notificationInfo.getAppIcon()); builder.setAutoCancel(allowSwipe); builder.setOngoing(!allowSwipe); if (pendingIntent != null) { customNotificationViews.setOnClickPendingIntent(R.id.playlistcore_notification_touch_area, pendingIntent); } //Set the notification category on lollipop if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS); builder.setVisibility(Notification.VISIBILITY_PUBLIC); } //Build the notification and set the expanded content view if there is a service to inform of clicks if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && mediaServiceClass != null) { RemoteViews bigNotificationView = getBigNotification(serviceClass); bigNotificationView.setOnClickPendingIntent(R.id.playlistcore_big_notification_touch_area, pendingIntent); builder.setCustomBigContentView(bigNotificationView); } return builder.build(); }
From source file:org.physical_web.physicalweb.UrlDeviceDiscoveryService.java
/** * Create the big view for the summary notification. *///from w ww . j a v a 2s . co m private RemoteViews updateSummaryNotificationRemoteViews(List<PwPair> pwPairs) { RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_big_view); // Fill in the data for the top two beacon views updateSummaryNotificationRemoteViewsFirstBeacon(pwPairs.get(0), remoteViews); updateSummaryNotificationRemoteViewsSecondBeacon(pwPairs.get(1), remoteViews); // Create a pending intent that will open the physical web app // TODO(cco3): Use a clickListener on the VIEW MORE button to do this PendingIntent pendingIntent = createReturnToAppPendingIntent(); remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent); return remoteViews; }
From source file:com.android.mail.widget.WidgetService.java
public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) { remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); // Launch an intent to avoid ANRs final Intent intent = new Intent(context, serviceClass); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CAPABILITIES, folderCapabilities); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.conversation_list, intent); // Open mail app when click on header final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account); mailIntent.setPackage(context.getPackageName()); PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent); // On click intent for Compose final Intent composeIntent = new Intent(); composeIntent.setPackage(context.getPackageName()); composeIntent.setAction(Intent.ACTION_SEND); composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); composeIntent.setData(account.composeIntentUri); composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true); if (account.composeIntentUri != null) { composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri); }//from w w w . jav a 2 s . co m // Build a task stack that forces the conversation list on the stack before the compose // activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent); // On click intent for Conversation final Intent conversationIntent = new Intent(); conversationIntent.setPackage(context.getPackageName()); conversationIntent.setAction(Intent.ACTION_VIEW); clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent); }
From source file:org.messic.android.smartphone.notifications.MessicPlayerNotification.java
private void createNotification() { if (this.notification != null) { return;//ww w.j a v a2 s . c o m } mNotificationManager = (NotificationManager) this.service.getSystemService(Context.NOTIFICATION_SERVICE); RemoteViews smallContentView = new RemoteViews(this.service.getPackageName(), R.layout.notification_small); RemoteViews bigContentView = new RemoteViews(this.service.getPackageName(), R.layout.notification_big); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this.service); mBuilder.setSmallIcon(R.mipmap.ic_launcher); mBuilder.setContentTitle("title"); mBuilder.setPriority(Notification.PRIORITY_MAX); mBuilder.setContent(bigContentView); Notification n = mBuilder.build(); n.contentView = smallContentView; n.bigContentView = bigContentView; Intent intentClose = new Intent(ACTION_CLOSE); PendingIntent pintentClose = PendingIntent.getBroadcast(this.service, 0, intentClose, 0); bigContentView.setOnClickPendingIntent(R.id.bignotification_ivclose, pintentClose); smallContentView.setOnClickPendingIntent(R.id.bignotification_ivclose, pintentClose); Intent intentBack = new Intent(ACTION_BACK); PendingIntent pintentBack = PendingIntent.getBroadcast(this.service, 0, intentBack, 0); bigContentView.setOnClickPendingIntent(R.id.bignotification_ivback, pintentBack); smallContentView.setOnClickPendingIntent(R.id.bignotification_ivback, pintentBack); Intent intentPlay = new Intent(ACTION_PLAY); PendingIntent pintentPlay = PendingIntent.getBroadcast(this.service, 0, intentPlay, 0); bigContentView.setOnClickPendingIntent(R.id.bignotification_ivplay, pintentPlay); smallContentView.setOnClickPendingIntent(R.id.bignotification_ivplay, pintentPlay); Intent intentPause = new Intent(ACTION_PAUSE); PendingIntent pintentPause = PendingIntent.getBroadcast(this.service, 0, intentPause, 0); bigContentView.setOnClickPendingIntent(R.id.bignotification_ivpause, pintentPause); smallContentView.setOnClickPendingIntent(R.id.bignotification_ivpause, pintentPause); Intent intentNext = new Intent(ACTION_NEXT); PendingIntent pintentNext = PendingIntent.getBroadcast(this.service, 0, intentNext, 0); bigContentView.setOnClickPendingIntent(R.id.bignotification_ivnext, pintentNext); smallContentView.setOnClickPendingIntent(R.id.bignotification_ivnext, pintentNext); Intent intentAlbum = new Intent(ACTION_ALBUM); PendingIntent pintentAlbum = PendingIntent.getBroadcast(this.service, 0, intentAlbum, PendingIntent.FLAG_CANCEL_CURRENT); bigContentView.setOnClickPendingIntent(R.id.bignotification_ivcurrent_cover, pintentAlbum); bigContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_author, pintentAlbum); bigContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_song, pintentAlbum); smallContentView.setOnClickPendingIntent(R.id.bignotification_ivcurrent_cover, pintentAlbum); smallContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_author, pintentAlbum); smallContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_song, pintentAlbum); this.notification = n; this.service.startForeground(ONGOING_NOTIFICATION_ID, notification); this.registerBroadcastActions(); }
From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // Perform this loop procedure for each App Widget that belongs to this provider for (int appWidgetId : appWidgetIds) { // Get the layout for the App Widget and attach an on-click listener // to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget); if (NLService.isEnabled()) { views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green)); } else {/*w ww . jav a2 s . c om*/ views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red)); } views.setOnClickPendingIntent(R.id.widgetToggleButton, getPendingSelfIntent(context, appWidgetId, TOGGLE_CLICKED)); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls.java
private void updateNotification() { if (mService == null) return;/*from www . ja v a 2 s . co m*/ if (mMediaNotificationInfo == null) { // Notification was hidden before we could update it. assert mNotificationBuilder == null; return; } // Android doesn't badge the icons for RemoteViews automatically when // running the app under the Work profile. if (mNotificationIcon == null) { Drawable notificationIconDrawable = ApiCompatibilityUtils.getUserBadgedIcon(mContext, R.drawable.audio_playing); mNotificationIcon = drawableToBitmap(notificationIconDrawable); } if (mNotificationBuilder == null) { mNotificationBuilder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.audio_playing) .setAutoCancel(false).setLocalOnly(true) .setDeleteIntent(mService.getPendingIntent(ListenerService.ACTION_STOP)); } mNotificationBuilder.setOngoing(!mMediaNotificationInfo.isPaused); mNotificationBuilder.setContentIntent(createContentIntent()); RemoteViews contentView = createContentView(); contentView.setTextViewText(R.id.title, mMediaNotificationInfo.title); contentView.setTextViewText(R.id.status, getStatus()); if (mNotificationIcon != null) { contentView.setImageViewBitmap(R.id.icon, mNotificationIcon); } else { contentView.setImageViewResource(R.id.icon, R.drawable.audio_playing); } if (mMediaNotificationInfo.isPaused) { contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_play); contentView.setContentDescription(R.id.playpause, mPlayDescription); contentView.setOnClickPendingIntent(R.id.playpause, mService.getPendingIntent(ListenerService.ACTION_PLAY)); } else { contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_pause); contentView.setContentDescription(R.id.playpause, mPauseDescription); contentView.setOnClickPendingIntent(R.id.playpause, mService.getPendingIntent(ListenerService.ACTION_PAUSE)); } mNotificationBuilder.setContent(contentView); mNotificationBuilder.setVisibility(mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY_PRIVATE : NotificationCompat.VISIBILITY_PUBLIC); if (mMediaSession == null) { mMediaSession = new MediaSessionCompat(mContext, mContext.getString(R.string.app_name), new ComponentName(mContext.getPackageName(), MediaButtonReceiver.class.getName()), null); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mMediaSession.setCallback(mMediaSessionCallback); mMediaSession.setActive(true); } mMediaSession.setMetadata(createMetadata()); PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder() .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE); if (mMediaNotificationInfo.isPaused) { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } else { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } mMediaSession.setPlaybackState(playbackStateBuilder.build()); Notification notification = mNotificationBuilder.build(); // We keep the service as a foreground service while the media is playing. When it is not, // the service isn't stopped but is no longer in foreground, thus at a lower priority. // While the service is in foreground, the associated notification can't be swipped away. // Moving it back to background allows the user to remove the notification. if (mMediaNotificationInfo.isPaused) { mService.stopForeground(false /* removeNotification */); NotificationManagerCompat manager = NotificationManagerCompat.from(mContext); manager.notify(R.id.media_playback_notification, notification); } else { mService.startForeground(R.id.media_playback_notification, notification); } }