Search in sources :

Example 1 with LegacyEditorFragment

use of org.wordpress.android.editor.LegacyEditorFragment in project WordPress-Android by wordpress-mobile.

the class EditPostActivity method setPostContentFromShareAction.

protected void setPostContentFromShareAction() {
    Intent intent = getIntent();
    // Check for shared text
    String text = intent.getStringExtra(Intent.EXTRA_TEXT);
    String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
    if (text != null) {
        if (title != null) {
            mEditorFragment.setTitle(title);
        }
        // Create an <a href> element around links
        text = AutolinkUtils.autoCreateLinks(text);
        if (mEditorFragment instanceof LegacyEditorFragment) {
            mEditorFragment.setContent(WPHtml.fromHtml(StringUtils.addPTags(text), this, mPost, getMaximumThumbnailWidthForEditor()));
        } else {
            mEditorFragment.setContent(text);
        }
    }
    // Check for shared media
    if (intent.hasExtra(Intent.EXTRA_STREAM)) {
        String action = intent.getAction();
        String type = intent.getType();
        ArrayList<Uri> sharedUris;
        if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            sharedUris = intent.getParcelableArrayListExtra((Intent.EXTRA_STREAM));
        } else {
            // For a single media share, we only allow images and video types
            if (type != null && (type.startsWith("image") || type.startsWith("video"))) {
                sharedUris = new ArrayList<Uri>();
                sharedUris.add((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
            } else {
                return;
            }
        }
        if (sharedUris != null) {
            for (Uri uri : sharedUris) {
                addMedia(uri);
            }
        }
    }
}
Also used : LegacyEditorFragment(org.wordpress.android.editor.LegacyEditorFragment) Intent(android.content.Intent) Uri(android.net.Uri)

Aggregations

Intent (android.content.Intent)1 Uri (android.net.Uri)1 LegacyEditorFragment (org.wordpress.android.editor.LegacyEditorFragment)1