diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java index e729d22610..005e52c7b7 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java @@ -47,6 +47,7 @@ public class ActivityWidgetUnified extends ActivityBase { private CheckBox cbFlagged; private CheckBox cbSemiTransparent; private Spinner spFontSize; + private Spinner spPadding; private Button btnSave; private ContentLoadingProgressBar pbWait; private Group grpReady; @@ -54,6 +55,7 @@ public class ActivityWidgetUnified extends ActivityBase { private ArrayAdapter adapterAccount; private ArrayAdapter adapterFolder; private ArrayAdapter adapterFontSize; + private ArrayAdapter adapterPadding; @Override protected void onCreate(Bundle savedInstanceState) { @@ -77,6 +79,7 @@ public class ActivityWidgetUnified extends ActivityBase { cbFlagged = findViewById(R.id.cbFlagged); cbSemiTransparent = findViewById(R.id.cbSemiTransparent); spFontSize = findViewById(R.id.spFontSize); + spPadding = findViewById(R.id.spPadding); btnSave = findViewById(R.id.btnSave); pbWait = findViewById(R.id.pbWait); grpReady = findViewById(R.id.grpReady); @@ -108,6 +111,7 @@ public class ActivityWidgetUnified extends ActivityBase { editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked()); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); editor.putInt("widget." + appWidgetId + ".font", spFontSize.getSelectedItemPosition()); + editor.putInt("widget." + appWidgetId + ".padding", spPadding.getSelectedItemPosition()); editor.apply(); @@ -179,10 +183,15 @@ public class ActivityWidgetUnified extends ActivityBase { }); String[] sizes = getResources().getStringArray(R.array.fontSizeNames); + adapterFontSize = new ArrayAdapter<>(this, R.layout.spinner_item1, android.R.id.text1, sizes); adapterFontSize.setDropDownViewResource(R.layout.spinner_item1_dropdown); spFontSize.setAdapter(adapterFontSize); + adapterPadding = new ArrayAdapter<>(this, R.layout.spinner_item1, android.R.id.text1, sizes); + adapterPadding.setDropDownViewResource(R.layout.spinner_item1_dropdown); + spPadding.setAdapter(adapterPadding); + grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/WidgetUnified.java b/app/src/main/java/eu/faircode/email/WidgetUnified.java index 52c9774087..bb670315f9 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnified.java @@ -45,6 +45,7 @@ public class WidgetUnified extends AppWidgetProvider { String type = prefs.getString("widget." + appWidgetId + ".type", null); boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true); int font = prefs.getInt("widget." + appWidgetId + ".font", 0); + int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0); Intent view = new Intent(context, ActivityView.class); view.setAction("folder:" + folder); @@ -62,6 +63,11 @@ public class WidgetUnified extends AppWidgetProvider { if (font > 0) views.setTextViewTextSize(R.id.title, TypedValue.COMPLEX_UNIT_SP, getFontSizeSp(font)); + if (padding > 0) { + int px = getPaddingPx(padding, context); + views.setViewPadding(R.id.title, px, px, px, px); + } + if (name == null) views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified)); else @@ -99,6 +105,17 @@ public class WidgetUnified extends AppWidgetProvider { } } + static int getPaddingPx(int padding, Context context) { + switch (padding) { + case 1: // small + return Helper.dp2pixels(context, 3); + case 3: // large + return Helper.dp2pixels(context, 9); + default: // medium + return Helper.dp2pixels(context, 6); + } + } + static void init(Context context, int appWidgetId) { Log.i("Widget unified init=" + appWidgetId); diff --git a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java index 09e9873aae..4516dd777c 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java @@ -52,6 +52,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot private boolean unseen; private boolean flagged; private int font; + private int padding; private int colorWidgetForeground; private int colorWidgetRead; private int colorSeparator; @@ -85,6 +86,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false); flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false); font = prefs.getInt("widget." + appWidgetId + ".font", 0); + padding = prefs.getInt("widget." + appWidgetId + ".padding", 0); colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground); colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead); colorSeparator = ContextCompat.getColor(context, R.color.lightColorSeparator); @@ -132,6 +134,19 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot int idSubject = (subject_top ? R.id.tvFrom : R.id.tvSubject); int idAccount = (subject_top ? R.id.tvTime : R.id.tvAccount); + if (font > 0) { + int sp = WidgetUnified.getFontSizeSp(font); + views.setTextViewTextSize(idFrom, TypedValue.COMPLEX_UNIT_SP, sp); + views.setTextViewTextSize(idTime, TypedValue.COMPLEX_UNIT_SP, sp); + views.setTextViewTextSize(idSubject, TypedValue.COMPLEX_UNIT_SP, sp); + views.setTextViewTextSize(idAccount, TypedValue.COMPLEX_UNIT_SP, sp); + } + + if (padding > 0) { + int px = WidgetUnified.getPaddingPx(padding, context); + views.setViewPadding(R.id.llMessage, px, px, px, px); + } + if (position >= messages.size()) return views; @@ -170,15 +185,6 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot ssAccount.setSpan(new StyleSpan(Typeface.BOLD), 0, ssAccount.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); } - if (font > 0) { - int text_size = WidgetUnified.getFontSizeSp(font); - - views.setTextViewTextSize(idFrom, TypedValue.COMPLEX_UNIT_SP, text_size); - views.setTextViewTextSize(idTime, TypedValue.COMPLEX_UNIT_SP, text_size); - views.setTextViewTextSize(idSubject, TypedValue.COMPLEX_UNIT_SP, text_size); - views.setTextViewTextSize(idAccount, TypedValue.COMPLEX_UNIT_SP, text_size); - } - views.setTextViewText(idFrom, ssFrom); views.setTextViewText(idTime, ssTime); views.setTextViewText(idSubject, ssSubject); diff --git a/app/src/main/res/layout/activity_widget_unified.xml b/app/src/main/res/layout/activity_widget_unified.xml index d3cfa46cc8..671a66d177 100644 --- a/app/src/main/res/layout/activity_widget_unified.xml +++ b/app/src/main/res/layout/activity_widget_unified.xml @@ -87,6 +87,24 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvFontSize" /> + + + +