android:name=".providers.FileContentProvider"
android:authorities="@string/authority"
android:enabled="true"
- android:exported="false"
+ android:exported="true"
android:label="@string/sync_string_files"
android:syncable="true" >
</provider>
+ <provider
+ android:name=".ui.adapter.DiskLruImageCacheFileProvider"
+ android:authorities="com.owncloud.imageCache.provider">
+ </provider>
+
<activity
android:name=".authentication.AuthenticatorActivity"
android:exported="true"
import android.accounts.Account;
import android.accounts.AccountManager;
+import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
+import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.AsyncTask;
+import android.view.Display;
+import android.view.View;
+import android.view.WindowManager;
import android.widget.ImageView;
+import android.widget.ProgressBar;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
public static class ThumbnailGenerationTask extends AsyncTask<Object, Void, Bitmap> {
private final WeakReference<ImageView> mImageViewReference;
+ private WeakReference<ProgressBar> mProgressWheelRef;
private static Account mAccount;
private Object mFile;
+ private Boolean mIsThumbnail;
private FileDataStorageManager mStorageManager;
-
public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager,
Account account) {
// Use a WeakReference to ensure the ImageView can be garbage collected
mAccount = account;
}
+ public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager,
+ Account account, ProgressBar progressWheel) {
+ this(imageView, storageManager, account);
+ mProgressWheelRef = new WeakReference<ProgressBar>(progressWheel);
+ }
+
public ThumbnailGenerationTask(ImageView imageView) {
// Use a WeakReference to ensure the ImageView can be garbage collected
mImageViewReference = new WeakReference<ImageView>(imageView);
}
mFile = params[0];
+ mIsThumbnail = (Boolean) params[1];
+
if (mFile instanceof OCFile) {
- thumbnail = doOCFileInBackground();
+ thumbnail = doOCFileInBackground(mIsThumbnail);
} else if (mFile instanceof File) {
- thumbnail = doFileInBackground();
+ thumbnail = doFileInBackground(mIsThumbnail);
} else {
// do nothing
}
tagId = String.valueOf(((File)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);
}
}
}
* @param imageKey: thumb key
* @param bitmap: image for extracting thumbnail
* @param path: image path
- * @param px: thumbnail dp
+ * @param pxW: thumbnail width
+ * @param pxH: thumbnail height
* @return Bitmap
*/
- private Bitmap addThumbnailToCache(String imageKey, Bitmap bitmap, String path, int px){
+ private Bitmap addThumbnailToCache(String imageKey, Bitmap bitmap, String path, int pxW, int pxH){
- Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
+ Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH);
// Rotate image, obeying exif tag
thumbnail = BitmapUtils.rotateImage(thumbnail,path);
return (int) 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
thumbnail = getBitmapFromDiskCache(imageKey);
// Not found in disk cache
if (thumbnail == null || file.needsUpdateThumbnail()) {
-
- int px = getThumbnailDimension();
+ int pxW = 0;
+ int pxH = 0;
+ if (mIsThumbnail) {
+ pxW = pxH = getThumbnailDimension();
+ } else {
+ Point p = getScreenDimension();
+ pxW = p.x;
+ pxH = p.y;
+ }
if (file.isDown()) {
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
- file.getStoragePath(), px, px);
+ file.getStoragePath(), pxW, pxH);
if (bitmap != null) {
- thumbnail = addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), px);
+ thumbnail = addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), pxW, pxH);
file.setNeedsUpdateThumbnail(false);
mStorageManager.saveFile(file);
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);
if (status == HttpStatus.SC_OK) {
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);
+
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0,
bytes.length);
- thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
+
+ if (mIsThumbnail) {
+ thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH);
+ } else {
+ thumbnail = bitmap;
+ }
// Add thumbnail to cache
if (thumbnail != null) {
}
- private Bitmap doFileInBackground() {
+ private Bitmap doFileInBackground(Boolean mIsThumbnail) {
Bitmap thumbnail = null;
File file = (File)mFile;
// Not found in disk cache
if (thumbnail == null) {
-
- int px = getThumbnailDimension();
+ int pxW = 0;
+ int pxH = 0;
+ if (mIsThumbnail) {
+ pxW = pxH = getThumbnailDimension();
+ } else {
+ Point p = getScreenDimension();
+ pxW = p.x;
+ pxH = p.y;
+ }
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
- file.getAbsolutePath(), px, px);
+ file.getAbsolutePath(), pxW, pxH);
if (bitmap != null) {
- thumbnail = addThumbnailToCache(imageKey, bitmap, file.getPath(), px);
+ thumbnail = addThumbnailToCache(imageKey, bitmap, file.getPath(), pxW, pxH);
}
}
return thumbnail;
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.datamodel.OCFile;
+import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.ui.activity.FileActivity;
+import com.owncloud.android.ui.adapter.DiskLruImageCacheFileProvider;
import com.owncloud.android.ui.dialog.ShareLinkToDialog;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
/**
*
*/
Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
}
}
+
+ public void sendCachedImage(OCFile file) {
+ if (file != null) {
+ Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
+ // set MimeType
+ sendIntent.setType(file.getMimetype());
+// sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + "/#" + file.getRemoteId() + "#" + file.getFileName()));
+ sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + file.getRemotePath()));
+ sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action
+
+ // Show dialog, without the own app
+ String[] packagesToExclude = new String[] { mFileActivity.getPackageName() };
+ DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude, file);
+ chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
+ } else {
+ Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
+ }
+ }
public void syncFile(OCFile file) {
}
final InputStream in = snapshot.getInputStream( 0 );
if ( in != null ) {
- final BufferedInputStream buffIn =
+ final BufferedInputStream buffIn =
new BufferedInputStream( in, IO_BUFFER_SIZE );
- bitmap = BitmapFactory.decodeStream( buffIn );
- }
+ bitmap = BitmapFactory.decodeStream( buffIn );
+ }
} catch ( IOException e ) {
e.printStackTrace();
} finally {
--- /dev/null
+/**
+ * ownCloud Android client application
+ *
+ * Copyright (C) 2015 Tobias Kaminsky
+ * Copyright (C) 2015 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * adapted from: http://stephendnicholas.com/archives/974
+ *
+ */
+
+package com.owncloud.android.ui.adapter;
+
+import android.accounts.Account;
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.ParcelFileDescriptor;
+
+import com.owncloud.android.MainApp;
+import com.owncloud.android.authentication.AccountUtils;
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.ThumbnailsCacheManager;
+import com.owncloud.android.lib.common.utils.Log_OC;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class DiskLruImageCacheFileProvider extends ContentProvider {
+ private static String TAG = FileDataStorageManager.class.getSimpleName();
+
+ public static final String AUTHORITY = "com.owncloud.imageCache.provider";
+
+ @Override
+ public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
+ Account account = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
+ FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
+ MainApp.getAppContext().getContentResolver());
+
+ OCFile ocFile = fileDataStorageManager.getFileByPath(uri.getPath());
+
+ Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
+ String.valueOf("r" + ocFile.getRemoteId()));
+
+ // create a file to write bitmap data
+ File f = new File(MainApp.getAppContext().getCacheDir(), ocFile.getFileName());
+ try {
+ f.createNewFile();
+
+ //Convert bitmap to byte array
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bos);
+ byte[] bitmapdata = bos.toByteArray();
+
+ //write the bytes in file
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(f);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ fos.write(bitmapdata);
+ fos.flush();
+ fos.close();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
+ }
+
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+ return null;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return null;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ return 0;
+ }
+}
task\r
);\r
fileIcon.setImageDrawable(asyncDrawable);\r
- task.execute(file);\r
+ task.execute(file, true);\r
}\r
}\r
} else {\r
mContainerActivity.getFileOperationsHelper().openFile(file);
}
- } else {
- // automatic download, preview on finish
- ((FileDisplayActivity)mContainerActivity).startDownloadForPreview(file);
}
-
}
} else {
} else {
OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position);
getSupportActionBar().setTitle(currentFile.getFileName());
- if (!currentFile.isDown()) {
- if (!mPreviewImagePagerAdapter.pendingErrorAt(position)) {
- requestForDownload(currentFile);
- }
- }
// Call to reset image zoom to initial state
((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom();
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;
private TextView mMessageView;
private ProgressBar mProgressWheel;
+ private Boolean mShowResizedImage = false;
+
public Bitmap mBitmap = null;
private static final String TAG = PreviewImageFragment.class.getSimpleName();
*
* When 'imageFile' or 'ocAccount' are null
*
- * @param imageFile An {@link OCFile} to preview as an image in the fragment
+ * @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 PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) {
+ public PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState, boolean showResizedImage) {
super(fileToDetail);
mAccount = ocAccount;
+ mShowResizedImage = showResizedImage;
mIgnoreFirstSavedState = ignoreFirstSavedState;
}
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");
- }
}
public void onStart() {
super.onStart();
if (getFile() != null) {
- mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel);
- mLoadBitmapTask.execute(new String[]{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
+ );
+ 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()});
+ }
}
}
return true;
}
case R.id.action_send_file: {
- mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
- return true;
+ if (getFile().isImage() && !getFile().isDown()){
+ mContainerActivity.getFileOperationsHelper().sendCachedImage(getFile());
+ return true;
+ } else {
+ mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
+ return true;
+ }
}
case R.id.action_sync_file: {
mContainerActivity.getFileOperationsHelper().syncFile(getFile());
/**
- * Weak reference to the target {@link Progressbar} shown while the load is in progress.
+ * Weak reference to the target {@link ProgressBar} shown while the load is in progress.
*
* Using a weak reference will avoid memory leaks if the target ImageView is retired from memory before the load finishes.
*/
import java.util.Vector;
import android.accounts.Account;
+import android.graphics.Bitmap;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.ui.adapter.FileListListAdapter;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.utils.FileStorageUtils;
OCFile file = mImageFiles.get(i);
Fragment fragment = null;
if (file.isDown()) {
- fragment = new PreviewImageFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)));
-
+ fragment = new PreviewImageFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)), false);
} else if (mDownloadErrors.contains(Integer.valueOf(i))) {
fragment = new FileDownloadFragment(file, mAccount, true);
((FileDownloadFragment)fragment).setError(true);
mDownloadErrors.remove(Integer.valueOf(i));
-
} else {
- fragment = new FileDownloadFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)));
+ fragment = new PreviewImageFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)), true);
}
mObsoletePositions.remove(Integer.valueOf(i));
return fragment;