Fix issue #296
This commit is contained in:
parent
c16cae9924
commit
e00e2d2d19
|
@ -114,7 +114,7 @@ dependencies {
|
||||||
|
|
||||||
implementation 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0'
|
implementation 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0'
|
||||||
implementation 'yogesh.firzen:MukkiyaSevaigal:1.0.6'
|
implementation 'yogesh.firzen:MukkiyaSevaigal:1.0.6'
|
||||||
|
implementation 'id.zelory:compressor:2.1.0'
|
||||||
implementation "ch.acra:acra-mail:$acraVersion"
|
implementation "ch.acra:acra-mail:$acraVersion"
|
||||||
implementation "ch.acra:acra-limiter:$acraVersion"
|
implementation "ch.acra:acra-limiter:$acraVersion"
|
||||||
implementation "ch.acra:acra-notification:$acraVersion"
|
implementation "ch.acra:acra-notification:$acraVersion"
|
||||||
|
|
|
@ -544,7 +544,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
header_picture = Helper.compressImage(EditProfileActivity.this, fileUri, Helper.MediaType.MEDIA);
|
header_picture = Helper.compressImage(EditProfileActivity.this, fileUri);
|
||||||
} else if (requestCode == PICK_IMAGE_PROFILE && resultCode == RESULT_OK) {
|
} else if (requestCode == PICK_IMAGE_PROFILE && resultCode == RESULT_OK) {
|
||||||
if (data == null || data.getData() == null) {
|
if (data == null || data.getData() == null) {
|
||||||
Toasty.error(getApplicationContext(), getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
Toasty.error(getApplicationContext(), getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
||||||
|
@ -562,7 +562,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
profile_picture = Helper.compressImage(EditProfileActivity.this, fileUri, Helper.MediaType.PROFILE);
|
profile_picture = Helper.compressImage(EditProfileActivity.this, fileUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1490,7 +1490,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
||||||
if (error) {
|
if (error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bs = Helper.compressImage(activityWeakReference.get(), uriFile, Helper.MediaType.MEDIA);
|
bs = Helper.compressImage(activityWeakReference.get(), uriFile);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1809,32 +1809,21 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
||||||
});
|
});
|
||||||
|
|
||||||
//Resize
|
//Resize
|
||||||
final Spinner resize_layout_spinner = rootView.findViewById(R.id.set_resize_picture);
|
final CheckBox set_resize_picture = rootView.findViewById(R.id.set_resize_picture);
|
||||||
ArrayAdapter<CharSequence> adapterResize = ArrayAdapter.createFromResource(getContext(),
|
boolean compress = sharedpreferences.getBoolean(Helper.SET_PICTURE_COMPRESSED, true);
|
||||||
R.array.settings_resize_picture, android.R.layout.simple_spinner_item);
|
set_resize_picture.setChecked(compress);
|
||||||
resize_layout_spinner.setAdapter(adapterResize);
|
set_resize_picture.setOnClickListener(new View.OnClickListener() {
|
||||||
int positionSpinnerResize = sharedpreferences.getInt(Helper.SET_PICTURE_RESIZE, Helper.S_4MO);
|
|
||||||
resize_layout_spinner.setSelection(positionSpinnerResize);
|
|
||||||
resize_layout_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onClick(View v) {
|
||||||
if (count4 > 0) {
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
editor.putBoolean(Helper.SET_PICTURE_COMPRESSED, set_resize_picture.isChecked());
|
||||||
editor.putInt(Helper.SET_PICTURE_RESIZE, position);
|
editor.apply();
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
count4++;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
||||||
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
||||||
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||||
|
|
|
@ -221,6 +221,7 @@ import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
||||||
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
||||||
import app.fedilab.android.sqlite.AccountDAO;
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
import id.zelory.compressor.Compressor;
|
||||||
import info.guardianproject.netcipher.client.StrongBuilder;
|
import info.guardianproject.netcipher.client.StrongBuilder;
|
||||||
import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder;
|
import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder;
|
||||||
import okhttp3.ConnectionSpec;
|
import okhttp3.ConnectionSpec;
|
||||||
|
@ -349,7 +350,7 @@ public class Helper {
|
||||||
public static final String SET_DISABLE_ANIMATED_EMOJI = "set_disable_animated_emoji";
|
public static final String SET_DISABLE_ANIMATED_EMOJI = "set_disable_animated_emoji";
|
||||||
public static final String SET_CAPITALIZE = "set_capitalize";
|
public static final String SET_CAPITALIZE = "set_capitalize";
|
||||||
public static final String SET_WYSIWYG = "set_wysiwyg";
|
public static final String SET_WYSIWYG = "set_wysiwyg";
|
||||||
public static final String SET_PICTURE_RESIZE = "set_picture_resize";
|
public static final String SET_PICTURE_COMPRESSED = "set_picture_compressed";
|
||||||
public static final String SET_FORWARD_TAGS_IN_REPLY = "set_forward_tags_in_reply";
|
public static final String SET_FORWARD_TAGS_IN_REPLY = "set_forward_tags_in_reply";
|
||||||
public static final String SET_FULL_PREVIEW = "set_full_preview";
|
public static final String SET_FULL_PREVIEW = "set_full_preview";
|
||||||
public static final String SET_COMPACT_MODE = "set_compact_mode";
|
public static final String SET_COMPACT_MODE = "set_compact_mode";
|
||||||
|
@ -383,13 +384,6 @@ public class Helper {
|
||||||
public static final String SET_AUTO_BACKUP_STATUSES = "set_auto_backup_statuses";
|
public static final String SET_AUTO_BACKUP_STATUSES = "set_auto_backup_statuses";
|
||||||
public static final String SET_AUTO_BACKUP_NOTIFICATIONS = "set_auto_backup_notifications";
|
public static final String SET_AUTO_BACKUP_NOTIFICATIONS = "set_auto_backup_notifications";
|
||||||
|
|
||||||
public static final int S_NO = 0;
|
|
||||||
static final int S_512KO = 1;
|
|
||||||
public static final int S_1MO = 2;
|
|
||||||
public static final int S_2MO = 3;
|
|
||||||
public static final int S_4MO = 4;
|
|
||||||
public static final int S_6MO = 5;
|
|
||||||
public static final int S_8MO = 6;
|
|
||||||
|
|
||||||
public static final int ATTACHMENT_ALWAYS = 1;
|
public static final int ATTACHMENT_ALWAYS = 1;
|
||||||
public static final int ATTACHMENT_WIFI = 2;
|
public static final int ATTACHMENT_WIFI = 2;
|
||||||
|
@ -3420,23 +3414,14 @@ public class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ByteArrayInputStream compressImage(Context context, android.net.Uri uriFile, MediaType mediaType) {
|
public static ByteArrayInputStream compressImage(Context context, android.net.Uri uriFile) {
|
||||||
|
|
||||||
ContentResolver cr = context.getContentResolver();
|
ContentResolver cr = context.getContentResolver();
|
||||||
String mime = cr.getType(uriFile);
|
String mime = cr.getType(uriFile);
|
||||||
|
File file = new File(uriFile.getPath());
|
||||||
ByteArrayInputStream bs = null;
|
ByteArrayInputStream bs = null;
|
||||||
if (mime != null && mime.toLowerCase().contains("image")) {
|
if (mime != null && mime.toLowerCase().contains("image")) {
|
||||||
Bitmap takenImage;
|
|
||||||
try {
|
|
||||||
takenImage = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uriFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
try {
|
|
||||||
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ExifInterface exif = null;
|
ExifInterface exif = null;
|
||||||
try (InputStream inputStream = context.getContentResolver().openInputStream(uriFile)) {
|
try (InputStream inputStream = context.getContentResolver().openInputStream(uriFile)) {
|
||||||
assert inputStream != null;
|
assert inputStream != null;
|
||||||
|
@ -3444,99 +3429,56 @@ public class Helper {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Matrix matrix = null;
|
|
||||||
if (takenImage != null) {
|
|
||||||
int size = takenImage.getByteCount();
|
|
||||||
if (exif != null) {
|
|
||||||
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
|
||||||
int rotationDegree = 0;
|
|
||||||
if (rotation == ExifInterface.ORIENTATION_ROTATE_90) {
|
|
||||||
rotationDegree = 90;
|
|
||||||
} else if (rotation == ExifInterface.ORIENTATION_ROTATE_180) {
|
|
||||||
rotationDegree = 180;
|
|
||||||
} else if (rotation == ExifInterface.ORIENTATION_ROTATE_270) {
|
|
||||||
rotationDegree = 270;
|
|
||||||
}
|
|
||||||
matrix = new Matrix();
|
|
||||||
if (rotation != 0f) {
|
|
||||||
matrix.preRotate(rotationDegree);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
Matrix matrix;
|
||||||
int resizeSet = sharedpreferences.getInt(Helper.SET_PICTURE_RESIZE, Helper.S_4MO);
|
if (exif != null) {
|
||||||
if (mediaType == MediaType.PROFILE)
|
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
||||||
resizeSet = Helper.S_1MO;
|
int rotationDegree = 0;
|
||||||
double resizeby = size;
|
if (rotation == ExifInterface.ORIENTATION_ROTATE_90) {
|
||||||
if (resizeSet == Helper.S_512KO) {
|
rotationDegree = 90;
|
||||||
resizeby = 4194304;
|
} else if (rotation == ExifInterface.ORIENTATION_ROTATE_180) {
|
||||||
} else if (resizeSet == Helper.S_1MO) {
|
rotationDegree = 180;
|
||||||
resizeby = 8388608;
|
} else if (rotation == ExifInterface.ORIENTATION_ROTATE_270) {
|
||||||
} else if (resizeSet == Helper.S_2MO) {
|
rotationDegree = 270;
|
||||||
resizeby = 16777216;
|
|
||||||
} else if (resizeSet == Helper.S_4MO) {
|
|
||||||
resizeby = 33554432;
|
|
||||||
} else if (resizeSet == Helper.S_6MO) {
|
|
||||||
resizeby = 50331648;
|
|
||||||
} else if (resizeSet == Helper.S_8MO) {
|
|
||||||
resizeby = 67108864;
|
|
||||||
}
|
}
|
||||||
|
matrix = new Matrix();
|
||||||
|
if (rotation != 0f) {
|
||||||
|
matrix.preRotate(rotationDegree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double resize = ((double) size) / resizeby;
|
InputStream resizedIS = null;
|
||||||
if (resize > 1) {
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||||
Bitmap newBitmap = Bitmap.createScaledBitmap(takenImage, (int) (takenImage.getWidth() / resize),
|
boolean compressed = sharedpreferences.getBoolean(Helper.SET_PICTURE_COMPRESSED, true);
|
||||||
(int) (takenImage.getHeight() / resize), true);
|
|
||||||
Bitmap adjustedBitmap;
|
if( compressed) {
|
||||||
if (matrix != null)
|
|
||||||
try {
|
|
||||||
adjustedBitmap = Bitmap.createBitmap(newBitmap, 0, 0, newBitmap.getWidth(), newBitmap.getHeight(), matrix, true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
adjustedBitmap = newBitmap;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
adjustedBitmap = newBitmap;
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
||||||
if (mime.contains("png") || mime.contains(".PNG"))
|
|
||||||
adjustedBitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
|
|
||||||
else
|
|
||||||
adjustedBitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
|
|
||||||
byte[] bitmapdata = bos.toByteArray();
|
|
||||||
bs = new ByteArrayInputStream(bitmapdata);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
InputStream inputStream = context.getContentResolver().openInputStream(uriFile);
|
|
||||||
byte[] buff = new byte[8 * 1024];
|
|
||||||
int bytesRead;
|
|
||||||
ByteArrayOutputStream bao = new ByteArrayOutputStream();
|
|
||||||
assert inputStream != null;
|
|
||||||
while ((bytesRead = inputStream.read(buff)) != -1) {
|
|
||||||
bao.write(buff, 0, bytesRead);
|
|
||||||
}
|
|
||||||
byte[] data = bao.toByteArray();
|
|
||||||
bs = new ByteArrayInputStream(data);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
InputStream inputStream = context.getContentResolver().openInputStream(uriFile);
|
File compressedFile= new Compressor(context).compressToFile(file);
|
||||||
byte[] buff = new byte[8 * 1024];
|
resizedIS = new FileInputStream(compressedFile.getAbsolutePath());
|
||||||
int bytesRead;
|
|
||||||
ByteArrayOutputStream bao = new ByteArrayOutputStream();
|
|
||||||
assert inputStream != null;
|
|
||||||
while ((bytesRead = inputStream.read(buff)) != -1) {
|
|
||||||
bao.write(buff, 0, bytesRead);
|
|
||||||
}
|
|
||||||
byte[] data = bao.toByteArray();
|
|
||||||
bs = new ByteArrayInputStream(data);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
try {
|
||||||
|
resizedIS = context.getContentResolver().openInputStream(uriFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
byte[] buff = new byte[8 * 1024];
|
||||||
|
int bytesRead;
|
||||||
|
ByteArrayOutputStream bao = new ByteArrayOutputStream();
|
||||||
|
assert resizedIS != null;
|
||||||
|
while ((bytesRead = resizedIS.read(buff)) != -1) {
|
||||||
|
bao.write(buff, 0, bytesRead);
|
||||||
|
}
|
||||||
|
byte[] data = bao.toByteArray();
|
||||||
|
bs = new ByteArrayInputStream(data);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1519,27 +1519,6 @@
|
||||||
android:layout_height="wrap_content"></SeekBar>
|
android:layout_height="wrap_content"></SeekBar>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Resize pictures -->
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/set_resize_picture" />
|
|
||||||
|
|
||||||
<Spinner
|
|
||||||
android:id="@+id/set_resize_picture"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Translation engine -->
|
<!-- Translation engine -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -1846,6 +1825,41 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||||
|
android:layout_marginBottom="@dimen/settings_checkbox_margin"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/set_resize_picture"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/set_resize_picture_text"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="@string/set_resize_picture"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:textColor="@color/mastodonC2"
|
||||||
|
android:text="@string/set_resize_picture_indication"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<!-- WYSIWYG -->
|
<!-- WYSIWYG -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/set_wysiwyg_container"
|
android:id="@+id/set_wysiwyg_container"
|
||||||
|
|
|
@ -1220,4 +1220,5 @@
|
||||||
<string name="no_live_indication">Notifications will be fetched every 15 minutes.</string>
|
<string name="no_live_indication">Notifications will be fetched every 15 minutes.</string>
|
||||||
<string name="action_add_notes">Add notes</string>
|
<string name="action_add_notes">Add notes</string>
|
||||||
<string name="note_for_account">Notes for the account</string>
|
<string name="note_for_account">Notes for the account</string>
|
||||||
|
<string name="set_resize_picture_indication">Allow to compress large photos into smaller sized photos with very less or negligible loss in quality of the image.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue