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.freeme.filemanager.FileExplorerTabActivity.java

public void showButtonNotify() {
    mBuilder = new Builder(this);
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.view_custom_button);
    if (IsFreemeOs.isFreemeOs()) {
        Bitmap bitMap = getApplicationContext().getPackageManager().getIconBitmapWithThemeBg(
                getResources().getDrawable(R.drawable.notification_clean),
                getApplicationContext().getPackageName(), 0);
        remoteViews.setImageViewBitmap(R.id.filemanager_notification_clean, bitMap);
    } else {//from ww  w.  j  a v a2 s.com
        remoteViews.setImageViewResource(R.id.filemanager_notification_clean, R.drawable.notification_clean);
    }
    remoteViews.setTextViewText(R.id.tv_custom_title, getString(R.string.fileManager));
    remoteViews.setTextViewText(R.id.tv_custom_text, getString(R.string.clean_text));

    Intent buttonIntent = new Intent(ACTION_BUTTON);
    buttonIntent.putExtra(INTENT_BUTTONID_TAG, BUTTON_CLEAN_ID);
    PendingIntent intent_clean = PendingIntent.getBroadcast(this, 1, buttonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.btn_custom, intent_clean);

    mBuilder.setContent(remoteViews).setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL))
            .setWhen(System.currentTimeMillis()).setPriority(Notification.PRIORITY_DEFAULT).setOngoing(true)
            .setSmallIcon(R.drawable.notification_small_clean);
    notify = mBuilder.build();
    notify.flags = Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(200, notify);
}

From source file:info.corne.performancetool.MainActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
    String selectedProfile = (String) profilesAdapter.getItem(pos);
    dialog = ProgressDialog.show(this, getResources().getString(R.string.please_wait),
            getResources().getString(R.string.being_saved));
    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(getApplicationContext());

    RemoteViews rv = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_layout);
    if (pos == 0) {
        DefaultSettings settings = new DefaultSettings();
        String[] files = settings.getFileNames();
        String[] values = settings.getValues();

        SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true);
        task.addListener(this);
        task.execute();//from   w w w . ja v a 2s.co m
        rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_default);
    } else if (pos == 1) {
        PowerSettings settings = new PowerSettings();
        String[] files = settings.getFileNames();
        String[] values = settings.getValues();

        SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true);
        task.addListener(this);
        task.execute();
        rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_power);
    } else if (pos == 2) {
        AudioSettings settings = new AudioSettings();
        String[] files = settings.getFileNames();
        String[] values = settings.getValues();

        SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true);
        task.addListener(this);
        task.execute();
        rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_audio);
    } else {
        ProfileSettings settings = new ProfileSettings(selectedProfile, sharedPreferences);
        String[] files = settings.getFileNames();
        String[] values = settings.getValues();

        SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true);
        task.addListener(this);
        task.execute();
        rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_default);
    }

    Editor editor = sharedPreferences.edit();
    editor.putInt(Settings.CURRENT_WIDGET_PROFILE, pos);
    editor.commit();
    ComponentName cn = new ComponentName(getApplicationContext(), WidgetReceiver.class);
    (AppWidgetManager.getInstance(getApplicationContext())).updateAppWidget(cn, rv);
}

From source file:com.nd.android.u.square.service.MusicPlaybackService.java

Notification buildNotification(String text) {
    //        Log.d("yulin", "buildNotification, musicName = " + musicName + ", mIsPause = " + mIsPause);

    NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder(this);
    mNotificationBuilder.setOngoing(true);
    mNotificationBuilder.setAutoCancel(false);
    mNotificationBuilder.setSmallIcon(R.drawable.ic_square_notification_music_play);
    mNotificationBuilder.setTicker(text);

    //Grab the notification layout.
    RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.square_notification_music_play);

    Intent stopServiceIntent = new Intent(ACTION_STOP);
    PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
            stopServiceIntent, 0);//from   www. j  a v a2s  .com

    //Set the notification content.

    notificationView.setTextViewText(R.id.notification_base_line_one, text);

    //Set the "Stop Service" pending intent.
    notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent);

    //Set the album art.
    notificationView.setImageViewResource(R.id.notification_base_image, R.drawable.ic_square_music_default);

    //Attach the shrunken layout to the notification.
    mNotificationBuilder.setContent(notificationView);

    //Build the notification object and set its flags.
    Notification notification = mNotificationBuilder.build();
    notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR
            | Notification.FLAG_ONGOING_EVENT;

    return notification;
}

