Example usage for android.widget RemoteViews setOnClickPendingIntent

List of usage examples for android.widget RemoteViews setOnClickPendingIntent

Introduction

In this page you can find the example usage for android.widget RemoteViews setOnClickPendingIntent.

Prototype

public void setOnClickPendingIntent(int viewId, PendingIntent pendingIntent) 

Source Link

Document

Equivalent to calling android.view.View#setOnClickListener(android.view.View.OnClickListener) to launch the provided PendingIntent .

Usage

From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java

/**
 * Updates button to start/stop recording.
 * /*from w  w  w  .j  a v  a2  s  .  c om*/
 * @param remoteViews the remote views
 * @param action the action
 */
private void updateButton(RemoteViews remoteViews, String action) {
    boolean isRecording = trackStartedBroadcastAction.equals(action);
    remoteViews.setViewVisibility(R.id.track_widget_record_button, isRecording ? View.GONE : View.VISIBLE);
    remoteViews.setViewVisibility(R.id.track_widget_stop_button, isRecording ? View.VISIBLE : View.INVISIBLE);
    Intent intent = new Intent(context, ControlRecordingService.class).setAction(
            context.getString(isRecording ? R.string.track_action_end : R.string.track_action_start));
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(
            isRecording ? R.id.track_widget_stop_button : R.id.track_widget_record_button, pendingIntent);
}

From source file:com.customprogrammingsolutions.MediaStreamer.MediaStreamerService.java

private void startNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
    contentView.setImageViewResource(R.id.notification_icon, R.drawable.notification_icon);
    contentView.setTextViewText(R.id.notification_title, getString(R.string.notification_title));
    contentView.setTextViewText(R.id.notification_text, urlToStream);
    if (isPreparing) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon,
                R.drawable.notification_playback_loading);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon,
                PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0));
    } else if (isStreamError) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon,
                R.drawable.notification_playback_error);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon,
                PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0));
    } else if (isPlaying) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.stop_button);
        PendingIntent stopIntentPending = PendingIntent.getService(this, 0,
                new Intent(MainActivity.STOP_INTENT), PendingIntent.FLAG_CANCEL_CURRENT);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, stopIntentPending);
    } else {/*from  w w  w.j av a2  s.  co m*/
        contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.play_button);
        Intent playIntent = new Intent(MainActivity.PLAY_INTENT);
        playIntent.putExtra(MainActivity.URL_EXTRA, urlToStream);

        PendingIntent playIntentPending = PendingIntent.getService(this, 0, playIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, playIntentPending);
    }

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
    contentView.setOnClickPendingIntent(R.id.notification_layout, contentIntent);

    PendingIntent killIntentPending = PendingIntent.getService(this, 0,
            new Intent(MainActivity.KILL_SERVICE_INTENT), 0);
    contentView.setOnClickPendingIntent(R.id.close_notification_icon, killIntentPending);

    builder.setContent(contentView);

    builder.setSmallIcon(R.drawable.notification_icon);

    builder.setAutoCancel(false);

    startForeground(NOTIFICATION_ID, builder.build());
}

From source file:com.mb.android.playbackmediator.notification.VideoCastNotificationService.java

private void addPendingIntents(RemoteViews rv, boolean isPlaying, SessionInfoDto info) {
    Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK);
    playbackIntent.setPackage(getPackageName());
    PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0);

    Intent stopIntent = new Intent(ACTION_STOP);
    stopIntent.setPackage(getPackageName());
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);

    rv.setOnClickPendingIntent(R.id.playPauseView, playbackPendingIntent);
    rv.setOnClickPendingIntent(R.id.removeView, stopPendingIntent);

    if (isPlaying) {
        if (info.getNowPlayingItem().getRunTimeTicks() == null) {
            rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark);
        } else {/*w  ww . jav a 2 s .c o m*/
            rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_pause_sm_dark);
        }

    } else {
        rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_play_sm_dark);
    }
}

From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.UrlDeviceDiscoveryService.java

/**
 * Create the big view for the summary notification.
 *///from   w  ww.  j a v a  2 s  .  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
    PendingIntent pendingIntent = createReturnToAppPendingIntent();
    remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent);

    return remoteViews;
}

From source file:gsoc.google.com.byop.utils.PW.UrlDeviceDiscoveryService.java

/**
 * Create the big view for the summary notification.
 *///from   ww w .  j  a va  2  s. 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
    //
    PendingIntent pendingIntent = createReturnToAppPendingIntent();
    remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent);

    return remoteViews;
}

From source file:com.chen.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, 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_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);
    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.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  ww.j ava  2  s . com*/

    // 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.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}

From source file:free.yhc.netmbuddy.model.NotiManager.java

