integrate image- and video player
This commit is contained in:
parent
b6025f3506
commit
679ac2ea21
7 changed files with 210 additions and 39 deletions
11
build.gradle
11
build.gradle
|
@ -17,6 +17,12 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
playstoreCompile
|
||||
}
|
||||
|
@ -25,7 +31,6 @@ dependencies {
|
|||
compile project(':libs:MemorizingTrustManager')
|
||||
compile project(':libs:audiowife')
|
||||
|
||||
|
||||
playstoreCompile 'com.google.android.gms:play-services-gcm:9.0.0'
|
||||
compile 'org.sufficientlysecure:openpgp-api:10.0'
|
||||
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
|
||||
|
@ -48,6 +53,8 @@ dependencies {
|
|||
compile 'com.android.support:appcompat-v7:24.0.0-beta1'
|
||||
compile 'com.android.support:multidex:1.0.1'
|
||||
compile 'com.github.bumptech.glide:glide:3.5.2'
|
||||
compile 'com.github.chrisbanes:PhotoView:1.2.6'
|
||||
compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.0'
|
||||
compile 'com.google.android.gms:play-services-location:9.0.0'
|
||||
compile 'com.google.android.gms:play-services-maps:9.0.0'
|
||||
}
|
||||
|
@ -66,7 +73,7 @@ android {
|
|||
minSdkVersion 14
|
||||
targetSdkVersion 23
|
||||
versionCode 144
|
||||
versionName "1.12.3"
|
||||
versionName "1.12.4"
|
||||
archivesBaseName += "-$versionName"
|
||||
applicationId "eu.siacs.conversations"
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
android:label="@string/app_name"
|
||||
android:theme="@style/ConversationsTheme"
|
||||
android:name="android.support.multidex.MultiDexApplication"
|
||||
android:largeHeap="true"
|
||||
tools:replace="android:label">
|
||||
|
||||
<service android:name=".services.XmppConnectionService"/>
|
||||
|
@ -201,6 +202,11 @@
|
|||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.ShowFullscreenMessageActivity"
|
||||
android:configChanges="orientation|screenSize">
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.TrustKeysActivity"
|
||||
android:label="@string/trust_omemo_fingerprints"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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)) {
|
||||
|
|
20
src/main/res/layout/activity_fullscreen_message.xml
Normal file
20
src/main/res/layout/activity_fullscreen_message.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@android:color/black">
|
||||
|
||||
<uk.co.senab.photoview.PhotoView
|
||||
android:id="@id/message_image_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:adjustViewBounds="true"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.github.rtoshiro.view.video.FullscreenVideoLayout
|
||||
android:id="@id/message_video_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
|
@ -1,4 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="snackbar_location_message" type="id" />
|
||||
<item name="message_image_view" type="id" />
|
||||
<item name="message_video_view" type="id" />
|
||||
</resources>
|
Reference in a new issue