From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java

/**
 * Get the parameters from the message and create a notification from it.
 * @param context/*from  ww  w.jav a  2 s. c  om*/
 * @param intent
 */
public void handleMessage(Context context, Intent intent) {
    try {
        registerResources(context);
        extractColors(context);

        FREContext ctxt = C2DMExtension.context;

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        // icon is required for notification.
        // @see http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html

        int icon = notificationIcon;
        long when = System.currentTimeMillis();

        // json string

        String parameters = intent.getStringExtra("parameters");
        String facebookId = null;
        JSONObject object = null;
        if (parameters != null) {
            try {
                object = (JSONObject) new JSONTokener(parameters).nextValue();
            } catch (Exception e) {
                Log.d(TAG, "cannot parse the object");
            }
        }
        if (object != null && object.has("facebookId")) {
            facebookId = object.getString("facebookId");
        }

        CharSequence tickerText = intent.getStringExtra("tickerText");
        CharSequence contentTitle = intent.getStringExtra("contentTitle");
        CharSequence contentText = intent.getStringExtra("contentText");

        Intent notificationIntent = new Intent(context, Class.forName(context.getPackageName() + ".AppEntry"));

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        Notification notification = new Notification(icon, tickerText, when);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

        RemoteViews contentView = new RemoteViews(context.getPackageName(), customLayout);

        contentView.setTextViewText(customLayoutTitle, contentTitle);
        contentView.setTextViewText(customLayoutDescription, contentText);

        contentView.setTextColor(customLayoutTitle, notification_text_color);
        contentView.setFloat(customLayoutTitle, "setTextSize",
                notification_title_size_factor * notification_text_size);
        contentView.setTextColor(customLayoutDescription, notification_text_color);
        contentView.setFloat(customLayoutDescription, "setTextSize",
                notification_description_size_factor * notification_text_size);

        if (facebookId != null) {
            Log.d(TAG, "bitmap not null");
            CreateNotificationTask cNT = new CreateNotificationTask();
            cNT.setParams(customLayoutImageContainer, NotifId, nm, notification, contentView);
            String src = "http://graph.facebook.com/" + facebookId + "/picture?type=normal";
            URL url = new URL(src);
            cNT.execute(url);
        } else {
            Log.d(TAG, "bitmap null");
            contentView.setImageViewResource(customLayoutImageContainer, customLayoutImage);
            notification.contentView = contentView;
            nm.notify(NotifId, notification);
        }
        NotifId++;

        if (ctxt != null) {
            parameters = parameters == null ? "" : parameters;
            ctxt.dispatchStatusEventAsync("COMING_FROM_NOTIFICATION", parameters);
        }

    } catch (Exception e) {
        Log.e(TAG, "Error activating application:", e);
    }
}

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

private void refreshCityOrWeather(Context context, String what, int which) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetManager != null) {
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
        for (int appWidgetId : appWidgetIds) {
            RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
            if (1 == which) {
                widget.setTextViewText(R.id.city, what);
            } else if (2 == which) {
                if (what.equals("")) {
                    //widget.setTextViewText(R.id.temperature, context.getString(R.string.weather_network_error));
                } else if (what.contains(",")) {
                    String weather = what.split(",")[0];
                    String temperature = what.split(",")[1];
                    String image = what.split(",")[2];
                    widget.setTextViewText(R.id.temperature, temperature);
                    widget.setImageViewResource(R.id.weather, getWeatherImageId(image));
                }//ww  w  . jav  a 2s .  co  m
            }
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
        }
    }
}

From source file:org.videolan.vlc.MediaService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void showNotification() {
    try {/*from w w  w  .  j a  va  2s .  com*/
        Bitmap cover = AudioUtil.getCover(this, mCurrentMedia, 64);
        String title = mCurrentMedia.getTitle();
        String artist = mCurrentMedia.getArtist();
        String album = mCurrentMedia.getAlbum();
        Notification notification;

        // add notification to status bar
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false)
                .setOngoing(true);

        Intent notificationIntent = new Intent(this,
                mIsVout ? MediaPlayerActivity.class : AudioPlayerActivity.class);
        notificationIntent.setAction(Intent.ACTION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (Util.isJellyBeanOrLater()) {
            Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD);
            Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE);
            Intent iForward = new Intent(ACTION_REMOTE_FORWARD);
            Intent iStop = new Intent(ACTION_REMOTE_STOP);
            PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
            if (cover != null)
                view.setImageViewBitmap(R.id.cover, cover);
            view.setTextViewText(R.id.songName, title);
            view.setTextViewText(R.id.artist, artist);
            view.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play);
            view.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view.setOnClickPendingIntent(R.id.forward, piForward);
            view.setOnClickPendingIntent(R.id.stop, piStop);
            view.setOnClickPendingIntent(R.id.content, pendingIntent);

            RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);
            if (cover != null)
                view_expanded.setImageViewBitmap(R.id.cover, cover);
            view_expanded.setTextViewText(R.id.songName, title);
            view_expanded.setTextViewText(R.id.artist, artist);
            view_expanded.setTextViewText(R.id.album, album);
            view_expanded.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play);
            view_expanded.setOnClickPendingIntent(R.id.backward, piBackward);
            view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view_expanded.setOnClickPendingIntent(R.id.forward, piForward);
            view_expanded.setOnClickPendingIntent(R.id.stop, piStop);
            view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent);

            notification = builder.build();
            notification.contentView = view;
            notification.bigContentView = view_expanded;
        } else {
            builder.setLargeIcon(cover).setContentTitle(title)
                    .setContentText(Util.isJellyBeanOrLater() ? artist : mCurrentMedia.getSubtitle())
                    .setContentInfo(album).setContentIntent(pendingIntent);
            notification = builder.build();
        }

        startForeground(3, notification);
    } catch (NoSuchMethodError e) {
        // Compat library is wrong on 3.2
        // http://code.google.com/p/android/issues/detail?id=36359
        // http://code.google.com/p/android/issues/detail?id=36502
    }
}

From source file:com.namelessdev.mpdroid.NotificationService.java

/**
 * This method builds the base, otherwise known as the collapsed notification. The expanded
 * notification method builds upon this method.
 *
 * @param resultView The RemoteView to begin with, be it new or from the current notification.
 * @return The base, otherwise known as, collapsed notification resources for RemoteViews.
 *///from  w w  w  . ja v a  2 s  .  co m
private RemoteViews buildBaseNotification(final RemoteViews resultView) {
    final String title = mCurrentMusic.getTitle();

    /** If in streaming, the notification should be persistent. */
    if (app.getApplicationState().streamingMode && !StreamingService.isWoundDown()) {
        resultView.setViewVisibility(R.id.notificationClose, View.GONE);
    } else {
        resultView.setViewVisibility(R.id.notificationClose, View.VISIBLE);
        resultView.setOnClickPendingIntent(R.id.notificationClose, notificationClose);
    }

    if (MPDStatus.MPD_STATE_PLAYING.equals(getStatus().getState())) {
        resultView.setOnClickPendingIntent(R.id.notificationPlayPause, notificationPause);
        resultView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_media_pause);
    } else {
        resultView.setOnClickPendingIntent(R.id.notificationPlayPause, notificationPlay);
        resultView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_media_play);
    }

    /** When streaming, move things down (hopefully, very) temporarily. */
    if (mediaPlayerServiceIsBuffering) {
        resultView.setTextViewText(R.id.notificationTitle, getString(R.string.buffering));
        resultView.setTextViewText(R.id.notificationArtist, title);
    } else {
        resultView.setTextViewText(R.id.notificationTitle, title);
        resultView.setTextViewText(R.id.notificationArtist, mCurrentMusic.getArtist());
    }

    resultView.setOnClickPendingIntent(R.id.notificationNext, notificationNext);

    if (mAlbumCover != null) {
        resultView.setImageViewUri(R.id.notificationIcon, Uri.parse(mAlbumCoverPath));
    }

    return resultView;
}

