mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
rotate avatars
Conflicts: src/eu/siacs/conversations/persistance/FileBackend.java
This commit is contained in:
parent
d42ea45b1c
commit
c62937016b
@ -45,7 +45,8 @@ public class FileBackend {
|
||||
private Context context;
|
||||
private LruCache<String, Bitmap> thumbnailCache;
|
||||
|
||||
private SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS",Locale.US);
|
||||
private SimpleDateFormat imageDateFormat = new SimpleDateFormat(
|
||||
"yyyyMMdd_HHmmssSSS", Locale.US);
|
||||
|
||||
public FileBackend(Context context) {
|
||||
this.context = context;
|
||||
@ -92,7 +93,8 @@ public class FileBackend {
|
||||
|
||||
public JingleFile getJingleFile(Message message, boolean decrypted) {
|
||||
StringBuilder filename = new StringBuilder();
|
||||
filename.append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
|
||||
filename.append(Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_PICTURES).getAbsolutePath());
|
||||
filename.append("/Conversations/");
|
||||
filename.append(message.getUuid());
|
||||
if ((decrypted) || (message.getEncryption() == Message.ENCRYPTION_NONE)) {
|
||||
@ -144,7 +146,8 @@ public class FileBackend {
|
||||
private JingleFile copyImageToPrivateStorage(Message message, Uri image,
|
||||
int sampleSize) throws ImageCopyException {
|
||||
try {
|
||||
InputStream is = context.getContentResolver().openInputStream(image);
|
||||
InputStream is = context.getContentResolver()
|
||||
.openInputStream(image);
|
||||
JingleFile file = getJingleFile(message);
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
@ -197,14 +200,20 @@ public class FileBackend {
|
||||
|
||||
private int getRotation(Uri image) {
|
||||
if ("content".equals(image.getScheme())) {
|
||||
Cursor cursor = context.getContentResolver().query(image,
|
||||
new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
|
||||
|
||||
try {
|
||||
Cursor cursor = context
|
||||
.getContentResolver()
|
||||
.query(image,
|
||||
new String[] { MediaStore.Images.ImageColumns.ORIENTATION },
|
||||
null, null, null);
|
||||
if (cursor.getCount() != 1) {
|
||||
return -1;
|
||||
}
|
||||
cursor.moveToFirst();
|
||||
return cursor.getInt(0);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ExifInterface exif;
|
||||
try {
|
||||
@ -273,11 +282,13 @@ public class FileBackend {
|
||||
|
||||
public Uri getTakePhotoUri() {
|
||||
StringBuilder pathBuilder = new StringBuilder();
|
||||
pathBuilder.append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
|
||||
pathBuilder.append(Environment
|
||||
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
|
||||
pathBuilder.append('/');
|
||||
pathBuilder.append("Camera");
|
||||
pathBuilder.append('/');
|
||||
pathBuilder.append("IMG_"+this.imageDateFormat.format(new Date())+".jpg");
|
||||
pathBuilder.append("IMG_" + this.imageDateFormat.format(new Date())
|
||||
+ ".jpg");
|
||||
Uri uri = Uri.parse("file://" + pathBuilder.toString());
|
||||
File file = new File(uri.toString());
|
||||
file.getParentFile().mkdirs();
|
||||
@ -292,9 +303,11 @@ public class FileBackend {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream mByteArrayOutputStream = new ByteArrayOutputStream();
|
||||
Base64OutputStream mBase64OutputSttream = new Base64OutputStream(mByteArrayOutputStream, Base64.DEFAULT);
|
||||
Base64OutputStream mBase64OutputSttream = new Base64OutputStream(
|
||||
mByteArrayOutputStream, Base64.DEFAULT);
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||
DigestOutputStream mDigestOutputStream = new DigestOutputStream(mBase64OutputSttream, digest);
|
||||
DigestOutputStream mDigestOutputStream = new DigestOutputStream(
|
||||
mBase64OutputSttream, digest);
|
||||
if (!bm.compress(format, 75, mDigestOutputStream)) {
|
||||
return null;
|
||||
}
|
||||
@ -327,7 +340,8 @@ public class FileBackend {
|
||||
FileOutputStream mFileOutputStream = new FileOutputStream(file);
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||
digest.reset();
|
||||
DigestOutputStream mDigestOutputStream = new DigestOutputStream(mFileOutputStream, digest);
|
||||
DigestOutputStream mDigestOutputStream = new DigestOutputStream(
|
||||
mFileOutputStream, digest);
|
||||
mDigestOutputStream.write(avatar.getImageAsBytes());
|
||||
mDigestOutputStream.flush();
|
||||
mDigestOutputStream.close();
|
||||
@ -364,6 +378,10 @@ public class FileBackend {
|
||||
if (input == null) {
|
||||
return null;
|
||||
} else {
|
||||
int rotation = getRotation(image);
|
||||
if (rotation > 0) {
|
||||
input = rotate(input, rotation);
|
||||
}
|
||||
return cropCenterSquare(input, size);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
@ -381,8 +399,7 @@ public class FileBackend {
|
||||
float outHeight = scale * h;
|
||||
float left = (size - outWidth) / 2;
|
||||
float top = (size - outHeight) / 2;
|
||||
RectF target = new RectF(left, top, left + outWidth, top
|
||||
+ outHeight);
|
||||
RectF target = new RectF(left, top, left + outWidth, top + outHeight);
|
||||
|
||||
Bitmap output = Bitmap.createBitmap(size, size, input.getConfig());
|
||||
Canvas canvas = new Canvas(output);
|
||||
@ -436,7 +453,8 @@ public class FileBackend {
|
||||
}
|
||||
|
||||
public static Bitmap getAvatar(String avatar, int size, Context context) {
|
||||
Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar));
|
||||
Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context,
|
||||
avatar));
|
||||
if (bm == null) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user