Java Code Examples for android.widget.RemoteViews#setEmptyView()
The following examples show how to use
android.widget.RemoteViews#setEmptyView() .
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: WidgetHelper.java From materialistic with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void updateCollection(int appWidgetId, RemoteViews remoteViews, WidgetConfig config) { remoteViews.setTextViewText(R.id.subtitle, DateUtils.formatDateTime(mContext, System.currentTimeMillis(), DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME)); remoteViews.setOnClickPendingIntent(R.id.button_refresh, createRefreshPendingIntent(appWidgetId)); Intent intent = new Intent(mContext, WidgetService.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) .putExtra(WidgetService.EXTRA_CUSTOM_QUERY, config.customQuery) .putExtra(WidgetService.EXTRA_SECTION, config.section) .putExtra(WidgetService.EXTRA_LIGHT_THEME, config.isLightTheme); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { remoteViews.setRemoteAdapter(android.R.id.list, intent); } else { //noinspection deprecation remoteViews.setRemoteAdapter(appWidgetId, android.R.id.list, intent); } remoteViews.setEmptyView(android.R.id.list, R.id.empty); remoteViews.setPendingIntentTemplate(android.R.id.list, PendingIntent.getActivity(mContext, 0, new Intent(Intent.ACTION_VIEW), 0)); }
Example 2
Source File: WidgetProvider.java From budget-envelopes with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: AppWidgetProvider.java From WanAndroid with Apache License 2.0 | 6 votes |
private RemoteViews updateWidgetListView(Context context, int id) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.list_app_widget); Intent intent = new Intent(context, AppWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.list_view_widget, intent); remoteViews.setEmptyView(R.id.list_view_widget, R.id.empty_view); Intent tempIntent = new Intent(context, DetailActivity.class); tempIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); remoteViews.setPendingIntentTemplate(R.id.list_view_widget, PendingIntent.getActivity(context, 0, tempIntent, PendingIntent.FLAG_CANCEL_CURRENT)); return remoteViews; }
Example 4
Source File: WidgetProvider.java From DebugPurge with MIT License | 6 votes |
private RemoteViews updateWidgetListView(Context context, int appWidgetId) { //which layout to show on widget RemoteViews remoteViews = new RemoteViews( context.getPackageName(),R.layout.widget_layout); //RemoteViews Service needed to provide adapter for ListView Intent intent = new Intent(context, WidgetService.class); //passing app widget id to that RemoteViews Service intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse( intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(appWidgetId, R.id.listView, intent); remoteViews.setEmptyView(R.id.listView, R.id.emptyView); Intent toastIntent = new Intent(context, WidgetProvider.class); toastIntent.setAction(WidgetProvider.UNINSTALL_ACTION); toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.listView, toastPendingIntent); return remoteViews; }
Example 5
Source File: CheckListWidgetProvider.java From Travel-Mate with MIT License | 6 votes |
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 6
Source File: GitHubJourneyWidgetProvider.java From GitJourney with Apache License 2.0 | 6 votes |
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 7
Source File: PredatorPostsWidgetProvider.java From Capstone-Project with MIT License | 5 votes |
@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 8
Source File: UpcomingMovieUpdateService.java From Movie-Check with Apache License 2.0 | 5 votes |
@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 9
Source File: NoteListWidgetProvider.java From nono-android with GNU General Public License v3.0 | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for(int i=0;i<appWidgetIds.length;i++){ Intent intent = new Intent(context, NoteListWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.layout_widget_note_list); rv.setRemoteAdapter(appWidgetIds[i], R.id.note_list, intent); rv.setEmptyView(R.id.note_list, R.layout.empty_view); //新建笔记 Intent editIntent = new Intent(context, NoteEditActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,editIntent, 0); rv.setOnClickPendingIntent(R.id.add_new_note, pendingIntent); //启动应用 Intent launchIntent = new Intent(context, MainActivity.class); PendingIntent launchPendingIntent = PendingIntent.getActivity(context, 0,launchIntent, 0); rv.setOnClickPendingIntent(R.id.title_bar, launchPendingIntent); //快速打开笔记 Intent noteListIntent = new Intent(); noteListIntent.setAction(COLLECTION_VIEW_ACTION); noteListIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); PendingIntent noteListPendingIntent = PendingIntent.getBroadcast(context, 0, noteListIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.note_list, noteListPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], rv); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 10
Source File: MyCollectionViewWidget.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { // Create a Remote View. RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_collection_layout); // Listing 19-20: Adding a Click Listener to individual items // within a Collection View Widget using a Pending Intent Intent templateIntent = new Intent(context, MainActivity.class); templateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent templatePendingIntent = PendingIntent.getActivity( context, 0, templateIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_stack_view, templatePendingIntent); // Bind this widget to a Remote Views Service. Intent intent = new Intent(context, MyRemoteViewsService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); views.setRemoteAdapter(R.id.widget_stack_view, intent); // Specify a View within the Widget layout hierarchy to display // when the bound collection is empty. views.setEmptyView(R.id.widget_stack_view, R.id.widget_empty_text); // TODO Customize this Widgets UI based on configuration // settings etc. // Notify the App Widget Manager to update the widget using // the modified remote view. appWidgetManager.updateAppWidget(appWidgetId, views); }
Example 11
Source File: ZulipWidget.java From zulip-android with Apache License 2.0 | 5 votes |
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 12
Source File: DetailWidgetProvider.java From Advanced_Android_Development with Apache License 2.0 | 5 votes |
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 collection if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setRemoteAdapter(context, views); } else { 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); } }
Example 13
Source File: ExpensesWidgetProvider.java From Expense-Tracker-App with MIT License | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds){ Intent expenseDetailActivity = new Intent(context, ExpenseDetailActivity.class); Intent mainActivityIntent = new Intent(context, MainActivity.class); // Creating stack for builder item click TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); taskStackBuilder.addParentStack(MainActivity.class); taskStackBuilder.addNextIntent(mainActivityIntent); taskStackBuilder.addNextIntent(expenseDetailActivity); PendingIntent itemClickPendingIntent = taskStackBuilder.getPendingIntent(0 ,PendingIntent.FLAG_UPDATE_CURRENT); // Create pending intent for clicking the whole view, not an item PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent widgetServiceIntent = new Intent(context, ExpensesWidgetService.class); // widgetServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // widgetServiceIntent.setData(Uri.parse(widgetServiceIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_layout); remoteView.setOnClickPendingIntent(R.id.general_layout, mainPendingIntent); remoteView.setEmptyView(R.id.listViewWidget, R.id.empty_view); remoteView.setRemoteAdapter(appWidgetId, R.id.listViewWidget, widgetServiceIntent); remoteView.setTextViewText(R.id.tv_total, context.getString(R.string.today_expenses_total, Util.getFormattedCurrency(Expense.getTotalExpensesByDateMode(IDateMode.MODE_TODAY)))); remoteView.setPendingIntentTemplate(R.id.listViewWidget, itemClickPendingIntent); ComponentName component=new ComponentName(context, ExpensesWidgetProvider.class); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listViewWidget); appWidgetManager.updateAppWidget(component, remoteView); } }
Example 14
Source File: UpcomingWidgetProvider.java From cathode with Apache License 2.0 | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { Intent remoteViewsIntent = new Intent(context, UpcomingWidgetService.class); remoteViewsIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); remoteViewsIntent.setData(Uri.parse(remoteViewsIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.appwidget_upcoming); rv.setRemoteAdapter(android.R.id.list, remoteViewsIntent); rv.setEmptyView(android.R.id.list, android.R.id.empty); Intent homeIntent = new Intent(context, HomeActivity.class); homeIntent.setAction(HomeActivity.ACTION_SHOW_START_PAGE); homeIntent.putExtra(HomeActivity.EXTRA_START_PAGE, StartPage.SHOWS_UPCOMING); PendingIntent homePI = PendingIntent.getActivity(context, 0, homeIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setOnClickPendingIntent(R.id.header, homePI); Intent rowClickTemplate = new Intent(context, EpisodeDetailsActivity.class); rowClickTemplate.setData(Uri.parse(rowClickTemplate.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent piTemplate = PendingIntent.getActivity(context, 0, rowClickTemplate, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(android.R.id.list, piTemplate); appWidgetManager.updateAppWidget(appWidgetId, rv); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 15
Source File: EarthquakeListWidget.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
static void updateAppWidgets(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds, final PendingResult pendingResult) { Thread thread = new Thread() { public void run() { for (int appWidgetId: appWidgetIds) { // Set up the intent that starts the Earthquake // Remote Views Service, which will supply the views // shown in the List View. Intent intent = new Intent(context, EarthquakeRemoteViewsService.class); // Add the app widget ID to the intent extras. intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // Instantiate the RemoteViews object for the App Widget layout. RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.quake_collection_widget); // Set up the RemoteViews object to use a RemoteViews adapter. views.setRemoteAdapter(R.id.widget_list_view, intent); // The empty view is displayed when the collection has no items. views.setEmptyView(R.id.widget_list_view, R.id.widget_empty_text); // Notify the App Widget Manager to update the widget using // the modified remote view. appWidgetManager.updateAppWidget(appWidgetId, views); } if (pendingResult != null) pendingResult.finish(); } }; thread.start(); }
Example 16
Source File: ShotAppWidgetProvider.java From droidddle with Apache License 2.0 | 4 votes |
public static void setupWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, boolean refreshing) { boolean oauthed = OAuthUtils.haveToken(context); // Set up the intent that starts the StackViewService, which will // provide the views for this collection. Resources res = context.getResources(); Intent intent = new Intent(context, ShotWidgetService.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.shot_appwidget); // 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.setImageViewResource(R.id.shot_widget_update, R.drawable.ic_refresh_grey); // rv.setImageViewResource(R.id.shot_widget_icon, R.drawable.ic_launcher); rv.setTextViewText(R.id.shot_widget_title, res.getString(R.string.shot_widget_title)); rv.setViewVisibility(R.id.shot_widget_progress, refreshing ? View.VISIBLE : View.INVISIBLE); rv.setViewVisibility(R.id.shot_widget_update, refreshing ? View.INVISIBLE : View.VISIBLE); // 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.shot_stack_view, R.id.shot_widget_empty_view); rv.setTextViewText(R.id.shot_widget_empty_view, res.getString(R.string.shot_widget_empty)); if (oauthed) { rv.setRemoteAdapter(R.id.shot_stack_view, intent); rv.setViewVisibility(R.id.shot_widget_tips_view, View.GONE); } else { rv.setTextViewText(R.id.shot_widget_tips_view, res.getString(R.string.not_login)); rv.setViewVisibility(R.id.shot_widget_tips_view, View.VISIBLE); } final Intent onClickIntent = new Intent(context, ShotAppWidgetProvider.class); onClickIntent.setAction(ShotAppWidgetProvider.CLICK_ACTION); onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.shot_stack_view, onClickPendingIntent); final Intent refreshIntent = new Intent(context, ShotAppWidgetProvider.class); refreshIntent.setAction(ShotAppWidgetProvider.REFRESH_ACTION); final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setOnClickPendingIntent(R.id.shot_widget_update, refreshPendingIntent); appWidgetManager.updateAppWidget(appWidgetId, rv); final ComponentName cn = new ComponentName(context, ShotAppWidgetProvider.class); // appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetManager.getAppWidgetIds(cn), R.id.shot_stack_view); }
Example 17
Source File: TodayWidgetProvider.java From ETSMobile-Android2 with Apache License 2.0 | 4 votes |
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { RemoteViews views = new RemoteViews(context.getPackageName(), widgetInitialLayoutId); if (!syncEnCours && mUserLoggedIn) { views.setViewVisibility(syncBtnId, View.VISIBLE); views.setViewVisibility(progressBarId, View.GONE); } else if (syncEnCours && mUserLoggedIn) { views.setViewVisibility(progressBarId, View.VISIBLE); views.setProgressBar(progressBarId, 0, 0, true); views.setViewVisibility(syncBtnId, View.GONE); } int bgColor = TodayWidgetConfigureActivity.loadBgColorPref(context, appWidgetId); int textColor = TodayWidgetConfigureActivity.loadTextColorPref(context, appWidgetId); int bgOpacity = TodayWidgetConfigureActivity.loadOpacityPref(context, appWidgetId); // Vue affichée lorsque la liste est vide views.setTextColor(emptyViewId, textColor); views.setEmptyView(todayListId, emptyViewId); if (mUserLoggedIn) { views.setTextColor(todayNameTvId, textColor); Intent intent = new Intent(context, TodayWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Constants.TEXT_COLOR, textColor); intent.putExtra(Constants.DATE, dateTime.getMillis()); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); views.setTextViewText(emptyViewId, context.getString(R.string.no_classes_widget)); views.setRemoteAdapter(appWidgetId, todayListId, intent); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, todayListId); views.setViewVisibility(emptyViewId, View.VISIBLE); views.setViewVisibility(prevDayBtnId, View.VISIBLE); views.setViewVisibility(nextDayBtnId, View.VISIBLE); setUpSyncBtn(views, textColor); setUpPrevBtn(views, textColor); setUpNextBtn(views, textColor); } else { views.setViewVisibility(syncBtnId, View.GONE); views.setViewVisibility(progressBarId, View.GONE); views.setViewVisibility(todayListId, View.GONE); views.setViewVisibility(emptyViewId, View.GONE); views.setViewVisibility(prevDayBtnId, View.GONE); views.setViewVisibility(nextDayBtnId, View.GONE); } setUpTodayDateTv(context, views); setUpLoginBtn(context, views, textColor); bgColor = ColorUtils.setAlphaComponent(bgColor, bgOpacity); views.setInt(widgetLayoutId, "setBackgroundColor", bgColor); // Instruct the widget manager to update the widget appWidgetManager.updateAppWidget(appWidgetId, views); }
Example 18
Source File: WriteilyWidgetProvider.java From writeily-pro with MIT License | 4 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i = 0; i < N; i++) { int appWidgetId = appWidgetIds[i]; // Get the layout for the App Widget and attach an on-click listener to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); SharedPreferences sharedPreferences = context.getSharedPreferences( "" + appWidgetIds[i], Context.MODE_PRIVATE); String directory = sharedPreferences.getString(Constants.WIDGET_PATH, PreferenceManager.getDefaultSharedPreferences(context) .getString(context.getResources().getString(R.string.pref_root_directory), Constants.DEFAULT_WRITEILY_STORAGE_FOLDER)); Intent newNoteIntent = new Intent(context, NoteActivity.class) .putExtra(Constants.TARGET_DIR, directory); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, newNoteIntent, 0); views.setOnClickPendingIntent(R.id.widget_new_note, pendingIntent); Intent goToMain = new Intent(context, MainActivity.class); PendingIntent goToMainPendingIntent = PendingIntent.getActivity(context, 0, goToMain, 0); views.setOnClickPendingIntent(R.id.widget_header, goToMainPendingIntent); // ListView Intent notesListIntent = new Intent(context, FilesWidgetService.class); notesListIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); notesListIntent.putExtra(Constants.FOLDER_NAME, directory); notesListIntent.setData(Uri.parse(notesListIntent.toUri(Intent.URI_INTENT_SCHEME))); views.setEmptyView(R.id.widget_list_container, R.id.widget_empty_hint); views.setRemoteAdapter(R.id.widget_notes_list, notesListIntent); Intent openNoteIntent = new Intent(context, NoteActivity.class).setAction(Intent.ACTION_EDIT); PendingIntent openNotePendingIntent = PendingIntent.getActivity(context, 0, openNoteIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_notes_list, openNotePendingIntent); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 19
Source File: StackWidgetProvider.java From glimmr with Apache License 2.0 | 4 votes |
/** * 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 20
Source File: StackWidgetProvider.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // update each of the widgets with the remote adapter for (int i = 0; i < appWidgetIds.length; ++i) { // Here we setup the intent which points to the StackViewService // which will // provide the views for this collection. Intent intent = new Intent(context, StackWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); // 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))); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout); rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_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.stack_view, R.id.empty_view); // Here we setup the a pending intent template. Individuals items of // a collection // cannot setup their own pending intents, instead, the collection // as a whole can // setup a pending intent template, and the individual items can set // a fillInIntent // to create unique before on an item to item basis. Intent toastIntent = new Intent(context, StackWidgetProvider.class); toastIntent.setAction(StackWidgetProvider.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); rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], rv); } super.onUpdate(context, appWidgetManager, appWidgetIds); }