aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/Config.java2
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java8
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java26
-rw-r--r--src/main/res/values/arrays.xml12
-rw-r--r--src/main/res/values/strings.xml3
-rw-r--r--src/main/res/xml/preferences.xml8
6 files changed, 49 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java
index 1b8290970..3bd5171ae 100644
--- a/src/main/java/de/pixart/messenger/Config.java
+++ b/src/main/java/de/pixart/messenger/Config.java
@@ -72,10 +72,8 @@ public final class Config {
public static final int AVATAR_SIZE = 480;
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.JPEG;
- public static final int IMAGE_SIZE = 3840;
public static final Bitmap.CompressFormat IMAGE_FORMAT = Bitmap.CompressFormat.JPEG;
public static final int IMAGE_QUALITY = 75;
- public static final int IMAGE_MAX_SIZE = 1 * 1024 * 1024; // 1 MiB
public static final int DEFAULT_ZOOM = 15; //for locations
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 7f367f2b7..01a4070f1 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -249,7 +249,7 @@ public class FileBackend {
}
File file = new File(path);
long size = file.length();
- if (size == 0 || size >= Config.IMAGE_MAX_SIZE) {
+ if (size == 0 || size >= mXmppConnectionService.getCompressImageSizePreference()) {
return false;
}
BitmapFactory.Options options = new BitmapFactory.Options();
@@ -259,7 +259,7 @@ public class FileBackend {
if (options == null || options.outMimeType == null || options.outHeight <= 0 || options.outWidth <= 0) {
return false;
}
- return (options.outWidth <= Config.IMAGE_SIZE && options.outHeight <= Config.IMAGE_SIZE && options.outMimeType.contains(Config.IMAGE_FORMAT.name().toLowerCase()));
+ return (options.outWidth <= mXmppConnectionService.getCompressImageResolutionPreference() && options.outHeight <= mXmppConnectionService.getCompressImageResolutionPreference() && options.outMimeType.contains(Config.IMAGE_FORMAT.name().toLowerCase()));
} catch (FileNotFoundException e) {
return false;
}
@@ -370,7 +370,7 @@ public class FileBackend {
if (originalBitmap == null) {
throw new FileCopyException(R.string.error_not_an_image_file);
}
- Bitmap scaledBitmap = resize(originalBitmap, Config.IMAGE_SIZE);
+ Bitmap scaledBitmap = resize(originalBitmap, mXmppConnectionService.getCompressImageResolutionPreference());
int rotation = getRotation(image);
scaledBitmap = rotate(scaledBitmap, rotation);
boolean targetSizeReached = false;
@@ -382,7 +382,7 @@ public class FileBackend {
throw new FileCopyException(R.string.error_compressing_image);
}
os.flush();
- targetSizeReached = file.length() <= Config.IMAGE_MAX_SIZE || quality <= 50;
+ targetSizeReached = file.length() <= mXmppConnectionService.getCompressImageSizePreference() || quality <= 50;
quality -= 5;
}
scaledBitmap.recycle();
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 936a4591f..6cfef225b 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -888,6 +888,32 @@ public class XmppConnectionService extends Service {
return getPreferences().getString("picture_compression", "auto");
}
+ public int getCompressImageResolutionPreference() {
+ switch (getPreferences().getString("image_compression", "high")) {
+ case "low":
+ return 720;
+ case "mid":
+ return 1920;
+ case "high":
+ return 3840;
+ default:
+ return 3840;
+ }
+ }
+
+ public int getCompressImageSizePreference() {
+ switch (getPreferences().getString("image_compression", "high")) {
+ case "low":
+ return 209715; // 0.2 * 1024 * 1024 = 209715 (0.2 MiB)
+ case "mid":
+ return 524288; // 0.5 * 1024 * 1024 = 524288 (0.5 MiB)
+ case "high":
+ return 1048576; // 1 * 1024 * 1024 = 1048576 (1 MiB)
+ default:
+ return 1048576;
+ }
+ }
+
private int getCompressVideoResolutionPreference() {
switch (getPreferences().getString("video_compression", "high")) {
case "low":
diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml
index b61a512ae..fd19b9442 100644
--- a/src/main/res/values/arrays.xml
+++ b/src/main/res/values/arrays.xml
@@ -70,6 +70,18 @@
<item>@string/always</item>
</string-array>
+ <string-array name="image_compression_values">
+ <item>low</item>
+ <item>mid</item>
+ <item>high</item>
+ </string-array>
+
+ <string-array name="image_compression_entries">
+ <item>@string/image_low</item>
+ <item>@string/image_mid</item>
+ <item>@string/image_high</item>
+ </string-array>
+
<string-array name="video_compression_values">
<item>low</item>
<item>mid</item>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index d1e053943..a54257398 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -764,4 +764,7 @@
<string name="pref_use_tor">Connect via Tor</string>
<string name="pref_use_tor_summary">Tunnel all connections through the Tor network.</string>
<string name="pref_connection_options">Connection options</string>
+ <string name="image_low">low (720p)</string>
+ <string name="image_mid">middle (1920p)</string>
+ <string name="image_high">high (3840p)</string>
</resources>
diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml
index bf0ee8ac8..daddaf6fa 100644
--- a/src/main/res/xml/preferences.xml
+++ b/src/main/res/xml/preferences.xml
@@ -125,10 +125,10 @@
android:summary="@string/pref_accept_files_summary_mobileroaming"
android:title="@string/pref_accept_files_mobileroaming" />
<ListPreference
- android:defaultValue="auto"
- android:entries="@array/picture_compression_entries"
- android:entryValues="@array/picture_compression_values"
- android:key="picture_compression"
+ android:defaultValue="high"
+ android:entries="@array/image_compression_entries"
+ android:entryValues="@array/image_compression_values"
+ android:key="image_compression"
android:summary="@string/pref_picture_compression_summary"
android:title="@string/pref_picture_compression" />
<ListPreference