Java Code Examples for android.widget.RemoteViews#setRemoteAdapter()

The following examples show how to use android.widget.RemoteViews#setRemoteAdapter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfileWidget.java    From KA27 with Apache License 2.0 7 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int appWidgetId: appWidgetIds) {
        Intent svcIntent = new Intent(context, WidgetService.class);
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.profile_widget_layout);
        widget.setRemoteAdapter(R.id.profile_list, svcIntent);

        widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK));

        appWidgetManager.updateAppWidget(appWidgetId, widget);
    }
}
 
Example 2
Source File: Widget.java    From KernelAdiutor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int appWidgetId : appWidgetIds) {
        Intent svcIntent = new Intent(context, WidgetService.class);
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_profile);
        widget.setRemoteAdapter(R.id.profile_list, svcIntent);

        widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK));

        appWidgetManager.updateAppWidget(appWidgetId, widget);
    }
}
 
Example 3
Source File: WidgetProvider.java    From Birdays with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int i : appWidgetIds) {

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        Intent serviceIntent = new Intent(context, WidgetService.class);
        serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
        remoteViews.setRemoteAdapter(R.id.listview_widget, serviceIntent);

        remoteViews.setTextViewText(R.id.textview_widget_header_date,
                Utils.getDateWithoutYear(Calendar.getInstance().getTimeInMillis()));

        Intent clickIntent = new Intent(context, WidgetProvider.class);
        clickIntent.setAction(ACTION_ON_CLICK);

        PendingIntent clickPendingIntent = PendingIntent.getBroadcast(context, 0,
                clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setPendingIntentTemplate(R.id.listview_widget, clickPendingIntent);

        appWidgetManager.updateAppWidget(i, remoteViews);
        appWidgetManager.notifyAppWidgetViewDataChanged(i, R.id.listview_widget);
    }
}
 
Example 4
Source File: CheckListWidgetProvider.java    From Travel-Mate with MIT License 6 votes vote down vote up
private RemoteViews updateWidgetListView(Context context, int appWidgetId) {

        //which layout to show on widget
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.checklist_widget);

        //RemoteViews Service needed to provide adapter for ListView
        Intent svcIntent = new Intent(context, CheckListWidgetService.class);
        //passing app widget id to that RemoteViews Service
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        //setting a unique Uri to the intent
        //don't know its purpose to me right now
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
        //setting adapter to listview of the widget
        remoteViews.setRemoteAdapter(R.id.check_list_view, svcIntent);

        //setting an empty view in case of no data
        remoteViews.setEmptyView(R.id.check_list_view, R.id.empty_view);
        return remoteViews;
    }
 
Example 5
Source File: ProfileWidget.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        for (int appWidgetId : appWidgetIds) {
            Intent svcIntent = new Intent(context, WidgetService.class);
            svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

            RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.profile_widget_layout);
            widget.setRemoteAdapter(R.id.profile_list, svcIntent);

            widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK));

            appWidgetManager.updateAppWidget(appWidgetId, widget);
        }

}
 
Example 6
Source File: PlacesWidgetProvider.java    From protrip with MIT License 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int i = 0; i < appWidgetIds.length; i++) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_collection);

        Intent intent = new Intent(context, PlacesWidgetRemoteViewsService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        views.setRemoteAdapter(R.id.widget_list, intent);

        Intent toastIntent = new Intent(context, PlacesWidgetRemoteViewsService.class);
        toastIntent.setAction(PlacesWidgetProvider.TOAST_ACTION);
        toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, toastPendingIntent);

        appWidgetManager.updateAppWidget(appWidgetIds[i], views);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 7
Source File: Widget.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int appWidgetId : appWidgetIds) {
        Intent svcIntent = new Intent(context, WidgetService.class);
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_profile);
        widget.setRemoteAdapter(R.id.profile_list, svcIntent);

        widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK));

        appWidgetManager.updateAppWidget(appWidgetId, widget);
    }
}
 
