mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 19:53:39 +00:00
parent
37fbd769b7
commit
f1137927d4
@ -5,20 +5,10 @@
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/gray95">
|
||||
|
||||
<ImageView android:id="@+id/image"
|
||||
<org.thoughtcrime.securesms.components.ZoomingImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/media_preview_activity__image_content_description"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView android:id="@+id/error"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="#ff600000"
|
||||
android:textColor="#ffffffff"
|
||||
android:textSize="15sp"
|
||||
android:padding="10dp"
|
||||
android:visibility="gone" />
|
||||
android:contentDescription="@string/media_preview_activity__image_content_description" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,45 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.BitmapImageViewTarget;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
||||
|
||||
import uk.co.senab.photoview.PhotoViewAttacher;
|
||||
|
||||
public class ZoomingImageView extends ImageView {
|
||||
private PhotoViewAttacher attacher = new PhotoViewAttacher(this);
|
||||
|
||||
public ZoomingImageView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ZoomingImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ZoomingImageView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void setImageUri(MasterSecret masterSecret, Uri uri) {
|
||||
Glide.with(getContext())
|
||||
.load(new DecryptableUri(masterSecret, uri))
|
||||
.asBitmap()
|
||||
.dontTransform()
|
||||
.dontAnimate()
|
||||
.into(new BitmapImageViewTarget(this) {
|
||||
@Override protected void setResource(Bitmap resource) {
|
||||
super.setResource(resource);
|
||||
attacher.update();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user