From: tobiasKaminsky Date: Sat, 13 Sep 2014 08:10:57 +0000 (+0200) Subject: Re-added thumbnail generation for files that are not images. X-Git-Tag: oc-android-1.7.0_signed~163^2~8^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/2e5d99463df0187009cadec3e1d02a3e32346cb1?hp=--cc Re-added thumbnail generation for files that are not images. --- 2e5d99463df0187009cadec3e1d02a3e32346cb1 diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 5a069e72..8e281cda 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -187,32 +187,32 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { } else { // Download thumbnail from server // Commented out as maybe changes to client library are needed -// DefaultHttpClient httpclient = new DefaultHttpClient(); -// try { -// httpclient.getCredentialsProvider().setCredentials( -// new AuthScope(mClient.getBaseUri().toString().replace("https://", ""), 443), -// new UsernamePasswordCredentials(mClient.getCredentials().getUsername(), mClient.getCredentials().getAuthToken())); -// -// -// HttpGet httpget = new HttpGet(mClient.getBaseUri() + "/ocs/v1.php/thumbnail?x=50&y=50&path=" + URLEncoder.encode(file.getRemotePath(), "UTF-8")); -// HttpResponse response = httpclient.execute(httpget); -// HttpEntity entity = response.getEntity(); -// -// if (entity != null) { -// byte[] bytes = EntityUtils.toByteArray(entity); -// Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); -// thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px); -// -// // Add thumbnail to cache -// if (thumbnail != null){ -// addBitmapToCache(imageKey, thumbnail); -// } -// } -// } catch(Exception e){ -// e.printStackTrace(); -// }finally { -// httpclient.getConnectionManager().shutdown(); -// } + DefaultHttpClient httpclient = new DefaultHttpClient(); + try { + httpclient.getCredentialsProvider().setCredentials( + new AuthScope(mClient.getBaseUri().toString().replace("https://", ""), 443), + new UsernamePasswordCredentials(mClient.getCredentials().getUsername(), mClient.getCredentials().getAuthToken())); + + + HttpGet httpget = new HttpGet(mClient.getBaseUri() + "/ocs/v1.php/thumbnail?x=50&y=50&path=" + URLEncoder.encode(file.getRemotePath(), "UTF-8")); + HttpResponse response = httpclient.execute(httpget); + HttpEntity entity = response.getEntity(); + + if (entity != null) { + byte[] bytes = EntityUtils.toByteArray(entity); + Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); + thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px); + + // Add thumbnail to cache + if (thumbnail != null){ + addBitmapToCache(imageKey, thumbnail); + } + } + } catch(Exception e){ + e.printStackTrace(); + }finally { + httpclient.getConnectionManager().shutdown(); + } } } return thumbnail; @@ -373,6 +373,8 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { task.execute(file); } } + } else { + fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype(), file.getFileName())); } if (checkIfFileIsSharedWithMe(file)) {