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.tct.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);
    remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 ADD
    // 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);
    //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_S
    composeIntent.setPackage(context.getPackageName());
    //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_E
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_WIDGET, true); //TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 ADD
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }/*from  w w w  . j a v  a  2 s .  c o 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.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.ravi.apps.android.newsbytes.widget.NewsWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.d(LOG_TAG, context.getString(R.string.log_on_update));

    // Update each app widget instance with remote view and corresponding remote adapter.
    for (int appWidgetId : appWidgetIds) {
        // Create the remote views object for the widget instance.
        RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_news);

        // Create the intent that starts the service which will provide the views for this collection.
        Intent serviceIntent = new Intent(context, NewsWidgetRemoteViewsService.class);

        // Add the app widget id to the intent extras.
        serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));

        // Set the remote adapter onto the scores list view in the remote view.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            remoteView.setRemoteAdapter(R.id.widget_list_view, serviceIntent);
        } else {//  ww w .  j  a v a 2 s . co  m
            remoteView.setRemoteAdapter(appWidgetId, R.id.widget_list_view, serviceIntent);
        }

        // Create an intent to launch the main activity and set it on the remote view's title.
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        remoteView.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Create and add the list item click pending intent template.
        Intent listItemClickIntent = new Intent(context, MainActivity.class);
        listItemClickIntent.setAction(context.getString(R.string.action_item_clicked))
                .setData(Uri.parse(listItemClickIntent.toUri(Intent.URI_INTENT_SCHEME)));

        // Set the pending intent template.
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(listItemClickIntent)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteView.setPendingIntentTemplate(R.id.widget_list_view, clickPendingIntentTemplate);

        // Set an empty view in case of no data.
        remoteView.setEmptyView(R.id.widget_list_view, R.id.widget_empty);

        // Call app widget manager to update the app widget instance.
        appWidgetManager.updateAppWidget(appWidgetId, remoteView);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);
}