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:net.naonedbus.appwidget.HoraireWidgetProvider.java

/**
 * Set pending intent in remote views./*  ww  w  . j  a va2  s  . c  o m*/
 * 
 * @param context
 * @param views
 *            Content remote views
 * @param viewId
 *            The view listening to click
 */
private void setOnClickListener(final Context context, final RemoteViews views, final Favori favori) {
    final Intent intent = new Intent(context, this.getClass());
    intent.setAction(ACTION_APPWIDGET_ON_CLICK);
    intent.putExtra("favori", favori);

    final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, favori.getId(), intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.horaireWidget, pendingIntent);
}

From source file:ch.fixme.status.Widget.java

protected static void updateWidget(final Context ctxt, int widgetId, AppWidgetManager manager, Bitmap bitmap,
        String text) {//w w w.j  a  v  a 2 s.  co m
    RemoteViews views = new RemoteViews(ctxt.getPackageName(), R.layout.widget);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
    Editor edit = prefs.edit();
    if (prefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)) {
        views.setInt(R.id.widget_image, "setBackgroundResource", 0);
    } else {
        views.setInt(R.id.widget_image, "setBackgroundResource", android.R.drawable.btn_default_small);
    }
    if (bitmap != null) {
        views.setImageViewBitmap(R.id.widget_image, bitmap);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, false); // Don't
        // need
        // to
        // force
    } else {
        views.setImageViewResource(R.id.widget_image, android.R.drawable.ic_popup_sync);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, true); // Something
        // went
        // wrong
    }
    if (text != null) {
        views.setTextViewText(R.id.widget_status, text);
        views.setViewVisibility(R.id.widget_status, View.VISIBLE);
    } else {
        views.setViewVisibility(R.id.widget_status, View.GONE);
    }
    Intent clickIntent = new Intent(ctxt, Main.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
    PendingIntent pendingIntent = PendingIntent.getActivity(ctxt, widgetId, clickIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_image, pendingIntent);
    manager.updateAppWidget(widgetId, views);
    // Is initialized
    edit.putBoolean(Main.PREF_INIT_WIDGET + widgetId, true);
    edit.commit();
}

From source file:com.sean.takeastand.alarmprocess.AlarmService.java

private void updateNotification() {
    /*if (!bRepeatingAlarmStepCheck) {
    mNotifTimePassed++;// w  ww.j  av  a  2  s .com
    }
    Log.i(TAG, "time since first notification: " + mNotifTimePassed + setMinutes(mNotifTimePassed));*/
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent[] pendingIntents = makeNotificationIntents();
    RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification);
    rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]);
    rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime);
    /*rvRibbon.setTextViewText(R.id.stand_up_minutes, mNotifTimePassed +
        setMinutes(mNotifTimePassed));
    rvRibbon.setTextViewText(R.id.topTextView, getString(R.string.stand_up_time_up));*/
    NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this);
    alarmNotificationBuilder.setContent(rvRibbon);
    alarmNotificationBuilder.setContentIntent(pendingIntents[0]).setAutoCancel(false)
            .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small)
            .setContentTitle("Take A Stand ")
            //.setContentText("Mark Stood\n" + mNotifTimePassed + setMinutes(mNotifTimePassed))
            .extend(new NotificationCompat.WearableExtender().addAction(
                    new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[1])
                            .build())
                    .setContentAction(0).setHintHideIcon(true)
    //                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed))
    );

    boolean[] alertType;
    if (mCurrentAlarmSchedule != null) {
        alertType = mCurrentAlarmSchedule.getAlertType();
    } else {
        alertType = Utils.getDefaultAlertType(this);
    }

    if ((alertType[0])) {
        alarmNotificationBuilder.setLights(238154000, 1000, 4000);
    }
    if (Utils.getRepeatAlerts(this)) {
        if (alertType[1]) {
            boolean bUseLastStepCounters = false;
            if (!bRepeatingAlarmStepCheck) {
                bRepeatingAlarmStepCheck = true;
                bUseLastStepCounters = UseLastStepCounters(null);
            }
            if (!bUseLastStepCounters) {
                bRepeatingAlarmStepCheck = false;
                alarmNotificationBuilder.setVibrate(mVibrationPattern);
                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT
                        && Utils.getVibrateOverride(this)) {
                    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                    v.vibrate(mVibrationPattern, -1);
                }
            }
        }
        if (alertType[2]) {
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            alarmNotificationBuilder.setSound(soundUri);
        }
    }

    Notification alarmNotification = alarmNotificationBuilder.build();
    notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification);
}

