Example usage for android.widget RemoteViews RemoteViews

List of usage examples for android.widget RemoteViews RemoteViews

Introduction

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

Prototype

public RemoteViews(RemoteViews landscape, RemoteViews portrait) 

Source Link

Document

Create a new RemoteViews object that will inflate as the specified landspace or portrait RemoteViews, depending on the current configuration.

Usage

From source file:com.android.deskclock.data.StopwatchNotificationBuilderN.java

@Override
public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) {
    @StringRes//from   w ww  .j  a va2s .c o  m
    final int eventLabel = R.string.label_notification;

    // Intent to load the app when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    // Compute some values required below.
    final boolean running = stopwatch.isRunning();
    final String pname = context.getPackageName();
    final Resources res = context.getResources();
    final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime();

    final RemoteViews content = new RemoteViews(pname, R.layout.chronometer_notif_content);
    content.setChronometer(R.id.chronometer, base, null, running);

    final List<Notification.Action> actions = new ArrayList<>(2);

    if (running) {
        // Left button: Pause
        final Intent pause = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_pause_24dp);
        final CharSequence title1 = res.getText(R.string.sw_pause_button);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Add Lap
        if (DataModel.getDataModel().canAddMoreLaps()) {
            final Intent lap = new Intent(context, StopwatchService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

            final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_sw_lap_24dp);
            final CharSequence title2 = res.getText(R.string.sw_lap_button);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, lap);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());
        }

        // Show the current lap number if any laps have been recorded.
        final int lapCount = DataModel.getDataModel().getLaps().size();
        if (lapCount > 0) {
            final int lapNumber = lapCount + 1;
            final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber);
            content.setTextViewText(R.id.state, lap);
            content.setViewVisibility(R.id.state, VISIBLE);
        } else {
            content.setViewVisibility(R.id.state, GONE);
        }
    } else {
        // Left button: Start
        final Intent start = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_start_24dp);
        final CharSequence title1 = res.getText(R.string.sw_start_button);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, start);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Reset (dismisses notification and resets stopwatch)
        final Intent reset = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_reset_24dp);
        final CharSequence title2 = res.getText(R.string.sw_reset_button);
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset);
        actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

        // Indicate the stopwatch is paused.
        content.setTextViewText(R.id.state, res.getString(R.string.swn_paused));
        content.setViewVisibility(R.id.state, VISIBLE);
    }

    // Swipe away will reset the stopwatch without bringing forward the app.
    final Intent reset = new Intent(context, StopwatchService.class)
            .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    return new Notification.Builder(context).setLocalOnly(true).setOngoing(running)
            .setCustomContentView(content).setContentIntent(pendingShowApp).setAutoCancel(stopwatch.isPaused())
            .setPriority(Notification.PRIORITY_MAX).setSmallIcon(R.drawable.stat_notify_stopwatch)
            .setGroup(nm.getStopwatchNotificationGroupKey())
            .setStyle(new Notification.DecoratedCustomViewStyle())
            .setDeleteIntent(Utils.pendingServiceIntent(context, reset))
            .setActions(actions.toArray(new Notification.Action[actions.size()]))
            .setColor(ContextCompat.getColor(context, R.color.default_background)).build();
}

From source file:com.zion.music.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *///from   w  ww  . ja va 2 s  .  c om
public void buildNotification(final String artistName, final String trackName, final int artistId,
        final Bitmap albumArt, final boolean isPlaying) {
    // Default notification layout
    this.notificationTemplate = new RemoteViews(this.service.getPackageName(),
            R.layout.notification_mediaplayer);

    // Set up the content view
    this.initCollapsedLayout(trackName, artistName, albumArt);

    // Notification Builder
    this.notification = new NotificationCompat.Builder(this.service)
            .setSmallIcon(R.drawable.ic_stat_notify_app_icon).setContentIntent(this.getPendingIntent(artistId))
            .setPriority(Notification.PRIORITY_DEFAULT).setContent(this.notificationTemplate)
            .setAutoCancel(true).build();

    // Control playback from the notification
    this.initPlaybackActions(isPlaying);
    if (16 <= Build.VERSION.SDK_INT) {
        // Expanded notification style
        this.expandedView = new RemoteViews(this.service.getPackageName(),
                R.layout.notification_template_expanded);
        this.notification.bigContentView = this.expandedView;

        // Control playback from the expanded notification
        this.initExpandedPlaybackActions(isPlaying);

        // Set up the expanded content view
        this.initExpandedLayout(trackName, artistName, albumArt);
    }
    //      this.service.stopForeground(false);
    this.service.startForeground(NotificationHelper.NOTIFICATION_ID, this.notification);
}

