List of usage examples for android.widget RemoteViews setEmptyView
public void setEmptyView(int viewId, int emptyViewId)
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 w w .jav a 2 s . co 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.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); }/* ww w.j a v a 2s . c om*/ }
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); }// ww w . ja v a 2s .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.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); // }//from ww w.j a v a2 s . c om // 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; }
From source file:com.android.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. *///ww w . ja va2s.c o m public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.getDisplayName())) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.getEmailAddress(), folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderCapabilities, folderUri, folderConversationListUri, folderDisplayName, widgetService); }
From source file:barqsoft.footballscores.widget.WidgetListProvider.java
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) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_list); // Create an Intent to launch MainActivity Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget_item, pendingIntent); // Set up the collection if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setRemoteAdapter(context, views); } else {//from w ww . j a v a2 s . c om setRemoteAdapterV11(context, views); } Intent clickIntentTemplate = new Intent(context, MainActivity.class); PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(clickIntentTemplate) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate); views.setEmptyView(R.id.widget_list, R.id.widget_empty); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:com.example.olivi.maphap.widget.DetailWidgetProvider.java
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { //Start up DetailWidgetIntentService to query for regions data and see when it was last // updated. If the data is too old, the service will update it using MapHapService. Intent i = new Intent(context, DetailWidgetIntentService.class); context.startService(i);//from w w w . ja v a 2s. co m // Perform this loop procedure for each App Widget that belongs to this provider for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_detail); // Create an Intent to launch MainActivity Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget_detail, pendingIntent); // Set up the collection if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setRemoteAdapter(context, views); } else { setRemoteAdapterV11(context, views); } Intent clickIntentTemplate = new Intent(context, DetailActivity.class); PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(clickIntentTemplate) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate); views.setEmptyView(R.id.widget_list, R.id.widget_empty); // Tell the AppWidgetManager to perform an update on the current app com.example // .olivi.maphap.widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:co.carlosjimenez.android.currencyalerts.app.widget.DetailWidgetProvider.java
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) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_detail); // Create an Intent to launch MainActivity Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget, pendingIntent); // Set up the header setMainCurrencyDetails(context, views, appWidgetIds); // Set up the collection if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setRemoteAdapter(context, views, appWidgetIds); } else {/*w ww . j av a 2s . co m*/ setRemoteAdapterV11(context, views, appWidgetIds); } Intent clickIntentTemplate = new Intent(context, DetailActivity.class); PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(clickIntentTemplate) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate); views.setEmptyView(R.id.widget_list, R.id.widget_empty); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:com.xengar.android.stocktracker.widget.ListWidgetProvider.java
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) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_list); // Create an Intent to launch MainActivity Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget, pendingIntent); // Set up the collection if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setRemoteAdapter(context, views); } else {/* ww w . j a v a 2s . c om*/ setRemoteAdapterV11(context, views); } boolean useDetailActivity = context.getResources().getBoolean(R.bool.use_detail_activity); Intent clickIntentTemplate = useDetailActivity ? new Intent(context, DetailActivity.class) : new Intent(context, MainActivity.class); PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(clickIntentTemplate) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate); views.setEmptyView(R.id.widget_list, R.id.widget_empty); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:com.chen.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. *//*from w ww . j a v a 2 s . c om*/ public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.name)) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.name, folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } remoteViews.setViewVisibility(R.id.widget_account_noflip, View.VISIBLE); if (!TextUtils.isEmpty(account.name)) { remoteViews.setTextViewText(R.id.widget_account_noflip, account.name); remoteViews.setTextViewText(R.id.widget_account, account.name); } remoteViews.setViewVisibility(R.id.widget_account_unread_flipper, View.GONE); remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderUri, folderConversationListUri, folderDisplayName, widgetService); }