made image file format configurable by Config.java

This commit is contained in:
Daniel Gultsch 2015-07-21 23:49:35 +02:00
parent f076b4b5c8
commit 456d4c8b23
3 changed files with 18 additions and 8 deletions

View file

@ -19,6 +19,10 @@ public final class Config {
public static final int AVATAR_SIZE = 192;
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;
public static final int IMAGE_SIZE = 1920;
public static final Bitmap.CompressFormat IMAGE_FORMAT = Bitmap.CompressFormat.WEBP;
public static final int IMAGE_QUALITY = 75;
public static final int MESSAGE_MERGE_WINDOW = 20;
public static final int PAGE_SIZE = 50;

View file

@ -1,7 +1,5 @@
package eu.siacs.conversations.generator;
import android.util.Log;
import net.java.otr4j.OtrException;
import net.java.otr4j.session.Session;
@ -10,8 +8,6 @@ import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;

View file

@ -184,8 +184,18 @@ public class FileBackend {
return this.copyImageToPrivateStorage(message, image, 0);
}
private DownloadableFile copyImageToPrivateStorage(Message message,
Uri image, int sampleSize) throws FileCopyException {
private DownloadableFile copyImageToPrivateStorage(Message message,Uri image, int sampleSize) throws FileCopyException {
switch(Config.IMAGE_FORMAT) {
case JPEG:
message.setRelativeFilePath(message.getUuid()+".jpg");
break;
case PNG:
message.setRelativeFilePath(message.getUuid()+".png");
break;
case WEBP:
message.setRelativeFilePath(message.getUuid()+".webp");
break;
}
DownloadableFile file = getFile(message);
file.getParentFile().mkdirs();
InputStream is = null;
@ -205,13 +215,13 @@ public class FileBackend {
if (originalBitmap == null) {
throw new FileCopyException(R.string.error_not_an_image_file);
}
Bitmap scaledBitmap = resize(originalBitmap, IMAGE_SIZE);
Bitmap scaledBitmap = resize(originalBitmap, Config.IMAGE_SIZE);
int rotation = getRotation(image);
if (rotation > 0) {
scaledBitmap = rotate(scaledBitmap, rotation);
}
boolean success = scaledBitmap.compress(Bitmap.CompressFormat.WEBP, 75, os);
boolean success = scaledBitmap.compress(Config.IMAGE_FORMAT, Config.IMAGE_QUALITY, os);
if (!success) {
throw new FileCopyException(R.string.error_compressing_image);
}