From source file:com.sean.takeastand.alarmprocess.AlarmService.java

private void sendNotification() {
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent[] pendingIntents = makeNotificationIntents();
    RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification);
    rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]);
    notificationClockTime = Utils.getFormattedCalendarTime(Calendar.getInstance(), this);
    rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime);
    NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this);
    alarmNotificationBuilder.setContent(rvRibbon).setContentIntent(pendingIntents[0]).setAutoCancel(false)
            .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small)
            .setContentTitle("Take A Stand ").setContentText(
                    "Mark Stood")
            .extend(new NotificationCompat.WearableExtender().addAction(
                    new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[2])
                            .build())/*ww w.  ja v a  2  s  .  co  m*/
                    .setContentAction(0).setHintHideIcon(true)
    //                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed))
    );

    //Purpose of below is to figure out what type of user alert to give with the notification
    //If scheduled, check settings for that schedule
    //If unscheduled, check user defaults
    if (mCurrentAlarmSchedule != null) {
        boolean[] alertType = mCurrentAlarmSchedule.getAlertType();
        if ((alertType[0])) {
            alarmNotificationBuilder.setLights(238154000, 1000, 4000);
        }
        if (alertType[1]) {
            alarmNotificationBuilder.setVibrate(mVibrationPattern);
            AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) {
                Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(mVibrationPattern, -1);
            }
        }
        if (alertType[2]) {
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            alarmNotificationBuilder.setSound(soundUri);
        }
    } else {
        boolean[] alertType = Utils.getDefaultAlertType(this);
        if ((alertType[0])) {
            alarmNotificationBuilder.setLights(238154000, 1000, 4000);
        }
        if (alertType[1]) {
            alarmNotificationBuilder.setVibrate(mVibrationPattern);
            AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) {
                Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(mVibrationPattern, -1);
            }
        }
        if (alertType[2]) {
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            alarmNotificationBuilder.setSound(soundUri);
        }
    }
    Notification alarmNotification = alarmNotificationBuilder.build();
    notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification);

    if (getSharedPreferences(Constants.USER_SHARED_PREFERENCES, 0).getBoolean(Constants.STANDDTECTORTM_ENABLED,
            false)) {
        Intent standSensorIntent = new Intent(this, StandDtectorTM.class);
        standSensorIntent.setAction(com.heckbot.standdtector.Constants.STANDDTECTOR_START);
        standSensorIntent.putExtra("MILLISECONDS", (long) 60000);

        standSensorIntent.putExtra("pendingIntent", pendingIntents[1]);

        startService(standSensorIntent);
    }
}

From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java

/**
 * Updates the statistics container./* ww w  .  ja  v  a 2 s  .co  m*/
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param track the track
 */
private void updateStatisticsContainer(Context context, RemoteViews remoteViews, Track track) {
    Intent intent;
    if (track != null) {
        intent = IntentUtils.newIntent(context, TrackDetailActivity.class)
                .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId());
    } else {
        intent = IntentUtils.newIntent(context, TrackListActivity.class);
    }
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(context);
    taskStackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0);
    remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.track_widget_labels, pendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.track_widget_logo_button, pendingIntent);

}

From source file:org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls.java

private RemoteViews createContentView() {
    RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.playback_notification_bar);

    // On Android pre-L, dismissing the notification when the service is no longer in foreground
    // doesn't work. Instead, a STOP button is shown.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        contentView.setViewVisibility(R.id.stop, View.VISIBLE);
        contentView.setOnClickPendingIntent(R.id.stop, mService.getPendingIntent(ListenerService.ACTION_STOP));
    }//  w w  w  . ja  v  a 2 s  .  c om
    return contentView;
}

From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java

