mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Bitmap OOM and rotation fixes
// FREEBIE
This commit is contained in:
parent
bec5e45605
commit
348352cc71
@ -153,7 +153,16 @@ public class Exif {
|
|||||||
|
|
||||||
private static boolean read(InputStream is, byte[] buf, int length) {
|
private static boolean read(InputStream is, byte[] buf, int length) {
|
||||||
try {
|
try {
|
||||||
return is.read(buf, 0, length) == length;
|
int read;
|
||||||
|
int totalRead = 0;
|
||||||
|
while (totalRead != length) {
|
||||||
|
if ((read = is.read(buf, totalRead, length - totalRead)) < 0) {
|
||||||
|
Log.w(TAG, "stream EOF'd prematurely");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
totalRead += read;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.sms.OutgoingKeyExchangeMessage;
|
|||||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.jobqueue.JobParameters;
|
import org.whispersystems.jobqueue.JobParameters;
|
||||||
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
||||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||||
@ -99,7 +100,7 @@ public class ThumbnailGenerateJob extends MasterSecretJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap generateThumbnailForPart(MasterSecret masterSecret, PduPart part) {
|
private Bitmap generateThumbnailForPart(MasterSecret masterSecret, PduPart part) {
|
||||||
String contentType = new String(part.getContentType());
|
String contentType = Util.toIsoString(part.getContentType());
|
||||||
|
|
||||||
if (ContentType.isImageType(contentType)) return generateImageThumbnail(masterSecret, part);
|
if (ContentType.isImageType(contentType)) return generateImageThumbnail(masterSecret, part);
|
||||||
else return null;
|
else return null;
|
||||||
@ -109,7 +110,7 @@ public class ThumbnailGenerateJob extends MasterSecretJob {
|
|||||||
try {
|
try {
|
||||||
int maxSize = context.getResources().getDimensionPixelSize(R.dimen.thumbnail_max_size);
|
int maxSize = context.getResources().getDimensionPixelSize(R.dimen.thumbnail_max_size);
|
||||||
return BitmapUtil.createScaledBitmap(context, masterSecret, part.getDataUri(), maxSize, maxSize);
|
return BitmapUtil.createScaledBitmap(context, masterSecret, part.getDataUri(), maxSize, maxSize);
|
||||||
} catch (FileNotFoundException | BitmapDecodingException e) {
|
} catch (FileNotFoundException | BitmapDecodingException | OutOfMemoryError e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,15 @@ public class BitmapUtil {
|
|||||||
public static Bitmap createScaledBitmap(Context context, MasterSecret masterSecret, Uri uri, int maxWidth, int maxHeight)
|
public static Bitmap createScaledBitmap(Context context, MasterSecret masterSecret, Uri uri, int maxWidth, int maxHeight)
|
||||||
throws BitmapDecodingException, FileNotFoundException
|
throws BitmapDecodingException, FileNotFoundException
|
||||||
{
|
{
|
||||||
return createScaledBitmap(context, masterSecret, uri, maxWidth, maxHeight, false);
|
Bitmap bitmap;
|
||||||
|
try {
|
||||||
|
bitmap = createScaledBitmap(context, masterSecret, uri, maxWidth, maxHeight, false);
|
||||||
|
} catch(OutOfMemoryError oome) {
|
||||||
|
Log.w(TAG, "OutOfMemoryError when scaling precisely, doing rough scale to save memory instead");
|
||||||
|
bitmap = createScaledBitmap(context, masterSecret, uri, maxWidth, maxHeight, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap createScaledBitmap(Context context, MasterSecret masterSecret, Uri uri, int maxWidth, int maxHeight, boolean constrainedMemory)
|
private static Bitmap createScaledBitmap(Context context, MasterSecret masterSecret, Uri uri, int maxWidth, int maxHeight, boolean constrainedMemory)
|
||||||
|
Loading…
Reference in New Issue
Block a user