From: tobiasKaminsky Date: Wed, 1 Jul 2015 17:16:42 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/develop' into resizedImages X-Git-Tag: beta-20151122~1^2~9 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/ce35d6448e39f06d66596b23dc7e3ddf1e93ab5a?hp=--cc Merge remote-tracking branch 'upstream/develop' into resizedImages --- ce35d6448e39f06d66596b23dc7e3ddf1e93ab5a diff --cc owncloud-android-library index 9e761387,f5fbca24..d5aa05bc --- a/owncloud-android-library +++ b/owncloud-android-library @@@ -1,1 -1,1 +1,1 @@@ - Subproject commit 9e761387a0b406402684571f28c36c2d6d2b6301 -Subproject commit f5fbca24becbb01660abe2a7013c1b536ea8a301 ++Subproject commit d5aa05bc0ca126626536e035459a33b13eeaf0fd diff --cc src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index a5ea5952,0e59a834..49bda88e --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@@ -224,17 -205,10 +222,17 @@@ public class ThumbnailsCacheManager if (mFile instanceof OCFile){ tagId = String.valueOf(((OCFile)mFile).getFileId()); } else if (mFile instanceof File){ - tagId = String.valueOf(((File)mFile).hashCode()); + tagId = String.valueOf(mFile.hashCode()); } if (String.valueOf(imageView.getTag()).equals(tagId)) { + if (mProgressWheelRef != null) { + final ProgressBar progressWheel = mProgressWheelRef.get(); + if (progressWheel != null) { + progressWheel.setVisibility(View.GONE); + } + } imageView.setImageBitmap(bitmap); + imageView.setVisibility(View.VISIBLE); } } } @@@ -269,33 -242,16 +267,33 @@@ private int getThumbnailDimension(){ // Converts dp to pixel Resources r = MainApp.getAppContext().getResources(); - return (int) Math.round(r.getDimension(R.dimen.file_icon_size_grid)); + return Math.round(r.getDimension(R.dimen.file_icon_size_grid)); } - private Bitmap doOCFileInBackground() { + private Point getScreenDimension(){ + WindowManager wm = (WindowManager) MainApp.getAppContext().getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + Point test = new Point(); + display.getSize(test); + return test; + } + + private Bitmap doOCFileInBackground(Boolean isThumbnail) { + Bitmap thumbnail = null; OCFile file = (OCFile)mFile; - final String imageKey = String.valueOf(file.getRemoteId()); + // distinguish between thumbnail and resized image + String temp = String.valueOf(file.getRemoteId()); + if (isThumbnail){ + temp = "t" + temp; + } else { + temp = "r" + temp; + } + + final String imageKey = temp; // Check disk cache in background thread - Bitmap thumbnail = getBitmapFromDiskCache(imageKey); + thumbnail = getBitmapFromDiskCache(imageKey); // Not found in disk cache if (thumbnail == null || file.needsUpdateThumbnail()) { @@@ -322,38 -271,23 +320,42 @@@ } else { // Download thumbnail from server - if (mClient != null && mServerVersion != null) { - OwnCloudVersion serverOCVersion = new OwnCloudVersion(mServerVersion); - if (serverOCVersion.compareTo( - new OwnCloudVersion(MINOR_SERVER_VERSION_FOR_THUMBS)) >= 0) { + OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount); + if (mClient != null && serverOCVersion != null) { + if (serverOCVersion.supportsRemoteThumbnails()) { try { - int status = -1; - String uri = mClient.getBaseUri() + "" + "/index.php/apps/files/api/v1/thumbnail/" + - px + "/" + px + Uri.encode(file.getRemotePath(), "/"); + pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/"); Log_OC.d("Thumbnail", "URI: " + uri); GetMethod get = new GetMethod(uri); - status = mClient.executeMethod(get); + 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, px, px); ++ thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH); + byte[] bytes = get.getResponseBody(); + + String type = ""; + if (mIsThumbnail){ + type = "Thumbnail"; + } else { + type = "Resized image"; + } - Log_OC.d("Thumbnail", type + " size of " + file.getRemotePath() + ": " + bytes.length); ++ Log_OC.d("Thumbnail", ++ type + " size of " + file.getRemotePath() ++ + ": " + bytes.length); + - Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, - bytes.length); ++ // bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); + + if (mIsThumbnail) { + thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH); + } else { + thumbnail = bitmap; + } // Add thumbnail to cache if (thumbnail != null) { diff --cc src/com/owncloud/android/files/FileOperationsHelper.java index bddeed02,75fae370..b5eeb614 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@@ -24,18 -24,15 +24,18 @@@ package com.owncloud.android.files import org.apache.http.protocol.HTTP; import android.accounts.Account; - import android.accounts.AccountManager; import android.content.Intent; +import android.graphics.Bitmap; import android.net.Uri; import android.support.v4.app.DialogFragment; import android.webkit.MimeTypeMap; import android.widget.Toast; +import com.owncloud.android.MainApp; import com.owncloud.android.R; + import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; diff --cc src/com/owncloud/android/ui/preview/PreviewImageActivity.java index 7f4bfc39,2b0d96ce..bfb02d3b --- a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java @@@ -389,7 -414,13 +414,8 @@@ public class PreviewImageActivity exten } else { OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position); getSupportActionBar().setTitle(currentFile.getFileName()); - + mDrawerToggle.setDrawerIndicatorEnabled(false); - if (!currentFile.isDown()) { - if (!mPreviewImagePagerAdapter.pendingErrorAt(position)) { - requestForDownload(currentFile); - } - } - ++ // Call to reset image zoom to initial state ((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom(); } diff --cc src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 581526c3,7950ec98..bb33a9c6 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@@ -46,13 -40,8 +40,10 @@@ import android.widget.ImageView import android.widget.ProgressBar; import android.widget.TextView; - import com.actionbarsherlock.view.Menu; - import com.actionbarsherlock.view.MenuInflater; - import com.actionbarsherlock.view.MenuItem; +import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.files.FileMenuFilter; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; @@@ -91,22 -81,30 +85,32 @@@ public class PreviewImageFragment exten private LoadBitmapTask mLoadBitmapTask = null; - + /** - * Creates a fragment to preview an image. - * - * When 'imageFile' or 'ocAccount' are null - * - * @param fileToDetail An {@link OCFile} to preview as an image in the fragment - * @param ocAccount An ownCloud account; needed to start downloads - * @param ignoreFirstSavedState Flag to work around an unexpected behaviour of {@link FragmentStatePagerAdapter}; TODO better solution + * Public factory method to create a new fragment that previews an image. + * + * Android strongly recommends keep the empty constructor of fragments as the only public + * constructor, and + * use {@link #setArguments(Bundle)} to set the needed arguments. + * + * This method hides to client objects the need of doing the construction in two steps. + * + * @param imageFile An {@link OCFile} to preview as an image in the fragment + * @param ignoreFirstSavedState Flag to work around an unexpected behaviour of + * {@link FragmentStatePagerAdapter} + * ; TODO better solution */ - public PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState, boolean showResizedImage) { - super(fileToDetail); - mAccount = ocAccount; - mShowResizedImage = showResizedImage; - mIgnoreFirstSavedState = ignoreFirstSavedState; - public static PreviewImageFragment newInstance(OCFile imageFile, boolean ignoreFirstSavedState){ ++ public static PreviewImageFragment newInstance(OCFile imageFile, boolean ignoreFirstSavedState, ++ boolean showResizedImage){ + PreviewImageFragment frag = new PreviewImageFragment(); ++ frag.mShowResizedImage = showResizedImage; + Bundle args = new Bundle(); + args.putParcelable(ARG_FILE, imageFile); + args.putBoolean(ARG_IGNORE_FIRST, ignoreFirstSavedState); + frag.setArguments(args); + return frag; } + /** @@@ -175,9 -178,9 +184,6 @@@ if (getFile() == null) { throw new IllegalStateException("Instanced with a NULL OCFile"); } - if (mAccount == null) { - throw new IllegalStateException("Instanced with a NULL ownCloud Account"); - if (!getFile().isDown()) { - throw new IllegalStateException("There is no local file to preview"); -- } } @@@ -196,43 -198,9 +201,43 @@@ public void onStart() { super.onStart(); if (getFile() != null) { - mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel); - //mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()}); - mLoadBitmapTask.execute(getFile().getStoragePath()); + mImageView.setTag(getFile().getFileId()); + + if (mShowResizedImage){ + Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( + String.valueOf("r" + getFile().getRemoteId()) + ); + + if (thumbnail != null && !getFile().needsUpdateThumbnail()){ + mProgressWheel.setVisibility(View.GONE); + mImageView.setImageBitmap(thumbnail); - mImageView.setBitmap(thumbnail); + mImageView.setVisibility(View.VISIBLE); + mBitmap = thumbnail; + } else { + // generate new Thumbnail + if (ThumbnailsCacheManager.cancelPotentialWork(getFile(), mImageView)) { + final ThumbnailsCacheManager.ThumbnailGenerationTask task = + new ThumbnailsCacheManager.ThumbnailGenerationTask( - mImageView, mContainerActivity.getStorageManager(), mAccount, mProgressWheel - ); ++ mImageView, mContainerActivity.getStorageManager(), ++ mContainerActivity.getStorageManager().getAccount(), ++ mProgressWheel); + if (thumbnail == null) { + thumbnail = ThumbnailsCacheManager.mDefaultImg; + } + final ThumbnailsCacheManager.AsyncDrawable asyncDrawable = + new ThumbnailsCacheManager.AsyncDrawable( + MainApp.getAppContext().getResources(), + thumbnail, + task + ); + mImageView.setImageDrawable(asyncDrawable); + task.execute(getFile(), false); + } + } + } else { + mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel); - mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()}); ++ mLoadBitmapTask.execute(getFile().getStoragePath()); + } } } diff --cc src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java index 7a4eb22d,dda7dda2..d6ea3479 --- a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java +++ b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java @@@ -104,13 -103,18 +106,16 @@@ public class PreviewImagePagerAdapter e OCFile file = mImageFiles.get(i); Fragment fragment = null; if (file.isDown()) { - fragment = new PreviewImageFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)), false); + fragment = PreviewImageFragment.newInstance(file, - mObsoletePositions.contains(Integer.valueOf(i))); ++ mObsoletePositions.contains(Integer.valueOf(i)), false); + } else if (mDownloadErrors.contains(Integer.valueOf(i))) { - fragment = new FileDownloadFragment(file, mAccount, true); + fragment = FileDownloadFragment.newInstance(file, mAccount, true); ((FileDownloadFragment)fragment).setError(true); mDownloadErrors.remove(Integer.valueOf(i)); - } else { - fragment = new PreviewImageFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)), true); - fragment = FileDownloadFragment.newInstance( - file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)) - ); ++ fragment = PreviewImageFragment.newInstance(file, ++ mObsoletePositions.contains(Integer.valueOf(i)), true); } mObsoletePositions.remove(Integer.valueOf(i)); return fragment;