Sharing images and text from other apps is now supported. Closes #52
This commit is contained in:
parent
0719512134
commit
27dd106988
|
@ -39,6 +39,11 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".ComposeActivity"
|
android:name=".ComposeActivity"
|
||||||
android:windowSoftInputMode="stateVisible|adjustResize">
|
android:windowSoftInputMode="stateVisible|adjustResize">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SEND" />
|
<action android:name="android.intent.action.SEND" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
|
@ -81,7 +81,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -484,37 +483,51 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
|
||||||
for (SavedQueuedMedia item : savedMediaQueued) {
|
for (SavedQueuedMedia item : savedMediaQueued) {
|
||||||
addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
|
addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
|
||||||
}
|
}
|
||||||
} else if (savedInstanceState == null) {
|
} else if (intent != null && savedInstanceState == null) {
|
||||||
/* Get incoming images being sent through a share action from another app. Only do this
|
/* Get incoming images being sent through a share action from another app. Only do this
|
||||||
* when savedInstanceState is null, otherwise both the images from the intent and the
|
* when savedInstanceState is null, otherwise both the images from the intent and the
|
||||||
* instance state will be re-queued. */
|
* instance state will be re-queued. */
|
||||||
String type = intent.getType();
|
String type = intent.getType();
|
||||||
if (type != null && type.startsWith("image/")) {
|
if (type != null) {
|
||||||
List<Uri> uriList = new ArrayList<>();
|
if (type.startsWith("image/")) {
|
||||||
switch (intent.getAction()) {
|
List<Uri> uriList = new ArrayList<>();
|
||||||
case Intent.ACTION_SEND: {
|
switch (intent.getAction()) {
|
||||||
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
case Intent.ACTION_SEND: {
|
||||||
if (uri != null) {
|
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
uriList.add(uri);
|
if (uri != null) {
|
||||||
|
uriList.add(uri);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case Intent.ACTION_SEND_MULTIPLE: {
|
||||||
}
|
ArrayList<Uri> list = intent.getParcelableArrayListExtra(
|
||||||
case Intent.ACTION_SEND_MULTIPLE: {
|
Intent.EXTRA_STREAM);
|
||||||
ArrayList<Uri> list = intent.getParcelableArrayListExtra(
|
if (list != null) {
|
||||||
Intent.EXTRA_STREAM);
|
for (Uri uri : list) {
|
||||||
if (list != null) {
|
if (uri != null) {
|
||||||
for (Uri uri : list) {
|
uriList.add(uri);
|
||||||
if (uri != null) {
|
}
|
||||||
uriList.add(uri);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Uri uri : uriList) {
|
||||||
|
long mediaSize = getMediaSize(getContentResolver(), uri);
|
||||||
|
pickMedia(uri, mediaSize);
|
||||||
|
}
|
||||||
|
} else if (type.equals("text/plain")) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (action != null && action.equals(Intent.ACTION_SEND)) {
|
||||||
|
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
|
if (text != null) {
|
||||||
|
int start = Math.max(textEditor.getSelectionStart(), 0);
|
||||||
|
int end = Math.max(textEditor.getSelectionEnd(), 0);
|
||||||
|
int left = Math.min(start, end);
|
||||||
|
int right = Math.max(start, end);
|
||||||
|
textEditor.getText().replace(left, right, text, 0, text.length());
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (Uri uri : uriList) {
|
|
||||||
long mediaSize = getMediaSize(getContentResolver(), uri);
|
|
||||||
pickMedia(uri, mediaSize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue