public RemoteViews getRemoteViews(Context context, int id, String date) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.appwidget_timetable); Application.getComponent(context).inject(this); User user = mSharedPreferenceHelper.getUser(); mSharedPreferenceHelper.setDateForWidget(date); remoteViews.setTextViewText(R.id.value_widget, user.getTitleValue()); if (user.getType() < 2) { if (TimetableUtils.getDayOfWeek(date) == TimetableUtils.getDayOfWeek(TimetableUtils.todayDate()) && TimetableUtils.getParity(date) == TimetableUtils.getParity(TimetableUtils.todayDate())) remoteViews.setTextViewText( R.id.day_widget, String.format(context.getString(R.string.today), TimetableUtils.getDayOfWeek(date))); else remoteViews.setTextViewText(R.id.day_widget, TimetableUtils.getDayOfWeek(date)); remoteViews.setTextViewText(R.id.date_widget, TimetableUtils.getParity(date) + " неделя"); } else { if (TimetableUtils.todayDate().equals(date)) remoteViews.setTextViewText( R.id.day_widget, String.format(context.getString(R.string.today), TimetableUtils.getDayOfWeek(date))); else remoteViews.setTextViewText(R.id.day_widget, TimetableUtils.getDayOfWeek(date)); remoteViews.setTextViewText(R.id.date_widget, TimetableUtils.getDayAndMonth(date)); } setUpPreviousButton(context, remoteViews, id, date); setUpNextButton(context, remoteViews, id, date); setUpTodayButton(context, remoteViews, id); setUpAdapter(context, remoteViews, id, date); setUpHeaderClick(context, remoteViews, id); return remoteViews; }
private void setRemotes(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int id : appWidgetIds) { RemoteViews remoteViews = getRemoteViews(context, id, TimetableUtils.todayDate()); if (remoteViews != null) { appWidgetManager.updateAppWidget(id, remoteViews); } } appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.list_widget); }
private void setUpTodayButton(Context context, RemoteViews remoteViews, int id) { Intent clickIntent = new Intent(context, TimetableWidgetProvider.class); clickIntent.setAction(ACTION_TODAY_CLICK); clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id); clickIntent.putExtra(EXTRA_DATE, TimetableUtils.todayDate()); PendingIntent clickPendingIntent = PendingIntent.getBroadcast(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.today_button, clickPendingIntent); }