From ad9c675fa4ba2d23d2ce33667384f363552928c8 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 25 Jan 2019 14:40:46 +0000 Subject: [PATCH] Fixed shared spanned text --- .../eu/faircode/email/ActivityCompose.java | 12 ++++++-- app/src/main/java/eu/faircode/email/Log.java | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index 5fb5ab8af9..bd68336889 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -22,6 +22,8 @@ package eu.faircode.email; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.text.Html; +import android.text.Spanned; import android.text.TextUtils; import android.view.MenuItem; @@ -62,6 +64,8 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager. Intent.ACTION_SENDTO.equals(action) || Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { + Log.logExtras(intent); + args = new Bundle(); args.putString("action", "new"); args.putLong("account", -1); @@ -122,9 +126,13 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager. if (html != null) args.putString("body", Jsoup.clean(html, Whitelist.relaxed())); } else if (intent.hasExtra(Intent.EXTRA_TEXT)) { - String body = intent.getStringExtra(Intent.EXTRA_TEXT); + CharSequence body = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); if (body != null) - args.putString("body", body); + if (body instanceof Spanned) + args.putString("body", + Jsoup.clean(Html.toHtml((Spanned) body), Whitelist.relaxed())); + else + args.putString("body", body.toString()); // TODO: clean? } if (intent.hasExtra(Intent.EXTRA_STREAM)) diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index b0055ba00b..16aae23030 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -19,6 +19,12 @@ package eu.faircode.email; Copyright 2018-2019 by Marcel Bokhorst (M66B) */ +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; + +import java.util.Set; + public class Log { static final String TAG = "fairemail"; @@ -52,4 +58,27 @@ public class Log { public static int e(String prefix, Throwable ex) { return android.util.Log.e(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex)); } + + public static void logExtras(Intent intent) { + if (intent != null) + logBundle(intent.getExtras()); + } + + public static void logBundle(Bundle data) { + if (data != null) { + Set keys = data.keySet(); + StringBuilder stringBuilder = new StringBuilder(); + for (String key : keys) { + Object value = data.get(key); + if (value instanceof String[]) + value = TextUtils.join(", ", (String[]) value); + stringBuilder.append(key) + .append("=") + .append(value) + .append(value == null ? "" : " (" + value.getClass().getSimpleName() + ")") + .append("\r\n"); + } + i(stringBuilder.toString()); + } + } } \ No newline at end of file