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:android.support.v7.app.NotificationCompatImplBase.java

private static <T extends NotificationCompatBase.Action> RemoteViews generateContentView(Context context,
        CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number,
        Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, List<T> actions,
        int[] actionsToShowInCompact, boolean showCancelButton, PendingIntent cancelButtonIntent) {
    RemoteViews view = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon,
            subText, useChronometer, when, R.layout.notification_template_media, true /* fitIn1U */);

    final int numActions = actions.size();
    final int N = actionsToShowInCompact == null ? 0
            : Math.min(actionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT);
    view.removeAllViews(R.id.media_actions);
    if (N > 0) {
        for (int i = 0; i < N; i++) {
            if (i >= numActions) {
                throw new IllegalArgumentException(String.format(
                        "setShowActionsInCompactView: action %d out of bounds (max %d)", i, numActions - 1));
            }//from w  w  w.  j  a va 2  s  . c o  m

            final NotificationCompatBase.Action action = actions.get(actionsToShowInCompact[i]);
            final RemoteViews button = generateMediaActionButton(context, action);
            view.addView(R.id.media_actions, button);
        }
    }
    if (showCancelButton) {
        view.setViewVisibility(R.id.end_padder, View.GONE);
        view.setViewVisibility(R.id.cancel_action, View.VISIBLE);
        view.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent);
        view.setInt(R.id.cancel_action, "setAlpha",
                context.getResources().getInteger(R.integer.cancel_button_image_alpha));
    } else {
        view.setViewVisibility(R.id.end_padder, View.VISIBLE);
        view.setViewVisibility(R.id.cancel_action, View.GONE);
    }
    return view;
}

From source file:org.chromium.chrome.browser.notifications.CustomNotificationBuilder.java

@Override
public Notification build() {
    RemoteViews compactView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification);
    RemoteViews bigView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_big);

    String time = DateFormat.getTimeFormat(mContext).format(new Date());
    for (RemoteViews view : new RemoteViews[] { compactView, bigView }) {
        view.setTextViewText(R.id.time, time);
        view.setTextViewText(R.id.title, mTitle);
        view.setTextViewText(R.id.body, mBody);
        view.setTextViewText(R.id.origin, mOrigin);
        view.setImageViewBitmap(R.id.icon, mLargeIcon);
    }/* ww w  . j a  v a2  s  .  c o m*/

    if (!mActions.isEmpty()) {
        bigView.setViewVisibility(R.id.button_divider, View.VISIBLE);
        bigView.setViewVisibility(R.id.buttons, View.VISIBLE);
        for (Action action : mActions) {
            RemoteViews button = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_button);
            button.setTextViewCompoundDrawablesRelative(R.id.button, action.getIcon(), 0, 0, 0);
            button.setTextViewText(R.id.button, action.getTitle());
            button.setOnClickPendingIntent(R.id.button, action.getActionIntent());
            bigView.addView(R.id.buttons, button);
        }
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setTicker(mTickerText);
    builder.setSmallIcon(mSmallIconId);
    builder.setContentIntent(mContentIntent);
    builder.setDeleteIntent(mDeleteIntent);
    builder.setDefaults(mDefaults);
    builder.setVibrate(mVibratePattern);
    builder.setContent(compactView);

    Notification notification = builder.build();
    notification.bigContentView = bigView;
    return notification;
}

From source file:co.carlosjimenez.android.currencyalerts.app.widget.DetailWidgetProvider.java

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) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_detail);

        // Create an Intent to launch MainActivity
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        views.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Set up the header
        setMainCurrencyDetails(context, views, appWidgetIds);

        // Set up the collection
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            setRemoteAdapter(context, views, appWidgetIds);
        } else {/* w  w  w .  j av a  2s .com*/
            setRemoteAdapterV11(context, views, appWidgetIds);
        }
        Intent clickIntentTemplate = new Intent(context, DetailActivity.class);

        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
        views.setEmptyView(R.id.widget_list, R.id.widget_empty);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:com.frostwire.android.gui.NotificationUpdateDemon.java

private void setupNotification() {
    if (!ConfigurationManager.instance()
            .getBoolean(Constants.PREF_KEY_GUI_ENABLE_PERMANENT_STATUS_NOTIFICATION)) {
        return;//from w w w .  ja  va  2s . c  om
    }

    RemoteViews remoteViews = new RemoteViews(mParentContext.getPackageName(),
            R.layout.view_permanent_status_notification);

    PendingIntent showFrostWireIntent = createShowFrostwireIntent();
    PendingIntent shutdownIntent = createShutdownIntent();

    remoteViews.setOnClickPendingIntent(R.id.view_permanent_status_shutdown, shutdownIntent);
    remoteViews.setOnClickPendingIntent(R.id.view_permanent_status_text_title, showFrostWireIntent);
    Notification notification = new NotificationCompat.Builder(mParentContext,
            Constants.FROSTWIRE_NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.frostwire_notification_flat)
                    .setContentIntent(showFrostWireIntent).setContent(remoteViews).build();

    notification.flags |= Notification.FLAG_NO_CLEAR;

    notificationViews = remoteViews;
    notificationObject = notification;
}

From source file:com.mathi_amorim.emmanuel.metrictime.UpdateTimeService.java

private void updateWidget() {
    mCalendar.setTimeInMillis(System.currentTimeMillis());

    MetricTime time = MetricTimeConverter.currentMetricTime();
    String currentTime = String.format("%1$01d:%2$02d", time.hours, time.minutes);

    RemoteViews mRemoteViews = new RemoteViews(getPackageName(), R.layout.metric_time_widget);
    mRemoteViews.setTextViewText(R.id.widget1label, currentTime);

    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    mRemoteViews.setOnClickPendingIntent(R.id.widget1label, pendingIntent);

    ComponentName mComponentName = new ComponentName(this, MetricTimeWidgetProvider.class);
    AppWidgetManager mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetManager.updateAppWidget(mComponentName, mRemoteViews);
}

From source file:com.tingtingapps.securesms.service.KeyCachingService.java

private void foregroundServiceICS() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    RemoteViews remoteViews = new RemoteViews(getPackageName(),
            com.tingtingapps.securesms.R.layout.key_caching_notification);

    remoteViews.setOnClickPendingIntent(com.tingtingapps.securesms.R.id.lock_cache_icon, buildLockIntent());

    builder.setSmallIcon(com.tingtingapps.securesms.R.drawable.icon_cached);
    builder.setContent(remoteViews);/*from ww  w  .ja  va2  s.c  om*/
    builder.setContentIntent(buildLaunchIntent());

    stopForeground(true);
    startForeground(SERVICE_RUNNING_ID, builder.build());
}

From source file:com.audiokernel.euphonyrmt.service.NotificationHandler.java

/**
 * A method to update the play state icon to a "paused" state.
 *
 * @param resultView The notification view to edit.
 *//*from w ww.j  a  va  2  s. c  o m*/
private void updateStatePaused(final RemoteViews resultView) {
    final PendingIntent playAction = buildPendingIntent(MPDControl.ACTION_PLAY);

    resultView.setOnClickPendingIntent(R.id.notificationPlayPause, playAction);
    resultView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_media_play);
}

From source file:com.audiokernel.euphonyrmt.service.NotificationHandler.java

/**
 * A method to update the play state icon to a "play" state.
 *
 * @param resultView The notification view to edit.
 *///w w w .ja  va  2s  .  c  o  m
private void updateStatePlaying(final RemoteViews resultView) {
    final PendingIntent pauseAction = buildPendingIntent(MPDControl.ACTION_PAUSE);

    resultView.setOnClickPendingIntent(R.id.notificationPlayPause, pauseAction);
    resultView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_media_pause);
}

From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java

void showNotification(boolean custom) {
    final Resources res = getResources();
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            NOTIFICATION_SERVICE);//from   w  ww.j  a  v a  2s.c o m

    Notification.Builder builder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notify_example).setAutoCancel(true)
            .setTicker(getString(R.string.notification_text))
            .setContentIntent(getDialogPendingIntent("Tapped the notification entry."));

    if (custom) {
        // Sets a custom content view for the notification, including an image button.
        RemoteViews layout = new RemoteViews(getPackageName(), R.layout.notification);
        layout.setTextViewText(R.id.notification_title, getString(R.string.app_name));
        layout.setOnClickPendingIntent(R.id.notification_button,
                getDialogPendingIntent("Tapped the 'dialog' button in the notification."));
        builder.setContent(layout);

        // Notifications in Android 3.0 now have a standard mechanism for displaying large
        // bitmaps such as contact avatars. Here, we load an example image and resize it to the
        // appropriate size for large bitmaps in notifications.
        Bitmap largeIconTemp = BitmapFactory.decodeResource(res, R.drawable.notification_default_largeicon);
        Bitmap largeIcon = Bitmap.createScaledBitmap(largeIconTemp,
                res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height), false);
        largeIconTemp.recycle();

        builder.setLargeIcon(largeIcon);

    } else {
        builder.setNumber(7) // An example number.
                .setContentTitle(getString(R.string.app_name))
                .setContentText(getString(R.string.notification_text));
    }

    notificationManager.notify(NOTIFICATION_DEFAULT, builder.getNotification());
}

From source file:com.devbrackets.android.playlistcore.helper.NotificationHelper.java

/**
 * Creates the RemoteViews used for the expanded (big) notification
 *
 * @return The resulting RemoteViews/*from ww  w .j  a v a2 s . com*/
 */
@NonNull
protected RemoteViews getBigNotification(Class<? extends Service> serviceClass) {
    RemoteViews bigContent = new RemoteViews(context.getPackageName(),
            R.layout.playlistcore_big_notification_content);

    bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_close,
            createPendingIntent(RemoteActions.ACTION_STOP, serviceClass));
    bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_playpause,
            createPendingIntent(RemoteActions.ACTION_PLAY_PAUSE, serviceClass));
    bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_next,
            createPendingIntent(RemoteActions.ACTION_NEXT, serviceClass));
    bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_prev,
            createPendingIntent(RemoteActions.ACTION_PREVIOUS, serviceClass));

    bigContent.setTextViewText(R.id.playlistcore_big_notification_title, notificationInfo.getTitle());
    bigContent.setTextViewText(R.id.playlistcore_big_notification_album, notificationInfo.getAlbum());
    bigContent.setTextViewText(R.id.playlistcore_big_notification_artist, notificationInfo.getArtist());
    bigContent.setBitmap(R.id.playlistcore_big_notification_large_image, "setImageBitmap",
            notificationInfo.getLargeImage());
    bigContent.setBitmap(R.id.playlistcore_big_notification_secondary_image, "setImageBitmap",
            notificationInfo.getSecondaryImage());

    //Makes sure the play/pause, next, and previous are displayed correctly
    if (notificationInfo.getMediaState() != null) {
        updateBigNotificationMediaState(bigContent);
    }

    return bigContent;
}