mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-30 21:58:52 +02: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)));
|
||||
|
||||
Reference in New Issue
Block a user