diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-05-28 22:17:22 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-05-28 22:17:22 +0200 |
commit | 5ec8a55ba51aa60862ec77eecb017257105fac80 (patch) | |
tree | 5988834eb4dd0ce1af72b61dd3d8e29b1d044b83 /src/main/java | |
parent | b6025f3506ee5adf5ccf42cefd9c3ff57d9ff1a1 (diff) | |
parent | 679ac2ea21709d3a4b0e80bdebe740beceac274d (diff) |
Merge branch 'refs/heads/internal-Image/Video-Viewer'
Diffstat (limited to 'src/main/java')
3 files changed, 173 insertions, 37 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ShowFullscreenMessageActivity.java b/src/main/java/eu/siacs/conversations/ui/ShowFullscreenMessageActivity.java new file mode 100644 index 000000000..1f2ba9291 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/ShowFullscreenMessageActivity.java @@ -0,0 +1,110 @@ +package eu.siacs.conversations.ui; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.Configuration; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Bundle; +import android.view.View; +import android.view.Window; +import android.widget.ImageView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.BitmapImageViewTarget; +import com.github.rtoshiro.view.video.FullscreenVideoLayout; + +import java.io.File; +import java.io.IOException; + +import eu.siacs.conversations.R; +import uk.co.senab.photoview.PhotoView; +import uk.co.senab.photoview.PhotoViewAttacher; + +public class ShowFullscreenMessageActivity extends Activity { + + PhotoView mImage; + FullscreenVideoLayout mVideo; + ImageView mFullscreenbutton; + Uri mFileUri; + File mFile; + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().requestFeature(Window.FEATURE_ACTION_BAR); + getActionBar().hide(); + setContentView(R.layout.activity_fullscreen_message); + mImage = (PhotoView) findViewById(R.id.message_image_view); + mVideo = (FullscreenVideoLayout) findViewById(R.id.message_video_view); + mFullscreenbutton = (ImageView) findViewById(R.id.vcv_img_fullscreen); + } + + @Override + protected void onResume() { + super.onResume(); + Intent intent = getIntent(); + + if (intent != null) { + if (intent.hasExtra("image")) { + mFileUri = intent.getParcelableExtra("image"); + mFile = new File(mFileUri.getPath()); + if (mFileUri != null) { + DisplayImage(mFile); + } else { + Toast.makeText(ShowFullscreenMessageActivity.this, getString(R.string.file_deleted), Toast.LENGTH_SHORT).show(); + } + } else if (intent.hasExtra("video")) { + mFileUri = intent.getParcelableExtra("video"); + if (mFileUri != null) { + DisplayVideo(mFileUri); + } else { + Toast.makeText(ShowFullscreenMessageActivity.this, getString(R.string.file_deleted), Toast.LENGTH_SHORT).show(); + } + } + } + } + + @Override + protected void onPause() { + super.onPause(); + } + + private void DisplayImage(File file) { + final PhotoViewAttacher mAttacher = new PhotoViewAttacher(mImage); + mImage.setVisibility(View.VISIBLE); + try { + Glide.with(this) + .load(file) + .asBitmap() + .into(new BitmapImageViewTarget(mImage) { + @Override + public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { + super.onResourceReady(resource, glideAnimation); + mAttacher.update(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void DisplayVideo(Uri uri) { + try { + mVideo.setVisibility(View.VISIBLE); + mVideo.setVideoURI(uri); + mFullscreenbutton.setVisibility(View.INVISIBLE); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } +}
\ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index faa314752..0cefe1d2d 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -1193,18 +1193,22 @@ public abstract class XmppActivity extends Activity { return xmppConnectionService.getAvatarService(); } - public void loadBitmap(Message message, ImageView imageView) { - File bm; - bm = xmppConnectionService.getFileBackend().getFile(message, true); - Glide.with(this) - .load(bm) - .override(400, 400) - .fitCenter() - //.centerCrop() - .diskCacheStrategy(DiskCacheStrategy.RESULT) - .into(imageView); + public void loadBitmap(Message message, ImageView imageView) { + File bm; + bm = xmppConnectionService.getFileBackend().getFile(message, true); + try { + Glide.with(this) + .load(bm) + .override(400, 400) + .fitCenter() + //.centerCrop() + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .into(imageView); + } catch (Exception e) { + e.printStackTrace(); + } - } + } public void loadVideoPreview(Message message, ImageView imageView) { File vp = xmppConnectionService.getFileBackend().getFile(message, true); @@ -1214,7 +1218,7 @@ public abstract class XmppActivity extends Activity { retriever.setDataSource(this, Uri.fromFile(vp)); String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); long microSecond = Long.parseLong(time); - int duration = (int) microSecond / 2; //preview at half of video + int duration = (int) Math.ceil(microSecond / 2); //preview at half of video BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool(); VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(duration); FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 8fe1d029a..54cf97933 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -51,6 +51,7 @@ import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message.FileParams; import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.ui.ConversationActivity; +import eu.siacs.conversations.ui.ShowFullscreenMessageActivity; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.UIHelper; @@ -746,31 +747,52 @@ public class MessageAdapter extends ArrayAdapter<Message> { return view; } - public void openDownloadable(Message message) { - DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); - if (!file.exists()) { - Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show(); - return; - } - Intent openIntent = new Intent(Intent.ACTION_VIEW); - String mime = file.getMimeType(); - if (mime == null) { - mime = "*/*"; - } - openIntent.setDataAndType(Uri.fromFile(file), mime); - PackageManager manager = activity.getPackageManager(); - List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0); - if (infos.size() == 0) { - openIntent.setDataAndType(Uri.fromFile(file),"*/*"); - } - try { - getContext().startActivity(openIntent); - return; - } catch (ActivityNotFoundException e) { - //ignored - } - Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show(); - } + public void openDownloadable(Message message) { + DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); + if (!file.exists()) { + Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); + return; + } + String mime = file.getMimeType(); + + if (mime.startsWith("image/")) { + Intent intent = new Intent(getContext(), ShowFullscreenMessageActivity.class); + intent.putExtra("image", Uri.fromFile(file)); + try { + activity.startActivity(intent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + } else if (mime.startsWith("video/")) { + Intent intent = new Intent(getContext(), ShowFullscreenMessageActivity.class); + intent.putExtra("video", Uri.fromFile(file)); + try { + activity.startActivity(intent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + } + Intent openIntent = new Intent(Intent.ACTION_VIEW); + if (mime == null) { + mime = "*/*"; + } + openIntent.setDataAndType(Uri.fromFile(file), mime); + PackageManager manager = activity.getPackageManager(); + List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0); + if (infos.size() == 0) { + openIntent.setDataAndType(Uri.fromFile(file), "*/*"); + } + try { + getContext().startActivity(openIntent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + Toast.makeText(activity, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + + } public void showLocation(Message message) { for(Intent intent : GeoHelper.createGeoIntentsFromMessage(message)) { |