From source file:com.wizardsofm.deskclock.data.StopwatchNotificationBuilderN.java

@Override
public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) {
    @StringRes/*from   www .  j ava  2 s  .  com*/
    final int eventLabel = com.wizardsofm.deskclock.R.string.label_notification;

    // Intent to load the app when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    // Compute some values required below.
    final boolean running = stopwatch.isRunning();
    final String pname = context.getPackageName();
    final Resources res = context.getResources();
    final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime();

    final RemoteViews content = new RemoteViews(pname,
            com.wizardsofm.deskclock.R.layout.chronometer_notif_content);
    content.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, running);

    final List<Notification.Action> actions = new ArrayList<>(2);

    if (running) {
        // Left button: Pause
        final Intent pause = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_pause_24dp);
        final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_pause_button);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Add Lap
        if (DataModel.getDataModel().canAddMoreLaps()) {
            final Intent lap = new Intent(context, StopwatchService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

            final Icon icon2 = Icon.createWithResource(context,
                    com.wizardsofm.deskclock.R.drawable.ic_sw_lap_24dp);
            final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_lap_button);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, lap);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());
        }

        // Show the current lap number if any laps have been recorded.
        final int lapCount = DataModel.getDataModel().getLaps().size();
        if (lapCount > 0) {
            final int lapNumber = lapCount + 1;
            final String lap = res.getString(com.wizardsofm.deskclock.R.string.sw_notification_lap_number,
                    lapNumber);
            content.setTextViewText(com.wizardsofm.deskclock.R.id.state, lap);
            content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, VISIBLE);
        } else {
            content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, GONE);
        }
    } else {
        // Left button: Start
        final Intent start = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_start_24dp);
        final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_start_button);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, start);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Reset (dismisses notification and resets stopwatch)
        final Intent reset = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp);
        final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_reset_button);
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset);
        actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

        // Indicate the stopwatch is paused.
        content.setTextViewText(com.wizardsofm.deskclock.R.id.state,
                res.getString(com.wizardsofm.deskclock.R.string.swn_paused));
        content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, VISIBLE);
    }

    // Swipe away will reset the stopwatch without bringing forward the app.
    final Intent reset = new Intent(context, StopwatchService.class)
            .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    return new Notification.Builder(context).setLocalOnly(true).setOngoing(running)
            .setCustomContentView(content).setContentIntent(pendingShowApp).setAutoCancel(stopwatch.isPaused())
            .setPriority(Notification.PRIORITY_MAX)
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_stopwatch)
            .setGroup(nm.getStopwatchNotificationGroupKey())
            .setStyle(new Notification.DecoratedCustomViewStyle())
            .setDeleteIntent(Utils.pendingServiceIntent(context, reset))
            .setActions(actions.toArray(new Notification.Action[actions.size()]))
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .build();
}

From source file:com.metinkale.prayerapp.vakit.WidgetService.java

