|
|
|
@ -21,8 +21,6 @@ import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.opengl.GLES20;
|
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
|
import android.os.Build.VERSION;
|
|
|
|
|
import android.os.Build.VERSION_CODES;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
@ -33,25 +31,18 @@ import android.view.MenuInflater;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.components.ZoomingImageView;
|
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener;
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
|
|
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
|
|
|
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DateUtils;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
|
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
import uk.co.senab.photoview.PhotoViewAttacher;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Activity for displaying media attachments in-app
|
|
|
|
|
*/
|
|
|
|
@ -64,12 +55,9 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
|
|
private MasterSecret masterSecret;
|
|
|
|
|
private boolean paused;
|
|
|
|
|
|
|
|
|
|
private TextView errorText;
|
|
|
|
|
private Bitmap bitmap;
|
|
|
|
|
private ImageView image;
|
|
|
|
|
private PhotoViewAttacher imageAttacher;
|
|
|
|
|
private ZoomingImageView image;
|
|
|
|
|
private Uri mediaUri;
|
|
|
|
|
private String mediaType;
|
|
|
|
|
private Recipient recipient;
|
|
|
|
@ -114,14 +102,14 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|
|
|
|
} else {
|
|
|
|
|
relativeTimeSpan = null;
|
|
|
|
|
}
|
|
|
|
|
getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you) : recipient.toShortString());
|
|
|
|
|
getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you)
|
|
|
|
|
: recipient.toShortString());
|
|
|
|
|
getSupportActionBar().setSubtitle(relativeTimeSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
paused = false;
|
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
|
if (recipient != null) recipient.addListener(this);
|
|
|
|
|
initializeMedia();
|
|
|
|
@ -130,7 +118,6 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|
|
|
|
@Override
|
|
|
|
|
public void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
paused = true;
|
|
|
|
|
if (recipient != null) recipient.removeListener(this);
|
|
|
|
|
cleanupMedia();
|
|
|
|
|
}
|
|
|
|
@ -145,9 +132,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeViews() {
|
|
|
|
|
errorText = (TextView) findViewById(R.id.error);
|
|
|
|
|
image = (ImageView) findViewById(R.id.image);
|
|
|
|
|
imageAttacher = new PhotoViewAttacher(image);
|
|
|
|
|
image = (ZoomingImageView)findViewById(R.id.image);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeResources() {
|
|
|
|
@ -175,7 +160,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|
|
|
|
Log.w(TAG, "Loading Part URI: " + mediaUri);
|
|
|
|
|
|
|
|
|
|
if (mediaType != null && mediaType.startsWith("image/")) {
|
|
|
|
|
displayImage();
|
|
|
|
|
image.setImageUri(masterSecret, mediaUri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -187,42 +172,6 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void displayImage() {
|
|
|
|
|
new AsyncTask<Void,Void,Bitmap>() {
|
|
|
|
|
@Override
|
|
|
|
|
protected Bitmap doInBackground(Void... params) {
|
|
|
|
|
try {
|
|
|
|
|
int[] maxTextureSizeParams = new int[1];
|
|
|
|
|
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSizeParams, 0);
|
|
|
|
|
int maxTextureSize = Math.max(maxTextureSizeParams[0], 2048);
|
|
|
|
|
Log.w(TAG, "reported GL_MAX_TEXTURE_SIZE: " + maxTextureSize);
|
|
|
|
|
return BitmapUtil.createScaledBitmap(MediaPreviewActivity.this, masterSecret, mediaUri,
|
|
|
|
|
maxTextureSize, maxTextureSize);
|
|
|
|
|
} catch (IOException | BitmapDecodingException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(Bitmap bitmap) {
|
|
|
|
|
if (paused) {
|
|
|
|
|
if (bitmap != null) bitmap.recycle();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bitmap == null) {
|
|
|
|
|
errorText.setText(R.string.MediaPreviewActivity_cant_display);
|
|
|
|
|
errorText.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
MediaPreviewActivity.this.bitmap = bitmap;
|
|
|
|
|
image.setImageBitmap(bitmap);
|
|
|
|
|
image.setVisibility(View.VISIBLE);
|
|
|
|
|
imageAttacher.update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveToDisk() {
|
|
|
|
|
SaveAttachmentTask.showWarningDialog(this, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|