/**
 * Link up various button actions using {@link PendingIntents}.
 * //from w  ww.ja  v a2 s.co m
 * @param playerActive True if player is active in background, which means
 *            widget click will launch {@link MediaPlayerActivity},
 *            otherwise we launch {@link UriListActivity}.
 */
private void linkButtons(Context context, RemoteViews views, boolean playerActive) {
    // Connect up various buttons and touch events
    Intent intent;
    PendingIntent pendingIntent;

    final ComponentName serviceName = new ComponentName(context, MediaPlaybackService.class);

    if (playerActive) {
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntentWithParentStack(
                new Intent(context, MediaPlayerActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        pendingIntent = stackBuilder.getPendingIntent((int) System.currentTimeMillis(), 0);
        views.setOnClickPendingIntent(R.id.appwidget_two, pendingIntent);
    } else {
        intent = new Intent(context, MainActivity.class);
        pendingIntent = PendingIntent.getActivity(context, 0 /* no requestCode */, intent, 0 /* no flags */);
        views.setOnClickPendingIntent(R.id.appwidget_two, pendingIntent);
    }

    intent = new Intent(MediaPlaybackService.PREVIOUS_ACTION);
    intent.setComponent(serviceName);
    pendingIntent = PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);

    intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION);
    intent.setComponent(serviceName);
    pendingIntent = PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.control_play, pendingIntent);

    intent = new Intent(MediaPlaybackService.NEXT_ACTION);
    intent.setComponent(serviceName);
    pendingIntent = PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}

From source file:org.messic.android.player.MessicPlayerNotification.java

private void createNotification() {
    if (this.notification != null) {
        return;/*from   w  w w  .ja va 2s  .c  o m*/
    }

    mNotificationManager = (NotificationManager) this.service.getSystemService(Context.NOTIFICATION_SERVICE);
    RemoteViews contentView = new RemoteViews(this.service.getPackageName(),
            R.layout.bignotification_player_layout);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this.service)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("title")
            .setPriority(Notification.PRIORITY_MAX).setContent(contentView);

    Notification n = mBuilder.build();
    n.bigContentView = contentView;

    Intent intentClose = new Intent(ACTION_CLOSE);
    PendingIntent pintentClose = PendingIntent.getBroadcast(this.service, 0, intentClose, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivclose, pintentClose);
    Intent intentBack = new Intent(ACTION_BACK);
    PendingIntent pintentBack = PendingIntent.getBroadcast(this.service, 0, intentBack, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivback, pintentBack);
    Intent intentPlay = new Intent(ACTION_PLAY);
    PendingIntent pintentPlay = PendingIntent.getBroadcast(this.service, 0, intentPlay, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivplay, pintentPlay);
    Intent intentPause = new Intent(ACTION_PAUSE);
    PendingIntent pintentPause = PendingIntent.getBroadcast(this.service, 0, intentPause, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivpause, pintentPause);
    Intent intentNext = new Intent(ACTION_NEXT);
    PendingIntent pintentNext = PendingIntent.getBroadcast(this.service, 0, intentNext, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivnext, pintentNext);

    this.notification = n;
    this.service.startForeground(ONGOING_NOTIFICATION_ID, notification);
    this.registerBroadcastActions();
}

From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java

private void addPendingIntents(RemoteViews rv, boolean isPlaying, MediaInfo 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.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) {
            rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark);
        } else {//from ww  w  .j  a  v  a 2  s.  com
            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.google.android.apps.mytracks.widgets.TrackWidgetProvider.java

/**
 * Updates the stop button./*from w w w .  ja v  a2s .co  m*/
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param isRecording true if recording
 */
private void updateStopButton(Context context, RemoteViews remoteViews, boolean isRecording) {
    remoteViews.setImageViewResource(R.id.track_widget_stop_button,
            isRecording ? R.drawable.ic_stop_1 : R.drawable.ic_stop_0);
    remoteViews.setBoolean(R.id.track_widget_stop_button, "setEnabled", isRecording);
    if (isRecording) {
        Intent intent = new Intent(context, ControlRecordingService.class)
                .setAction(context.getString(R.string.track_action_end));
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.track_widget_stop_button, pendingIntent);
    }
}