mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-06 12:54:11 +01:00
Added optional widget compose button
This commit is contained in:
@@ -71,7 +71,9 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
||||
@Override
|
||||
public void onBackStackChanged() {
|
||||
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
|
||||
if (!isShared(getIntent().getAction())) {
|
||||
String action = getIntent().getAction();
|
||||
if (!isShared(action) &&
|
||||
(action == null || !action.startsWith("widget:"))) {
|
||||
Intent parent = getParentActivityIntent();
|
||||
if (parent != null)
|
||||
if (shouldUpRecreateTask(parent))
|
||||
|
||||
@@ -60,6 +60,7 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
private ViewButtonColor btnColor;
|
||||
private Spinner spFontSize;
|
||||
private Spinner spPadding;
|
||||
private CheckBox cbCompose;
|
||||
private Button btnSave;
|
||||
private ContentLoadingProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
@@ -91,6 +92,7 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
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);
|
||||
boolean compose = prefs.getBoolean("widget." + appWidgetId + ".compose", false);
|
||||
|
||||
getSupportActionBar().setSubtitle(R.string.title_widget_title_list);
|
||||
setContentView(R.layout.activity_widget_unified);
|
||||
@@ -103,6 +105,7 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
btnColor = findViewById(R.id.btnColor);
|
||||
spFontSize = findViewById(R.id.spFontSize);
|
||||
spPadding = findViewById(R.id.spPadding);
|
||||
cbCompose = findViewById(R.id.cbCompose);
|
||||
btnSave = findViewById(R.id.btnSave);
|
||||
pbWait = findViewById(R.id.pbWait);
|
||||
grpReady = findViewById(R.id.grpReady);
|
||||
@@ -170,6 +173,7 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor());
|
||||
editor.putInt("widget." + appWidgetId + ".font", tinyOut(font));
|
||||
editor.putInt("widget." + appWidgetId + ".padding", tinyOut(padding));
|
||||
editor.putBoolean("widget." + appWidgetId + ".compose", cbCompose.isChecked());
|
||||
editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE);
|
||||
|
||||
editor.apply();
|
||||
@@ -287,6 +291,7 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
btnColor.setColor(background);
|
||||
spFontSize.setSelection(tinyIn(font));
|
||||
spPadding.setSelection(tinyIn(padding));
|
||||
cbCompose.setChecked(compose);
|
||||
|
||||
grpReady.setVisibility(View.GONE);
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
@@ -48,6 +49,7 @@ public class WidgetUnified extends AppWidgetProvider {
|
||||
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);
|
||||
boolean compose = prefs.getBoolean("widget." + appWidgetId + ".compose", false);
|
||||
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
|
||||
|
||||
if (version <= 1550)
|
||||
@@ -67,6 +69,14 @@ public class WidgetUnified extends AppWidgetProvider {
|
||||
PendingIntent pi = PendingIntentCompat.getActivity(
|
||||
context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Intent edit = new Intent(context, ActivityCompose.class);
|
||||
edit.setAction("widget:" + appWidgetId);
|
||||
edit.putExtra("action", "new");
|
||||
edit.putExtra("account", account);
|
||||
edit.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent piCompose = PendingIntentCompat.getActivity(
|
||||
context, appWidgetId, edit, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_unified);
|
||||
|
||||
views.setTextViewTextSize(R.id.title, TypedValue.COMPLEX_UNIT_SP, getFontSizeSp(font));
|
||||
@@ -81,6 +91,10 @@ public class WidgetUnified extends AppWidgetProvider {
|
||||
|
||||
views.setOnClickPendingIntent(R.id.title, pi);
|
||||
|
||||
views.setViewVisibility(R.id.compose, compose ? View.VISIBLE : View.GONE);
|
||||
views.setViewPadding(R.id.compose, px, px, px, px);
|
||||
views.setOnClickPendingIntent(R.id.compose, piCompose);
|
||||
|
||||
Intent service = new Intent(context, WidgetUnifiedService.class);
|
||||
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
service.setData(Uri.parse(service.toUri(Intent.URI_INTENT_SCHEME)));
|
||||
|
||||
@@ -121,6 +121,16 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPadding" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbCompose"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:checked="true"
|
||||
android:text="@string/title_widget_compose"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/spPadding" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -130,7 +140,7 @@
|
||||
android:drawablePadding="6dp"
|
||||
android:text="@string/title_save"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/spPadding" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbCompose" />
|
||||
|
||||
<eu.faircode.email.ContentLoadingProgressBar
|
||||
android:id="@+id/pbWait"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/widget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@@ -8,16 +9,33 @@
|
||||
android:paddingStart="6dp"
|
||||
android:paddingEnd="6dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="6dp"
|
||||
android:text="@string/title_widget_title_list"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="@color/colorWidgetForeground"
|
||||
android:textStyle="bold" />
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:padding="6dp"
|
||||
android:text="@string/title_widget_title_list"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="@color/colorWidgetForeground"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/compose"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:contentDescription="@string/title_compose"
|
||||
android:padding="6dp"
|
||||
android:src="@drawable/twotone_edit_24"
|
||||
app:tint="@color/colorWidgetForeground" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/separator"
|
||||
|
||||
@@ -1696,6 +1696,7 @@
|
||||
<string name="title_widget_font_size">Text size</string>
|
||||
<string name="title_widget_padding">Padding size</string>
|
||||
<string name="title_widget_semi_transparent">Semi transparent background</string>
|
||||
<string name="title_widget_compose">Show compose new message button</string>
|
||||
<string name="title_widget_background">Background color</string>
|
||||
|
||||
<string name="title_accessibility_collapsed">Collapsed</string>
|
||||
|
||||
Reference in New Issue
Block a user