Skip to content

Commit

Permalink
#137 Allow to share a file with uMath: implemented in premium version
Browse files Browse the repository at this point in the history
  • Loading branch information
mkulesh committed Mar 21, 2024
1 parent 4d298ae commit 466321a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 14 deletions.
67 changes: 56 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,68 @@
</intent-filter>


<!-- This filter captures protocols with type info -->
<!-- This filter captures protocols without file extension -->
<intent-filter
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" >
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.OPENABLE"/>

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:scheme="ftp"/>
<data android:scheme="ftps"/>
<data android:scheme="sftp"/>
<data android:scheme="content"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:scheme="smb"/>

<data android:scheme="file" />
<data android:scheme="content" />

<data android:mimeType="text/plain" />
<data android:mimeType="text/xml" />

<data android:pathPattern=".*\\.xml" />
<data android:pathPattern=".*\\.mmt" />
<data android:mimeType="application/mmt" />
<data android:mimeType="application/octet-stream" />
</intent-filter>

<!-- This filter captures protocols with file extension -->
<intent-filter
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" >
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.OPENABLE"/>

<data android:scheme="file"/>
<data android:scheme="ftp"/>
<data android:scheme="ftps"/>
<data android:scheme="sftp"/>
<data android:scheme="content"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:scheme="smb"/>

<data android:host="*"/>
<data android:pathPattern=".*.MMT" />
<data android:pathPattern=".*.mmt" />
<data android:pathPattern=".*\\..*\\.MMT" />
<data android:pathPattern=".*\\..*\\.mmt" />
<data android:pathPattern=".*\\..*\\..*\\.MMT" />
<data android:pathPattern=".*\\..*\\..*\\.mmt" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.MMT" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.mmt" />
</intent-filter>

<!-- This filter captures "Share" option -->
<intent-filter
android:icon="@mipmap/ic_launcher"
android:label="Open with uMath+">
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>

<data android:mimeType="text/xml" />
<data android:mimeType="application/mmt" />
<data android:mimeType="application/octet-stream" />
</intent-filter>

<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/mkulesh/micromath/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/mkulesh/micromath/utils/CompatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 466321a

Please sign in to comment.