Example usage for android.widget RemoteViews setImageViewResource

List of usage examples for android.widget RemoteViews setImageViewResource

Introduction

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

Prototype

public void setImageViewResource(int viewId, int srcId) 

Source Link

Document

Equivalent to calling ImageView#setImageResource(int)

Usage

From source file:com.devbrackets.android.exomedia.EMNotification.java

/**
 * Updates the images for the play/pause button so that only valid ones are
 * displayed with the correct state.//from   ww w  .  ja va  2s.c  om
 *
 * @param customNotification The RemoteViews to use to modify the state
 */
private void updateCustomNotificationMediaState(RemoteViews customNotification) {
    NotificationMediaState state = notificationInfo.getMediaState();
    if (customNotification == null || state == null) {
        return;
    }

    customNotification.setImageViewResource(R.id.exomedia_notification_playpause,
            state.isPlaying() ? R.drawable.exomedia_notification_pause : R.drawable.exomedia_notification_play);
    customNotification.setInt(R.id.exomedia_notification_prev, "setVisibility",
            state.isPreviousEnabled() ? View.VISIBLE : View.GONE);
    customNotification.setInt(R.id.exomedia_notification_next, "setVisibility",
            state.isNextEnabled() ? View.VISIBLE : View.GONE);
}

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  w w .  ja va  2s  . c om
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.download_icon;

    return notification;

}

From source file:de.hero.vertretungsplan.HtmlWork.java

@SuppressLint("NewApi")
private void updateWidget(boolean before) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
        AppWidgetManager appManager = AppWidgetManager.getInstance(context);
        ComponentName name = new ComponentName(context, WidgetProvider.class);
        if (before) {
            widget.setImageViewResource(R.id.aktButton, R.drawable.ic_action_aktualisieren_pressed);
        } else {//from www  .  j a v  a  2  s  .c  o m
            widget.setImageViewResource(R.id.aktButton, R.drawable.aktualisieren_drawable);
            if (dataChanged) {
                appManager.notifyAppWidgetViewDataChanged(appManager.getAppWidgetIds(name), R.id.words);
            }
        }
        appManager.partiallyUpdateAppWidget(appManager.getAppWidgetIds(name), widget);
    }
}

From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java

/**
 * Make notification and post it to the NotificationManager
 * //from  www .  j av a  2 s .co m
 * @param tickerIcon
 *            Icon shown in notification bar
 * @param contentIcon
 *            Icon shown in notification
 * @param tickerText
 *            Text shown in notification bar
 * @param contentTitle
 *            Title shown in notification
 * @param contentText
 *            Description shown in notification
 * @param contentTime
 *            Time shown in notification
 * @param when2
 */
private void makeNotification(int tickerIcon, int contentIcon, CharSequence tickerText,
        CharSequence contentTitle, CharSequence contentText, CharSequence contentTime, long when2,
        Float temperature) {
    final long when = System.currentTimeMillis();
    // Make notification
    Notification notification = null;

    final Intent notificationIntent = new Intent(WeatherNotificationService.this,
            WeatherNotificationService.class);
    final PendingIntent contentIntent = PendingIntent.getService(WeatherNotificationService.this, 0,
            notificationIntent, 0);

    // Check if Notification.Builder exists (11+)
    if (Build.VERSION.SDK_INT >= 11) {
        // Honeycomb ++
        NotificationBuilder builder = new NotificationBuilder(this);
        builder.setAutoCancel(false);
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        builder.setTicker(tickerText);
        builder.setWhen(when2);
        builder.setSmallIcon(tickerIcon);
        builder.setOngoing(true);
        builder.setContentIntent(contentIntent);
        if (temperature != null)
            builder.makeContentView(contentTitle, contentText, when2, temperature, tickerIcon);
        notification = builder.getNotification();
    } else {
        // Gingerbread --
        notification = new Notification(tickerIcon, tickerText, when);
        notification.flags = Notification.FLAG_ONGOING_EVENT;

        final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.weathernotification);
        contentView.setImageViewResource(R.id.icon, contentIcon);
        contentView.setTextViewText(R.id.title, contentTitle);
        contentView.setTextViewText(R.id.title, contentTitle);
        contentView.setTextViewText(R.id.text, contentText);
        contentView.setTextViewText(R.id.time, contentTime);
        notification.contentView = contentView;
    }
    notification.contentIntent = contentIntent;

    // Post notification
    final NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, notification);
}

From source file:de.hackerspacebremen.push.PushIntentService.java

private void updateAppWidget(Context context, SpaceData data) {
    SharedPreferences dataPersistence = getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();/*from  ww w  .j  a v a  2  s  .  c o m*/

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.appwidget);
    remoteViews.setViewVisibility(R.id.indicatorImage, View.VISIBLE);
    remoteViews.setViewVisibility(R.id.errorText, View.GONE);

    if (data.isSpaceOpen()) {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner);
    } else {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner_blur);
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName componentName = new ComponentName(context, HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}

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

/**
 * Updates the images for the play/pause, next, and previous buttons so that only valid ones are
 * displayed with the correct state.//from   w  w  w  . ja  va 2  s. c  o  m
 *
 * @param bigContent The RemoteViews to use to modify the state
 */
protected void updateBigNotificationMediaState(@Nullable RemoteViews bigContent) {
    NotificationMediaState state = notificationInfo.getMediaState();
    if (bigContent == null || state == null) {
        return;
    }

    bigContent.setImageViewResource(R.id.playlistcore_big_notification_playpause,
            state.isPlaying() ? R.drawable.playlistcore_notification_pause
                    : R.drawable.playlistcore_notification_play);
    bigContent.setInt(R.id.playlistcore_big_notification_prev, "setVisibility",
            state.isPreviousEnabled() ? View.VISIBLE : View.INVISIBLE);
    bigContent.setInt(R.id.playlistcore_big_notification_next, "setVisibility",
            state.isNextEnabled() ? View.VISIBLE : View.INVISIBLE);
}

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

/**
 * Updates the images for the play/pause button so that only valid ones are
 * displayed with the correct state./*w  w  w  . j a v  a  2  s. c  o m*/
 *
 * @param customNotification The RemoteViews to use to modify the state
 */
protected void updateCustomNotificationMediaState(@Nullable RemoteViews customNotification) {
    NotificationMediaState state = notificationInfo.getMediaState();
    if (customNotification == null || state == null) {
        return;
    }

    customNotification.setImageViewResource(R.id.playlistcore_notification_playpause,
            state.isPlaying() ? R.drawable.playlistcore_notification_pause
                    : R.drawable.playlistcore_notification_play);
    customNotification.setInt(R.id.playlistcore_notification_prev, "setVisibility",
            state.isPreviousEnabled() ? View.VISIBLE : View.GONE);
    customNotification.setInt(R.id.playlistcore_notification_next, "setVisibility",
            state.isNextEnabled() ? View.VISIBLE : View.GONE);
}

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.
 *//* ww w  . j  av  a2  s  .co  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:de.hackerspacebremen.fragments.StatusFragment.java

private void updateAppWidget(SpaceData data) {
    SharedPreferences dataPersistence = getActivity().getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();/*from   ww w . ja v a 2s  . com*/

    RemoteViews remoteViews = new RemoteViews(getActivity().getPackageName(), R.layout.appwidget);
    remoteViews.setViewVisibility(R.id.indicatorImage, View.VISIBLE);
    remoteViews.setViewVisibility(R.id.errorText, View.GONE);

    if (data.isSpaceOpen()) {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner);
    } else {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner_blur);
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
    ComponentName componentName = new ComponentName(getActivity(), HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}