Example 8
Source File: GitHubJourneyWidgetProvider.java    From GitJourney with Apache License 2.0 6 votes vote down vote up
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId, Parcelable[] parcelables) {
    Log.v(TAG, "updateAppWidget parcelables = " + parcelables.length);
    // Construct the RemoteViews object
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.git_hub_journey_widget);

    Intent startActivityIntent = new Intent(context, GeneralActivity.class);
    PendingIntent startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setPendingIntentTemplate(R.id.widget_data_view, startActivityPendingIntent);

    Calendar calendar = Calendar.getInstance();
    DateFormat dateFormat = Utils.createDateFormatterWithTimeZone(context, context.getString(R.string.add_widget_date_format));
    views.setTextViewText(R.id.widget_date, dateFormat.format(calendar.getTime()));
    Intent intent = new Intent(context, StackWidgetService.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.
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    Bundle bundle = new Bundle();
    bundle.putParcelableArray("parcelables", parcelables);
    intent.putExtra("bundle", bundle);
    views.setRemoteAdapter(R.id.widget_data_view, intent);
    views.setEmptyView(R.id.widget_data_view, R.id.empty_view);
    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 9
Source File: Widget.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int appWidgetId : appWidgetIds) {
        Intent svcIntent = new Intent(context, WidgetService.class);
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_profile);
        widget.setRemoteAdapter(R.id.profile_list, svcIntent);

        widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK));

        appWidgetManager.updateAppWidget(appWidgetId, widget);
    }
}
 
Example 10
Source File: BookmarkWidgetProvider.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void performUpdate(Context context,
        AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
        Intent updateIntent = new Intent(context, BookmarkWidgetService.class);
        updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        updateIntent.setData(Uri.parse(updateIntent.toUri(Intent.URI_INTENT_SCHEME)));

        int layoutId = shouldShowIconsOnly(appWidgetManager, appWidgetId)
                ? R.layout.bookmark_widget_icons_only
                : R.layout.bookmark_widget;
        RemoteViews views = new RemoteViews(context.getPackageName(), layoutId);
        views.setRemoteAdapter(R.id.bookmarks_list, updateIntent);

        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.bookmarks_list);
        Intent ic = new Intent(context, BookmarkWidgetProxy.class);
        views.setPendingIntentTemplate(R.id.bookmarks_list,
                PendingIntent.getBroadcast(context, 0, ic,
                PendingIntent.FLAG_UPDATE_CURRENT));
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
Example 11
Source File: WidgetProvider.java    From budget-envelopes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void onUpdate(Context cntx, AppWidgetManager manager,
                               int[] widgetIds) {
    final int l = widgetIds.length;
    for (int i = 0; i != l; ++i) {
        int widgetId = widgetIds[i];
        Log.d("Budget", "WidgetProvider.id="+widgetId);
        RemoteViews views = new RemoteViews(
            cntx.getPackageName(),
            R.layout.widget
        );
        Intent srv = new Intent(cntx, WidgetService.class);
        srv.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetIds[i]);
        srv.setData(Uri.parse(srv.toUri(Intent.URI_INTENT_SCHEME)));
        views.setRemoteAdapter(widgetIds[i], R.id.grid, srv);
        views.setEmptyView(R.id.grid, R.id.empty);
        Intent act = new Intent(cntx, EnvelopesActivity.class);
        act.setData(Uri.parse("fragment://"+EnvelopeDetailsFragment.class.getName()+"/"+widgetIds[i]));
        act.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetIds[i]);
        PendingIntent actPending = PendingIntent.getActivity(
            cntx, 0, act, PendingIntent.FLAG_UPDATE_CURRENT
        );
        views.setPendingIntentTemplate(R.id.grid, actPending);
        manager.updateAppWidget(widgetIds[i], views);
    }
    super.onUpdate(cntx, manager, widgetIds);
}
 
Example 12
Source File: MyWidget.java    From ClassSchedule with Apache License 2.0 5 votes vote down vote up
private void updateAction(Context context) {

        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetId = appWidgetManager.getAppWidgetIds(new ComponentName(context, MyWidget.class));

        thisWidget = new ComponentName(context, MyWidget.class);
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_all);

        int month = TimeUtils.getNowMonth();
        remoteViews.setTextViewText(R.id.tv_month,month+"\n月");

        Intent intent = new Intent(context, UpdateService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

        //配置适配器
        remoteViews.setRemoteAdapter(R.id.widget_list, intent);

        Intent intent1 = new Intent(context, CourseActivity.class);
        PendingIntent pendingIntentTemplate = PendingIntent.getActivity(
                context, 1, intent1, PendingIntent.FLAG_UPDATE_CURRENT);

        ////拼接PendingIntent
        remoteViews.setPendingIntentTemplate(R.id.widget_list, pendingIntentTemplate);

        //更新remoteViews
        appWidgetManager.updateAppWidget(thisWidget, remoteViews);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list);

        AppWidgetManager manager = AppWidgetManager.getInstance(context);
        manager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list);
    }
 
