Example usage for android.widget RemoteViews setRemoteAdapter

List of usage examples for android.widget RemoteViews setRemoteAdapter

Introduction

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

Prototype

public void setRemoteAdapter(int viewId, Intent intent) 

Source Link

Document

Equivalent to calling android.widget.AbsListView#setRemoteViewsAdapter(Intent) .

Usage

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./*from w  ww.j a  v  a  2  s .  c  o  m*/
    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:com.udacity.stockhawk.ui.widget.StockWidget.java

private void setRemoteAdapter(Context context, RemoteViews views) {
    views.setRemoteAdapter(R.id.lv_widget_stock, new Intent(context, StockRemoteViewService.class));
}

From source file:com.example.olivi.maphap.widget.DetailWidgetProvider.java

/**
 * Sets the remote adapter used to fill in the list items
 *
 * @param views RemoteViews to set the RemoteAdapter
 *///from  ww w .j  a  va2 s .c  om
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteAdapter(Context context, @NonNull final RemoteViews views) {
    views.setRemoteAdapter(R.id.widget_list, new Intent(context, DetailWidgetRemoteViewsService.class));
}

From source file:com.xengar.android.stocktracker.widget.ListWidgetProvider.java

/**
 * Sets the remote adapter used to fill in the list items.
 *
 * @param views RemoteViews to set the RemoteAdapter
 *///from  w ww. j  a  v a  2 s. com
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteAdapter(Context context, @NonNull final RemoteViews views) {
    views.setRemoteAdapter(R.id.widget_list, new Intent(context, ListWidgetRemoteViewsService.class));
}

From source file:barqsoft.footballscores.widget.WidgetListProvider.java

/**
 * Sets the remote adapter used to fill in the list items
 * @param views RemoteViews to set the RemoteAdapter
 *//*from w w w . j a v a  2s  . c o m*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteAdapter(Context context, @NonNull final RemoteViews views) {
    views.setRemoteAdapter(R.id.widget_list, new Intent(context, WidgetListRemoteViewsService.class));
}

From source file:co.carlosjimenez.android.currencyalerts.app.widget.DetailWidgetProvider.java

/**
 * Sets the remote adapter used to fill in the list items
 *
 * @param views RemoteViews to set the RemoteAdapter
 *///from w ww  .  j  av  a  2  s  . c  o  m
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteAdapter(Context context, @NonNull final RemoteViews views, int[] appWidgetIds) {
    views.setRemoteAdapter(R.id.widget_list, new Intent(context, DetailWidgetRemoteViewsService.class));
}

From source file:com.udacity.stockhawk.widget.StockAppWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.stock_app_widget);

        // Set up the collection
        views.setRemoteAdapter(R.id.lv_stock_list, new Intent(context, StockAppRemoteViewsService.class));

        Intent clickIntentTemplate = new Intent(context, ChartActivity.class);
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.lv_stock_list, clickPendingIntentTemplate);

        views.setEmptyView(R.id.lv_stock_list, R.id.tv_widget_empty);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }/*from   w ww  . ja  v  a2 s . co  m*/
}

From source file:com.chen.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final Uri folderUri, final Uri folderConversationListUri,
        final String folderDisplayName, Class<?> serviceClass) {
    remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE);

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, serviceClass);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(R.id.conversation_list, intent);
    // Open mail app when click on header
    final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account);
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent();
    composeIntent.setAction(Intent.ACTION_SEND);
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }/*from w w  w.j a  va  2  s.  c om*/

    // Build a task stack that forces the conversation list on the stack before the compose
    // activity.
    final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    final Intent conversationIntent = new Intent();
    conversationIntent.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}

From source file:com.android.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final int folderCapabilities, final Uri folderUri,
        final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) {
    remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE);

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, serviceClass);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CAPABILITIES, folderCapabilities);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(R.id.conversation_list, intent);
    // Open mail app when click on header
    final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account);
    mailIntent.setPackage(context.getPackageName());
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent();
    composeIntent.setPackage(context.getPackageName());
    composeIntent.setAction(Intent.ACTION_SEND);
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }/*from   ww  w.  j  ava2s .  co  m*/

    // Build a task stack that forces the conversation list on the stack before the compose
    // activity.
    final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    final Intent conversationIntent = new Intent();
    conversationIntent.setPackage(context.getPackageName());
    conversationIntent.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

private RemoteViews buildLayout(Context context, int appWidgetId, boolean showProgress) {
    RemoteViews rv;
    // Specify the service to provide data for the collection widget. Note
    // that we need to
    // embed the appWidgetId via the data otherwise it will be ignored.
    final Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    rv = new RemoteViews(context.getPackageName(), R.layout.listwidget);
    rv.setRemoteAdapter(R.id.widget_list, intent);

    // Set the empty view to be displayed if the collection is empty. It
    // must be a sibling
    // view of the collection view.
    rv.setEmptyView(R.id.widget_list, R.id.empty_view);

    // Set click listener for the logo
    //        Intent clickIntent = new Intent(context, LoginScreen.class);
    //        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickIntent, 0);
    //        rv.setOnClickPendingIntent(R.id.listwidget_header, pendingIntent);

    // Set click listener for the 'add' button
    //        if (isAuthenticated(context)) {
    //            PendingIntent taskStackBuilderPendingIntent = TaskStackBuilder
    //                    .create(context)
    //                    .addNextIntent(new Intent(context, TodoTxtTouch.class))
    //                    .addNextIntent(new Intent(context, AddTask.class))
    //                    .getPendingIntent(0, 0);
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem,
    //                    taskStackBuilderPendingIntent);
    //        } else {
    //            // if not logged in, just go to login screen
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem, pendingIntent);
    //        }/*ww  w .  jav  a 2s  . co  m*/

    // Bind a click listener template for the contents of the list.
    // Note that we
    // need to update the intent's data if we set an extra, since the extras
    // will be
    // ignored otherwise.
    final Intent onClickIntent = new Intent(context, TodoTxtTouch.class);
    onClickIntent.setAction(ListWidgetProvider.ITEM_ACTION);
    onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent onClickPendingIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0);
    rv.setPendingIntentTemplate(R.id.widget_list, onClickPendingIntent);

    // Bind the click intent for the refresh button on the widget
    final Intent refreshIntent = new Intent(context, ListWidgetProvider.class);
    refreshIntent.setAction(ListWidgetProvider.REFRESH_ACTION);
    refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.listwidget_refresh, refreshPendingIntent);

    if (showProgress) {
        rv.setViewVisibility(R.id.listwidget_progress, View.VISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.INVISIBLE);
    } else {
        rv.setViewVisibility(R.id.listwidget_progress, View.INVISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.VISIBLE);
    }

    return rv;
}