Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/video_thumbnail' into …
Browse files Browse the repository at this point in the history
…beta
  • Loading branch information
tobiasKaminsky committed Nov 1, 2015
2 parents 465ff1b + 366ec0b commit ec83a9f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2015-11-01
- PR [#1236](https://github.com/owncloud/android/pull/1236) "Streaming video/audio" merged
- PR [#1035](https://github.com/owncloud/android/pull/1035) "Enable video thumbnail" merged

# 2015-10-31
- updated all PR
- bugfix: #1234, #1230
Expand Down
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.
64 changes: 62 additions & 2 deletions src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
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;
Expand All @@ -37,6 +39,8 @@
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
Expand All @@ -60,6 +64,7 @@
import com.owncloud.android.ui.adapter.DiskLruImageCache;
import com.owncloud.android.utils.BitmapUtils;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.FileStorageUtils;

/**
* Manager for concurrent access to thumbnails cache.
Expand Down Expand Up @@ -216,10 +221,20 @@ protected Bitmap doInBackground(Object... params) {

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

if (((OCFile) mFile).isVideo()){
thumbnail = addVideoOverlay(thumbnail);
}
} else if (mFile instanceof File) {
thumbnail = doFileInBackground(mIsThumbnail);
} else {
// do nothing

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

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

}catch(Throwable t){
Expand Down Expand Up @@ -493,6 +508,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)) *
(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 class AsyncDrawable extends BitmapDrawable {
private final WeakReference<ThumbnailGenerationTask> bitmapWorkerTaskReference;

Expand Down
13 changes: 11 additions & 2 deletions src/com/owncloud/android/ui/adapter/FileListListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
Expand Down Expand Up @@ -345,12 +348,18 @@ 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(
"t" + 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.cancelPotentialWork(file, fileIcon)) {
Expand Down
3 changes: 2 additions & 1 deletion src/com/owncloud/android/ui/fragment/OCFileListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private void updateLayout() {
if (!file.isHidden()) {
filesCount++;

if (file.isImage()) {
if (file.isImage() || file.isVideo()) {
imagesCount++;
}
}
Expand All @@ -781,6 +781,7 @@ private void updateLayout() {
registerLongClickListener();
} else {
switchToListView();
// switchToGridView();
}
}
}
Expand Down

0 comments on commit ec83a9f

Please sign in to comment.