+
+ private Bitmap doOCFileInBackground() {
+ Bitmap thumbnail = null;
+ OCFile file = (OCFile)mFile;
+
+ final String imageKey = String.valueOf(file.getRemoteId());
+
+ // Check disk cache in background thread
+ thumbnail = getBitmapFromDiskCache(imageKey);
+
+ // Not found in disk cache
+ if (thumbnail == null || file.needsUpdateThumbnail()) {
+
+ int px = getThumbnailDimension();
+
+ if (file.isDown()) {
+ Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
+ file.getStoragePath(), px, px);
+
+ if (bitmap != null) {
+ thumbnail = addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), px);
+
+ file.setNeedsUpdateThumbnail(false);
+ mStorageManager.saveFile(file);
+ }
+
+ } 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) {
+ try {
+ int status = -1;
+
+ 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);
+ 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);
+
+ // Add thumbnail to cache
+ if (thumbnail != null) {
+ addBitmapToCache(imageKey, thumbnail);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ Log_OC.d(TAG, "Server too old");
+ }
+ }
+ }
+ }
+
+ return thumbnail;
+
+ }
+
+ private Bitmap doFileInBackground() {
+ Bitmap thumbnail = null;
+ File file = (File)mFile;
+
+ final String imageKey = String.valueOf(file.hashCode());
+
+ // Check disk cache in background thread
+ thumbnail = getBitmapFromDiskCache(imageKey);
+
+ // Not found in disk cache
+ if (thumbnail == null) {
+
+ int px = getThumbnailDimension();
+
+ Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
+ file.getAbsolutePath(), px, px);
+
+ if (bitmap != null) {
+ thumbnail = addThumbnailToCache(imageKey, bitmap, file.getPath(), px);
+ }
+ }
+ return thumbnail;
+ }
+