Example 13
Source File: PredatorPostsWidgetProvider.java    From Capstone-Project with MIT License 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    int numberOfWidgetsAvail = appWidgetIds.length;
    for (int i = 0; i < numberOfWidgetsAvail; i++) {
        int appWidgetId = appWidgetIds[i];

        Intent widgetServiceIntent = new Intent(context, PredatorPostsWidgetService.class);
        widgetServiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        widgetServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        widgetServiceIntent.setData(Uri.parse(widgetServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));

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

        views.setRemoteAdapter(R.id.list_view_posts, widgetServiceIntent);

        views.setEmptyView(R.id.list_view_posts, R.id.text_view_posts_unavailable);

        Intent clickIntentMyStocks = new Intent(context, SplashActivity.class);
        PendingIntent clickPendingIntentMyStocks = PendingIntent
                .getActivity(context, 0,
                        clickIntentMyStocks,
                        PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.text_view_posts_unavailable, clickPendingIntentMyStocks);

        Intent clickIntentMyStockDetails = new Intent(context, PostDetailsActivity.class);
        PendingIntent clickPendingIntentMyStockDetails = PendingIntent
                .getActivity(context, 0,
                        clickIntentMyStockDetails,
                        PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.list_view_posts, clickPendingIntentMyStockDetails);

        appWidgetManager.updateAppWidget(appWidgetIds[i], views);

        Logger.d(TAG, "onUpdate: widgetId: " + appWidgetId);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 14
Source File: RssfeedWidgetProvider.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private static RemoteViews createWidgetLayout(Context context, int appWidgetId) {
	
	// create layout
	Intent intent = new Intent(context, RssfeedWidgetService.class);
	intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
	intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
       RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
       views.setRemoteAdapter(R.id.feeds_list, intent);
       views.setEmptyView(R.id.feeds_list, R.layout.widget_empty_layout);

       // set last update time
       String time = DateFormat.getTimeFormat(context).format(new Date());
       String date = DateFormat.getDateFormat(context).format(new Date());
       views.setTextViewText(R.id.last_update, String.format("%1$s, %2$s", time, date));
       
       // assign onRefresh handler
       Intent onRefreshIntent = new Intent(context, RssfeedWidgetProvider.class);
       onRefreshIntent.setAction(ACTION_REFRESH);
       PendingIntent onRefreshPending = PendingIntent.getBroadcast(
       		context, 0, onRefreshIntent, PendingIntent.FLAG_UPDATE_CURRENT);
       views.setOnClickPendingIntent(R.id.refresh, onRefreshPending);
	
       // assign onItemClick handler
       Intent onItemClickIntent = new Intent(context, RssfeedWidgetProvider.class);
       onItemClickIntent.setAction(ACTION_SHOW_LINK);
       onItemClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
       onItemClickIntent.setData(Uri.parse(onItemClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
       final PendingIntent onItemClickPending = PendingIntent.getBroadcast(context, 0,
       		onItemClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
       views.setPendingIntentTemplate(R.id.feeds_list, onItemClickPending);
       
	return views;
}
 
Example 15
Source File: ZulipWidget.java    From zulip-android with Apache License 2.0 5 votes vote down vote up
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    String title = ZulipWidgetConfigureActivity.loadPref(context, appWidgetId, TITLE_PREFRENCE);
    if (title != null) {
        String from = ZulipWidgetConfigureActivity.loadPref(context, appWidgetId, FROM_PREFERENCE);
        String interval = ZulipWidgetConfigureActivity.loadPref(context, appWidgetId, INTERVAL_PREFERENCE);
        intervalMilliseconds = 60000 * Integer.parseInt(TextUtils.substring(interval, 0, interval.length() - 1));
        // Construct the RemoteViews object
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.zulip_widget);
        final Intent intent = new Intent(context, ZulipWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        intent.putExtra(TITLE_PREFRENCE, title);
        intent.putExtra(FROM_PREFERENCE, from);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        remoteViews.setTextViewText(R.id.widget_title, title);
        remoteViews.setRemoteAdapter(appWidgetId, R.id.widget_list, intent);
        remoteViews.setEmptyView(R.id.widget_list, R.id.widget_nomsg);

        if (asyncGetEvents == null) {
            setupGetEvents();
        }
        final Intent refreshIntent = new Intent(context, ZulipWidget.class);
        refreshIntent.setAction(ZulipWidget.WIDGET_REFRESH);
        final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.widget_refresh, refreshPendingIntent);
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
}
 
Example 16
Source File: UpcomingMovieUpdateService.java    From Movie-Check with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {

    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());

    int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);

    for (final int widgetId : allWidgetIds) {

        final RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_upcomingmovies);

        try {
            Response<List<Movie>> response = new ApiModule().provideMovieResource(this).listUpComing(getString(R.string.themoviedbapi_key), 1).execute();
            switch (response.code()) {
                case HTTP_OK:
                    remoteViews.setViewVisibility(R.id.linearlayout_loadfailed, View.GONE);
                    remoteViews.setViewVisibility(R.id.listview_movies, View.VISIBLE);
                    remoteViews.setRemoteAdapter(R.id.listview_movies, UpcomingMovieWidgetRemoteViewsService.newIntent(getApplicationContext(), widgetId, response.body()));
                    appWidgetManager.updateAppWidget(widgetId, remoteViews);
                    break;
            }
        } catch (Exception e) {
            remoteViews.setViewVisibility(R.id.listview_movies, View.GONE);
            remoteViews.setViewVisibility(R.id.linearlayout_loadfailed, View.VISIBLE);
        }

        remoteViews.setViewVisibility(R.id.linearlayout_loading, View.GONE);
        remoteViews.setEmptyView(R.id.listview_movies, R.id.linearlayout_anyfounded);
        Intent startActivityIntent = new Intent(getApplicationContext(), MovieProfileActivity.class);
        PendingIntent startActivityPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setPendingIntentTemplate(R.id.listview_movies, startActivityPendingIntent);


        appWidgetManager.updateAppWidget(widgetId, remoteViews);

    }
}
 
Example 17
Source File: StackWidgetProvider.java    From glimmr with Apache License 2.0 4 votes vote down vote up
/**
 * Called when first added or as requested by updatePeriodMillis
 *
 * appWidgetIds refers to each instance of the widget added to the
 * homescreen
 */
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    if (BuildConfig.DEBUG) Log.d(TAG, "onUpdate: " + appWidgetIds.length);

    for (int appWidgetId : appWidgetIds) {
        /* Intent for creating the collection's views */
        Intent intent = new Intent(context, StackWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                appWidgetId);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        RemoteViews rv = new RemoteViews(context.getPackageName(),
                R.layout.stackview_widget_layout);
        rv.setEmptyView(R.id.stack_view, R.id.empty_view);

        rv.setRemoteAdapter(R.id.stack_view, intent);

        /* Intent for clicking on an item */
        Intent photoViewerIntent = new Intent(context,
                StackWidgetProvider.class);
        photoViewerIntent.setAction(
                StackWidgetProvider.ACTION_START_VIEWER);
        photoViewerIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                appWidgetId);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                context, 0, photoViewerIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setPendingIntentTemplate(R.id.stack_view, pendingIntent);

        /* Intent for clicking on the empty view to refresh */
        Intent refreshIntent = new Intent(context,
                StackWidgetProvider.class);
        refreshIntent.setAction(ACTION_REFRESH);
        refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                appWidgetId);
        PendingIntent pendingIntent2 = PendingIntent.getBroadcast(
                context, 0, refreshIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setOnClickPendingIntent(R.id.empty_view, pendingIntent2);

        appWidgetManager.updateAppWidget(appWidgetId, rv);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 18
Source File: DetailWidgetProvider.java    From Advanced_Android_Development with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the remote adapter used to fill in the list items
 *
 * @param views RemoteViews to set the RemoteAdapter
 */
@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));
}
 
