diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-06-28 19:07:51 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-06-28 19:07:51 +0200 |
commit | 71e7f822d5f772ba7380bbc468bde65d716720a0 (patch) | |
tree | 1f0272173ce280b917eb3f2f58f3eeddf57bcdab /src/main/java/eu/siacs/conversations/ui/ConversationActivity.java | |
parent | 8110a3804933d895b7b4156bc052235623fcf2c2 (diff) |
check if bitmap is null and clear pending uris when pressing cancel
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/ConversationActivity.java | 132 |
1 files changed, 71 insertions, 61 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 3920adc81..3cb9aea83 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1764,70 +1764,80 @@ public class ConversationActivity extends XmppActivity String imagePath = FileUtils.getPath(this, uri); Bitmap bitmap = BitmapFactory.decodeFile(imagePath); - int scaleSize = 400; - int originalWidth = bitmap.getWidth(); - int originalHeight = bitmap.getHeight(); - int newWidth = -1; - int newHeight = -1; - float multFactor = -1.0F; - 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 ; - } + if (bitmap != null) { + int scaleSize = 400; + int originalWidth = bitmap.getWidth(); + int originalHeight = bitmap.getHeight(); + int newWidth = -1; + int newHeight = -1; + float multFactor = -1.0F; + 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.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<Message>() { - - @Override - public void userInputRequried(PendingIntent pi, Message object) { - hidePrepareFileToast(prepareFileToast); - } + 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<Message>() { - @Override - public void success(Message message) { - hidePrepareFileToast(prepareFileToast); - xmppConnectionService.sendMessage(message); - } + @Override + public void userInputRequried(PendingIntent pi, Message object) { + hidePrepareFileToast(prepareFileToast); + } - @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, null); - builder.create().show(); + @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(); + } } private void hidePrepareFileToast(final Toast prepareFileToast) { |