From: Bartek Przybylski Date: Mon, 25 Jun 2012 18:55:34 +0000 (+0200) Subject: always show image preview if there is only enough memory X-Git-Tag: oc-android-1.4.3~336 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/f7fb16963b2fba0b65245f0d5eed6ccc98c7952c?hp=--cc always show image preview if there is only enough memory --- f7fb16963b2fba0b65245f0d5eed6ccc98c7952c diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b056899c..905391e7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.133B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/res/layout/file_details_fragment.xml b/res/layout/file_details_fragment.xml index e9406425..777f2446 100644 --- a/res/layout/file_details_fragment.xml +++ b/res/layout/file_details_fragment.xml @@ -159,8 +159,8 @@ diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 21d12413..ee695553 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/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);