Explorar el Código

always show image preview if there is only enough memory

Bartek Przybylski hace 13 años
padre
commit
f7fb16963b

+ 1 - 1
AndroidManifest.xml

@@ -18,7 +18,7 @@
  -->
 <manifest package="eu.alefzero.owncloud"
     android:versionCode="1"
-    android:versionName="0.1.132B" xmlns:android="http://schemas.android.com/apk/res/android">
+    android:versionName="0.1.133B" xmlns:android="http://schemas.android.com/apk/res/android">
 
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />

+ 2 - 2
res/layout/file_details_fragment.xml

@@ -159,8 +159,8 @@
 
                 <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" />

+ 23 - 3
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

@@ -21,6 +21,7 @@ import java.util.List;
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
+import android.app.ActionBar.LayoutParams;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -28,6 +29,8 @@ import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.graphics.BitmapFactory.Options;
+import android.graphics.Path.FillType;
 import android.net.Uri;
 import android.os.Bundle;
 import android.util.Log;
@@ -195,14 +198,31 @@ public class FileDetailFragment extends SherlockFragment implements
             
             // Update preview
             if (mFile.getStoragePath() != null) {
+                ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);
                 try {
                     if (mFile.getMimetype().startsWith("image/")) {
-                        ImageView preview = (ImageView) getView().findViewById(
-                                R.id.fdPreview);
-                        Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath());
+                        BitmapFactory.Options options = new Options();
+                        options.inScaled = true;
+                        options.inMutable = false;
+                        options.inPreferQualityOverSpeed = false;
+                        options.inPurgeable = true;
+
+                        Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);
+
+                        int width = options.outWidth;
+                        int height = options.outHeight;
+                        int scale = 1;
+                        if (width >= 2048 || height >= 2048) {
+                            scale = (int) (Math.ceil(Math.max(height, width)/2048.));
+                            options.inSampleSize = scale;
+                            bmp.recycle();
+
+                            bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);
+                        }
                         preview.setImageBitmap(bmp);
                     }
                 } catch (OutOfMemoryError e) {
+                    preview.setVisibility(View.INVISIBLE);
                     Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength());
                 }
                 downloadButton.setText(R.string.filedetails_open);