mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-01 22:10:49 +00:00
parent
85c6957b63
commit
3f6aae633e
@ -21,8 +21,8 @@ public abstract class MediaConstraints {
|
|||||||
public static MediaConstraints MMS_CONSTRAINTS = new MmsMediaConstraints();
|
public static MediaConstraints MMS_CONSTRAINTS = new MmsMediaConstraints();
|
||||||
public static MediaConstraints PUSH_CONSTRAINTS = new PushMediaConstraints();
|
public static MediaConstraints PUSH_CONSTRAINTS = new PushMediaConstraints();
|
||||||
|
|
||||||
public abstract int getImageMaxWidth();
|
public abstract int getImageMaxWidth(Context context);
|
||||||
public abstract int getImageMaxHeight();
|
public abstract int getImageMaxHeight(Context context);
|
||||||
public abstract int getImageMaxSize();
|
public abstract int getImageMaxSize();
|
||||||
|
|
||||||
public abstract int getVideoMaxSize();
|
public abstract int getVideoMaxSize();
|
||||||
@ -44,8 +44,8 @@ public abstract class MediaConstraints {
|
|||||||
public boolean isWithinBounds(Context context, MasterSecret masterSecret, Uri uri) throws IOException {
|
public boolean isWithinBounds(Context context, MasterSecret masterSecret, Uri uri) throws IOException {
|
||||||
InputStream is = PartAuthority.getPartStream(context, masterSecret, uri);
|
InputStream is = PartAuthority.getPartStream(context, masterSecret, uri);
|
||||||
Pair<Integer, Integer> dimensions = BitmapUtil.getDimensions(is);
|
Pair<Integer, Integer> dimensions = BitmapUtil.getDimensions(is);
|
||||||
return dimensions.first > 0 && dimensions.first <= getImageMaxWidth() &&
|
return dimensions.first > 0 && dimensions.first <= getImageMaxWidth(context) &&
|
||||||
dimensions.second > 0 && dimensions.second <= getImageMaxHeight();
|
dimensions.second > 0 && dimensions.second <= getImageMaxHeight(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canResize(PduPart part) {
|
public boolean canResize(PduPart part) {
|
||||||
@ -61,8 +61,8 @@ public abstract class MediaConstraints {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return BitmapUtil.createScaledBytes(context, masterSecret, part.getDataUri(),
|
return BitmapUtil.createScaledBytes(context, masterSecret, part.getDataUri(),
|
||||||
getImageMaxWidth(),
|
getImageMaxWidth(context),
|
||||||
getImageMaxHeight(),
|
getImageMaxHeight(context),
|
||||||
getImageMaxSize());
|
getImageMaxSize());
|
||||||
} catch (BitmapDecodingException bde) {
|
} catch (BitmapDecodingException bde) {
|
||||||
throw new IOException(bde);
|
throw new IOException(bde);
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
package org.thoughtcrime.securesms.mms;
|
package org.thoughtcrime.securesms.mms;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
public class MmsMediaConstraints extends MediaConstraints {
|
public class MmsMediaConstraints extends MediaConstraints {
|
||||||
private static final int MAX_IMAGE_DIMEN = 1024;
|
private static final int MAX_IMAGE_DIMEN_LOWMEM = 768;
|
||||||
public static final int MAX_MESSAGE_SIZE = 280 * 1024;
|
private static final int MAX_IMAGE_DIMEN = 1024;
|
||||||
|
public static final int MAX_MESSAGE_SIZE = 280 * 1024;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getImageMaxWidth() {
|
public int getImageMaxWidth(Context context) {
|
||||||
return MAX_IMAGE_DIMEN;
|
return Util.isLowMemory(context) ? MAX_IMAGE_DIMEN_LOWMEM : MAX_IMAGE_DIMEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getImageMaxHeight() {
|
public int getImageMaxHeight(Context context) {
|
||||||
return MAX_IMAGE_DIMEN;
|
return getImageMaxWidth(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
package org.thoughtcrime.securesms.mms;
|
package org.thoughtcrime.securesms.mms;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
public class PushMediaConstraints extends MediaConstraints {
|
public class PushMediaConstraints extends MediaConstraints {
|
||||||
private static final int MAX_IMAGE_DIMEN = 1280;
|
private static final int MAX_IMAGE_DIMEN_LOWMEM = 768;
|
||||||
private static final int KB = 1024;
|
private static final int MAX_IMAGE_DIMEN = 1280;
|
||||||
private static final int MB = 1024 * KB;
|
private static final int KB = 1024;
|
||||||
|
private static final int MB = 1024 * KB;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getImageMaxWidth() {
|
public int getImageMaxWidth(Context context) {
|
||||||
return MAX_IMAGE_DIMEN;
|
return Util.isLowMemory(context) ? MAX_IMAGE_DIMEN_LOWMEM : MAX_IMAGE_DIMEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getImageMaxHeight() {
|
public int getImageMaxHeight(Context context) {
|
||||||
return MAX_IMAGE_DIMEN;
|
return getImageMaxWidth(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,6 +18,7 @@ package org.thoughtcrime.securesms.util;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
@ -324,4 +325,12 @@ public class Util {
|
|||||||
public static int hashCode(@Nullable Object... objects) {
|
public static int hashCode(@Nullable Object... objects) {
|
||||||
return Arrays.hashCode(objects);
|
return Arrays.hashCode(objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(VERSION_CODES.KITKAT)
|
||||||
|
public static boolean isLowMemory(Context context) {
|
||||||
|
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
|
||||||
|
return (VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice()) ||
|
||||||
|
activityManager.getMemoryClass() <= 64;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user