Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Andoird text snippet sharing #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ SOFTWARE.
<platform name="android">

<preference name="ANDROID_MIME_TYPES" />
<preference name="ANDROID_EXTRA_ACTIONS" default=" " />
<preference name="ANDROID_EXTRA_ACTIONS" />

<js-module src="www/openwith.js" name="openwith">
<clobbers target="cordova.openwith" />
Expand All @@ -100,8 +100,8 @@ SOFTWARE.
$ANDROID_MIME_TYPES
<action android:name="android.intent.action.SEND" />
$ANDROID_EXTRA_ACTIONS
<!-- action android:name="android.intent.action.VIEW" / -->
<!-- action android:name="android.intent.action.SEND_MULTIPLE" / -->
<!-- <action android:name="android.intent.action.VIEW" /> -->
<!-- <action android:name="android.intent.action.SEND_MULTIPLE" /> -->
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</config-file>
Expand Down
40 changes: 37 additions & 3 deletions src/android/cc/fovea/openwith/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public static boolean readExitOnSent(final Bundle extras) {

/** Extract the list of items from clip data (if available).
*
* Defaults to null. */
* Defaults to null.
*
* Expanded extraction list based on https://github.com/JochenHeizmann/cordova-plugin-openwith/commit/331e244a048c8aead1f58cc2e7e836893b0ddc55
* */
public static JSONArray itemsFromClipData(
final ContentResolver contentResolver,
final ClipData clipData)
Expand All @@ -81,7 +84,15 @@ public static JSONArray itemsFromClipData(
final int clipItemCount = clipData.getItemCount();
JSONObject[] items = new JSONObject[clipItemCount];
for (int i = 0; i < clipItemCount; i++) {
items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getUri());
if (clipData.getItemAt(i).getUri() != null) {
items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getUri());
} else if (clipData.getItemAt(i).getText() != null) {
items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getText().toString());
} else if (clipData.getItemAt(i).getHtmlText() != null) {
items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getHtmlText());
} else {
items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).toString());
}
}
return new JSONArray(items);
}
Expand Down Expand Up @@ -153,6 +164,29 @@ public static JSONObject toJSONObject(
return json;
}

/** Convert an String to JSON object.
*
* Object will include:
* "type" of data;
* "text" itself;
* "path" to the file, if applicable.
* "data" for the file.
*
* Based on https://github.com/JochenHeizmann/cordova-plugin-openwith/commit/331e244a048c8aead1f58cc2e7e836893b0ddc55
*/
public static JSONObject toJSONObject(
final ContentResolver contentResolver,
final String text)
throws JSONException {
if (text == null) {
return null;
}
final JSONObject json = new JSONObject();
json.put("type", "text/plain");
json.put("content", text);
return json;
}

/** Return data contained at a given Uri as Base64. Defaults to null. */
public static String getDataFromURI(
final ContentResolver contentResolver,
Expand Down Expand Up @@ -189,4 +223,4 @@ public static String getRealPathFromURI(
return result;
}
}
// vim: ts=4:sw=4:et
// vim: ts=4:sw=4:et