From: tobiasKaminsky Date: Sat, 31 Oct 2015 07:36:39 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/resizedImages' into beta X-Git-Tag: beta-20151122~68 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/8dfc1622bd406869a635d0e85c1c82ee1bb9ca18?hp=-c Merge remote-tracking branch 'remotes/upstream/resizedImages' into beta --- 8dfc1622bd406869a635d0e85c1c82ee1bb9ca18 diff --combined src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 3586fd58,9b31f3aa..56c9063d --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@@ -35,10 -35,8 +35,10 @@@ 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.Point; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.media.ThumbnailUtils; import android.net.Uri; @@@ -81,8 -79,8 +81,8 @@@ public class ThumbnailsCacheManager public static Bitmap mDefaultImg = BitmapFactory.decodeResource( - MainApp.getAppContext().getResources(), - DisplayUtils.getFileTypeIconId("image/png", "default.png") + MainApp.getAppContext().getResources(), + R.drawable.file_image ); @@@ -147,28 -145,6 +147,28 @@@ return null; } + /** + * Sets max size of cache + * @param maxSize in MB + * @return + */ + public static boolean setMaxSize(long maxSize){ + if (mThumbnailCache != null){ + mThumbnailCache.setMaxSize(maxSize * 1024 * 1024); + return true; + } else { + return false; + } + } + + public static long getMaxSize(){ + if (mThumbnailCache != null) { + return mThumbnailCache.getMaxSize(); + } else { + return -1l; + } + } + public static class ThumbnailGenerationTask extends AsyncTask { private final WeakReference mImageViewReference; private WeakReference mProgressWheelRef; @@@ -234,6 -210,10 +234,6 @@@ } protected void onPostExecute(Bitmap bitmap){ - if (isCancelled()) { - bitmap = null; - } - if (bitmap != null) { final ImageView imageView = mImageViewReference.get(); final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView); @@@ -328,18 -308,11 +328,18 @@@ } if (file.isDown()) { - Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile( + Bitmap tempBitmap = BitmapUtils.decodeSampledBitmapFromFile( file.getStoragePath(), pxW, pxH); + Bitmap bitmap = ThumbnailUtils.extractThumbnail(tempBitmap, pxW, pxH); if (bitmap != null) { - thumbnail = addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), pxW, pxH); + // Handle PNG + if (file.getMimetype().equalsIgnoreCase("image/png")) { + bitmap = handlePNG(bitmap, pxW); + } + + thumbnail = addThumbnailToCache(imageKey, bitmap, + file.getStoragePath(), pxW, pxH); file.setNeedsUpdateThumbnail(false); mStorageManager.saveFile(file); @@@ -351,51 -324,32 +351,51 @@@ if (mClient != null && serverOCVersion != null) { if (serverOCVersion.supportsRemoteThumbnails()) { try { - String uri = mClient.getBaseUri() + "" + - "/index.php/apps/files/api/v1/thumbnail/" + - pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/"); - Log_OC.d("Thumbnail", "URI: " + uri); - GetMethod get = new GetMethod(uri); - int status = mClient.executeMethod(get); - if (status == HttpStatus.SC_OK) { -// byte[] bytes = get.getResponseBody(); -// Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, -// bytes.length); - InputStream inputStream = get.getResponseBodyAsStream(); - Bitmap bitmap = BitmapFactory.decodeStream(inputStream); - thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH); - byte[] bytes = get.getResponseBody(); - - if (mIsThumbnail) { + if (mIsThumbnail) { + String uri = mClient.getBaseUri() + "" + + "/index.php/apps/files/api/v1/thumbnail/" + + pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/"); + Log_OC.d("Thumbnail", "Download URI: " + uri); + GetMethod get = new GetMethod(uri); + int status = mClient.executeMethod(get); + if (status == HttpStatus.SC_OK) { + InputStream inputStream = get.getResponseBodyAsStream(); + Bitmap bitmap = BitmapFactory.decodeStream(inputStream); thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH); } else { - thumbnail = bitmap; + Log_OC.d(TAG, "Status: " + status); + } + } else { + String gallery = ""; + if (serverOCVersion.supportsNativeGallery()){ + gallery = "gallery"; + } else { + gallery = "galleryplus"; } - // Add thumbnail to cache - if (thumbnail != null) { - addBitmapToCache(imageKey, thumbnail); + String uri = mClient.getBaseUri() + + "/index.php/apps/" + gallery + "/api/preview/" + Integer.parseInt(file.getRemoteId().substring(0,8)) + + "/" + pxW + "/" + pxH; + Log_OC.d("Thumbnail", "FileName: " + file.getFileName() + " Download URI: " + uri); + GetMethod get = new GetMethod(uri); + int status = mClient.executeMethod(get); + if (status == HttpStatus.SC_OK) { + InputStream inputStream = get.getResponseBodyAsStream(); + Bitmap bitmap = BitmapFactory.decodeStream(inputStream); + // Download via gallery app + thumbnail = bitmap; } } + + // Handle PNG + if (thumbnail != null && file.getMimetype().equalsIgnoreCase("image/png")) { + thumbnail = handlePNG(thumbnail, pxW); + } + + // Add thumbnail to cache + if (thumbnail != null) { + addBitmapToCache(imageKey, thumbnail); + } } catch (Exception e) { e.printStackTrace(); } @@@ -410,27 -364,21 +410,34 @@@ } + private Bitmap handlePNG(Bitmap bitmap, int px){ + Bitmap resultBitmap = Bitmap.createBitmap(px, + px, + Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(resultBitmap); + + c.drawColor(MainApp.getAppContext().getResources(). + getColor(R.color.background_color)); + c.drawBitmap(bitmap, 0, 0, null); + + return resultBitmap; + } + private Bitmap doFileInBackground(Boolean mIsThumbnail) { - Bitmap thumbnail = null; File file = (File)mFile; - final String imageKey = String.valueOf(file.hashCode()); + // distinguish between thumbnail and resized image + String temp = String.valueOf(file.hashCode()); + if (mIsThumbnail){ + temp = "t" + temp; + } else { + temp = "r" + temp; + } + + final String imageKey = temp; // Check disk cache in background thread - thumbnail = getBitmapFromDiskCache(imageKey); + Bitmap thumbnail = getBitmapFromDiskCache(imageKey); // Not found in disk cache if (thumbnail == null) { @@@ -465,7 -413,6 +472,7 @@@ if (bitmapData == null || bitmapData != file) { // Cancel previous task bitmapWorkerTask.cancel(true); + Log_OC.v(TAG, "Cancelled generation of thumbnail for a reused imageView"); } else { // The same work is already in progress return false; diff --combined src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 7657d107,897f9804..3aecd7e8 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -4,7 -4,6 +4,7 @@@ * @author Bartek Przybylski * @author Tobias Kaminsky * @author David A. Velasco + * @author masensio * Copyright (C) 2011 Bartek Przybylski * Copyright (C) 2015 ownCloud Inc. * @@@ -25,16 -24,12 +25,16 @@@ package com.owncloud.android.ui.adapter import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.Vector; import android.accounts.Account; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.graphics.Color; import android.os.Build; import android.preference.PreferenceManager; import android.text.format.DateUtils; @@@ -59,7 -54,6 +59,7 @@@ import com.owncloud.android.services.Op import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; +import com.owncloud.android.utils.MimetypeIconUtil; /** @@@ -83,8 -77,6 +83,8 @@@ public class FileListListAdapter extend private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM }; private SharedPreferences mAppPreferences; + + private HashMap mSelection = new HashMap(); public FileListListAdapter( boolean justFolders, @@@ -160,7 -152,7 +160,7 @@@ 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; @@@ -200,37 -192,35 +200,37 @@@ switch (viewType){ case LIST_ITEM: TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); + TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator); TextView lastModV = (TextView) view.findViewById(R.id.last_mod); - ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox); + lastModV.setVisibility(View.VISIBLE); lastModV.setText(showRelativeTimestamp(file)); - checkBoxV.setVisibility(View.GONE); + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); - if (!file.isFolder()) { - AbsListView parentList = (AbsListView)parent; - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) { - checkBoxV.setVisibility(View.GONE); - } else { - if (parentList.isItemChecked(position)) { - checkBoxV.setImageResource( - android.R.drawable.checkbox_on_background); - } else { - checkBoxV.setImageResource( - android.R.drawable.checkbox_off_background); - } - checkBoxV.setVisibility(View.VISIBLE); - } - } - - } else { //Folder +// if (!file.isFolder()) { +// AbsListView parentList = (AbsListView)parent; +// if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { +// if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) { +// checkBoxV.setVisibility(View.GONE); +// } else { +// if (parentList.isItemChecked(position)) { +// checkBoxV.setImageResource( +// R.drawable.ic_checkbox_marked); +// } else { +// checkBoxV.setImageResource( +// R.drawable.ic_checkbox_blank_outline); +// } +// checkBoxV.setVisibility(View.VISIBLE); +// } +// } + + if (file.isFolder()) { + fileSizeSeparatorV.setVisibility(View.INVISIBLE); fileSizeV.setVisibility(View.INVISIBLE); } @@@ -278,43 -268,25 +278,43 @@@ } // 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; } + + ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox); + checkBoxV.setVisibility(View.GONE); + + AbsListView parentList = (AbsListView)parent; + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) { + checkBoxV.setVisibility(View.GONE); + } else if (parentList.getCheckedItemCount() > 0){ + if (parentList.isItemChecked(position)) { + checkBoxV.setImageResource( + android.R.drawable.checkbox_on_background); + } else { + checkBoxV.setImageResource( + android.R.drawable.checkbox_off_background); + } + checkBoxV.setVisibility(View.VISIBLE); + } + } // For all Views // 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); @@@ -325,8 -297,7 +325,7 @@@ if (file.isImage() && file.getRemoteId() != null){ // Thumbnail in Cache? Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( - String.valueOf(file.getRemoteId()) - ); + "t" + String.valueOf(file.getRemoteId())); if (thumbnail != null && !file.needsUpdateThumbnail()){ fileIcon.setImageBitmap(thumbnail); } else { @@@ -349,32 -320,27 +348,32 @@@ task.execute(file, true); } } + + if (file.getMimetype().equalsIgnoreCase("image/png")) { + fileIcon.setBackgroundColor(mContext.getResources() + .getColor(R.color.background_color)); + } + + } else { - fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), + fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(file.getMimetype(), file.getFileName())); } } else { // Folder - if (checkIfFileIsSharedWithMe(file)) { - fileIcon.setImageResource(R.drawable.shared_with_me_folder); - } else if (file.isShareByLink()) { - // If folder is sharedByLink, icon folder must be changed to - // folder-public one - fileIcon.setImageResource(R.drawable.folder_public); - } else { - fileIcon.setImageResource( - DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName()) - ); - } + fileIcon.setImageResource( + MimetypeIconUtil.getFolderTypeIconId( + checkIfFileIsSharedWithMe(file), file.isShareByLink())); } } + if (mSelection.get(position) != null) { + view.setBackgroundColor(Color.rgb(248, 248, 248)); + } else { + view.setBackgroundColor(Color.WHITE); + } + return view; } @@@ -441,14 -407,15 +440,14 @@@ * mStorageManager if is different (and not NULL) */ public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager - /*, boolean onlyOnDevice*/) { + , boolean onlyOnDevice) { mFile = directory; if (updatedStorageManager != null && updatedStorageManager != mStorageManager) { mStorageManager = updatedStorageManager; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); } if (mStorageManager != null) { - // TODO Enable when "On Device" is recovered ? - mFiles = mStorageManager.getFolderContent(mFile/*, onlyOnDevice*/); + mFiles = mStorageManager.getFolderContent(mFile, onlyOnDevice); mFilesOrig.clear(); mFilesOrig.addAll(mFiles); @@@ -459,7 -426,7 +458,7 @@@ mFiles = null; } - mFiles = FileStorageUtils.sortFolder(mFiles); + mFiles = FileStorageUtils.sortOcFolder(mFiles); notifyDataSetChanged(); } @@@ -506,7 -473,7 +505,7 @@@ FileStorageUtils.mSortAscending = ascending; - mFiles = FileStorageUtils.sortFolder(mFiles); + mFiles = FileStorageUtils.sortOcFolder(mFiles); notifyDataSetChanged(); } @@@ -519,45 -486,4 +518,45 @@@ public void setGridMode(boolean gridMode) { mGridMode = gridMode; } + + public boolean isGridMode() { + return mGridMode; + } + + public void setNewSelection(int position, boolean checked) { + mSelection.put(position, checked); + notifyDataSetChanged(); + } + + public void removeSelection(int position) { + mSelection.remove(position); + notifyDataSetChanged(); + } + + public void removeSelection(){ + mSelection.clear(); + notifyDataSetChanged(); + } + + public ArrayList getCheckedItemPositions() { + ArrayList ids = new ArrayList(); + + for (Map.Entry entry : mSelection.entrySet()){ + if (entry.getValue()){ + ids.add(entry.getKey()); + } + } + return ids; + } + + public ArrayList getCheckedItems() { + ArrayList files = new ArrayList(); + + for (Map.Entry entry : mSelection.entrySet()){ + if (entry.getValue()){ + files.add((OCFile) getItem(entry.getKey())); + } + } + return files; + } }