public static void updateOngoing() {
    extractColors();//w w  w . j a va  2 s.  c  o m
    NotificationManager nm = (NotificationManager) App.getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    for (int i = mOngoing.size() - 1; i >= 0; i--) {
        long id = mOngoing.get(i);
        Times t = Times.getTimes(id);

        if ((t == null) || !t.isOngoingNotificationActive()) {
            nm.cancel(id + "", NotIds.ONGOING);
            mOngoing.remove(i);
        }
    }
    List<Long> ids = Times.getIds();
    for (long id : ids) {

        Times t = Times.getTimes(id);

        if ((t != null) && t.isOngoingNotificationActive() && !mOngoing.contains(id)) {
            mOngoing.add(id);
        }
    }

    LocalDate cal = LocalDate.now();
    String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
    for (long id : mOngoing) {

        Times t = Times.getTimes(id);

        String[] dt = { t.getTime(cal, 0), t.getTime(cal, 1), t.getTime(cal, 2), t.getTime(cal, 3),
                t.getTime(cal, 4), t.getTime(cal, 5) };
        boolean icon = Prefs.showOngoingIcon();
        boolean number = Prefs.showOngoingNumber();
        Crashlytics.setBool("showIcon", icon);
        Crashlytics.setBool("showNumber", number);

        Notification noti;
        if (Prefs.getAlternativeOngoing()) {
            RemoteViews views = new RemoteViews(App.getContext().getPackageName(),
                    R.layout.notification_layout);

            int[] timeIds = { R.id.time0, R.id.time1, R.id.time2, R.id.time3, R.id.time4, R.id.time5 };
            int[] vakitIds = { R.id.imsak, R.id.gunes, R.id.ogle, R.id.ikindi, R.id.aksam, R.id.yatsi };

            int next = t.getNext();
            if (Prefs.getVakitIndicator().equals("next"))
                next++;
            for (int i = 0; i < dt.length; i++) {
                if ((next - 1) == i) {
                    views.setTextViewText(timeIds[i],
                            Html.fromHtml("<strong><em>" + Utils.fixTime(dt[i]) + "</em></strong>"));
                } else {
                    views.setTextViewText(timeIds[i], Utils.fixTime(dt[i]));
                }
            }

            for (int i = 0; i < dt.length; i++) {
                if ((next - 1) == i) {
                    views.setTextViewText(vakitIds[i],
                            Html.fromHtml("<strong><em>" + Vakit.getByIndex(i).getString() + "</em></strong>"));
                } else {
                    views.setTextViewText(vakitIds[i], Vakit.getByIndex(i).getString());
                }
            }

            views.setTextViewText(R.id.time, t.getLeft(t.getNext(), false));
            views.setTextViewText(R.id.city, t.getName());

            views.setTextColor(R.id.imsak, COLOR_1ST);
            views.setTextColor(R.id.gunes, COLOR_1ST);
            views.setTextColor(R.id.ogle, COLOR_1ST);
            views.setTextColor(R.id.ikindi, COLOR_1ST);
            views.setTextColor(R.id.aksam, COLOR_1ST);
            views.setTextColor(R.id.yatsi, COLOR_1ST);

            views.setTextColor(R.id.time0, COLOR_1ST);
            views.setTextColor(R.id.time1, COLOR_1ST);
            views.setTextColor(R.id.time2, COLOR_1ST);
            views.setTextColor(R.id.time3, COLOR_1ST);
            views.setTextColor(R.id.time4, COLOR_1ST);
            views.setTextColor(R.id.time5, COLOR_1ST);

            views.setTextColor(R.id.time, COLOR_1ST);
            views.setTextColor(R.id.city, COLOR_1ST);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                long left = t.getLeftMinutes(t.getNext());
                noti = new Notification.Builder(App.getContext()).setContent(views)
                        .setContentIntent(Main.getPendingIntent(t))
                        .setSmallIcon(icon
                                ? (number ? Icon.createWithBitmap(getIconFromMinutes(left))
                                        : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon))
                                : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder))
                        .setOngoing(true).build();
            } else {
                noti = new NotificationCompat.Builder(App.getContext()).setContent(views)
                        .setContentIntent(Main.getPendingIntent(t))
                        .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder).setOngoing(true)
                        .build();
            }
        } else {
            int n = t.getNext();
            String sum = App.getContext().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(),
                    left_part[n], t.getLeft().substring(0, 5));

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                long left = t.getLeftMinutes(t.getNext());
                noti = new Notification.InboxStyle(
                        new Notification.Builder(App.getContext())
                                .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("")
                                .setLargeIcon(mAbIcon)
                                .setSmallIcon(icon
                                        ? (number ? Icon.createWithBitmap(getIconFromMinutes(left))
                                                : Icon.createWithResource(App.getContext(),
                                                        R.drawable.ic_abicon))
                                        : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder))
                                .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t))
                                .setOngoing(true))
                                        .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0]))
                                        .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1]))
                                        .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2]))
                                        .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3]))
                                        .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4]))
                                        .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5]))
                                        .setSummaryText("").build();
            } else {
                noti = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(App.getContext())
                        .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("")
                        .setLargeIcon(mAbIcon)
                        .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder)
                        .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true))
                                .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0]))
                                .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1]))
                                .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2]))
                                .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3]))
                                .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4]))
                                .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5]))
                                .setSummaryText("").build();
            }

        }

        if (Build.VERSION.SDK_INT >= 16) {
            noti.priority = Notification.PRIORITY_LOW;
        }
        noti.when = icon ? System.currentTimeMillis() : 0;
        try {
            nm.notify(id + "", NotIds.ONGOING, noti);
        } catch (Exception e) {
            Crashlytics.logException(e);
        }

    }

}

From source file:org.ado.minesync.gui.notification.MineSyncNotification.java

