Reconfigurable list widget

pull/204/head
M66B 3 years ago
parent cd74c63b1c
commit 78c9b8449f

@ -82,6 +82,16 @@ public class ActivityWidgetUnified extends ActivityBase {
appWidgetId = extras.getInt( appWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
boolean unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false);
boolean flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
int font = prefs.getInt("widget." + appWidgetId + ".font", 0);
int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);
getSupportActionBar().setSubtitle(R.string.title_widget_title_list); getSupportActionBar().setSubtitle(R.string.title_widget_title_list);
setContentView(R.layout.activity_widget_unified); setContentView(R.layout.activity_widget_unified);
@ -151,16 +161,6 @@ public class ActivityWidgetUnified extends ActivityBase {
int font = spFontSize.getSelectedItemPosition(); int font = spFontSize.getSelectedItemPosition();
int padding = spPadding.getSelectedItemPosition(); int padding = spPadding.getSelectedItemPosition();
if (font == 1) // tiny
font = 4;
else if (font > 1)
font--;
if (padding == 1) // tiny
padding = 4;
else if (padding > 1)
padding--;
editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id); editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id);
editor.putLong("widget." + appWidgetId + ".folder", folder == null ? -1L : folder.id); editor.putLong("widget." + appWidgetId + ".folder", folder == null ? -1L : folder.id);
editor.putString("widget." + appWidgetId + ".type", folder == null ? null : folder.type); editor.putString("widget." + appWidgetId + ".type", folder == null ? null : folder.type);
@ -168,8 +168,8 @@ public class ActivityWidgetUnified extends ActivityBase {
editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked()); editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked());
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked());
editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor());
editor.putInt("widget." + appWidgetId + ".font", font); editor.putInt("widget." + appWidgetId + ".font", tinyOut(font));
editor.putInt("widget." + appWidgetId + ".padding", padding); editor.putInt("widget." + appWidgetId + ".padding", tinyOut(padding));
editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE); editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE);
editor.apply(); editor.apply();
@ -250,7 +250,14 @@ public class ActivityWidgetUnified extends ActivityBase {
adapterFolder.clear(); adapterFolder.clear();
adapterFolder.addAll(folders); adapterFolder.addAll(folders);
spFolder.setSelection(0); int select = 0;
for (int i = 0; i < folders.size(); i++)
if (folders.get(i).id.equals(folder)) {
select = i;
break;
}
spFolder.setSelection(select);
} }
@Override @Override
@ -273,13 +280,21 @@ public class ActivityWidgetUnified extends ActivityBase {
adapterPadding.setDropDownViewResource(R.layout.spinner_item1_dropdown); adapterPadding.setDropDownViewResource(R.layout.spinner_item1_dropdown);
spPadding.setAdapter(adapterPadding); spPadding.setAdapter(adapterPadding);
btnColor.setColor(Color.TRANSPARENT); // Initialize
cbUnseen.setChecked(unseen);
cbFlagged.setChecked(flagged);
cbSemiTransparent.setChecked(semi);
btnColor.setColor(background);
spFontSize.setSelection(tinyIn(font));
spPadding.setSelection(tinyIn(padding));
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
setResult(RESULT_CANCELED, resultValue); setResult(RESULT_CANCELED, resultValue);
Bundle args = new Bundle();
new SimpleTask<List<EntityAccount>>() { new SimpleTask<List<EntityAccount>>() {
@Override @Override
protected List<EntityAccount> onExecute(Context context, Bundle args) { protected List<EntityAccount> onExecute(Context context, Bundle args) {
@ -301,6 +316,12 @@ public class ActivityWidgetUnified extends ActivityBase {
adapterAccount.addAll(accounts); adapterAccount.addAll(accounts);
for (int i = 0; i < accounts.size(); i++)
if (accounts.get(i).id.equals(account)) {
spAccount.setSelection(i);
break;
}
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
} }
@ -309,6 +330,24 @@ public class ActivityWidgetUnified extends ActivityBase {
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getSupportFragmentManager(), ex); Log.unexpectedError(getSupportFragmentManager(), ex);
} }
}.execute(this, new Bundle(), "widget:accounts"); }.execute(this, args, "widget:accounts");
}
private int tinyOut(int value) {
if (value == 1) // tiny
return 4;
else if (value > 1)
return value - 1;
else
return value;
}
private int tinyIn(int value) {
if (value == 4)
return 1;
else if (value >= 1)
return value + 1;
else
return value;
} }
} }

@ -50,6 +50,9 @@ public class WidgetUnified extends AppWidgetProvider {
int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0); int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);
int version = prefs.getInt("widget." + appWidgetId + ".version", 0); int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
if (version <= 1550)
semi = true; // Legacy
Intent view = new Intent(context, ActivityView.class); Intent view = new Intent(context, ActivityView.class);
view.setAction("folder:" + folder); view.setAction("folder:" + folder);
view.putExtra("account", account); view.putExtra("account", account);
@ -96,8 +99,13 @@ public class WidgetUnified extends AppWidgetProvider {
views.setPendingIntentTemplate(R.id.lv, piItem); views.setPendingIntentTemplate(R.id.lv, piItem);
if (background == Color.TRANSPARENT) { if (background == Color.TRANSPARENT) {
if (!semi && version > 1550) if (semi)
views.setInt(R.id.widget, "setBackgroundResource", R.drawable.widget_background);
else
views.setInt(R.id.widget, "setBackgroundColor", background); views.setInt(R.id.widget, "setBackgroundColor", background);
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
views.setTextColor(R.id.title, colorWidgetForeground);
} else { } else {
float lum = (float) ColorUtils.calculateLuminance(background); float lum = (float) ColorUtils.calculateLuminance(background);
@ -110,7 +118,11 @@ public class WidgetUnified extends AppWidgetProvider {
views.setTextColor(R.id.title, Color.BLACK); views.setTextColor(R.id.title, Color.BLACK);
} }
int dp6 = Helper.dp2pixels(context, 6);
views.setViewPadding(R.id.widget, dp6, 0, dp6, 0);
appWidgetManager.updateAppWidget(appWidgetId, views); appWidgetManager.updateAppWidget(appWidgetId, views);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
} }
} }

@ -7,4 +7,5 @@
android:previewImage="@drawable/widget_preview_unified" android:previewImage="@drawable/widget_preview_unified"
android:resizeMode="horizontal|vertical" android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="0" android:updatePeriodMillis="0"
android:widgetCategory="home_screen" /> android:widgetCategory="home_screen"
android:widgetFeatures="reconfigurable" />

Loading…
Cancel
Save