Search in sources :

Example 1 with UriImage

use of com.android.mms.ui.UriImage in project android-aosp-mms by slvn.

the class ImageModel method resizeMedia.

@Override
protected void resizeMedia(int byteLimit, long messageId) throws MmsException {
    UriImage image = new UriImage(mContext, getUri());
    int widthLimit = MmsConfig.getMaxImageWidth();
    int heightLimit = MmsConfig.getMaxImageHeight();
    int size = getMediaSize();
    // possible.
    if (image.getHeight() > image.getWidth()) {
        int temp = widthLimit;
        widthLimit = heightLimit;
        heightLimit = temp;
    }
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "resizeMedia size: " + size + " image.getWidth(): " + image.getWidth() + " widthLimit: " + widthLimit + " image.getHeight(): " + image.getHeight() + " heightLimit: " + heightLimit + " image.getContentType(): " + image.getContentType());
    }
    // set the size.
    if (size != 0 && size <= byteLimit && image.getWidth() <= widthLimit && image.getHeight() <= heightLimit && SUPPORTED_MMS_IMAGE_CONTENT_TYPES.contains(image.getContentType())) {
        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.v(TAG, "resizeMedia - already sized");
        }
        return;
    }
    PduPart part = image.getResizedImageAsPart(widthLimit, heightLimit, byteLimit);
    if (part == null) {
        throw new ExceedMessageSizeException("Not enough memory to turn image into part: " + getUri());
    }
    // Update the content type because it may have changed due to resizing/recompressing
    mContentType = new String(part.getContentType());
    String src = getSrc();
    byte[] srcBytes = src.getBytes();
    part.setContentLocation(srcBytes);
    int period = src.lastIndexOf(".");
    byte[] contentId = period != -1 ? src.substring(0, period).getBytes() : srcBytes;
    part.setContentId(contentId);
    PduPersister persister = PduPersister.getPduPersister(mContext);
    this.mSize = part.getData().length;
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "resizeMedia mSize: " + mSize);
    }
    Uri newUri = persister.persistPart(part, messageId, null);
    setUri(newUri);
}
Also used : UriImage(com.android.mms.ui.UriImage) PduPersister(com.google.android.mms.pdu.PduPersister) PduPart(com.google.android.mms.pdu.PduPart) ExceedMessageSizeException(com.android.mms.ExceedMessageSizeException) Uri(android.net.Uri)

Example 2 with UriImage

use of com.android.mms.ui.UriImage in project android-aosp-mms by slvn.

the class ImageModel method initModelFromUri.

private void initModelFromUri(Uri uri) throws MmsException {
    UriImage uriImage = new UriImage(mContext, uri);
    mContentType = uriImage.getContentType();
    if (TextUtils.isEmpty(mContentType)) {
        throw new MmsException("Type of media is unknown.");
    }
    mSrc = uriImage.getSrc();
    mWidth = uriImage.getWidth();
    mHeight = uriImage.getHeight();
    if (LOCAL_LOGV) {
        Log.v(TAG, "New ImageModel created:" + " mSrc=" + mSrc + " mContentType=" + mContentType + " mUri=" + uri);
    }
}
Also used : UriImage(com.android.mms.ui.UriImage) MmsException(com.google.android.mms.MmsException)

Example 3 with UriImage

use of com.android.mms.ui.UriImage in project android-aosp-mms by slvn.

the class ImageModel method decodeImageBounds.

private void decodeImageBounds(Uri uri) {
    UriImage uriImage = new UriImage(mContext, uri);
    mWidth = uriImage.getWidth();
    mHeight = uriImage.getHeight();
    if (LOCAL_LOGV) {
        Log.v(TAG, "Image bounds: " + mWidth + "x" + mHeight);
    }
}
Also used : UriImage(com.android.mms.ui.UriImage)

Aggregations

UriImage (com.android.mms.ui.UriImage)3 Uri (android.net.Uri)1 ExceedMessageSizeException (com.android.mms.ExceedMessageSizeException)1 MmsException (com.google.android.mms.MmsException)1 PduPart (com.google.android.mms.pdu.PduPart)1 PduPersister (com.google.android.mms.pdu.PduPersister)1