mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 22:45:18 +01:00
fix loading avatar. Now possible even from remote file
This commit is contained in:
parent
4d79111c96
commit
743e099a09
2 changed files with 20 additions and 22 deletions
|
@ -276,12 +276,8 @@ public class PhotoCropActivity extends BaseFragment {
|
||||||
@Override
|
@Override
|
||||||
public boolean onFragmentCreate() {
|
public boolean onFragmentCreate() {
|
||||||
super.onFragmentCreate();
|
super.onFragmentCreate();
|
||||||
String photoPath = getArguments().getString("photoPath");
|
imageToCrop = getArguments().getParcelable("bitmap");
|
||||||
if (photoPath == null) {
|
if (imageToCrop == null) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
File f = new File(photoPath);
|
|
||||||
if (!f.exists()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Point displaySize = new Point();
|
Point displaySize = new Point();
|
||||||
|
@ -292,10 +288,6 @@ public class PhotoCropActivity extends BaseFragment {
|
||||||
display.getSize(displaySize);
|
display.getSize(displaySize);
|
||||||
}
|
}
|
||||||
int size = Math.max(displaySize.x, displaySize.y);
|
int size = Math.max(displaySize.x, displaySize.y);
|
||||||
imageToCrop = FileLoader.loadBitmap(photoPath, size, size);
|
|
||||||
if (imageToCrop == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
drawable = new BitmapDrawable(imageToCrop);
|
drawable = new BitmapDrawable(imageToCrop);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,10 @@ package org.telegram.ui.Views;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
import org.telegram.TL.TLRPC;
|
import org.telegram.TL.TLRPC;
|
||||||
|
@ -25,9 +27,10 @@ import org.telegram.ui.ApplicationActivity;
|
||||||
import org.telegram.ui.PhotoCropActivity;
|
import org.telegram.ui.PhotoCropActivity;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
|
||||||
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoCropActivityDelegate {
|
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoCropActivityDelegate {
|
||||||
public String currentPicturePath;
|
public Uri currentPicture;
|
||||||
private TLRPC.PhotoSize smallPhoto;
|
private TLRPC.PhotoSize smallPhoto;
|
||||||
private TLRPC.PhotoSize bigPhoto;
|
private TLRPC.PhotoSize bigPhoto;
|
||||||
public String uploadingAvatar = null;
|
public String uploadingAvatar = null;
|
||||||
|
@ -57,8 +60,8 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
File image = Utilities.generatePicturePath();
|
File image = Utilities.generatePicturePath();
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
|
currentPicture = Uri.fromFile(image);
|
||||||
currentPicturePath = image.getAbsolutePath();
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, currentPicture);
|
||||||
}
|
}
|
||||||
if (parentFragment != null) {
|
if (parentFragment != null) {
|
||||||
parentFragment.startActivityForResult(takePictureIntent, 0);
|
parentFragment.startActivityForResult(takePictureIntent, 0);
|
||||||
|
@ -84,9 +87,13 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startCrop(String path) {
|
private void startCrop(Uri uri) {
|
||||||
try {
|
try {
|
||||||
|
ParcelFileDescriptor parcelFileDescriptor = null;
|
||||||
if (parentFragment != null) {
|
if (parentFragment != null) {
|
||||||
|
parcelFileDescriptor = parentFragment.parentActivity.getContentResolver().openFileDescriptor(uri, "r");
|
||||||
|
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
|
||||||
|
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
|
||||||
ApplicationActivity activity = (ApplicationActivity)parentFragment.parentActivity;
|
ApplicationActivity activity = (ApplicationActivity)parentFragment.parentActivity;
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
activity = (ApplicationActivity)parentFragment.getActivity();
|
activity = (ApplicationActivity)parentFragment.getActivity();
|
||||||
|
@ -95,14 +102,14 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bundle params = new Bundle();
|
Bundle params = new Bundle();
|
||||||
params.putString("photoPath", path);
|
params.putParcelable("bitmap", image);
|
||||||
PhotoCropActivity photoCropActivity = new PhotoCropActivity();
|
PhotoCropActivity photoCropActivity = new PhotoCropActivity();
|
||||||
photoCropActivity.delegate = this;
|
photoCropActivity.delegate = this;
|
||||||
photoCropActivity.setArguments(params);
|
photoCropActivity.setArguments(params);
|
||||||
activity.presentFragment(photoCropActivity, "crop", false);
|
activity.presentFragment(photoCropActivity, "crop", false);
|
||||||
} else {
|
} else {
|
||||||
Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
||||||
cropIntent.setDataAndType(Uri.fromFile(new File(path)), "image/*");
|
cropIntent.setDataAndType(uri, "image/*");
|
||||||
cropIntent.putExtra("crop", "true");
|
cropIntent.putExtra("crop", "true");
|
||||||
cropIntent.putExtra("aspectX", 1);
|
cropIntent.putExtra("aspectX", 1);
|
||||||
cropIntent.putExtra("aspectY", 1);
|
cropIntent.putExtra("aspectY", 1);
|
||||||
|
@ -121,7 +128,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
Bitmap bitmap = FileLoader.loadBitmap(path, 800, 800);
|
Bitmap bitmap = FileLoader.loadBitmap("", 800, 800);
|
||||||
processBitmap(bitmap);
|
processBitmap(bitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,10 +136,10 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
if (requestCode == 0) {
|
if (requestCode == 0) {
|
||||||
Utilities.addMediaToGallery(currentPicturePath);
|
Utilities.addMediaToGallery(currentPicture);
|
||||||
startCrop(currentPicturePath);
|
startCrop(currentPicture);
|
||||||
|
|
||||||
currentPicturePath = null;
|
currentPicture = null;
|
||||||
} else if (requestCode == 1) {
|
} else if (requestCode == 1) {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -140,8 +147,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||||
try {
|
try {
|
||||||
Uri imageUri = data.getData();
|
Uri imageUri = data.getData();
|
||||||
if (imageUri != null) {
|
if (imageUri != null) {
|
||||||
String imageFilePath = Utilities.getPath(imageUri);
|
startCrop(imageUri);
|
||||||
startCrop(imageFilePath);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
|
Loading…
Reference in a new issue