made image file format configurable by Config.java
This commit is contained in:
parent
f076b4b5c8
commit
456d4c8b23
|
@ -19,6 +19,10 @@ public final class Config {
|
||||||
public static final int AVATAR_SIZE = 192;
|
public static final int AVATAR_SIZE = 192;
|
||||||
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;
|
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 MESSAGE_MERGE_WINDOW = 20;
|
||||||
|
|
||||||
public static final int PAGE_SIZE = 50;
|
public static final int PAGE_SIZE = 50;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package eu.siacs.conversations.generator;
|
package eu.siacs.conversations.generator;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import net.java.otr4j.OtrException;
|
import net.java.otr4j.OtrException;
|
||||||
import net.java.otr4j.session.Session;
|
import net.java.otr4j.session.Session;
|
||||||
|
|
||||||
|
@ -10,8 +8,6 @@ import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
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.crypto.axolotl.XmppAxolotlMessage;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
|
|
@ -184,8 +184,18 @@ public class FileBackend {
|
||||||
return this.copyImageToPrivateStorage(message, image, 0);
|
return this.copyImageToPrivateStorage(message, image, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DownloadableFile copyImageToPrivateStorage(Message message,
|
private DownloadableFile copyImageToPrivateStorage(Message message,Uri image, int sampleSize) throws FileCopyException {
|
||||||
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);
|
DownloadableFile file = getFile(message);
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
@ -205,13 +215,13 @@ public class FileBackend {
|
||||||
if (originalBitmap == null) {
|
if (originalBitmap == null) {
|
||||||
throw new FileCopyException(R.string.error_not_an_image_file);
|
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);
|
int rotation = getRotation(image);
|
||||||
if (rotation > 0) {
|
if (rotation > 0) {
|
||||||
scaledBitmap = rotate(scaledBitmap, rotation);
|
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) {
|
if (!success) {
|
||||||
throw new FileCopyException(R.string.error_compressing_image);
|
throw new FileCopyException(R.string.error_compressing_image);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue