Merge remote-tracking branch 'remotes/upstream/resizeCache' into beta
authortobiasKaminsky <tobias@kaminsky.me>
Thu, 29 Oct 2015 17:37:28 +0000 (18:37 +0100)
committertobiasKaminsky <tobias@kaminsky.me>
Thu, 29 Oct 2015 17:37:28 +0000 (18:37 +0100)
1  2 
CHANGELOG.md
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
src/com/owncloud/android/ui/activity/Preferences.java
src/com/owncloud/android/ui/adapter/DiskLruImageCache.java

diff --combined CHANGELOG.md
@@@ -1,12 -1,60 +1,13 @@@
 -## 1.8.0 (September 2015)
 -- New MATERIAL DESIGN theme
 -- Updated FILE TYPE ICONS
 -- Preview TXT files within the app
 -- COPY files & folders
 -- Preview the full file/folder name from the long press menu
 -- Set a file as FAVORITE (kept-in-sync) from the CONTEXT MENU
 -- Updated CONFLICT RESOLUTION dialog (wording)
 -- Updated background for images with TRANSPARENCY in GALLERY
 -- Hidden files will not enforce list view instead of GRID VIEW (folders from Picasa & others)
 -- Security:
 -  + Updated network stack with security fixes (Jackrabbit 2.10.1)
 -- Bugs fixed:
 -  + Fixed crash when ETag is lost
 -  + Passcode creation not restarted on device rotation
 -  + Recovered share icon shown on folders 'shared with me'
 -  + User name added to subject when sending a share link through e-mail (fixed on SAMLed apps)
 -
 -## 1.7.2 (July 2015)
 -- New navigation drawer
 -- Improved Passcode
 -- Automatic grid view just for folders full of images
 -- More characters allowed in file names
 -- Support for servers in same domain, different path
 -- Bugs fixed:
 -  + Frequent crashes in folder with several images
 -  + Sync error in servers with huge quota and external storage enable
 -  + Share by link error 
 -  + Some other crashes and minor bugs
 -
 -## 1.7.1 (April 2015)
 -
 -- Share link even with password enforced by server
 -- Get the app ready for oc 8.1 servers
 -- Added option to create new folder in uploads from external apps
 -- Improved management of deleted users
 -- Bugs fixed
 -  + Fixed crash on Android 2.x devices
 -  + Improvements on uploads
 -
 -## 1.7.0 (February 2015)
 -
 -- Download full folders
 -- Grid view for images
 -- Remote thumbnails (OC Server 8.0+)
 -- Added number of files and folders at the end of the list
 -- "Open with" in contextual menu
 -- Downloads added to Media Provider
 -- Uploads:
 -  + Local thumbnails in section "Files"
 -  + Multiple selection in "Content from other apps" (Android 4.3+)
 -- Gallery: 
 -  + proper handling of EXIF
 -  + obey sorting in the list of files
 -- Settings view updated
 -- Improved subjects in e-mails
 -- Bugs fixed
 -
 -
 -
 +# 2015-10-29
 +- PR [#1099](https://github.com/owncloud/android/pull/1099) "Switch list vs grid" merged
 +- PR [#1100](https://github.com/owncloud/android/pull/1100) "Material FAB with speed dial implementation" merged
 +- PR [#1209](https://github.com/owncloud/android/pull/1209) "Material buttons - before in #1090" merged
 +- PR [#1205](https://github.com/owncloud/android/pull/1205) "Switch between online and offline files" merged
++- PR [#1195](https://github.com/owncloud/android/pull/1195) "Resize Cache" merged
 +
 +
 +# 2015-10-26
 +- start of branch
 +- PR [#745](https://github.com/owncloud/android/pull/745) merged
 +- PR [#1044](https://github.com/owncloud/android/pull/1044) merged: < 8.1: GalleryPlus app needed, >= 8.2 Gallery app needed
 +- PR [#1111](https://github.com/owncloud/android/pull/1111) merged
diff --combined res/values/strings.xml
@@@ -23,7 -23,8 +23,7 @@@
      <!-- TODO re-enable when "Accounts" is available in Navigation Drawer -->
      <!--<string name="drawer_item_accounts">Accounts</string>-->
      <string name="drawer_item_all_files">All files</string>
 -    <!-- TODO re-enable when "On Device" is available
 -    <string name="drawer_item_on_device">On device</string>-->
 +    <string name="drawer_item_on_device">On device</string>
      <string name="drawer_item_settings">Settings</string>
      <string name="drawer_item_logs">Logs</string>
        <string name="drawer_close">Close</string>
      <string name="placeholder_filesize">389 KB</string>
      <string name="placeholder_timestamp">2012/05/18 12:23 PM</string>
      <string name="placeholder_media_time">12:23:45</string>
 -
 -    <string name="instant_upload_on_wifi">Upload pictures via WiFi only</string>
 -    <string name="instant_video_upload_on_wifi">Upload videos via WiFi only</string>
 +    
 +    <string name="instant_upload_on_wifi">Upload pictures via wifi only</string>
 +    <string name="instant_upload_on_charging">Upload when charging only</string>
 +    <string name="instant_video_upload_on_wifi">Upload videos via wifi only</string>
 +    <string name="instant_video_upload_on_charging">Upload when charging only</string>
      <string name="instant_upload_path">/InstantUpload</string>
      <string name="conflict_title">File conflict</string>
      <string name="conflict_message">Which files do you want to keep? If you select both versions, the local file will have a number added to its name.</string>
      <string name="preview_image_error_unknown_format">This image cannot be shown</string>
  
      <string name="error__upload__local_file_not_copied">%1$s could not be copied to %2$s local folder</string>
 -    <string name="prefs_instant_upload_path_title">Upload Path</string>
 +    <string name="prefs_instant_upload_path_title">Upload path</string>
  
        <string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your
                administrator.</string>
      <string name="prefs_category_instant_uploading">Instant Uploads</string>
        <string name="prefs_category_security">Security</string>
  
 -      <string name="prefs_instant_video_upload_path_title">Upload Video Path</string>
 +      <string name="prefs_instant_video_upload_path_title">Upload video path</string>
      <string name="download_folder_failed_content">Download of %1$s folder could not be completed</string>
  
        <string name="shared_subject_header">shared</string>
      <string name="file_list__footer__files">%1$d files</string>
      <string name="file_list__footer__files_and_folder">%1$d files, 1 folder</string>
      <string name="file_list__footer__files_and_folders">%1$d files, %2$d folders</string>
 +    <string name="action_switch_grid_view">Switch to grid view</string>
 +    <string name="action_switch_list_view">Switch to list view</string>
+     <string name="common_category">Common</string>
+     <string name="pref_cache_size">Cache size</string>
  </resources>
diff --combined res/xml/preferences.xml
@@@ -3,7 -3,7 +3,7 @@@
    ownCloud Android client application
  
    Copyright (C) 2012  Bartek Przybylski
 -  Copyright (C) 2015 ownCloud Inc.
 +  Copyright (C) 2012-2013 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,
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
  <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
 -    <PreferenceCategory android:title="@string/prefs_category_accounts" android:key="accounts_category">
 +    <PreferenceCategory
 +              android:title="@string/prefs_category_accounts"
 +              android:key="accounts_category">
      </PreferenceCategory>
      
        <PreferenceCategory android:title="@string/prefs_category_security">
 -          <android.preference.CheckBoxPreference android:title="@string/prefs_passcode" android:key="set_pincode" />
 +              <!-- ListPreference
 +            android:key="select_oc_account"
 +            android:title="@string/prefs_select_oc_account"
 +            android:summary="@string/prefs_summary_select_oc_account"
 +            / -->
 +              <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:title="@string/prefs_pincode" android:key="set_pincode"
 +                      android:summary="@string/prefs_pincode_summary"/>
        </PreferenceCategory>
  
 -    <PreferenceCategory android:title="@string/prefs_category_instant_uploading" android:key="instant_uploading_category">
 -         <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
 -                              android:title="@string/prefs_instant_upload"
 -                              android:summary="@string/prefs_instant_upload_summary"/>
 -         <com.owncloud.android.ui.PreferenceWithLongSummary
 -                                                      android:title="@string/prefs_instant_upload_path_title"
 -                                                      android:key="instant_upload_path" />
 +    <PreferenceCategory android:title="@string/prefs_category_instant_uploading"
 +              android:key="instant_uploading_category">
 +
 +          <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
 +                      android:key="instant_uploading"
 +              android:title="@string/prefs_instant_upload"
 +              android:summary="@string/prefs_instant_upload_summary"/>
 +              <com.owncloud.android.ui.PreferenceWithLongSummary
 +                      android:dependency="instant_uploading"
 +                      android:disableDependentsState="true"
 +                      android:title="@string/prefs_instant_upload_path_title"
 +                      android:key="instant_upload_path" />
            <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
 -                                              android:title="@string/instant_upload_on_wifi"
 -                                              android:key="instant_upload_on_wifi"/>
 -          <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
 -                              android:title="@string/prefs_instant_video_upload"
 -                              android:summary="@string/prefs_instant_video_upload_summary" />
 +                      android:dependency="instant_uploading"
 +                      android:disableDependentsState="true"
 +              android:title="@string/instant_upload_on_wifi"
 +              android:key="instant_upload_on_wifi"/>
 +              <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
 +                      android:dependency="instant_uploading"
 +                      android:disableDependentsState="true"
 +                      android:title="@string/instant_upload_on_charging"
 +                      android:key="instant_upload_on_charging"/>
 +
 +              <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
 +                      android:key="instant_video_uploading"
 +              android:title="@string/prefs_instant_video_upload"
 +              android:summary="@string/prefs_instant_video_upload_summary" />
            <com.owncloud.android.ui.PreferenceWithLongSummary
 -                                                      android:title="@string/prefs_instant_video_upload_path_title"
 -                                                      android:key="instant_video_upload_path" />
 +                      android:dependency="instant_video_uploading"
 +                      android:disableDependentsState="true"
 +                      android:title="@string/prefs_instant_video_upload_path_title"
 +                      android:key="instant_video_upload_path" />
            <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
 -                                              android:title="@string/instant_video_upload_on_wifi"
 -                                              android:key="instant_video_upload_on_wifi"/>
 -          <!-- DISABLED FOR RELEASE UNTIL FIXED
 +                      android:dependency="instant_video_uploading"
 +                      android:disableDependentsState="true"
 +              android:title="@string/instant_video_upload_on_wifi"
 +              android:key="instant_video_upload_on_wifi"/>
 +              <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
 +                      android:dependency="instant_video_uploading"
 +                      android:disableDependentsState="true"
 +                      android:title="@string/instant_video_upload_on_charging"
 +                      android:key="instant_video_upload_on_charging"/>
 +      </PreferenceCategory>
 +      
 +      <PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
 +              <!-- DISABLED FOR RELEASE UNTIL FIXED
            CheckBoxPreference android:key="log_to_file"
                                android:title="@string/prefs_log_title"
                                android:summary="@string/prefs_log_summary"/>
                <Preference             android:key="log_history"
                                android:title="@string/prefs_log_title_history"
                                android:summary="@string/prefs_log_summary_history"/ -->
-               <Preference android:title="@string/prefs_help" android:key="help" />
-               <Preference android:title="@string/prefs_recommend" android:key="recommend" />
-               <Preference android:title="@string/prefs_feedback" android:key="feedback" />
-               <Preference android:title="@string/prefs_imprint" android:key="imprint" />
+                         
+     </PreferenceCategory>
+       <PreferenceCategory android:title="@string/common_category" android:key="common_category">
+               <EditTextPreference android:title="@string/pref_cache_size"
+                                                       android:key="pref_cache_size"
+                                                       android:digits="0123456789"/>
+       </PreferenceCategory>
  
-               <Preference             android:id="@+id/about_app"
-                       android:title="@string/about_title"
-                       android:key="about_app" />
+       <PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
+     <Preference android:title="@string/prefs_help" android:key="help" />
+     <Preference android:title="@string/prefs_recommend" android:key="recommend" />
+     <Preference android:title="@string/prefs_feedback" android:key="feedback" />
+     <Preference android:title="@string/prefs_imprint" android:key="imprint" />
+                         
+       <Preference             android:id="@+id/about_app" 
+                                       android:title="@string/about_title" 
+                                       android:key="about_app" />
        </PreferenceCategory>
 -    
 +
  
  </PreferenceScreen>
@@@ -29,25 -29,18 +29,25 @@@ import org.apache.commons.httpclient.Ht
  import org.apache.commons.httpclient.methods.GetMethod;
  
  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.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;
  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;
@@@ -147,14 -140,35 +147,36 @@@ public class ThumbnailsCacheManager 
          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<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();
 -                //} else {  do nothing
 +                    thumbnail = doFileInBackground(mIsThumbnail);
 +                } else {
 +                    // do nothing
                  }
  
                  }catch(Throwable t){
                          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);
                      }
                  }
              }
           * @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 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()) {
 -
 -                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 temp = BitmapUtils.decodeSampledBitmapFromFile(
 -                            file.getStoragePath(), px, px);
 -                    Bitmap bitmap = ThumbnailUtils.extractThumbnail(temp, px, px);
 +                    Bitmap tempBitmap = BitmapUtils.decodeSampledBitmapFromFile(
 +                            file.getStoragePath(), pxW, pxH);
 +                    Bitmap bitmap = ThumbnailUtils.extractThumbnail(tempBitmap, pxW, pxH);
  
                      if (bitmap != null) {
                          // Handle PNG
                          if (file.getMimetype().equalsIgnoreCase("image/png")) {
 -                            bitmap = handlePNG(bitmap, px);
 +                            bitmap = handlePNG(bitmap, pxW);
                          }
  
 -                        thumbnail = addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), px);
 +                        thumbnail = addThumbnailToCache(imageKey, bitmap,
 +                                                        file.getStoragePath(), pxW, pxH);
  
                          file.setNeedsUpdateThumbnail(false);
                          mStorageManager.saveFile(file);
                      if (mClient != null && serverOCVersion != null) {
                          if (serverOCVersion.supportsRemoteThumbnails()) {
                              try {
 -                                String uri = mClient.getBaseUri() + "" +
 -                                        "/index.php/apps/files/api/v1/thumbnail/" +
 -                                        px + "/" + px + 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) {
 -                                    InputStream inputStream = get.getResponseBodyAsStream();
 -                                    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
 -                                    thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
 -
 -                                    // Handle PNG
 -                                    if (file.getMimetype().equalsIgnoreCase("image/png")) {
 -                                        thumbnail = handlePNG(thumbnail, px);
 +                                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 {
 +                                        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();
                              }
              return resultBitmap;
          }
  
 -        private Bitmap doFileInBackground() {
 +        private Bitmap doFileInBackground(Boolean mIsThumbnail) {
 +            Bitmap thumbnail = null;
              File file = (File)mFile;
  
              final String imageKey = String.valueOf(file.hashCode());
  
              // Check disk cache in background thread
 -            Bitmap thumbnail = getBitmapFromDiskCache(imageKey);
 +            thumbnail = getBitmapFromDiskCache(imageKey);
  
              // 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;
@@@ -70,6 -70,7 +70,7 @@@ import com.owncloud.android.authenticat
  import com.owncloud.android.authentication.AuthenticatorActivity;
  import com.owncloud.android.datamodel.FileDataStorageManager;
  import com.owncloud.android.datamodel.OCFile;
+ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
  import com.owncloud.android.db.DbHandler;
  import com.owncloud.android.files.FileOperationsHelper;
  import com.owncloud.android.files.services.FileDownloader;
@@@ -237,6 -238,27 +238,27 @@@ public class Preferences extends Prefer
              
          }
  
+         final Preference pCacheSize = findPreference("pref_cache_size");
+         if (pCacheSize != null){
+             final SharedPreferences appPrefs =
+                     PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+             Long cacheSize = ThumbnailsCacheManager.getMaxSize();
+             pCacheSize.setSummary(cacheSize + " Mb");
+             pCacheSize.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+                 @Override
+                 public boolean onPreferenceChange(Preference preference, Object newValue) {
+                     Long size = Long.decode((String) newValue);
+                     if (ThumbnailsCacheManager.setMaxSize(size)){
+                         appPrefs.edit().putString("pref_cache_size", size.toString());
+                         pCacheSize.setSummary(size + " MB");
+                         return true;
+                     } else {
+                         return false;
+                     }
+                 }
+             });
+         }
          PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
          
          boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
              mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPathWiFi);
              mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPath);
          } else {
 -            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi);
 -            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath);
 +//            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi);
 +//            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath);
          }
      }
      
              mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi);
              mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath);
          } else {
 -            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
 -            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
 +//            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
 +//            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
          }
      }
  
          SharedPreferences appPrefs =
                  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
          mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path));
 -        mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
 +//        mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
      }
  
      /**
@@@ -120,10 -120,10 +120,10 @@@ public class DiskLruImageCache 
              }
              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 {
              e.printStackTrace();
          }
      }
+     public void setMaxSize(long maxSize){
+         mDiskCache.setMaxSize(maxSize);
+     }
+     public long getMaxSize(){
+         return mDiskCache.getMaxSize();
+     }
  }