don't automatically crop avatar
This commit is contained in:
parent
89eea3636f
commit
aa24a0f779
|
@ -7,6 +7,8 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
|
@ -27,13 +29,12 @@ import eu.siacs.conversations.persistance.FileBackend;
|
|||
import eu.siacs.conversations.utils.ExifHelper;
|
||||
import eu.siacs.conversations.utils.FileUtils;
|
||||
import eu.siacs.conversations.utils.PhoneHelper;
|
||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||
import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||
|
||||
public class PublishProfilePictureActivity extends XmppActivity {
|
||||
|
||||
private static final int REQUEST_CHOOSE_FILE = 0xac23;
|
||||
private static final int REQUEST_CHOOSE_FILE_AND_CROP = 0xac23;
|
||||
private static final int REQUEST_CHOOSE_FILE = 0xac24;
|
||||
private ImageView avatar;
|
||||
private TextView accountTextView;
|
||||
private TextView hintOrWarning;
|
||||
|
@ -138,7 +139,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (hasStoragePermission(REQUEST_CHOOSE_FILE)) {
|
||||
chooseAvatar();
|
||||
chooseAvatar(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,32 +147,52 @@ public class PublishProfilePictureActivity extends XmppActivity {
|
|||
this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext());
|
||||
}
|
||||
|
||||
private void chooseAvatar() {
|
||||
private void chooseAvatar(boolean crop) {
|
||||
Intent attachFileIntent = new Intent();
|
||||
attachFileIntent.setType("image/*");
|
||||
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
|
||||
startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
|
||||
startActivityForResult(chooser, crop ? REQUEST_CHOOSE_FILE_AND_CROP : REQUEST_CHOOSE_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
if (grantResults.length > 0)
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
if (requestCode == REQUEST_CHOOSE_FILE) {
|
||||
chooseAvatar();
|
||||
if (requestCode == REQUEST_CHOOSE_FILE_AND_CROP) {
|
||||
chooseAvatar(true);
|
||||
} else if (requestCode == REQUEST_CHOOSE_FILE) {
|
||||
chooseAvatar(false);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.publish_avatar, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_crop_image) {
|
||||
if (hasStoragePermission(REQUEST_CHOOSE_FILE_AND_CROP)) {
|
||||
chooseAvatar(true);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CHOOSE_FILE:
|
||||
case REQUEST_CHOOSE_FILE_AND_CROP:
|
||||
Uri source = data.getData();
|
||||
String original = FileUtils.getPath(this, source);
|
||||
if (original != null) {
|
||||
|
@ -181,9 +202,17 @@ public class PublishProfilePictureActivity extends XmppActivity {
|
|||
final int size = getPixel(192);
|
||||
Crop.of(source, destination).asSquare().withMaxSize(size, size).start(this);
|
||||
break;
|
||||
case REQUEST_CHOOSE_FILE:
|
||||
this.avatarUri = data.getData();
|
||||
if (xmppConnectionServiceBound) {
|
||||
loadImageIntoPreview(this.avatarUri);
|
||||
}
|
||||
break;
|
||||
case Crop.REQUEST_CROP:
|
||||
this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
|
||||
if (xmppConnectionServiceBound) {
|
||||
loadImageIntoPreview(this.avatarUri);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -248,21 +277,10 @@ public class PublishProfilePictureActivity extends XmppActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private Bitmap loadScaledBitmap(Uri uri, int reqSize) throws FileNotFoundException {
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
|
||||
int rotation = ExifHelper.getOrientation(getContentResolver().openInputStream(uri));
|
||||
options.inSampleSize = FileBackend.calcSampleSize(options, reqSize);
|
||||
options.inJustDecodeBounds = false;
|
||||
Bitmap bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
|
||||
return FileBackend.rotate(bm,rotation);
|
||||
}
|
||||
|
||||
protected void loadImageIntoPreview(Uri uri) {
|
||||
Bitmap bm = null;
|
||||
try {
|
||||
bm = loadScaledBitmap(uri, getPixel(192));
|
||||
bm = xmppConnectionService.getFileBackend().cropCenterSquare(uri, getPixel(192));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
BIN
src/main/res/drawable-hdpi/ic_crop_white_24dp.png
Normal file
BIN
src/main/res/drawable-hdpi/ic_crop_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 302 B |
BIN
src/main/res/drawable-mdpi/ic_crop_white_24dp.png
Normal file
BIN
src/main/res/drawable-mdpi/ic_crop_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 B |
BIN
src/main/res/drawable-xhdpi/ic_crop_white_24dp.png
Normal file
BIN
src/main/res/drawable-xhdpi/ic_crop_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 272 B |
BIN
src/main/res/drawable-xxhdpi/ic_crop_white_24dp.png
Normal file
BIN
src/main/res/drawable-xxhdpi/ic_crop_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 326 B |
BIN
src/main/res/drawable-xxxhdpi/ic_crop_white_24dp.png
Normal file
BIN
src/main/res/drawable-xxxhdpi/ic_crop_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 394 B |
8
src/main/res/menu/publish_avatar.xml
Normal file
8
src/main/res/menu/publish_avatar.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_crop_image"
|
||||
android:showAsAction="always"
|
||||
android:icon="@drawable/ic_crop_white_24dp"
|
||||
android:title="@string/select_image_and_crop"/>
|
||||
</menu>
|
|
@ -602,4 +602,5 @@
|
|||
<string name="correct_message">Correct message</string>
|
||||
<string name="send_corrected_message">Send corrected message</string>
|
||||
<string name="no_keys_just_confirm">You already trust this contact. By selecting \'done\' you are just confirming that %s is part of this conference.</string>
|
||||
<string name="select_image_and_crop">Select image and crop</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue