From 68d1c8b03e41f6c3078c9b9b6ca1e3bffb5f3f78 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 22 Sep 2020 19:44:53 +0200 Subject: [PATCH] Added B/W toast --- .../java/eu/faircode/email/FragmentCompose.java | 14 ++++++++++++++ app/src/main/java/eu/faircode/email/ToastEx.java | 15 +++++++++++++++ .../java/eu/faircode/email/ViewImageHint.java | 5 +++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 1edfbdce3f..cc29d1c2da 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -68,6 +68,7 @@ import android.text.style.ParagraphStyle; import android.text.style.QuoteSpan; import android.text.style.URLSpan; import android.util.TypedValue; +import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -1330,6 +1331,19 @@ public class FragmentCompose extends FragmentBase { onMenuEncrypt(); } }); + ib.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + int[] pos = new int[2]; + ib.getLocationOnScreen(pos); + int dp24 = Helper.dp2pixels(v.getContext(), 24); + + Toast toast = ToastEx.makeTextBw(getContext(), getString(R.string.title_encrypt), Toast.LENGTH_LONG); + toast.setGravity(Gravity.TOP | Gravity.START, pos[0], pos[1] + dp24); + toast.show(); + return true; + } + }); super.onCreateOptionsMenu(menu, inflater); } diff --git a/app/src/main/java/eu/faircode/email/ToastEx.java b/app/src/main/java/eu/faircode/email/ToastEx.java index 2a731a5f7f..2cb106cc66 100644 --- a/app/src/main/java/eu/faircode/email/ToastEx.java +++ b/app/src/main/java/eu/faircode/email/ToastEx.java @@ -21,6 +21,7 @@ package eu.faircode.email; import android.content.Context; import android.content.res.Resources; +import android.graphics.Color; import android.os.Looper; import android.view.Gravity; import android.view.LayoutInflater; @@ -54,6 +55,20 @@ public class ToastEx extends Toast { return toast; } + public static ToastEx makeTextBw(Context context, CharSequence text, int duration) { + ToastEx toast = new ToastEx(context); + LayoutInflater inflater = LayoutInflater.from(context); + View view = inflater.inflate(R.layout.toast, null); + view.setBackground(context.getDrawable(android.R.drawable.toast_frame)); + + TextView tv = view.findViewById(android.R.id.message); + tv.setTextColor(Color.parseColor("#de000000")); // primary_text_default_material_light + tv.setText(text); + toast.setView(view); + toast.setDuration(duration); + return toast; + } + @Override public void show() { // https://developer.android.com/preview/features/toasts diff --git a/app/src/main/java/eu/faircode/email/ViewImageHint.java b/app/src/main/java/eu/faircode/email/ViewImageHint.java index c39be94f63..8cfd02e1b3 100644 --- a/app/src/main/java/eu/faircode/email/ViewImageHint.java +++ b/app/src/main/java/eu/faircode/email/ViewImageHint.java @@ -33,9 +33,10 @@ public class ViewImageHint extends AppCompatImageView implements View.OnClickLis if (!TextUtils.isEmpty(title)) { int[] pos = new int[2]; getLocationOnScreen(pos); + int dp6 = Helper.dp2pixels(v.getContext(), 6); - Toast toast = ToastEx.makeText(getContext(), title, Toast.LENGTH_LONG); - toast.setGravity(Gravity.TOP | Gravity.START, pos[0], pos[1]); + Toast toast = ToastEx.makeTextBw(getContext(), title, Toast.LENGTH_LONG); + toast.setGravity(Gravity.TOP | Gravity.START, pos[0], pos[1] + dp6); toast.show(); } }