From source file:com.yamin.kk.service.AudioService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void showNotification() {
    try {// w w w.  j a v  a2  s.c o m
        Bitmap cover = AudioUtil.getCover(this, getCurrentMedia(), 64);
        String title = getCurrentMedia().getTitle();
        String artist = getCurrentMedia().getArtist();
        String album = getCurrentMedia().getAlbum();
        Notification notification;

        // add notification to status bar
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false)
                .setOngoing(true);

        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(MainActivity.ACTION_SHOW_PLAYER);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (Util.isJellyBeanOrLater()) {
            Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD);
            Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE);
            Intent iForward = new Intent(ACTION_REMOTE_FORWARD);
            Intent iStop = new Intent(ACTION_REMOTE_STOP);
            PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
            if (cover != null)
                view.setImageViewBitmap(R.id.cover, cover);
            view.setTextViewText(R.id.songName, title);
            view.setTextViewText(R.id.artist, artist);
            view.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play);
            view.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view.setOnClickPendingIntent(R.id.forward, piForward);
            view.setOnClickPendingIntent(R.id.stop, piStop);
            view.setOnClickPendingIntent(R.id.content, pendingIntent);

            RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);
            if (cover != null)
                view_expanded.setImageViewBitmap(R.id.cover, cover);
            view_expanded.setTextViewText(R.id.songName, title);
            view_expanded.setTextViewText(R.id.artist, artist);
            view_expanded.setTextViewText(R.id.album, album);
            view_expanded.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play);
            view_expanded.setOnClickPendingIntent(R.id.backward, piBackward);
            view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view_expanded.setOnClickPendingIntent(R.id.forward, piForward);
            view_expanded.setOnClickPendingIntent(R.id.stop, piStop);
            view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent);

            notification = builder.build();
            notification.contentView = view;
            notification.bigContentView = view_expanded;
        } else {
            builder.setLargeIcon(cover).setContentTitle(title)
                    .setContentText(Util.isJellyBeanOrLater() ? artist : getCurrentMedia().getSubtitle())
                    .setContentInfo(album).setContentIntent(pendingIntent);
            notification = builder.build();
        }

        startService(new Intent(this, AudioService.class));
        startForeground(3, notification);
    } catch (NoSuchMethodError e) {
        // Compat library is wrong on 3.2
        // http://code.google.com/p/android/issues/detail?id=36359
        // http://code.google.com/p/android/issues/detail?id=36502
    }
}

From source file:eu.trentorise.smartcampus.widget.shortcuts.StackWidgetService.java

