mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
Merge 'master' including conflict fixing
Conflicts: src/com/owncloud/android/ui/adapter/FileListListAdapter.java src/com/owncloud/android/ui/fragment/OCFileListFragment.java
This commit is contained in:
commit
62c918f59a
12 changed files with 129 additions and 10 deletions
BIN
res/drawable-hdpi/view_play.png
Normal file
BIN
res/drawable-hdpi/view_play.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 230 B |
BIN
res/drawable-mdpi/view_play.png
Normal file
BIN
res/drawable-mdpi/view_play.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 203 B |
BIN
res/drawable-xhdpi/view_play.png
Normal file
BIN
res/drawable-xhdpi/view_play.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 266 B |
BIN
res/drawable-xxhdpi/view_play.png
Normal file
BIN
res/drawable-xxhdpi/view_play.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 320 B |
BIN
res/drawable-xxxhdpi/view_play.png
Normal file
BIN
res/drawable-xxxhdpi/view_play.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 382 B |
|
@ -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;
|
||||
|
@ -55,6 +65,7 @@ import org.apache.commons.httpclient.methods.GetMethod;
|
|||
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.
|
||||
|
@ -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> {
|
||||
|
||||
|
@ -194,8 +211,19 @@ public class ThumbnailsCacheManager {
|
|||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -586,6 +614,51 @@ public class ThumbnailsCacheManager {
|
|||
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 AvatarGenerationTask getAvatarWorkerTask(Object callContext) {
|
||||
if (callContext instanceof ImageView)
|
||||
return getAvatarWorkerTask(((ImageView)callContext).getDrawable());
|
||||
|
|
|
@ -48,6 +48,7 @@ import com.owncloud.android.files.services.FileUploader;
|
|||
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;
|
||||
|
||||
|
@ -419,7 +420,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
|||
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(
|
||||
|
@ -451,7 +456,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
|||
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(
|
||||
|
|
|
@ -29,8 +29,10 @@ import java.util.Vector;
|
|||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -142,7 +144,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
// Find out which layout should be displayed
|
||||
ViewType viewType;
|
||||
if (parent instanceof GridView) {
|
||||
if (file != null && file.isImage()) {
|
||||
if (file != null && (file.isImage() || file.isVideo())) {
|
||||
viewType = ViewType.GRID_IMAGE;
|
||||
} else {
|
||||
viewType = ViewType.GRID_ITEM;
|
||||
|
@ -299,13 +301,19 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
|
||||
// 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)) {
|
||||
|
@ -314,7 +322,11 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
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(
|
||||
|
|
|
@ -166,7 +166,11 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
|
|||
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(
|
||||
|
|
|
@ -105,7 +105,11 @@ public class UploaderAdapter extends SimpleAdapter {
|
|||
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(),
|
||||
|
|
|
@ -677,6 +677,10 @@ public class OCFileListFragment extends ExtendedListFragment {
|
|||
} else {
|
||||
if (!file.isHidden()) {
|
||||
filesCount++;
|
||||
|
||||
if (file.isImage() || file.isVideo()) {
|
||||
imagesCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,6 +275,19 @@ public class BitmapUtils {
|
|||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue