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.teclib.service.NotificationAdminRequest.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);

    Intent intent = new Intent(this, MQTTNotifierActivity.class);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.installAsk_string))
            .setOngoing(true).setContentIntent(pIntent).setAutoCancel(true).setContent(remoteViews);

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.installAsk_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(6, builder.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  www. java  2 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.rks.musicx.services.NotificationHandler.java

public static void buildNotification(MusicXService musicXService, String what) {
    if (musicXService == null) {
        return;//from www  . jav a  2s .  c  om
    }
    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:github.daneren2005.dsub.util.Util.java

private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing) {

    // Use the same text for the ticker and the expanded notification
    String title = song.getTitle();
    String arist = song.getArtist();
    String album = song.getAlbum();

    // Set the album art.
    try {/*  w  ww  . j  a v  a  2  s .c om*/
        int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight();
        Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size);
        if (bitmap == null) {
            // set default album art
            rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
        } else {
            rv.setImageViewBitmap(R.id.notification_image, bitmap);
        }
    } catch (Exception x) {
        Log.w(TAG, "Failed to get notification cover art", x);
        rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
    }

    // set the text for the notifications
    rv.setTextViewText(R.id.notification_title, title);
    rv.setTextViewText(R.id.notification_artist, arist);
    rv.setTextViewText(R.id.notification_album, album);

    Pair<Integer, Integer> colors = getNotificationTextColors(context);
    if (colors.getFirst() != null) {
        rv.setTextColor(R.id.notification_title, colors.getFirst());
    }
    if (colors.getSecond() != null) {
        rv.setTextColor(R.id.notification_artist, colors.getSecond());
    }

    if (!playing) {
        rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play);
        rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop);
    }

    // Create actions for media buttons
    PendingIntent pendingIntent;
    if (playing) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
        prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
    } else {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
        prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
    }

    Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
    pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
    pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
    rv.setOnClickPendingIntent(R.id.control_pause, pendingIntent);

    Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
    nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
    pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
    rv.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}

From source file:com.teclib.service.NotificationPasswordPolicies.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);
    Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setOngoing(true)
            .setTicker(getString(R.string.passwordPoliciesNotification_string)).setContentIntent(pIntent)
            .setContent(remoteViews);//w ww . jav  a2 s.  c o  m

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.passwordPoliciesNotification_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(5, builder.build());

}

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

private void updateNotification() {
    if (mService == null)
        return;/*  www. j  a v a  2 s.  com*/

    if (mMediaNotificationInfo == null) {
        // Notification was hidden before we could update it.
        assert mNotificationBuilder == null;
        return;
    }

    // Android doesn't badge the icons for RemoteViews automatically when
    // running the app under the Work profile.
    if (mNotificationIcon == null) {
        Drawable notificationIconDrawable = ApiCompatibilityUtils.getUserBadgedIcon(mContext,
                R.drawable.audio_playing);
        mNotificationIcon = drawableToBitmap(notificationIconDrawable);
    }

    if (mNotificationBuilder == null) {
        mNotificationBuilder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.audio_playing)
                .setAutoCancel(false).setLocalOnly(true)
                .setDeleteIntent(mService.getPendingIntent(ListenerService.ACTION_STOP));
    }
    mNotificationBuilder.setOngoing(!mMediaNotificationInfo.isPaused);
    mNotificationBuilder.setContentIntent(createContentIntent());

    RemoteViews contentView = createContentView();

    contentView.setTextViewText(R.id.title, mMediaNotificationInfo.title);
    contentView.setTextViewText(R.id.status, getStatus());
    if (mNotificationIcon != null) {
        contentView.setImageViewBitmap(R.id.icon, mNotificationIcon);
    } else {
        contentView.setImageViewResource(R.id.icon, R.drawable.audio_playing);
    }

    if (mMediaNotificationInfo.isPaused) {
        contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_play);
        contentView.setContentDescription(R.id.playpause, mPlayDescription);
        contentView.setOnClickPendingIntent(R.id.playpause,
                mService.getPendingIntent(ListenerService.ACTION_PLAY));
    } else {
        contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_pause);
        contentView.setContentDescription(R.id.playpause, mPauseDescription);
        contentView.setOnClickPendingIntent(R.id.playpause,
                mService.getPendingIntent(ListenerService.ACTION_PAUSE));
    }

    mNotificationBuilder.setContent(contentView);
    mNotificationBuilder.setVisibility(mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY_PRIVATE
            : NotificationCompat.VISIBILITY_PUBLIC);

    if (mMediaSession == null) {
        mMediaSession = new MediaSessionCompat(mContext, mContext.getString(R.string.app_name),
                new ComponentName(mContext.getPackageName(), MediaButtonReceiver.class.getName()), null);
        mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mMediaSession.setCallback(mMediaSessionCallback);
        mMediaSession.setActive(true);
    }

    mMediaSession.setMetadata(createMetadata());

    PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder()
            .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE);
    if (mMediaNotificationInfo.isPaused) {
        playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED,
                PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
    } else {
        playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING,
                PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
    }
    mMediaSession.setPlaybackState(playbackStateBuilder.build());

    Notification notification = mNotificationBuilder.build();

    // We keep the service as a foreground service while the media is playing. When it is not,
    // the service isn't stopped but is no longer in foreground, thus at a lower priority.
    // While the service is in foreground, the associated notification can't be swipped away.
    // Moving it back to background allows the user to remove the notification.
    if (mMediaNotificationInfo.isPaused) {
        mService.stopForeground(false /* removeNotification */);

        NotificationManagerCompat manager = NotificationManagerCompat.from(mContext);
        manager.notify(R.id.media_playback_notification, notification);
    } else {
        mService.startForeground(R.id.media_playback_notification, notification);
    }
}

From source file:com.teclib.service.MQTTNotificationService.java

public void CustomNotificationNoConnected(String title) {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_mqtt_no_connect);

    String strtitle = getString(R.string.app_name);

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("title", strtitle);
    intent.putExtra("text", title);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.enrolement_string))
            .setOngoing(true).setContentIntent(pIntent).setContent(remoteViews);

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_no_connect);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, title);

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(1, builder.build());

}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshDataStatus(Context context, RemoteViews widget, boolean isDataEnabled) {
    if (isDataEnabled) {
        widget.setImageViewResource(R.id.data, R.drawable.status_data_on);
    } else {/*www.  ja va  2  s .  co m*/
        widget.setImageViewResource(R.id.data, R.drawable.status_data_off);
    }
}

From source file:com.teclib.service.MQTTNotificationService.java

public void CustomNotificationConnected(String title) {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_mqtt_connect);

    String strtitle = getString(R.string.app_name);

    Intent intent = new Intent(this, MQTTNotifierActivity.class);

    intent.putExtra("title", strtitle);
    intent.putExtra("text", title);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.enrolement_string))
            .setContentIntent(pIntent).setOngoing(true).setContent(remoteViews);

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_connect);
    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, title);

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(1, builder.build());

}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshGpsStatus(Context context, RemoteViews widget, boolean isLocationEnabled) {
    if (isLocationEnabled) {
        widget.setImageViewResource(R.id.gps, R.drawable.status_gps_on);
    } else {//  w  ww. j a  v  a  2s.  c  o  m
        widget.setImageViewResource(R.id.gps, R.drawable.status_gps_off);
    }
}