public void buildNotification(boolean syncActive, boolean startForeground) {
    notificationTemplate = new RemoteViews(service.getPackageName(), R.layout.layout_notification);
    PendingIntent pendingIntent = getMainPendingIntent();
    notification = new NotificationCompat.Builder(service.getApplicationContext())
            .setTicker(getResourceText(R.string.label_notification_service_title))
            .setContent(notificationTemplate).setSmallIcon(android.R.color.transparent)
            .setContentIntent(pendingIntent).setPriority(NotificationCompat.PRIORITY_MIN).setOngoing(true)
            .setAutoCancel(false).setColor(getColor(R.color.dropbox_blue)).build();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    initActions(syncActive);/* ww w .  j  a v  a 2s  .c o m*/
    /*        if (startForeground) {
    service.startForeground(NOTIFICATION_SYNC, notification);
            }*/
}

From source file:com.commonsware.android.hcnotify.SillyService.java

private RemoteViews buildContent(int progress) {
    RemoteViews content = new RemoteViews(this.getPackageName(), R.layout.content);

    return (content);
}

From source file:it.polimi.spf.app.SPFApp.java

private void initNotification() {
    //Intent for the stop button in the notification layout
    Intent stopSpf = new Intent(STOPSPF);
    PendingIntent pendingIntentStop = PendingIntent.getBroadcast(this, 0, stopSpf, 0);

    //intent for the click inside the notification area
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //set my custom contentView with a layout
    this.contentView = new RemoteViews(this.getApplicationContext().getPackageName(),
            R.layout.notification_layout);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentIntent(pIntent);//from  w  w w .j a v a 2  s .c o m
    builder.setTicker(getResources().getString(R.string.notification_ticker));
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setAutoCancel(true);

    //------------------------------------------------------------------------------------
    // when you click on buttons in a notification, the actions will be implemented in
    // SPSService in the Framework's module.
    //add the onclickpendingintent to the button
    this.contentView.setOnClickPendingIntent(R.id.stopSpfButton, pendingIntentStop);
    //------------------------------------------------------------------------------------

    //build the notification
    this.notification = builder.build();

    // Set data in the RemoteViews programmatically
    this.setContentViewWithMinimalElements();

    /* Workaround: Need to set the content view here directly on the notification.
     * NotificationCompatBuilder contains a bug that prevents this from working on platform
     * versions HoneyComb.
     * See https://code.google.com/p/android/issues/detail?id=30495
     */
    notification.contentView = contentView;
}

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
    if (settings == null)
        settings = PreferenceManager.getDefaultSharedPreferences(context);

    wContext = context;/*from  w ww .  ja v a 2s. c o  m*/

    Refresh();

    handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                Bundle Values = msg.getData();

                final int N = appWidgetIds.length;
                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.zenoss_widget_graph);
                //Intent intent = new Intent(context, rhestr.class);
                //PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

                //Log.i("GraphWidget","Drawing Graph!");
                for (int i = 0; i < N; i++) {
                    int appWidgetId = appWidgetIds[i];
                    views.setImageViewBitmap(R.id.graphCanvas, RenderBarGraph(Values.getInt("CritCount"),
                            Values.getInt("ErrCount"), Values.getInt("WarnCount")));
                    appWidgetManager.updateAppWidget(appWidgetId, views);
                }
            }
        }
    };
}

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

/**
 * Initialize given widgets to default state, where we launch ServeStream on default click
 * and hide actions if service not running.
 *//*from  w  ww. j  av a2  s.c o  m*/
private void defaultAppWidget(Context context, int[] appWidgetIds) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_one);

    views.setViewVisibility(R.id.title, View.INVISIBLE);
    views.setViewVisibility(R.id.artist, View.INVISIBLE);

    linkButtons(context, views, false /* not playing */);
    pushUpdate(context, appWidgetIds, views);
}

From source file:org.artags.android.app.widget.AbstractWidgetProvider.java

private void updateTag(Tag tag) {
    setCurrentTag(tag);// w ww  .  ja v a 2 s.c om
    RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.widget);
    remoteViews.setImageViewBitmap(R.id.widget_thumbnail, tag.getBitmap());
    remoteViews.setTextViewText(R.id.widget_text, tag.getText());
    Intent active = new Intent(mContext, getClass());
    active.setAction(Constants.ACTION_SHOW_TAG);
    PendingIntent actionPendingIntent = PendingIntent.getBroadcast(mContext, 0, active, 0);
    remoteViews.setOnClickPendingIntent(R.id.widget_thumbnail, actionPendingIntent);
    if ((tag != null) && (remoteViews != null)) {
        mAppWidgetManager.updateAppWidget(mAppWidgetIds, remoteViews);
        Log.d(Constants.LOG_TAG, "Widget updated");
    }
}