mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-27 11:25:13 +01:00
Added optional widget compose button
This commit is contained in:
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user