Added widget padding option

pull/178/head
M66B 5 years ago
parent f6543e7705
commit 4a5342aff3

@ -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<EntityAccount> adapterAccount;
private ArrayAdapter<TupleFolderEx> adapterFolder;
private ArrayAdapter<String> adapterFontSize;
private ArrayAdapter<String> 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);

@ -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);

@ -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);

@ -87,6 +87,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFontSize" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvPadding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_widget_padding"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spFontSize" />
<Spinner
android:id="@+id/spPadding"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPadding" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
@ -94,7 +112,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spFontSize" />
app:layout_constraintTop_toBottomOf="@id/spPadding" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait"

@ -1274,6 +1274,7 @@
<string name="title_widget_unseen">Unread messages only</string>
<string name="title_widget_flagged">Starred messages only</string>
<string name="title_widget_font_size">Font size</string>
<string name="title_widget_padding">Padding</string>
<string name="title_widget_semi_transparent">Semi transparent background</string>
<string name="title_accessibility_collapsed">Collapsed</string>

Loading…
Cancel
Save