1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-02-23 22:51:02 +00:00

Reconfigurable count widget

This commit is contained in:
M66B 2021-08-22 13:29:37 +02:00
parent 5b4fcad9d3
commit 9188bcb84a
3 changed files with 37 additions and 5 deletions

View file

@ -76,6 +76,12 @@ public class ActivityWidget extends ActivityBase {
appWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidget.this);
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */);
getSupportActionBar().setSubtitle(R.string.title_widget_title_count);
setContentView(R.layout.activity_widget);
@ -154,7 +160,6 @@ public class ActivityWidget extends ActivityBase {
public void onClick(View view) {
EntityAccount account = (EntityAccount) spAccount.getSelectedItem();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidget.this);
SharedPreferences.Editor editor = prefs.edit();
if (account != null && account.id > 0)
editor.putString("widget." + appWidgetId + ".name", account.name);
@ -178,10 +183,14 @@ public class ActivityWidget extends ActivityBase {
adapterAccount.setDropDownViewResource(R.layout.spinner_item1_dropdown);
spAccount.setAdapter(adapterAccount);
// Initialize
((TextView) inOld.findViewById(R.id.tvCount)).setText("12");
((TextView) inNew.findViewById(R.id.tvCount)).setText("12");
btnColor.setColor(Color.TRANSPARENT);
cbSemiTransparent.setChecked(semi);
btnColor.setColor(background);
rbOld.setChecked(layout != 1);
rbNew.setChecked(layout == 1);
setBackground();
grpReady.setVisibility(View.GONE);
@ -189,6 +198,8 @@ public class ActivityWidget extends ActivityBase {
setResult(RESULT_CANCELED, resultValue);
Bundle args = new Bundle();
new SimpleTask<List<EntityAccount>>() {
@Override
protected List<EntityAccount> onExecute(Context context, Bundle args) {
@ -210,6 +221,12 @@ public class ActivityWidget extends ActivityBase {
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);
pbWait.setVisibility(View.GONE);
}
@ -218,7 +235,7 @@ public class ActivityWidget extends ActivityBase {
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getSupportFragmentManager(), ex);
}
}.execute(this, new Bundle(), "widget:accounts");
}.execute(this, args, "widget:accounts");
}
private void setBackground() {

View file

@ -27,6 +27,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.widget.RemoteViews;
@ -62,6 +63,9 @@ public class Widget extends AppWidgetProvider {
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 0);
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
if (version <= 1550)
semi = true; // Legacy
List<EntityFolder> folders = db.folder().getNotifyingFolders(account);
if (folders == null)
folders = new ArrayList<>();
@ -126,8 +130,15 @@ public class Widget extends AppWidgetProvider {
}
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);
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground);
views.setTextColor(R.id.tvCount, colorWidgetForeground);
views.setTextColor(R.id.tvAccount, colorWidgetForeground);
} else {
float lum = (float) ColorUtils.calculateLuminance(background);
@ -143,6 +154,9 @@ public class Widget extends AppWidgetProvider {
}
}
int pad = Helper.dp2pixels(context, layout == 0 ? 3 : 6);
views.setViewPadding(R.id.widget, pad, pad, pad, pad);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}

View file

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