Search in sources :

Example 1 with UriImage

use of com.moez.QKSMS.common.google.UriImage in project qksms by moezbhatti.

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.moez.QKSMS.common.google.UriImage) MmsException(com.google.android.mms.MmsException)

Example 2 with UriImage

use of com.moez.QKSMS.common.google.UriImage in project qksms by moezbhatti.

the class MessageUtils method resizeImageAsync.

public static void resizeImageAsync(final Context context, final Uri imageUri, final Handler handler, final ResizeImageResultCallback cb, final boolean append) {
    // Show a progress toast if the resize hasn't finished
    // within one second.
    // Stash the runnable for showing it away so we can cancel
    // it later if the resize completes ahead of the deadline.
    final Runnable showProgress = new Runnable() {

        @Override
        public void run() {
            Toast.makeText(context, R.string.compressing, Toast.LENGTH_SHORT).show();
        }
    };
    // Schedule it for one second from now.
    handler.postDelayed(showProgress, 1000);
    new Thread(new Runnable() {

        @Override
        public void run() {
            final PduPart part;
            try {
                UriImage image = new UriImage(context, imageUri);
                int widthLimit = MmsConfig.getMaxImageWidth();
                int heightLimit = MmsConfig.getMaxImageHeight();
                // as little as possible.
                if (image.getHeight() > image.getWidth()) {
                    int temp = widthLimit;
                    widthLimit = heightLimit;
                    heightLimit = temp;
                }
                part = image.getResizedImageAsPart(widthLimit, heightLimit, MmsConfig.getMaxMessageSize() - MESSAGE_OVERHEAD);
            } finally {
                // Cancel pending show of the progress toast if necessary.
                handler.removeCallbacks(showProgress);
            }
            handler.post(new Runnable() {

                @Override
                public void run() {
                    cb.onResizeResult(part, append);
                }
            });
        }
    }, "MessageUtils.resizeImageAsync").start();
}
Also used : UriImage(com.moez.QKSMS.common.google.UriImage) PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 3 with UriImage

use of com.moez.QKSMS.common.google.UriImage in project qksms by moezbhatti.

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.moez.QKSMS.common.google.UriImage)

Example 4 with UriImage

use of com.moez.QKSMS.common.google.UriImage in project qksms by moezbhatti.

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.moez.QKSMS.common.google.UriImage) PduPersister(com.google.android.mms.pdu_alt.PduPersister) PduPart(com.google.android.mms.pdu_alt.PduPart) ExceedMessageSizeException(com.moez.QKSMS.ExceedMessageSizeException) Uri(android.net.Uri)

Aggregations

UriImage (com.moez.QKSMS.common.google.UriImage)4 PduPart (com.google.android.mms.pdu_alt.PduPart)2 Uri (android.net.Uri)1 MmsException (com.google.android.mms.MmsException)1 PduPersister (com.google.android.mms.pdu_alt.PduPersister)1 ExceedMessageSizeException (com.moez.QKSMS.ExceedMessageSizeException)1