From 466321ab87a78bb2c46abb8e54274849285630fb Mon Sep 17 00:00:00 2001 From: Mikhail Kulesh Date: Thu, 21 Mar 2024 10:56:06 +0100 Subject: [PATCH] #137 Allow to share a file with uMath: implemented in premium version --- app/src/main/AndroidManifest.xml | 67 ++++++++++++++++--- .../com/mkulesh/micromath/MainActivity.java | 13 +++- .../mkulesh/micromath/utils/CompatUtils.java | 21 ++++++ 3 files changed, 87 insertions(+), 14 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c7830d16..050de119 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -45,23 +45,68 @@ - + - + + + + - - + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/mkulesh/micromath/MainActivity.java b/app/src/main/java/com/mkulesh/micromath/MainActivity.java index 7d035381..8a711bb4 100644 --- a/app/src/main/java/com/mkulesh/micromath/MainActivity.java +++ b/app/src/main/java/com/mkulesh/micromath/MainActivity.java @@ -128,20 +128,27 @@ protected void onCreate(Bundle savedInstanceState) } else if (SHORTCUT_NEW_DOCUMENT.equals(intent.getAction())) { - ViewUtils.Debug(this, "Called with shortcut intent: " + intent.toString()); + ViewUtils.Debug(this, "Called with shortcut intent: " + intent); selectWorksheet(R.id.action_new_document); intentProcessed = true; } else if (intent.getData() != null) { - ViewUtils.Debug(this, "Called with external UIR: " + intent.toString()); + ViewUtils.Debug(this, "Called with external URI: " + intent); externalUri = intent.getData(); selectWorksheet(BaseFragment.INVALID_ACTION_ID); intentProcessed = true; } + else if (CompatUtils.getClipDataUri(intent) != null) + { + ViewUtils.Debug(this, "Called with ClipData URI: " + intent); + externalUri = CompatUtils.getClipDataUri(intent); + selectWorksheet(BaseFragment.INVALID_ACTION_ID); + intentProcessed = true; + } else { - ViewUtils.Debug(this, "Called with unknown indent: " + intent.toString()); + ViewUtils.Debug(this, "Called with unknown indent: " + intent); } } if (!intentProcessed && savedInstanceState == null) diff --git a/app/src/main/java/com/mkulesh/micromath/utils/CompatUtils.java b/app/src/main/java/com/mkulesh/micromath/utils/CompatUtils.java index 958519ee..f627bd97 100644 --- a/app/src/main/java/com/mkulesh/micromath/utils/CompatUtils.java +++ b/app/src/main/java/com/mkulesh/micromath/utils/CompatUtils.java @@ -19,6 +19,7 @@ import android.content.Intent; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Environment; @@ -281,4 +282,24 @@ public static boolean isToastVisible(Toast toast) return toast != null && toast.getView() != null && toast.getView().isShown(); } } + + public static Uri getClipDataUri(Intent intent) + { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) + { + return null; + } + if (intent.getClipData() == null) + { + return null; + } + for (int i = 0; i < intent.getClipData().getItemCount(); i++) + { + if (intent.getClipData().getItemAt(i).getUri() != null) + { + return intent.getClipData().getItemAt(i).getUri(); + } + } + return null; + } }