Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c0b7590
enable video thumbnail
tobiasKaminsky Jun 27, 2015
921e38f
fallback if server does not support video thumbnails
tobiasKaminsky Jun 28, 2015
924bc65
fallback if server does not support video thumbnails
tobiasKaminsky Jun 28, 2015
e14533e
overlay is added also when downloading new thumbnails
tobiasKaminsky Jul 24, 2015
689199a
wip
tobiasKaminsky Jul 30, 2015
608febb
wip
tobiasKaminsky Jul 31, 2015
8fab264
resized video overlay
tobiasKaminsky Aug 2, 2015
f4f3ecf
fixed line break
tobiasKaminsky Aug 2, 2015
928ce1a
play icon (from google's material icon set) for the various resoluti…
AndyScherzinger Aug 10, 2015
a1b24de
Merge branch 'master' of https://github.com/owncloud/android into vid…
AndyScherzinger Aug 10, 2015
c50aa8b
Merge remote-tracking branch 'upstream/video_thumbnail' into video_th…
tobiasKaminsky Aug 14, 2015
366ec0b
changed back to latest owncloud-android-library
tobiasKaminsky Aug 14, 2015
a48db2f
show big thumbnails for videos
tobiasKaminsky Oct 5, 2015
e9bf119
avoid NPE
tobiasKaminsky Dec 2, 2015
09af6b7
Merge branch 'master' of github.com:owncloud/android
tobiasKaminsky Feb 12, 2016
8a56a55
Merge branch 'master' of github.com:owncloud/android
tobiasKaminsky Mar 5, 2016
b8a6486
Merge remote-tracking branch 'upstream/master'
tobiasKaminsky Mar 11, 2016
2c516e3
Merge branch 'master' of github.com:owncloud/android
tobiasKaminsky Apr 15, 2016
8122e8f
Merge branch 'master' of github.com:owncloud/android
tobiasKaminsky May 6, 2016
a3f4c97
Merge branch 'master' of github.com:owncloud/android
tobiasKaminsky May 12, 2016
2c7256e
Merge remote-tracking branch 'remotes/origin/videoBigThumbnails' into…
tobiasKaminsky Jun 19, 2016
bed5a16
Merge remote-tracking branch 'remotes/origin/master' into video_thumb…
tobiasKaminsky Jun 19, 2016
d2e05d1
remove commented line
tobiasKaminsky Jun 20, 2016
7843c09
Merge remote-tracking branch 'remotes/owncloud/master' into video_thu…
tobiasKaminsky Jul 2, 2016
1edc488
Merge remote-tracking branch 'remotes/origin/master' into video_thumb…
tobiasKaminsky Jul 2, 2016
644f255
show video placeholder correctly
tobiasKaminsky Jul 2, 2016
411e539
Merge remote-tracking branch 'remotes/origin/master' into video_thumb…
tobiasKaminsky Jul 15, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added res/drawable-hdpi/view_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/view_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/view_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/view_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxxhdpi/view_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@

package com.owncloud.android.datamodel;

import java.io.File;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.FileNameMap;
import java.net.URLConnection;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;

import android.accounts.Account;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.Image;
Expand Down Expand Up @@ -55,6 +65,7 @@
import java.io.File;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import com.owncloud.android.utils.FileStorageUtils;

/**
* Manager for concurrent access to thumbnails cache.
Expand All @@ -80,6 +91,12 @@ public class ThumbnailsCacheManager {
R.drawable.file_image
);

public static Bitmap mDefaultVideo =
BitmapFactory.decodeResource(
MainApp.getAppContext().getResources(),
R.drawable.file_movie
);


public static class InitDiskCacheTask extends AsyncTask<File, Void, Void> {

Expand Down Expand Up @@ -192,8 +209,19 @@ protected Bitmap doInBackground(Object... params) {

if (mFile instanceof OCFile) {
thumbnail = doOCFileInBackground();

if (((OCFile) mFile).isVideo() && thumbnail != null){
thumbnail = addVideoOverlay(thumbnail);
}
} else if (mFile instanceof File) {
thumbnail = doFileInBackground();

String url = ((File) mFile).getAbsolutePath();
String mMimeType = FileStorageUtils.getMimeTypeFromName(url);

if (mMimeType != null && mMimeType.startsWith("video/") && thumbnail != null){
thumbnail = addVideoOverlay(thumbnail);
}
//} else { do nothing
}

Expand Down Expand Up @@ -584,6 +612,51 @@ public static ThumbnailGenerationTask getBitmapWorkerTask(ImageView imageView) {
return null;
}

public static Bitmap addVideoOverlay(Bitmap thumbnail){
Bitmap playButton = BitmapFactory.decodeResource(MainApp.getAppContext().getResources(),
R.drawable.view_play);

Bitmap resizedPlayButton = Bitmap.createScaledBitmap(playButton,
(int) (thumbnail.getWidth() * 0.3),
(int) (thumbnail.getHeight() * 0.3), true);

Bitmap resultBitmap = Bitmap.createBitmap(thumbnail.getWidth(),
thumbnail.getHeight(),
Bitmap.Config.ARGB_8888);

Canvas c = new Canvas(resultBitmap);

// compute visual center of play button, according to resized image
int x1 = resizedPlayButton.getWidth();
int y1 = resizedPlayButton.getHeight() / 2;
int x2 = 0;
int y2 = resizedPlayButton.getWidth();
int x3 = 0;
int y3 = 0;

double ym = ( ((Math.pow(x3,2) - Math.pow(x1,2) + Math.pow(y3,2) - Math.pow(y1,2)) *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of zeros in the calculations so this probably can be simplified ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt so, as this is a mainly pythagoras and he needs three coordinates.
To simplify it, I have chosen them to be mostly zero.

(x2 - x1)) - (Math.pow(x2,2) - Math.pow(x1,2) + Math.pow(y2,2) -
Math.pow(y1,2)) * (x3 - x1) ) / (2 * ( ((y3 - y1) * (x2 - x1)) -
((y2 - y1) * (x3 - x1)) ));
double xm = ( (Math.pow(x2,2) - Math.pow(x1,2)) + (Math.pow(y2,2) - Math.pow(y1,2)) -
(2*ym*(y2 - y1)) ) / (2*(x2 - x1));

// offset to top left
double ox = - xm;
double oy = thumbnail.getHeight() - ym;


c.drawBitmap(thumbnail, 0, 0, null);

Paint p = new Paint();
p.setAlpha(230);

c.drawBitmap(resizedPlayButton, (float) ((thumbnail.getWidth() / 2) + ox),
(float) ((thumbnail.getHeight() / 2) - ym), p);

return resultBitmap;
}

public static AvatarGenerationTask getAvatarWorkerTask(Object callContext) {
if (callContext instanceof ImageView)
return getAvatarWorkerTask(((ImageView)callContext).getDrawable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.utils.BitmapUtils;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimetypeIconUtil;

Expand Down Expand Up @@ -413,7 +414,11 @@ public void onClick(View v) {
fileIcon, mParentActivity.getStorageManager(), mParentActivity.getAccount()
);
if (thumbnail == null) {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
if (fakeFileToCheatThumbnailsCacheManagerInterface.isVideo()) {
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
} else {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
}
}
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
Expand Down Expand Up @@ -445,7 +450,11 @@ public void onClick(View v) {
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
if (thumbnail == null) {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
if (BitmapUtils.isVideo(file)) {
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
} else {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
}
}
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
Expand Down
21 changes: 17 additions & 4 deletions src/com/owncloud/android/ui/adapter/FileListListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import android.accounts.Account;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -146,7 +149,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
ViewType viewType;
if (!mGridMode){
viewType = ViewType.LIST_ITEM;
} else if (file.isImage()){
} else if (file.isImage() || file.isVideo()){
viewType = ViewType.GRID_IMAGE;
} else {
viewType = ViewType.GRID_ITEM;
Expand Down Expand Up @@ -298,13 +301,19 @@ public View getView(int position, View convertView, ViewGroup parent) {

// No Folder
if (!file.isFolder()) {
if (file.isImage() && file.getRemoteId() != null){
if ((file.isImage() || file.isVideo()) && file.getRemoteId() != null){
// Thumbnail in Cache?
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
String.valueOf(file.getRemoteId())
);
if (thumbnail != null && !file.needsUpdateThumbnail()){
fileIcon.setImageBitmap(thumbnail);

if (file.isVideo()) {
Bitmap withOverlay = ThumbnailsCacheManager.addVideoOverlay(thumbnail);
fileIcon.setImageBitmap(withOverlay);
} else {
fileIcon.setImageBitmap(thumbnail);
}
} else {
// generate new Thumbnail
if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, fileIcon)) {
Expand All @@ -313,7 +322,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
fileIcon, mStorageManager, mAccount
);
if (thumbnail == null) {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
if (file.isVideo()) {
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
} else {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
}
}
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
if (thumbnail == null) {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
if (BitmapUtils.isVideo(file)) {
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
} else {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
}
}
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
Expand Down
6 changes: 5 additions & 1 deletion src/com/owncloud/android/ui/adapter/UploaderAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon, mStorageManager,
mAccount);
if (thumbnail == null) {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
if (file.isVideo()) {
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
} else {
thumbnail = ThumbnailsCacheManager.mDefaultImg;
}
}
final AsyncThumbnailDrawable asyncDrawable = new AsyncThumbnailDrawable(
mContext.getResources(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ private void updateLayout() {
if (!file.isHidden()) {
filesCount++;

if (file.isImage()) {
if (file.isImage() || file.isVideo()) {
imagesCount++;
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/com/owncloud/android/utils/BitmapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ public static boolean isImage(File file) {
return (mimeType != null && mimeType.startsWith("image/"));
}

/**
* Checks if file passed is a video
* @param file
* @return true/false
*/
public static boolean isVideo(File file) {
Uri selectedUri = Uri.fromFile(file);
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase());
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);

return (mimeType != null && mimeType.startsWith("video/"));
}

/**
* calculates the RGB value based on a given account name.
*
Expand Down