always show image preview if there is only enough memory
authorBartek Przybylski <bart.p.pl@gmail.com>
Mon, 25 Jun 2012 18:55:34 +0000 (20:55 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Mon, 25 Jun 2012 18:55:34 +0000 (20:55 +0200)
AndroidManifest.xml
res/layout/file_details_fragment.xml
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

index b056899..905391e 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.132B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.133B" xmlns:android="http://schemas.android.com/apk/res/android">\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
index e940642..777f244 100644 (file)
 
                 <ImageView
                     android:id="@+id/fdPreview"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
                     android:layout_centerHorizontal="true"
                     android:layout_marginTop="16dp"
                     android:src="@drawable/owncloud_logo" />
index 21d1241..ee69555 100644 (file)
@@ -21,6 +21,7 @@ import java.util.List;
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
+import android.app.ActionBar.LayoutParams;\r
 import android.content.BroadcastReceiver;\r
 import android.content.Context;\r
 import android.content.Intent;\r
@@ -28,6 +29,8 @@ import android.content.IntentFilter;
 import android.content.pm.PackageManager;\r
 import android.graphics.Bitmap;\r
 import android.graphics.BitmapFactory;\r
+import android.graphics.BitmapFactory.Options;\r
+import android.graphics.Path.FillType;\r
 import android.net.Uri;\r
 import android.os.Bundle;\r
 import android.util.Log;\r
@@ -195,14 +198,31 @@ public class FileDetailFragment extends SherlockFragment implements
             \r
             // Update preview\r
             if (mFile.getStoragePath() != null) {\r
+                ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);\r
                 try {\r
                     if (mFile.getMimetype().startsWith("image/")) {\r
-                        ImageView preview = (ImageView) getView().findViewById(\r
-                                R.id.fdPreview);\r
-                        Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath());\r
+                        BitmapFactory.Options options = new Options();\r
+                        options.inScaled = true;\r
+                        options.inMutable = false;\r
+                        options.inPreferQualityOverSpeed = false;\r
+                        options.inPurgeable = true;\r
+\r
+                        Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+\r
+                        int width = options.outWidth;\r
+                        int height = options.outHeight;\r
+                        int scale = 1;\r
+                        if (width >= 2048 || height >= 2048) {\r
+                            scale = (int) (Math.ceil(Math.max(height, width)/2048.));\r
+                            options.inSampleSize = scale;\r
+                            bmp.recycle();\r
+\r
+                            bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+                        }\r
                         preview.setImageBitmap(bmp);\r
                     }\r
                 } catch (OutOfMemoryError e) {\r
+                    preview.setVisibility(View.INVISIBLE);\r
                     Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength());\r
                 }\r
                 downloadButton.setText(R.string.filedetails_open);\r