1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-29 11:15:51 +00:00

Allow setting message widget font size

This commit is contained in:
M66B 2020-05-25 09:42:54 +02:00
parent aa8740226f
commit d6148505c2
5 changed files with 60 additions and 1 deletions

View file

@ -46,12 +46,14 @@ public class ActivityWidgetUnified extends ActivityBase {
private CheckBox cbUnseen;
private CheckBox cbFlagged;
private CheckBox cbSemiTransparent;
private Spinner spFontSize;
private Button btnSave;
private ContentLoadingProgressBar pbWait;
private Group grpReady;
private ArrayAdapter<EntityAccount> adapterAccount;
private ArrayAdapter<TupleFolderEx> adapterFolder;
private ArrayAdapter<String> adapterFontSize;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -74,6 +76,7 @@ public class ActivityWidgetUnified extends ActivityBase {
cbUnseen = findViewById(R.id.cbUnseen);
cbFlagged = findViewById(R.id.cbFlagged);
cbSemiTransparent = findViewById(R.id.cbSemiTransparent);
spFontSize = findViewById(R.id.spFontSize);
btnSave = findViewById(R.id.btnSave);
pbWait = findViewById(R.id.pbWait);
grpReady = findViewById(R.id.grpReady);
@ -89,6 +92,7 @@ public class ActivityWidgetUnified extends ActivityBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetUnified.this);
SharedPreferences.Editor editor = prefs.edit();
if (account != null && account.id > 0)
if (folder != null && folder.id > 0)
editor.putString("widget." + appWidgetId + ".name", folder.getDisplayName(ActivityWidgetUnified.this));
@ -96,12 +100,15 @@ public class ActivityWidgetUnified extends ActivityBase {
editor.putString("widget." + appWidgetId + ".name", account.name);
else
editor.remove("widget." + appWidgetId + ".name");
editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id);
editor.putLong("widget." + appWidgetId + ".folder", folder == null ? -1L : folder.id);
editor.putString("widget." + appWidgetId + ".type", folder == null ? null : folder.type);
editor.putBoolean("widget." + appWidgetId + ".unseen", cbUnseen.isChecked());
editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked());
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked());
editor.putInt("widget." + appWidgetId + ".font", spFontSize.getSelectedItemPosition());
editor.apply();
WidgetUnified.init(ActivityWidgetUnified.this, appWidgetId);
@ -171,6 +178,11 @@ 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);
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);

View file

@ -28,6 +28,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.util.TypedValue;
import android.widget.RemoteViews;
import androidx.preference.PreferenceManager;
@ -43,6 +44,7 @@ public class WidgetUnified extends AppWidgetProvider {
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
String type = prefs.getString("widget." + appWidgetId + ".type", null);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int font = prefs.getInt("widget." + appWidgetId + ".font", 0);
Intent view = new Intent(context, ActivityView.class);
view.setAction("folder:" + folder);
@ -57,6 +59,9 @@ public class WidgetUnified extends AppWidgetProvider {
if (!semi)
views.setInt(R.id.widget, "setBackgroundColor", Color.TRANSPARENT);
if (font > 0)
views.setTextViewTextSize(R.id.title, TypedValue.COMPLEX_UNIT_SP, getFontSizeSp(font));
if (name == null)
views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified));
else
@ -83,6 +88,17 @@ public class WidgetUnified extends AppWidgetProvider {
}
}
static int getFontSizeSp(int size) {
switch (size) {
case 1: // small
return 14;
case 3: // large
return 22;
default: // medium
return 18;
}
}
static void init(Context context, int appWidgetId) {
Log.i("Widget unified init=" + appWidgetId);

View file

@ -28,6 +28,7 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.TypedValue;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
@ -50,6 +51,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private long account;
private boolean unseen;
private boolean flagged;
private int font;
private int colorWidgetForeground;
private int colorWidgetRead;
private int colorSeparator;
@ -82,6 +84,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false);
flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false);
font = prefs.getInt("widget." + appWidgetId + ".font", 0);
colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground);
colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead);
colorSeparator = ContextCompat.getColor(context, R.color.lightColorSeparator);
@ -167,6 +170,15 @@ 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);

View file

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

View file

@ -1273,6 +1273,7 @@
<string name="title_widget_folder_unified">Unified inbox folders</string>
<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_semi_transparent">Semi transparent background</string>
<string name="title_accessibility_collapsed">Collapsed</string>