Example usage for android.widget RemoteViews setInt

List of usage examples for android.widget RemoteViews setInt

Introduction

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

Prototype

public void setInt(int viewId, String methodName, int value) 

Source Link

Document

Call a method taking one int on a view in the layout for this RemoteViews.

Usage

From source file:ch.fixme.status.Widget.java

protected static void updateWidget(final Context ctxt, int widgetId, AppWidgetManager manager, Bitmap bitmap,
        String text) {/*from  ww w  . j ava  2s.c om*/
    RemoteViews views = new RemoteViews(ctxt.getPackageName(), R.layout.widget);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
    Editor edit = prefs.edit();
    if (prefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)) {
        views.setInt(R.id.widget_image, "setBackgroundResource", 0);
    } else {
        views.setInt(R.id.widget_image, "setBackgroundResource", android.R.drawable.btn_default_small);
    }
    if (bitmap != null) {
        views.setImageViewBitmap(R.id.widget_image, bitmap);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, false); // Don't
        // need
        // to
        // force
    } else {
        views.setImageViewResource(R.id.widget_image, android.R.drawable.ic_popup_sync);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, true); // Something
        // went
        // wrong
    }
    if (text != null) {
        views.setTextViewText(R.id.widget_status, text);
        views.setViewVisibility(R.id.widget_status, View.VISIBLE);
    } else {
        views.setViewVisibility(R.id.widget_status, View.GONE);
    }
    Intent clickIntent = new Intent(ctxt, Main.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
    PendingIntent pendingIntent = PendingIntent.getActivity(ctxt, widgetId, clickIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_image, pendingIntent);
    manager.updateAppWidget(widgetId, views);
    // Is initialized
    edit.putBoolean(Main.PREF_INIT_WIDGET + widgetId, true);
    edit.commit();
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static RemoteViews buildRemoteViews(Context context, AppWidgetManager appWidgetManager,
        int appWidgetId) {
    // setup intent pointing to RemoteViewsService providing the views for the collection
    Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // When intents are compared, the extras are ignored, so we need to
    // embed the extras into the data so that the extras will not be
    // ignored.// w ww  . ja v  a2  s  . com
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

    // determine layout (current size) and theme (user pref)
    final boolean isCompactLayout = isCompactLayout(appWidgetManager, appWidgetId);
    final boolean isLightTheme = WidgetSettings.isLightTheme(context, appWidgetId);
    int layoutResId;
    if (isLightTheme) {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_light_compact : R.layout.appwidget_v11_light;
    } else {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_compact : R.layout.appwidget_v11;
    }

    // build widget views
    RemoteViews rv = new RemoteViews(context.getPackageName(), layoutResId);
    rv.setRemoteAdapter(R.id.list_view, intent);
    // The empty view is displayed when the collection has no items. It
    // should be a sibling of the collection view.
    rv.setEmptyView(R.id.list_view, R.id.empty_view);

    // set the background color
    int bgColor = WidgetSettings.getWidgetBackgroundColor(context, appWidgetId, isLightTheme);
    rv.setInt(R.id.container, "setBackgroundColor", bgColor);

    // determine type specific values
    final int widgetType = WidgetSettings.getWidgetListType(context, appWidgetId);
    int showsTabIndex;
    int titleResId;
    int emptyResId;
    if (widgetType == WidgetSettings.Type.UPCOMING) {
        // upcoming
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_UPCOMING;
        titleResId = R.string.upcoming;
        emptyResId = R.string.noupcoming;
    } else if (widgetType == WidgetSettings.Type.RECENT) {
        // recent
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_RECENT;
        titleResId = R.string.recent;
        emptyResId = R.string.norecent;
    } else {
        // favorites
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_SHOWS;
        titleResId = R.string.action_shows_filter_favorites;
        emptyResId = R.string.no_nextepisode;
    }

    // change title and empty view based on type
    rv.setTextViewText(R.id.empty_view, context.getString(emptyResId));
    if (!isCompactLayout) {
        // only regular layout has text title
        rv.setTextViewText(R.id.widgetTitle, context.getString(titleResId));
    }

    // app launch button
    final Intent appLaunchIntent = new Intent(context, ShowsActivity.class)
            .putExtra(ShowsActivity.InitBundle.SELECTED_TAB, showsTabIndex);
    PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(appLaunchIntent)
            .getPendingIntent(appWidgetId, PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.widget_title, pendingIntent);

    // item intent template, launches episode detail view
    TaskStackBuilder builder = TaskStackBuilder.create(context);
    builder.addNextIntent(appLaunchIntent);
    builder.addNextIntent(new Intent(context, EpisodesActivity.class));
    rv.setPendingIntentTemplate(R.id.list_view, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT));

    // settings button
    Intent settingsIntent = new Intent(context, ListWidgetConfigure.class)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    rv.setOnClickPendingIntent(R.id.widget_settings,
            PendingIntent.getActivity(context, appWidgetId, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    return rv;
}

From source file:android.support.v7.app.NotificationCompatImplBase.java

private static <T extends NotificationCompatBase.Action> RemoteViews generateBigContentView(Context context,
        CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number,
        Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, List<T> actions,
        boolean showCancelButton, PendingIntent cancelButtonIntent) {
    final int actionCount = Math.min(actions.size(), MAX_MEDIA_BUTTONS);
    RemoteViews big = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon,
            subText, useChronometer, when, getBigLayoutResource(actionCount), false /* fitIn1U */);

    big.removeAllViews(R.id.media_actions);
    if (actionCount > 0) {
        for (int i = 0; i < actionCount; i++) {
            final RemoteViews button = generateMediaActionButton(context, actions.get(i));
            big.addView(R.id.media_actions, button);
        }/*from  w  ww.j  a  v a  2s  . c  om*/
    }
    if (showCancelButton) {
        big.setViewVisibility(R.id.cancel_action, View.VISIBLE);
        big.setInt(R.id.cancel_action, "setAlpha",
                context.getResources().getInteger(R.integer.cancel_button_image_alpha));
        big.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent);
    } else {
        big.setViewVisibility(R.id.cancel_action, View.GONE);
    }
    return big;
}