@Override
public RemoteViews getViewAt(int position) {
    // position will always range from 0 to getCount() - 1.

    // We construct a remote views item based on our widget item xml
    // file, and set the
    // text based on the position.
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
    sd1.getPaint().setColor(0xFFFFFFFF);
    sd1.getPaint().setStyle(Style.STROKE);
    sd1.getPaint().setStrokeWidth(1);/*from w ww  .j  a v a2s .  c o  m*/
    Canvas c = new Canvas();
    sd1.draw(c);
    Bitmap b = Bitmap.createBitmap(120, 120, Bitmap.Config.ARGB_8888);
    c.drawBitmap(b, 0, 0, sd1.getPaint());
    // Next, we set a fill-intent which will be used to fill-in the
    // pending intent template
    // which is set on the collection view in StackWidgetProvider.

    if (ALLPREFERENCES != null && ALLPREFERENCES[position] != null) { //ALLPREFERENCES  dimensionato come le preferenze selezionate

        BookmarkDescriptor myDescriptor = ALLPREFERENCES[position];

        // set the widgetbutton
        if (WidgetHelper.PARAM_TYPE.equals(myDescriptor.params.get(0).name)) { //controllare con gli input da config activity?
            String type = myDescriptor.params.get(0).value;
            if (WidgetHelper.TYPE_DT.equals(type)) {
                // dt -> put icons and hide text
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));

                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_dt);

            } else if (WidgetHelper.TYPE_JP.equals(type)) {
                // jp -> put text and hide icon

                rv.setViewVisibility(R.id.image_widget_item, View.GONE);
                // rv.setImageViewBitmap(R.id.text_widget_item,
                // getBackground(Color.parseColor("#6EB046")));
                if (!("0".equals(myDescriptor.params.get(2).value))) {
                    //bus
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 80);

                    rv.setTextViewText(R.id.text_widget_item, RoutesHelper.getShortNameByRouteIdAndAgencyID(
                            myDescriptor.params.get(4).value, myDescriptor.params.get(3).value)); //4,3
                    rv.setTextColor(R.id.text_widget_item, Integer.parseInt(myDescriptor.params.get(2).value));//rv.setInt(R.id.text_widget_item, "setBackgroundColor",
                    //Integer.parseInt(myDescriptor.params.get(2).value));
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                } else {
                    //train
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 12);
                    //controllo contesto getRouteDescriptor i vari parametri
                    rv.setTextViewText(R.id.text_widget_item,
                            mContext.getString(
                                    RoutesHelper.getRouteDescriptorByRouteId(myDescriptor.params.get(3).value,
                                            myDescriptor.params.get(4).value).getNameResource()));
                    rv.setTextColor(R.id.text_widget_item, Color.BLACK);//Int(R.id.text_widget_item, "setBackgroundColor",Color.BLACK);
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                }

            } else if (WidgetHelper.TYPE_JP_PARKINGS.equals(type)) {
                // jp parcheggio -> put text and hide icon
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));
                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

            }
            BookmarkDescriptor bookmark = myDescriptor;
            Bundle extras = new Bundle();
            extras.putString(StackWidgetProvider.EXTRA_INTENT, bookmark.getIntent());
            if (bookmark.getParams() != null) {
                for (Param param : bookmark.getParams()) {
                    extras.putString(param.name, param.value);

                }

            }
            Intent fillInIntent = new Intent(bookmark.getIntent());
            fillInIntent.putExtras(extras);
            rv.setOnClickFillInIntent(R.id.layout, fillInIntent);
        }

    }
    // Return the remote views object.
    // AppWidgetManager manager = AppWidgetManager.getInstance(mContext);
    // manager.updateAppWidget(thisWidget, rv);
    return rv;
}

From source file:com.kiandastream.musicplayer.MusicService.java

public void setListeners(RemoteViews view, String songname) {
    //listener 1//www.j  a  v a  2s .  com
    view.setTextViewText(R.id.songname, songname);
    PendingIntent backword = PendingIntent.getService(this, 0, new Intent(MusicService.ACTION_REWIND), 0);
    view.setOnClickPendingIntent(R.id.backword, backword);

    //listener 2
    if (mState == State.Playing) {

        PendingIntent playpause = PendingIntent.getService(this, 1, new Intent(MusicService.ACTION_PAUSE), 0);
        view.setOnClickPendingIntent(R.id.play, playpause);
        view.setImageViewResource(R.id.play, R.drawable.pause);
    } else {
        if (mState == State.Paused) {
            PendingIntent playpause = PendingIntent.getService(this, 1, new Intent(MusicService.ACTION_RESUME),
                    0);
            view.setOnClickPendingIntent(R.id.play, playpause);
            view.setImageViewResource(R.id.play, R.drawable.play);
        }

    }
    //listener 3

    PendingIntent forward = PendingIntent.getService(this, 2, new Intent(MusicService.ACTION_NEXT), 0);
    view.setOnClickPendingIntent(R.id.forward, forward);

    //listener 4

    PendingIntent close = PendingIntent.getService(this, 3, new Intent(MusicService.ACTION_STOP), 0);
    view.setOnClickPendingIntent(R.id.close, close);
}