mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-02-27 00:37:59 +01:00
change the way we update the widget and update it every 10 hours
This commit is contained in:
parent
a23391ff56
commit
6326d71e5e
@ -41,5 +41,4 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -12,6 +12,7 @@ import android.view.View;
|
|||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
||||||
|
private static int[] widgetIds;
|
||||||
private static RemoteViews remoteViews;
|
private static RemoteViews remoteViews;
|
||||||
private static CalculatorImpl calc;
|
private static CalculatorImpl calc;
|
||||||
private static AppWidgetManager widgetManager;
|
private static AppWidgetManager widgetManager;
|
||||||
@ -59,6 +60,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initVariables() {
|
private void initVariables() {
|
||||||
|
updateWidgetIds();
|
||||||
prefs = initPrefs(cxt);
|
prefs = initPrefs(cxt);
|
||||||
final int defaultColor = cxt.getResources().getColor(R.color.dark_grey);
|
final int defaultColor = cxt.getResources().getColor(R.color.dark_grey);
|
||||||
final int newBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, defaultColor);
|
final int newBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, defaultColor);
|
||||||
@ -75,9 +77,16 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||||||
calc = new CalculatorImpl(this, displayValue);
|
calc = new CalculatorImpl(this, displayValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateWidgetIds() {
|
||||||
|
final ComponentName component = new ComponentName(cxt, MyWidgetProvider.class);
|
||||||
|
widgetManager = AppWidgetManager.getInstance(cxt);
|
||||||
|
widgetIds = widgetManager.getAppWidgetIds(component);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateWidget() {
|
private void updateWidget() {
|
||||||
final ComponentName thisWidget = new ComponentName(cxt, MyWidgetProvider.class);
|
for (int widgetId : widgetIds) {
|
||||||
AppWidgetManager.getInstance(cxt).updateAppWidget(thisWidget, remoteViews);
|
widgetManager.updateAppWidget(widgetId, remoteViews);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SharedPreferences initPrefs(Context context) {
|
private SharedPreferences initPrefs(Context context) {
|
||||||
@ -213,6 +222,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||||||
public void onDeleted(Context context, int[] appWidgetIds) {
|
public void onDeleted(Context context, int[] appWidgetIds) {
|
||||||
super.onDeleted(context, appWidgetIds);
|
super.onDeleted(context, appWidgetIds);
|
||||||
resetSavedValue(context);
|
resetSavedValue(context);
|
||||||
|
updateWidgetIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:configure="calculator.simplemobiletools.com.MyWidgetConfigure"
|
android:configure="calculator.simplemobiletools.com.MyWidgetConfigure"
|
||||||
android:initialLayout="@layout/activity_main"
|
android:initialLayout="@layout/activity_main"
|
||||||
|
android:updatePeriodMillis="36000000"
|
||||||
android:minHeight="250dp"
|
android:minHeight="250dp"
|
||||||
android:minWidth="250dp">
|
android:minWidth="250dp">
|
||||||
</appwidget-provider>
|
</appwidget-provider>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user