private Notification buildNotificationICS(NotiType ntype, CharSequence videoTitle) {
    RemoteViews rv = new RemoteViews(Utils.getAppContext().getPackageName(), R.layout.player_notification);
    NotificationCompat.Builder nbldr = new NotificationCompat.Builder(Utils.getAppContext());

    rv.setTextViewText(R.id.title, videoTitle);

    Intent intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class);
    intent.setAction(NOTI_INTENT_ACTION);
    intent.putExtra("type", ntype.name());
    PendingIntent pi = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setImageViewResource(R.id.action, ntype.getIcon());
    rv.setOnClickPendingIntent(R.id.action, pi);

    intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class);
    intent.setAction(NOTI_INTENT_STOP_PLAYER);
    pi = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setImageViewResource(R.id.stop, R.drawable.ic_media_stop);
    rv.setOnClickPendingIntent(R.id.stop, pi);

    intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class);
    intent.setAction(NOTI_INTENT_DELETE);
    PendingIntent piDelete = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    intent = new Intent(Utils.getAppContext(), YTMPActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent piContent = PendingIntent.getActivity(Utils.getAppContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    nbldr.setContent(rv).setContentIntent(piContent).setDeleteIntent(piDelete).setAutoCancel(true)
            .setSmallIcon(ntype.getIcon()).setTicker(null);
    return nbldr.build();
}

From source file:com.hang.exoplayer.PlayService.java

public void showNotification() {
    String title = "XXXXXXXX";
    String description = "YYYYYYYYYYYYY";
    NotificationCompat.Builder builder = new NotificationCompat.Builder(PlayService.this).setAutoCancel(false)
            .setOngoing(true);//from  w  ww. j a  v a2 s.  com
    Class<?> targetClass = PlayActivity.class;
    Intent notificationIntent = new Intent(PlayService.this, targetClass);
    PendingIntent pendingIntent = PendingIntent.getActivity(PlayService.this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    Intent playPauseIntent = new Intent(ExoApplication.getApplication(), PlayService.class);
    playPauseIntent.putExtra(ACTION_PLAY_PAUSE, true);
    Intent previousIntent = new Intent(ExoApplication.getApplication(), PlayService.class);
    previousIntent.putExtra(ACTION_PREVIOUS, true);
    Intent nextIntent = new Intent(ExoApplication.getApplication(), PlayService.class);
    nextIntent.putExtra(ACTION_NEXT, true);

    Intent dismissIntent = new Intent(ExoApplication.getApplication(), PlayService.class);
    dismissIntent.putExtra(ACTION_EXIT, true);

    PendingIntent playPendingIntent = PendingIntent.getService(PlayService.this, 1, playPauseIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    PendingIntent previousPendingIntent = PendingIntent.getService(PlayService.this, 2, previousIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent nextPendingIntent = PendingIntent.getService(PlayService.this, 3, nextIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent dismissPendingIntent = PendingIntent.getService(PlayService.this, 4, dismissIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_high_version_no_live);
    contentView.setTextViewText(R.id.songName, title);
    contentView.setTextViewText(R.id.artist, description);
    boolean isPlaying = SimplePlayer.getInstance().isPlaying();
    //        Log.d(TAG, "Notification is Playing?" + isPlaying);
    contentView.setImageViewResource(R.id.play_pause,
            isPlaying ? R.drawable.ic_noti_play_normal : R.drawable.ic_noti_pause_normal);
    contentView.setOnClickPendingIntent(R.id.play_pause, playPendingIntent);
    contentView.setOnClickPendingIntent(R.id.play_pre, previousPendingIntent);
    contentView.setOnClickPendingIntent(R.id.forward, nextPendingIntent);
    contentView.setOnClickPendingIntent(R.id.stop, dismissPendingIntent);
    //        builder.setCustomContentView(contentView);
    builder.setContent(contentView);
    Notification notification = builder.setSmallIcon(R.mipmap.ic_launcher).build();
    startForeground(ID_NOTIFICATION, notification);
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(ID_NOTIFICATION, notification);
}

From source file:com.perm.DoomPlay.DownloadNotifBuilder.java

public Notification createPaused() {
    Notification notification = new Notification();
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notif_download);

    views.setProgressBar(R.id.progressDownload, 100, 0, false);
    views.setTextViewText(R.id.notifTitle, context.getResources().getString(R.string.paused));
    views.setTextViewText(R.id.notifArtist, track.getArtist() + "-" + track.getTitle());
    views.setImageViewResource(R.id.notifPause, R.drawable.widget_play);

    Intent intentClose = new Intent(PlayingService.actionClose);
    intentClose.putExtra("aid", track.getAid());
    intentClose.setComponent(new ComponentName(context, DownloadingService.class));

    Intent intentPause = new Intent(PlayingService.actionIconPlay);
    intentPause.putExtra("aid", track.getAid());
    intentPause.setComponent(new ComponentName(context, DownloadingService.class));

    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  w  w. j  av  a 2 s  .  c  o m
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.download_icon;

    return notification;
}

From source file:com.devbrackets.android.exomedia.EMNotification.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  w  w . j a  v  a 2 s .  c om*/
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public Notification getNotification(@Nullable PendingIntent pendingIntent) {
    setClickPendingIntent(pendingIntent);
    RemoteViews customNotificationViews = getCustomNotification();

    boolean allowSwipe = notificationInfo.getMediaState() == null
            || !notificationInfo.getMediaState().isPlaying();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContent(customNotificationViews);
    builder.setContentIntent(pendingIntent);
    builder.setDeleteIntent(createPendingIntent(EMRemoteActions.ACTION_STOP, mediaServiceClass));
    builder.setSmallIcon(notificationInfo.getAppIcon());
    builder.setAutoCancel(allowSwipe);
    builder.setOngoing(!allowSwipe);

    if (pendingIntent != null) {
        customNotificationViews.setOnClickPendingIntent(R.id.exomedia_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
    Notification notification = builder.build();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && mediaServiceClass != null) {
        notification.bigContentView = getBigNotification();
        notification.bigContentView.setOnClickPendingIntent(R.id.exomedia_big_notification_touch_area,
                pendingIntent);
    }

    return notification;
}