From c6287b2e92e1126bf7cf9fc4e2e4253068acdea0 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Wed, 29 Jun 2016 12:36:20 +0200 Subject: reworked image preview a bit --- .../conversations/ui/ConversationActivity.java | 153 +++++++++++---------- src/main/res/values-de/strings.xml | 1 + src/main/res/values/strings.xml | 1 + 3 files changed, 84 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index bcab4dd6c..c66428ed4 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1762,80 +1762,91 @@ public class ConversationActivity extends XmppActivity final Conversation conversation_preview = conversation; final Uri uri_preview = uri; Bitmap bitmap = BitmapFactory.decodeFile(FileUtils.getPath(this, uri)); - if (bitmap != null) { - int scaleSize = 400; - int originalWidth = bitmap.getWidth(); - int originalHeight = bitmap.getHeight(); - int newWidth = -1; - int newHeight = -1; - float multFactor; - if (originalHeight > originalWidth) { - newHeight = scaleSize; - multFactor = (float) originalWidth / (float) originalHeight; - newWidth = (int) (newHeight * multFactor); - } else if (originalWidth > originalHeight) { - newWidth = scaleSize; - multFactor = (float) originalHeight / (float) originalWidth; - newHeight = (int) (newWidth * multFactor); - } else if (originalHeight == originalWidth) { - newHeight = scaleSize; - newWidth = scaleSize; - } - - Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); - ImageView ImagePreview = new ImageView(this); - LinearLayout.LayoutParams vp = - new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - ImagePreview.setLayoutParams(vp); - ImagePreview.setScaleType(ImageView.ScaleType.FIT_XY); - ImagePreview.setAdjustViewBounds(true); - ImagePreview.setImageBitmap(bitmap); - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setView(ImagePreview); - builder.setCancelable(false); - builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); - prepareFileToast.show(); - xmppConnectionService.attachImageToConversation(conversation_preview, uri_preview, - new UiCallback() { + if (bitmap != null) { + int scaleSize = 500; + int originalWidth = bitmap.getWidth(); + int originalHeight = bitmap.getHeight(); + int newWidth = -1; + int newHeight = -1; + float multFactor; + if (originalHeight > originalWidth) { + newHeight = scaleSize; + multFactor = (float) originalWidth / (float) originalHeight; + newWidth = (int) (newHeight * multFactor); + } else if (originalWidth > originalHeight) { + newWidth = scaleSize; + multFactor = (float) originalHeight / (float) originalWidth; + newHeight = (int) (newWidth * multFactor); + } else if (originalHeight == originalWidth) { + newHeight = scaleSize; + newWidth = scaleSize; + } + Log.d(Config.LOGTAG, "Scaling preview image from " + originalHeight + "px x " + originalWidth + "px to " + newHeight + "px x " + newWidth + "px"); + Bitmap preview = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); + ImageView ImagePreview = new ImageView(this); + + LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); + ImagePreview.setLayoutParams(vp); + //ImagePreview.setMaxWidth(newWidth); + //ImagePreview.setMaxHeight(newHeight); + //ImagePreview.setScaleType(ImageView.ScaleType.FIT_XY); + //ImagePreview.setAdjustViewBounds(true); + ImagePreview.setPadding(5, 5, 5, 5); + ImagePreview.setImageBitmap(preview); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setView(ImagePreview); + builder.setTitle(R.string.send_image); + builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int which) { + final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); + prepareFileToast.show(); + xmppConnectionService.attachImageToConversation(conversation_preview, uri_preview, + new UiCallback() { - @Override - public void userInputRequried(PendingIntent pi, Message object) { - hidePrepareFileToast(prepareFileToast); - } + @Override + public void userInputRequried(PendingIntent pi, Message object) { + hidePrepareFileToast(prepareFileToast); + } - @Override - public void success(Message message) { - hidePrepareFileToast(prepareFileToast); - xmppConnectionService.sendMessage(message); - } + @Override + public void success(Message message) { + hidePrepareFileToast(prepareFileToast); + xmppConnectionService.sendMessage(message); + } - @Override - public void error(final int error, Message message) { - hidePrepareFileToast(prepareFileToast); - runOnUiThread(new Runnable() { - @Override - public void run() { - replaceToast(getString(error)); - } - }); - } - }); - } - }); - builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - mPendingImageUris.clear(); - } - }); - builder.create().show(); - } else { - Toast.makeText(getApplicationContext(), getText(R.string.error_file_not_found), Toast.LENGTH_LONG).show(); - } + @Override + public void error(final int error, Message message) { + hidePrepareFileToast(prepareFileToast); + runOnUiThread(new Runnable() { + @Override + public void run() { + replaceToast(getString(error)); + } + }); + } + }); + } + }); + builder.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + mPendingImageUris.clear(); + } + }); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + builder.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + mPendingImageUris.clear(); + } + }); + } + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } else { + Toast.makeText(getApplicationContext(), getText(R.string.error_file_not_found), Toast.LENGTH_LONG).show(); + } } private void hidePrepareFileToast(final Toast prepareFileToast) { diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index 3f6e73b9c..90f798977 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -627,5 +627,6 @@ OpenPGP Schlüssel ID OTR Fingerabdruck der Nachricht Keine Verbindung zu OpenKeychain + Bild senden? diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index f318b7024..584d08a21 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -667,4 +667,5 @@ You have denied some or all permissions needed for Pix-Art Messenger. Would you like to jump to the settings and allow these permissions? If you denie any of these permissions, the app will close itself. Unable to connect to OpenKeychain Pix-Art Messenger has no permissions + Send image? -- cgit v1.2.3