Example 19
Source File: TaskListWidgetProvider.java    From opentasks with Apache License 2.0 4 votes vote down vote up
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
    /*
     * Iterate over all the widgets of this type and update them individually.
     */
    for (int i = 0; i < appWidgetIds.length; i++)
    {
        Log.d(TAG, "updating widget " + i);

        /** Create an Intent with the {@link RemoteViewsService } and pass it the Widget Id */
        Intent remoteServiceIntent = new Intent(context, TaskListWidgetUpdaterService.class);
        remoteServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        remoteServiceIntent.setData(Uri.parse(remoteServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.task_list_widget);

        /** Add pending Intent to start the Tasks app when the title is clicked */
        Intent tasksAppIntent = new Intent(context, TaskListActivity.class);
        tasksAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent taskAppPI = PendingIntent.getActivity(context, 0, tasksAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        widget.setOnClickPendingIntent(android.R.id.button1, taskAppPI);

        /** Add a pending Intent to start new Task Activity on the new Task Button */
        Intent editTaskIntent = new Intent(context, TaskListWidgetProvider.class);
        editTaskIntent.setAction(ACTION_CREATE_TASK);
        editTaskIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        PendingIntent newTaskPI = PendingIntent.getBroadcast(context, appWidgetIds[i], editTaskIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        widget.setOnClickPendingIntent(android.R.id.button2, newTaskPI);

        /** Set the {@link RemoteViewsService } subclass as the adapter for the {@link ListView} in the widget. */
        widget.setRemoteAdapter(R.id.task_list_widget_lv, remoteServiceIntent);

        Intent detailIntent = new Intent(Intent.ACTION_VIEW);
        detailIntent.putExtra(TaskListActivity.EXTRA_FORCE_LIST_SELECTION, true);
        PendingIntent clickPI = PendingIntent.getActivity(context, 0, detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        widget.setPendingIntentTemplate(R.id.task_list_widget_lv, clickPI);

        /* Finally update the widget */
        appWidgetManager.updateAppWidget(appWidgetIds[i], widget);
    }
}
 
Example 20
Source File: ListWidget.java    From kolabnotes-android with GNU Lesser General Public License v3.0 4 votes vote down vote up
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {

    String account = ListWidgetConfigureActivity.loadListWidgetAccountPref(context, appWidgetId);
    String notebook = ListWidgetConfigureActivity.loadListWidgetNotebookPref(context, appWidgetId);
    String tag = ListWidgetConfigureActivity.loadListWidgetTagPref(context, appWidgetId);

    // Set up the intent that starts the StackViewService, which will
    // provide the views for this collection.
    Intent intent = new Intent(context, ListWidgetService.class);
    // Add the app widget ID to the intent extras.
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    // Instantiate the RemoteViews object for the app widget layout.

    RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.list_widget);
    // Set up the RemoteViews object to use a RemoteViews adapter.
    // This adapter connects
    // to a RemoteViewsService  through the specified intent.
    // This is how you populate the data.
    rv.setRemoteAdapter(appWidgetId,R.id.widget_list_notes, intent);

    // The empty view is displayed when the collection has no items.
    // It should be in the same layout used to instantiate the RemoteViews
    // object above.
    //rv.setEmptyView(R.id.stack_view, R.id.empty_view);
    String correctAccountName = account;
    if("local".equals(account)){
        correctAccountName = context.getResources().getString(R.string.drawer_account_local);
    }
    rv.setTextViewText(R.id.widget_text, correctAccountName);

    Intent intentCreate = new Intent(context, DetailActivity.class);
    Intent intentMainActivity = new Intent(context, MainActivity.class);

    AccountIdentifier accId = Utils.getAccountIdentifierWithName(context, account);

    StringBuilder sb = new StringBuilder();

    if(!TextUtils.isEmpty(notebook)){
        sb.append(notebook);

        Notebook bySummary = new NotebookRepository(context).getBySummary(accId.getAccount(), accId.getRootFolder(), notebook);

        intent.putExtra(Utils.NOTEBOOK_UID, bySummary.getIdentification().getUid());
        intentCreate.putExtra(Utils.NOTEBOOK_UID, bySummary.getIdentification().getUid());
        intentMainActivity.putExtra(Utils.SELECTED_NOTEBOOK_NAME, notebook);
    }

    intentCreate.putExtra(Utils.INTENT_ACCOUNT_EMAIL, accId.getAccount());
    intentCreate.putExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER, accId.getRootFolder());
    PendingIntent pendingIntentCreate = PendingIntent.getActivity(context, appWidgetId, intentCreate,PendingIntent.FLAG_UPDATE_CURRENT);

    if(!TextUtils.isEmpty(tag)){
        if(sb.length() > 0){
            sb.append(" / ");
        }
        sb.append(tag);

        intentMainActivity.putExtra(Utils.SELECTED_TAG_NAME, tag);
    }

    if(sb.length() > 0){
        rv.setTextViewText(R.id.widget_text_detail, sb.toString());
    }

    intentMainActivity.putExtra(Utils.INTENT_ACCOUNT_EMAIL, accId.getAccount());
    intentMainActivity.putExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER, accId.getRootFolder());
    PendingIntent pendingIntentMainActivity = PendingIntent.getActivity(context, appWidgetId, intentMainActivity,PendingIntent.FLAG_UPDATE_CURRENT);


    rv.setOnClickPendingIntent(R.id.imageButton_icon,pendingIntentMainActivity);
    rv.setOnClickPendingIntent(R.id.imageButton_add,pendingIntentCreate);

    Intent clickIntent=new Intent(context, DetailActivity.class);
    PendingIntent clickPI=PendingIntent.getActivity(context, 0, clickIntent,PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setPendingIntentTemplate(R.id.widget_list_notes, clickPI);
    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, rv);
}