Clear widget data

This commit is contained in:
M66B 2021-03-13 15:20:52 +01:00
parent 3c721de1b9
commit f7bee91349
2 changed files with 34 additions and 0 deletions

View File

@ -134,6 +134,23 @@ public class Widget extends AppWidgetProvider {
});
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
for (int appWidgetId : appWidgetIds) {
String prefix = "widget." + appWidgetId + ".";
for (String key : prefs.getAll().keySet())
if (key.startsWith(prefix))
editor.remove(key);
}
editor.apply();
} catch (Throwable ex) {
Log.e(ex);
}
}
static void init(Context context, int appWidgetId) {
update(context);
}

View File

@ -103,6 +103,23 @@ public class WidgetUnified extends AppWidgetProvider {
}
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
for (int appWidgetId : appWidgetIds) {
String prefix = "widget." + appWidgetId + ".";
for (String key : prefs.getAll().keySet())
if (key.startsWith(prefix))
editor.remove(key);
}
editor.apply();
} catch (Throwable ex) {
Log.e(ex);
}
}
static int getFontSizeSp(int size) {
switch (size) {
case 1: // small