From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java

@Override
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) {
        // Get the layout for the App Widget and attach an on-click listener
        // to the button
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget);
        if (NLService.isEnabled()) {
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green));
        } else {//  w w w. j a  va 2  s  .c om
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red));
        }

        views.setOnClickPendingIntent(R.id.widgetToggleButton,
                getPendingSelfIntent(context, appWidgetId, TOGGLE_CLICKED));

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

From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (TOGGLE_CLICKED.equals(intent.getAction())) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget);
        if (NLService.isEnabled()) {
            NLService.setEnabled(false);
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red));
        } else {//ww w .j a va 2s .c  o  m
            NLService.setEnabled(true);
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green));
        }

        views.setOnClickPendingIntent(R.id.widgetToggleButton,
                getPendingSelfIntent(context, 0, TOGGLE_CLICKED));

        ComponentName componentName = new ComponentName(context, ServiceToggle.class);
        appWidgetManager.updateAppWidget(componentName, views);
    }
}

From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java

private void setStateColor(Context context, RemoteViews remoteViews, int state) {
    int color = (state == STATE_ON) ? ContextCompat.getColor(context, android.R.color.white)
            : ContextCompat.getColor(context, R.color.medium_gray);
    remoteViews.setTextColor(R.id.wifiNameTextView, color);
    remoteViews.setInt(R.id.wifiHeaderSpacerTextView, "setBackgroundColor", color);
    remoteViews.setTextColor(R.id.wifiInfoTopTextView, color);
    remoteViews.setTextColor(R.id.wifiInfoBottomTextView, color);
}

From source file:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java

private void setStateColor(Context context, RemoteViews remoteViews, int state) {
    int color = (state == STATE_ON) ? ContextCompat.getColor(context, android.R.color.white)
            : ContextCompat.getColor(context, R.color.medium_gray);
    remoteViews.setTextColor(R.id.mobileNameTextView, color);
    remoteViews.setInt(R.id.mobileHeaderSpacerTextView, "setBackgroundColor", color);
    remoteViews.setTextColor(R.id.mobileInfoTopTextView, color);
    remoteViews.setTextColor(R.id.mobileInfoBottomTextView, color);
}

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 ww w.j  av a 2 s. co 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:com.fanfou.app.opensource.service.DownloadService.java

private void updateProgress(final int progress) {
    final RemoteViews view = new RemoteViews(getPackageName(), R.layout.download_notification);
    view.setTextViewText(R.id.download_notification_text, "? " + progress + "%");
    view.setInt(R.id.download_notification_progress, "setProgress", progress);
    this.notification.contentView = view;
    this.nm.notify(DownloadService.NOTIFICATION_PROGRESS_ID, this.notification);
}

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

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

    bigContent.setImageViewResource(R.id.exomedia_big_notification_playpause,
            state.isPlaying() ? R.drawable.exomedia_notification_pause : R.drawable.exomedia_notification_play);
    bigContent.setInt(R.id.exomedia_big_notification_prev, "setVisibility",
            state.isPreviousEnabled() ? View.VISIBLE : View.INVISIBLE);
    bigContent.setInt(R.id.exomedia_big_notification_next, "setVisibility",
            state.isNextEnabled() ? View.VISIBLE : View.INVISIBLE);
}