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:org.dalol.orthodoxmezmurmedia.modules.player.PlayerNotificationDelegate.java

public void showNotification(MezmurPlayerService service, String text) {

    Intent playerIntent = new Intent(service, MezmursPlayerActivity.class);
    Intent dashboardIntent = new Intent(service, MezmurDashboardActivity.class);

    PendingIntent intent = TaskStackBuilder.create(service).addNextIntentWithParentStack(dashboardIntent)
            .addNextIntent(playerIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    RemoteViews views = new RemoteViews(service.getPackageName(), R.layout.player_small_notification);
    views.setOnClickPendingIntent(R.id.player_pause, getPendingAction(service, "pause"));
    views.setOnClickPendingIntent(R.id.player_previous, getPendingAction(service, "previous"));
    views.setOnClickPendingIntent(R.id.player_next, getPendingAction(service, "next"));
    views.setOnClickPendingIntent(R.id.player_close, getPendingAction(service, "stop"));
    views.setTextViewText(R.id.player_song_name, text);
    views.setViewVisibility(R.id.player_progress_bar, View.GONE);

    mNotificationBuilder = new NotificationCompat.Builder(service).setSmallIcon(R.mipmap.ic_launcher)
            .setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis())
            .setContentIntent(intent).setOngoing(true).setContent(views);

    service.startForeground(NOTIFICATION_ID, mNotificationBuilder.build());
}

From source file:org.dmfs.tasks.notification.NotificationActionUtils.java

/**
 * Creates and displays an Undo notification for the specified {@link NotificationAction}.
 *///from   ww  w  .jav  a  2 s . c  o  m
public static void createUndoNotification(final Context context, NotificationAction action) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(context.getString(action.getActionTextResId()

    ));
    builder.setSmallIcon(R.drawable.ic_notification);
    builder.setWhen(action.getWhen());

    // disable sound & vibration
    builder.setDefaults(0);

    final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification);
    undoView.setTextViewText(R.id.description_text, context.getString(action.mActionTextResId));

    final String packageName = context.getPackageName();

    final Intent clickIntent = new Intent(context, NotificationUpdaterService.class);
    clickIntent.setAction(ACTION_UNDO);
    clickIntent.setPackage(packageName);
    putNotificationActionExtra(clickIntent, action);
    final PendingIntent clickPendingIntent = PendingIntent.getService(context, action.getNotificationId(),
            clickIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    undoView.setOnClickPendingIntent(R.id.status_bar_latest_event_content, clickPendingIntent);
    builder.setContent(undoView);

    // When the notification is cleared, we perform the destructive action
    final Intent deleteIntent = new Intent(context, NotificationUpdaterService.class);
    deleteIntent.setAction(ACTION_DESTRUCT);
    deleteIntent.setPackage(packageName);
    putNotificationActionExtra(deleteIntent, action);
    final PendingIntent deletePendingIntent = PendingIntent.getService(context, action.getNotificationId(),
            deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setDeleteIntent(deletePendingIntent);

    final Notification notification = builder.build();

    final NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(action.getNotificationId(), notification);

    sUndoNotifications.put(action.getNotificationId(), action);
    sNotificationTimestamps.put(action.getNotificationId(), action.mWhen);
}

From source file:com.rks.musicx.services.NotificationHandler.java

public static void buildNotification(MusicXService musicXService, String what) {
    if (musicXService == null) {
        return;//  ww w  .j a v a 2 s . c  o  m
    }
    RemoteViews remoteViews = new RemoteViews(musicXService.getPackageName(), R.layout.widget);
    RemoteViews smallremoteView = new RemoteViews(musicXService.getPackageName(), R.layout.small_notification);

    Intent intent = new Intent(musicXService, PlayingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendInt = PendingIntent.getActivity(musicXService, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(
            musicXService).setWhen(System.currentTimeMillis()).setCategory(Intent.CATEGORY_APP_MUSIC)
                    .setPriority(Notification.PRIORITY_DEFAULT).setShowWhen(false).setAutoCancel(true)
                    .setCustomBigContentView(remoteViews).setContent(smallremoteView)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    remoteViews.setOnClickPendingIntent(R.id.item_view, pendInt);
    smallremoteView.setOnClickPendingIntent(R.id.small_item_view, pendInt);
    remoteViews.setTextViewText(R.id.title, musicXService.getsongTitle());
    remoteViews.setTextViewText(R.id.artist, musicXService.getsongArtistName());
    smallremoteView.setTextViewText(R.id.small_title, musicXService.getsongTitle());
    smallremoteView.setTextViewText(R.id.small_artist, musicXService.getsongArtistName());
    FavHelper favHelper = new FavHelper(musicXService);
    if (favHelper.isFavorite(musicXService.getsongId())) {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite);
    } else {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite_outline);
    }
    if (musicXService.isPlaying()) {
        builder.setSmallIcon(R.drawable.aw_ic_play);
        builder.setOngoing(true);
    } else {
        builder.setSmallIcon(R.drawable.aw_ic_pause);
        builder.setOngoing(false);
    }
    if (what.equals(PLAYSTATE_CHANGED)) {
        if (MediaPlayerSingleton.getInstance().getMediaPlayer().isPlaying()) {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_play);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_play);
        } else {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_pause);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_pause);
        }
    }
    handler.post(new Runnable() {
        @Override
        public void run() {
            ArtworkUtils.ArtworkLoader(musicXService, 300, 300, musicXService.getsongAlbumName(),
                    musicXService.getsongAlbumID(), new palette() {
                        @Override
                        public void palettework(Palette palette) {
                            int colors[] = Helper.getAvailableColor(musicXService, palette);
                            remoteViews.setInt(R.id.item_view, "setBackgroundColor", colors[0]);
                            remoteViews.setInt(R.id.title, "setTextColor", Color.WHITE);
                            remoteViews.setInt(R.id.artist, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_item_view, "setBackgroundColor", colors[0]);
                            smallremoteView.setInt(R.id.small_title, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_artist, "setTextColor", Color.WHITE);
                        }
                    }, new bitmap() {
                        @Override
                        public void bitmapwork(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }

                        @Override
                        public void bitmapfailed(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }
                    });
        }
    });
    controls(remoteViews, smallremoteView, musicXService);
}

