From: tobiasKaminsky Date: Fri, 14 Aug 2015 13:39:35 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/video_thumbnail' into video_thumbnail X-Git-Tag: beta-20151202~1^2~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/c50aa8bc2ad90bad0e1f97a3a7bab461dc05b0d1?ds=inline;hp=-c Merge remote-tracking branch 'upstream/video_thumbnail' into video_thumbnail --- c50aa8bc2ad90bad0e1f97a3a7bab461dc05b0d1 diff --combined owncloud-android-library index f5fbca24,dbc8c325..4eb9ce4b --- a/owncloud-android-library +++ b/owncloud-android-library @@@ -1,1 -1,1 +1,1 @@@ - Subproject commit f5fbca24becbb01660abe2a7013c1b536ea8a301 -Subproject commit dbc8c325d74f3f7e8da8236c5abe77a141ae4019 ++Subproject commit 4eb9ce4ba2d9272de561954b3638f5acde8b2ca5 diff --combined res/drawable-hdpi/view_play.png index 00000000,57c9fa54..53717245 mode 000000,100644..100644 Binary files differ diff --combined res/drawable-mdpi/view_play.png index 00000000,c61e948b..77b20272 mode 000000,100644..100644 Binary files differ diff --combined res/drawable-xhdpi/view_play.png index 00000000,a3c80e73..8482788e mode 000000,100644..100644 Binary files differ diff --combined res/drawable-xxhdpi/view_play.png index 00000000,547ef30a..fea738b9 mode 000000,100644..100644 Binary files differ diff --combined res/drawable-xxxhdpi/view_play.png index 00000000,be5c062b..3786b4d0 mode 000000,100644..100644 Binary files differ diff --combined src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 0e59a834,07849e18..5806a408 --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@@ -24,6 -24,8 +24,8 @@@ 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; @@@ -33,6 -35,8 +35,8 @@@ 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.ThumbnailUtils; @@@ -51,6 -55,6 +55,7 @@@ import com.owncloud.android.lib.resourc 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. @@@ -176,8 -180,20 +181,19 @@@ public class ThumbnailsCacheManager if (mFile instanceof OCFile) { thumbnail = doOCFileInBackground(); + + if (((OCFile) mFile).isVideo()){ + thumbnail = addVideoOverlay(thumbnail); + } } else if (mFile instanceof File) { thumbnail = doFileInBackground(); + + String url = ((File) mFile).getAbsolutePath(); - FileNameMap fileNameMap = URLConnection.getFileNameMap(); - String mMimeType = fileNameMap.getContentTypeFor("file://" + url); ++ String mMimeType = FileStorageUtils.getMimeTypeFromName(url); + + if (mMimeType != null && mMimeType.startsWith("video/")){ + thumbnail = addVideoOverlay(thumbnail); + } //} else { do nothing } @@@ -362,6 -378,51 +378,51 @@@ 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 bitmapWorkerTaskReference; diff --combined src/com/owncloud/android/ui/adapter/FileListListAdapter.java index a589512e,5c0e8e8c..26d77db5 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -30,6 -30,9 +30,9 @@@ import android.accounts.Account import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; + 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; @@@ -268,15 -271,14 +271,14 @@@ public class FileListListAdapter extend } // share with me icon - if (!file.isFolder()) { - ImageView sharedWithMeIconV = (ImageView) - view.findViewById(R.id.sharedWithMeIcon); - sharedWithMeIconV.bringToFront(); - if (checkIfFileIsSharedWithMe(file)) { - sharedWithMeIconV.setVisibility(View.VISIBLE); - } else { - sharedWithMeIconV.setVisibility(View.GONE); - } + ImageView sharedWithMeIconV = (ImageView) + view.findViewById(R.id.sharedWithMeIcon); + sharedWithMeIconV.bringToFront(); + if (checkIfFileIsSharedWithMe(file) && + (!file.isFolder() || !mGridMode)) { + sharedWithMeIconV.setVisibility(View.VISIBLE); + } else { + sharedWithMeIconV.setVisibility(View.GONE); } break; @@@ -286,7 -288,7 +288,7 @@@ // this if-else is needed even though favorite icon is visible by default // because android reuses views in listview - if (!file.keepInSync()) { + if (!file.isFavorite()) { view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE); } else { view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE); @@@ -300,7 -302,13 +302,13 @@@ 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)) { @@@ -308,19 -316,20 +316,17 @@@ new ThumbnailsCacheManager.ThumbnailGenerationTask( fileIcon, mStorageManager, mAccount ); - if (thumbnail != null) { - final ThumbnailsCacheManager.AsyncDrawable asyncDrawable = - new ThumbnailsCacheManager.AsyncDrawable( - mContext.getResources(), - thumbnail, - task - ); - fileIcon.setImageDrawable(asyncDrawable); - task.execute(file); - } else { - fileIcon.setImageResource(DisplayUtils.getFileTypeIconId( - file.getMimetype(), file.getFileName())); + if (thumbnail == null) { -// thumbnail = ThumbnailsCacheManager.mDefaultImg; - Integer id = DisplayUtils.getFileTypeIconId(file.getMimetype(), - file.getFileName()); - thumbnail = BitmapFactory.decodeResource(mContext.getResources(), id); ++ thumbnail = ThumbnailsCacheManager.mDefaultImg; } + final ThumbnailsCacheManager.AsyncDrawable asyncDrawable = + new ThumbnailsCacheManager.AsyncDrawable( - mContext.getResources(), - thumbnail, ++ mContext.getResources(), ++ thumbnail, + task + ); + fileIcon.setImageDrawable(asyncDrawable); + task.execute(file); } } } else {