mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-29 18:09:25 +01:00
small change to widget updating
This commit is contained in:
parent
927618b907
commit
2be922deba
@ -26,7 +26,6 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
|||||||
private static final String NEXT = "next";
|
private static final String NEXT = "next";
|
||||||
|
|
||||||
private static RemoteViews remoteViews;
|
private static RemoteViews remoteViews;
|
||||||
private static int[] widgetIds;
|
|
||||||
private static AppWidgetManager widgetManager;
|
private static AppWidgetManager widgetManager;
|
||||||
private static Intent intent;
|
private static Intent intent;
|
||||||
private static Context cxt;
|
private static Context cxt;
|
||||||
@ -39,11 +38,13 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
initVariables(context);
|
cxt = context;
|
||||||
|
initVariables();
|
||||||
|
updateWidget();
|
||||||
|
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initVariables(Context context) {
|
private void initVariables() {
|
||||||
cxt = context;
|
|
||||||
res = cxt.getResources();
|
res = cxt.getResources();
|
||||||
|
|
||||||
final SharedPreferences prefs = initPrefs(cxt);
|
final SharedPreferences prefs = initPrefs(cxt);
|
||||||
@ -51,13 +52,9 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
|||||||
textColor = Helpers.adjustAlpha(storedTextColor, Constants.HIGH_ALPHA);
|
textColor = Helpers.adjustAlpha(storedTextColor, Constants.HIGH_ALPHA);
|
||||||
weakTextColor = Helpers.adjustAlpha(storedTextColor, Constants.LOW_ALPHA);
|
weakTextColor = Helpers.adjustAlpha(storedTextColor, Constants.LOW_ALPHA);
|
||||||
|
|
||||||
|
|
||||||
dayTextSize = res.getDimension(R.dimen.day_text_size) / res.getDisplayMetrics().density;
|
dayTextSize = res.getDimension(R.dimen.day_text_size) / res.getDisplayMetrics().density;
|
||||||
todayTextSize = res.getDimension(R.dimen.today_text_size) / res.getDisplayMetrics().density;
|
todayTextSize = res.getDimension(R.dimen.today_text_size) / res.getDisplayMetrics().density;
|
||||||
|
|
||||||
final ComponentName component = new ComponentName(cxt, MyWidgetProvider.class);
|
|
||||||
widgetManager = AppWidgetManager.getInstance(cxt);
|
widgetManager = AppWidgetManager.getInstance(cxt);
|
||||||
widgetIds = widgetManager.getAppWidgetIds(component);
|
|
||||||
|
|
||||||
remoteViews = new RemoteViews(cxt.getPackageName(), R.layout.activity_main);
|
remoteViews = new RemoteViews(cxt.getPackageName(), R.layout.activity_main);
|
||||||
intent = new Intent(cxt, MyWidgetProvider.class);
|
intent = new Intent(cxt, MyWidgetProvider.class);
|
||||||
@ -70,8 +67,11 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
|||||||
|
|
||||||
calendar = new CalendarImpl(this);
|
calendar = new CalendarImpl(this);
|
||||||
calendar.updateCalendar(new DateTime());
|
calendar.updateCalendar(new DateTime());
|
||||||
|
}
|
||||||
|
|
||||||
widgetManager.updateAppWidget(widgetIds, remoteViews);
|
private void updateWidget() {
|
||||||
|
final ComponentName thisWidget = new ComponentName(cxt, MyWidgetProvider.class);
|
||||||
|
AppWidgetManager.getInstance(cxt).updateAppWidget(thisWidget, remoteViews);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupIntent(String action, int id) {
|
private void setupIntent(String action, int id) {
|
||||||
@ -91,8 +91,9 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (remoteViews == null || widgetManager == null || widgetIds == null || calendar == null)
|
cxt = context;
|
||||||
initVariables(context);
|
if (remoteViews == null || widgetManager == null || calendar == null)
|
||||||
|
initVariables();
|
||||||
|
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@ -148,7 +149,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
|||||||
public void updateCalendar(String month, List<Day> days) {
|
public void updateCalendar(String month, List<Day> days) {
|
||||||
updateMonth(month);
|
updateMonth(month);
|
||||||
updateDays(days);
|
updateDays(days);
|
||||||
widgetManager.updateAppWidget(widgetIds, remoteViews);
|
updateWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLabelColor() {
|
private void updateLabelColor() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user