From source file:com.oryx.notifications.NotificationService.java

private RemoteViews getNotiView(PendingIntent pi, PendingIntent pi2) {
    RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.noti_custom);
    remoteViews.setTextViewText(R.id.notiURL, this.url);
    remoteViews.setOnClickPendingIntent(R.id.notipause, pi);
    remoteViews.setOnClickPendingIntent(R.id.notiplay, pi2);
    return remoteViews;
}

From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java

/**
 * Updates the record button.//from  w ww  . j a va2s .  c  o m
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param isRecording true if recording
 * @param recordingTrackPaused true if recording track is paused
 */
private static void updateRecordButton(Context context, RemoteViews remoteViews, boolean isRecording,
        boolean recordingTrackPaused) {
    remoteViews.setImageViewResource(R.id.track_widget_record_button,
            isRecording && !recordingTrackPaused ? R.drawable.btn_pause : R.drawable.btn_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:HomescreenWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    for (int count = 0; count < appWidgetIds.length; count++) {
        RemoteViews appWidgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget);
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        appWidgetLayout.setOnClickPendingIntent(R.id.analogClock, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds[count], appWidgetLayout);
    }/* www .  j av  a2s.c  o m*/
}

From source file:org.chromium.tools.audio_focus_grabber.AudioFocusGrabberListenerService.java

private void showNotification() {
    RemoteViews view = new RemoteViews(this.getPackageName(), R.layout.audio_focus_grabber_notification_bar);
    view.setOnClickPendingIntent(R.id.notification_button_gain, createPendingIntent(ACTION_GAIN));
    view.setOnClickPendingIntent(R.id.notification_button_transient_pause,
            createPendingIntent(ACTION_TRANSIENT_PAUSE));
    view.setOnClickPendingIntent(R.id.notification_button_transient_duck,
            createPendingIntent(ACTION_TRANSIENT_DUCK));
    view.setOnClickPendingIntent(R.id.notification_button_hide, createPendingIntent(ACTION_HIDE_NOTIFICATION));

    NotificationManagerCompat manager = NotificationManagerCompat.from(this);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(view)
            .setSmallIcon(R.drawable.notification_icon);
    manager.notify(NOTIFICATION_ID, builder.build());
}

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

/**
 * Updates the record button.//from  w w w . ja v  a  2 s  . c  o m
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param isRecording true if recording
 * @param recordingTrackPaused true if recording track is paused
 */
private static void updateRecordButton(Context context, RemoteViews remoteViews, boolean isRecording,
        boolean recordingTrackPaused) {
    remoteViews.setImageViewResource(R.id.track_widget_record_button,
            isRecording && !recordingTrackPaused ? R.drawable.button_pause : R.drawable.button_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.example.samples.mp3player.Mp3PlayerService.java

/**
 * Show a notification while this service is running.
 *///ww w. j a v  a 2s  . c  o  m
private Notification buildMp3PlayerNotification() {
    CharSequence title = getText(R.string.mp3player_service_started);
    CharSequence text = getText(R.string.mp3player_service_label);

    Intent i = new Intent(this, Mp3Player.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle()
            .addLine("M.Twain (Google+) Haiku is more than a cert...").addLine("M.Twain Reminder")
            .addLine("M.Twain Lunch?").addLine("M.Twain Revised Specs").addLine("M.Twain ")
            .addLine("Google Play Celebrate 25 billion apps with Goo..")
            .addLine("Stack Exchange StackOverflow weekly Newsl...").setBigContentTitle("6 new message")
            .setSummaryText("mtwain@android.com");

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_sample).setContentTitle(title).setContentText(text);
    //.setContentIntent(contentIntent);

    Notification noti = mBuilder.build();

    RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.mp3player_notification);
    expandedView.setOnClickPendingIntent(R.id.noti_image, contentIntent);
    expandedView.setOnClickPendingIntent(R.id.noti_button_play, contentIntent);

    noti.bigContentView = expandedView;
    noti.flags |= Notification.FLAG_NO_CLEAR;

    return noti;
}

From source file:info.bits.phoneastablet.utils.NotificationHandler.java

/**
 * Sets the listeners for the buttons at the notification area.
 *
 * @param view//  w w w.ja  v  a  2 s.c o  m
 */
public void setListeners(RemoteViews view) {
    //App start listener
    Intent app = new Intent(context, NotificationButtonsHandler.class);
    app.putExtra("DO", "app");
    PendingIntent pApp = PendingIntent.getActivity(context, 0, app, 0);
    view.setOnClickPendingIntent(R.id.app, pApp);

    //default screen size listener
    Intent defaultResolution = new Intent(context, NotificationButtonsHandler.class);
    defaultResolution.putExtra("DO", "default");
    PendingIntent pDefaultResolution = PendingIntent.getActivity(context, 1, defaultResolution, 0);
    view.setOnClickPendingIntent(R.id.default_resolution, pDefaultResolution);

    //custom screen size listener
    Intent customResolution = new Intent(context, NotificationButtonsHandler.class);
    customResolution.putExtra("DO", "custom");
    PendingIntent pCustomResolution = PendingIntent.getActivity(context, 2, customResolution, 0);
    view.setOnClickPendingIntent(R.id.custom_resolution, pCustomResolution);
}