parent
85c6957b63
commit
3f6aae633e
4 changed files with 38 additions and 19 deletions
|
@ -21,8 +21,8 @@ public abstract class MediaConstraints {
|
|||
public static MediaConstraints MMS_CONSTRAINTS = new MmsMediaConstraints();
|
||||
public static MediaConstraints PUSH_CONSTRAINTS = new PushMediaConstraints();
|
||||
|
||||
public abstract int getImageMaxWidth();
|
||||
public abstract int getImageMaxHeight();
|
||||
public abstract int getImageMaxWidth(Context context);
|
||||
public abstract int getImageMaxHeight(Context context);
|
||||
public abstract int getImageMaxSize();
|
||||
|
||||
public abstract int getVideoMaxSize();
|
||||
|
@ -44,8 +44,8 @@ public abstract class MediaConstraints {
|
|||
public boolean isWithinBounds(Context context, MasterSecret masterSecret, Uri uri) throws IOException {
|
||||
InputStream is = PartAuthority.getPartStream(context, masterSecret, uri);
|
||||
Pair<Integer, Integer> dimensions = BitmapUtil.getDimensions(is);
|
||||
return dimensions.first > 0 && dimensions.first <= getImageMaxWidth() &&
|
||||
dimensions.second > 0 && dimensions.second <= getImageMaxHeight();
|
||||
return dimensions.first > 0 && dimensions.first <= getImageMaxWidth(context) &&
|
||||
dimensions.second > 0 && dimensions.second <= getImageMaxHeight(context);
|
||||
}
|
||||
|
||||
public boolean canResize(PduPart part) {
|
||||
|
@ -61,8 +61,8 @@ public abstract class MediaConstraints {
|
|||
|
||||
try {
|
||||
return BitmapUtil.createScaledBytes(context, masterSecret, part.getDataUri(),
|
||||
getImageMaxWidth(),
|
||||
getImageMaxHeight(),
|
||||
getImageMaxWidth(context),
|
||||
getImageMaxHeight(context),
|
||||
getImageMaxSize());
|
||||
} catch (BitmapDecodingException bde) {
|
||||
throw new IOException(bde);
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class MmsMediaConstraints extends MediaConstraints {
|
||||
private static final int MAX_IMAGE_DIMEN = 1024;
|
||||
public static final int MAX_MESSAGE_SIZE = 280 * 1024;
|
||||
private static final int MAX_IMAGE_DIMEN_LOWMEM = 768;
|
||||
private static final int MAX_IMAGE_DIMEN = 1024;
|
||||
public static final int MAX_MESSAGE_SIZE = 280 * 1024;
|
||||
|
||||
@Override
|
||||
public int getImageMaxWidth() {
|
||||
return MAX_IMAGE_DIMEN;
|
||||
public int getImageMaxWidth(Context context) {
|
||||
return Util.isLowMemory(context) ? MAX_IMAGE_DIMEN_LOWMEM : MAX_IMAGE_DIMEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageMaxHeight() {
|
||||
return MAX_IMAGE_DIMEN;
|
||||
public int getImageMaxHeight(Context context) {
|
||||
return getImageMaxWidth(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class PushMediaConstraints extends MediaConstraints {
|
||||
private static final int MAX_IMAGE_DIMEN = 1280;
|
||||
private static final int KB = 1024;
|
||||
private static final int MB = 1024 * KB;
|
||||
private static final int MAX_IMAGE_DIMEN_LOWMEM = 768;
|
||||
private static final int MAX_IMAGE_DIMEN = 1280;
|
||||
private static final int KB = 1024;
|
||||
private static final int MB = 1024 * KB;
|
||||
|
||||
@Override
|
||||
public int getImageMaxWidth() {
|
||||
return MAX_IMAGE_DIMEN;
|
||||
public int getImageMaxWidth(Context context) {
|
||||
return Util.isLowMemory(context) ? MAX_IMAGE_DIMEN_LOWMEM : MAX_IMAGE_DIMEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageMaxHeight() {
|
||||
return MAX_IMAGE_DIMEN;
|
||||
public int getImageMaxHeight(Context context) {
|
||||
return getImageMaxWidth(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.thoughtcrime.securesms.util;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Typeface;
|
||||
|
@ -324,4 +325,12 @@ public class Util {
|
|||
public static int hashCode(@Nullable Object... 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…
Add table
Reference in a new issue