Example usage for android.content ClipDescription MIMETYPE_TEXT_HTML

List of usage examples for android.content ClipDescription MIMETYPE_TEXT_HTML

Introduction

In this page you can find the example usage for android.content ClipDescription MIMETYPE_TEXT_HTML.

Prototype

String MIMETYPE_TEXT_HTML

To view the source code for android.content ClipDescription MIMETYPE_TEXT_HTML.

Click Source Link

Document

The MIME type for a clip holding HTML text.

Usage

From source file:im.vector.util.VectorRoomMediasSender.java

/**
 * Send a list of images from their URIs
 *///from   ww  w . j  a  v  a  2 s  .com
private void sendMedias() {
    // sanity checks
    if ((null == mVectorRoomActivity) || (null == mVectorMessageListFragment) || (null == mMediasCache)) {
        Log.d(LOG_TAG, "sendMedias : null parameters");
        return;
    }

    // detect end of messages sending
    if ((null == mSharedDataItems) || (0 == mSharedDataItems.size())) {
        Log.d(LOG_TAG, "sendMedias : done");
        mImageCompressionDescription = null;
        mSharedDataItems = null;

        mVectorRoomActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mVectorMessageListFragment.scrollToBottom();
                mVectorRoomActivity.cancelSelectionMode();
                mVectorRoomActivity.setProgressVisibility(View.GONE);
            }
        });

        return;
    }

    // display a spinner
    mVectorRoomActivity.cancelSelectionMode();
    mVectorRoomActivity.setProgressVisibility(View.VISIBLE);

    Log.d(LOG_TAG, "sendMedias : " + mSharedDataItems.size() + " items to send");

    mMediasSendingHandler.post(new Runnable() {
        @Override
        public void run() {
            SharedDataItem sharedDataItem = mSharedDataItems.get(0);
            String mimeType = sharedDataItem.getMimeType(mVectorRoomActivity);

            // avoid null case
            if (null == mimeType) {
                mimeType = "";
            }

            if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_INTENT, mimeType)) {
                Log.d(LOG_TAG, "sendMedias :  unsupported mime type");
                // don't know how to manage it -> skip it
                // GA issue
                if (mSharedDataItems.size() > 0) {
                    mSharedDataItems.remove(0);
                }
                sendMedias();
            } else if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_PLAIN, mimeType)
                    || TextUtils.equals(ClipDescription.MIMETYPE_TEXT_HTML, mimeType)) {
                sendTextMessage(sharedDataItem);
            } else {
                // check if it is an uri
                // else we don't know what to do
                if (null == sharedDataItem.getUri()) {
                    Log.e(LOG_TAG, "sendMedias : null uri");
                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();
                    return;
                }

                final String fFilename = sharedDataItem.getFileName(mVectorRoomActivity);
                ResourceUtils.Resource resource = ResourceUtils.openResource(mVectorRoomActivity,
                        sharedDataItem.getUri(), sharedDataItem.getMimeType(mVectorRoomActivity));

                if (null == resource) {
                    Log.e(LOG_TAG, "sendMedias : " + fFilename + " is not found");

                    mVectorRoomActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mVectorRoomActivity,
                                    mVectorRoomActivity.getString(R.string.room_message_file_not_found),
                                    Toast.LENGTH_LONG).show();
                        }
                    });

                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();

                    return;
                }

                if (mimeType.startsWith("image/")) {
                    sendImageMessage(sharedDataItem, resource);
                } else if (mimeType.startsWith("video/")) {
                    sendVideoMessage(sharedDataItem, resource);
                } else {
                    sendFileMessage(sharedDataItem, resource);
                }
            }
        }
    });
}

From source file:im.neon.util.VectorRoomMediasSender.java

/**
 * Send a list of images from their URIs
 */// ww  w . j  a  v  a 2  s  . c  o m
private void sendMedias() {
    // sanity checks
    if ((null == mVectorRoomActivity) || (null == mVectorMessageListFragment) || (null == mMediasCache)) {
        Log.d(LOG_TAG, "sendMedias : null parameters");
        return;
    }

    // detect end of messages sending
    if ((null == mSharedDataItems) || (0 == mSharedDataItems.size())) {
        Log.d(LOG_TAG, "sendMedias : done");
        mImageCompressionDescription = null;
        mSharedDataItems = null;

        mVectorRoomActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mVectorMessageListFragment.scrollToBottom();
                mVectorRoomActivity.cancelSelectionMode();
                mVectorRoomActivity.setProgressVisibility(View.GONE);
            }
        });

        return;
    }

    // display a spinner
    mVectorRoomActivity.cancelSelectionMode();
    mVectorRoomActivity.setProgressVisibility(View.VISIBLE);

    Log.d(LOG_TAG, "sendMedias : " + mSharedDataItems.size() + " items to send");

    mMediasSendingHandler.post(new Runnable() {
        @Override
        public void run() {
            SharedDataItem sharedDataItem = mSharedDataItems.get(0);
            String mimeType = sharedDataItem.getMimeType(mVectorRoomActivity);

            // avoid null case
            if (null == mimeType) {
                mimeType = "";
            }

            if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_INTENT, mimeType)) {
                Log.d(LOG_TAG, "sendMedias :  unsupported mime type");
                // don't know how to manage it -> skip it
                // GA issue
                if (mSharedDataItems.size() > 0) {
                    mSharedDataItems.remove(0);
                }
                sendMedias();
            } else if ((null == sharedDataItem.getUri())
                    && (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_PLAIN, mimeType)
                            || TextUtils.equals(ClipDescription.MIMETYPE_TEXT_HTML, mimeType))) {
                sendTextMessage(sharedDataItem);
            } else {
                // check if it is an uri
                // else we don't know what to do
                if (null == sharedDataItem.getUri()) {
                    Log.e(LOG_TAG, "sendMedias : null uri");
                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();
                    return;
                }

                final String fFilename = sharedDataItem.getFileName(mVectorRoomActivity);
                ResourceUtils.Resource resource = ResourceUtils.openResource(mVectorRoomActivity,
                        sharedDataItem.getUri(), sharedDataItem.getMimeType(mVectorRoomActivity));

                if (null == resource) {
                    Log.e(LOG_TAG, "sendMedias : " + fFilename + " is not found");

                    mVectorRoomActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mVectorRoomActivity,
                                    mVectorRoomActivity.getString(R.string.room_message_file_not_found),
                                    Toast.LENGTH_LONG).show();
                        }
                    });

                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();

                    return;
                }

                if (mimeType.startsWith("image/")) {
                    sendImageMessage(sharedDataItem, resource);
                } else if (mimeType.startsWith("video/")) {
                    sendVideoMessage(sharedDataItem, resource);
                } else {
                    sendFileMessage(sharedDataItem, resource);
                }
            }
        }
    });
}