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);
}
}
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();
}
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);
}
}
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);
}
Aggregations