Back to project page Tacere.
The source code is released under:
MIT License
If you think the Android project Tacere listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (c) 2014 Jonathan Nelson//from w ww . j a v a 2s . c o m * Released under the BSD license. For details see the COPYING file. */ package org.ciasaboark.tacere.widget; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.widget.RemoteViews; import org.ciasaboark.tacere.R; import org.ciasaboark.tacere.widget.service.WidgetService; public class EventListWidgetProvider extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { /*int[] appWidgetIds holds ids of multiple instance * of your widget * meaning you are placing more than one widgets on * your homescreen*/ final int N = appWidgetIds.length; for (int i = 0; i < N; ++i) { RemoteViews remoteViews = updateWidgetListView(context, appWidgetIds[i]); appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews); updateWidgetListView(context, i); } super.onUpdate(context, appWidgetManager, appWidgetIds); } private RemoteViews updateWidgetListView(Context context, int appWidgetId) { //which layout to show on widget RemoteViews remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget_event_list); //RemoteViews Service needed to provide adapter for ListView Intent svcIntent = new Intent(context, WidgetService.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(appWidgetId, R.id.widget_event_listview, svcIntent); //setting an empty view in case of no data remoteViews.setEmptyView(R.id.widget_event_listview, R.id.widget_event_listview); return remoteViews; } }