mirror of
https://github.com/pachli/pachli-android.git
synced 2025-02-09 00:18:56 +01:00
fix media resizing (#686)
* fix media resizing * move exception catching out of method
This commit is contained in:
parent
63f9d99390
commit
a42ce9b793
@ -85,7 +85,6 @@ import com.keylesspalace.tusky.adapter.EmojiAdapter;
|
|||||||
import com.keylesspalace.tusky.adapter.MentionAutoCompleteAdapter;
|
import com.keylesspalace.tusky.adapter.MentionAutoCompleteAdapter;
|
||||||
import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener;
|
import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener;
|
||||||
import com.keylesspalace.tusky.db.AccountEntity;
|
import com.keylesspalace.tusky.db.AccountEntity;
|
||||||
import com.keylesspalace.tusky.db.AccountManager;
|
|
||||||
import com.keylesspalace.tusky.db.AppDatabase;
|
import com.keylesspalace.tusky.db.AppDatabase;
|
||||||
import com.keylesspalace.tusky.db.InstanceEntity;
|
import com.keylesspalace.tusky.db.InstanceEntity;
|
||||||
import com.keylesspalace.tusky.di.Injectable;
|
import com.keylesspalace.tusky.di.Injectable;
|
||||||
@ -151,6 +150,7 @@ public final class ComposeActivity
|
|||||||
private static final String TAG = "ComposeActivity"; // logging tag
|
private static final String TAG = "ComposeActivity"; // logging tag
|
||||||
static final int STATUS_CHARACTER_LIMIT = 500;
|
static final int STATUS_CHARACTER_LIMIT = 500;
|
||||||
private static final int STATUS_MEDIA_SIZE_LIMIT = 8388608; // 8MiB
|
private static final int STATUS_MEDIA_SIZE_LIMIT = 8388608; // 8MiB
|
||||||
|
private static final int STATUS_MEDIA_PIXEL_SIZE_LIMIT = 16777216; // 4096^2 Pixels
|
||||||
private static final int MEDIA_PICK_RESULT = 1;
|
private static final int MEDIA_PICK_RESULT = 1;
|
||||||
private static final int MEDIA_TAKE_PHOTO_RESULT = 2;
|
private static final int MEDIA_TAKE_PHOTO_RESULT = 2;
|
||||||
private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
|
private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
|
||||||
@ -1063,11 +1063,17 @@ public final class ComposeActivity
|
|||||||
|
|
||||||
if (item.readyStage != QueuedMedia.ReadyStage.UPLOADED) {
|
if (item.readyStage != QueuedMedia.ReadyStage.UPLOADED) {
|
||||||
waitForMediaLatch.countUp();
|
waitForMediaLatch.countUp();
|
||||||
if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
|
|
||||||
|
try {
|
||||||
|
if (type == QueuedMedia.Type.IMAGE &&
|
||||||
|
(mediaSize > STATUS_MEDIA_SIZE_LIMIT || MediaUtils.getImageSquarePixels(getContentResolver(), item.uri) > STATUS_MEDIA_PIXEL_SIZE_LIMIT)) {
|
||||||
downsizeMedia(item);
|
downsizeMedia(item);
|
||||||
} else {
|
} else {
|
||||||
uploadMedia(item);
|
uploadMedia(item);
|
||||||
}
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
onUploadFailure(item, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,6 @@ public class DownsizeImageTask extends AsyncTask<Uri, Void, Boolean> {
|
|||||||
* test, and keep trying at smaller sizes. The initial estimate should be good for
|
* test, and keep trying at smaller sizes. The initial estimate should be good for
|
||||||
* many cases, so it should only iterate once, but the loop is used to be absolutely
|
* many cases, so it should only iterate once, but the loop is used to be absolutely
|
||||||
* sure it gets downsized to below the limit. */
|
* sure it gets downsized to below the limit. */
|
||||||
int iterations = 0;
|
|
||||||
int scaledImageSize = 1024;
|
int scaledImageSize = 1024;
|
||||||
do {
|
do {
|
||||||
stream.reset();
|
stream.reset();
|
||||||
@ -208,12 +207,11 @@ public class DownsizeImageTask extends AsyncTask<Uri, Void, Boolean> {
|
|||||||
} else {
|
} else {
|
||||||
format = Bitmap.CompressFormat.PNG;
|
format = Bitmap.CompressFormat.PNG;
|
||||||
}
|
}
|
||||||
reorientedBitmap.compress(format, 75, stream);
|
reorientedBitmap.compress(format, 85, stream);
|
||||||
reorientedBitmap.recycle();
|
reorientedBitmap.recycle();
|
||||||
scaledImageSize /= 2;
|
scaledImageSize /= 2;
|
||||||
iterations++;
|
|
||||||
} while (stream.size() > sizeLimit);
|
} while (stream.size() > sizeLimit);
|
||||||
Assert.expect(iterations < 3);
|
|
||||||
resultList.add(stream.toByteArray());
|
resultList.add(stream.toByteArray());
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -126,4 +126,17 @@ public class MediaUtils {
|
|||||||
source.recycle();
|
source.recycle();
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getImageSquarePixels(ContentResolver contentResolver, Uri uri) throws FileNotFoundException {
|
||||||
|
InputStream input;
|
||||||
|
input = contentResolver.openInputStream(uri);
|
||||||
|
|
||||||
|
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
|
options.inJustDecodeBounds = true;
|
||||||
|
BitmapFactory.decodeStream(input, null, options);
|
||||||
|
|
||||||
|
IOUtils.closeQuietly(input);
|
||||||
|
|
||||||
|
return (long) options.outWidth * options.outHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user