reduce permissions, optimize bitmap displaying
authorBartek Przybylski <bart.p.pl@gmail.com>
Thu, 12 Jul 2012 20:02:30 +0000 (22:02 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Thu, 12 Jul 2012 20:02:30 +0000 (22:02 +0200)
AndroidManifest.xml
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

index 408d148..3af24ef 100644 (file)
@@ -29,7 +29,6 @@
     <uses-permission android:name="android.permission.READ_SYNC_STATS" />\r
     <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />\r
     <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />\r
-    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />\r
     <uses-permission android:name="android.permission.BROADCAST_STICKY" />\r
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />\r
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />\r
@@ -41,8 +40,6 @@
 \r
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >\r
     </uses-permission>\r
-    <uses-permission android:name="android.permission.READ_CONTACTS" />\r
-    <uses-permission android:name="android.permission.WRITE_CONTACTS" />\r
 \r
     <application\r
         android:icon="@drawable/icon"\r
index db91641..bbc2473 100644 (file)
@@ -205,7 +205,6 @@ public class FileDetailFragment extends SherlockFragment implements
         mDownloadFinishReceiver = null;\r
         if (mPreview != null) {\r
             mPreview = null;\r
-            System.gc();\r
         }\r
     }\r
 \r
@@ -848,6 +847,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 BitmapFactory.Options options = new Options();\r
                 options.inScaled = true;\r
                 options.inPurgeable = true;\r
+                options.inJustDecodeBounds = true;\r
                 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {\r
                     options.inPreferQualityOverSpeed = false;\r
                 }\r
@@ -856,39 +856,36 @@ public class FileDetailFragment extends SherlockFragment implements
                 }\r
 \r
                 result = BitmapFactory.decodeFile(storagePath, options);\r
+                options.inJustDecodeBounds = false;\r
+\r
+                int width = options.outWidth;\r
+                int height = options.outHeight;\r
+                int scale = 1;\r
+                boolean recycle = false;\r
+                if (width >= 2048 || height >= 2048) {\r
+                    scale = (int) Math.ceil((Math.ceil(Math.max(height, width) / 2048.)));\r
+                    options.inSampleSize = scale;\r
+                }\r
+                Display display = getActivity().getWindowManager().getDefaultDisplay();\r
+                Point size = new Point();\r
+                int screenwidth;\r
+                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {\r
+                    display.getSize(size);\r
+                    screenwidth = size.x;\r
+                } else {\r
+                    screenwidth = display.getWidth();\r
+                }\r
 \r
-                if (result != null) {\r
-                    int width = options.outWidth;\r
-                    int height = options.outHeight;\r
-                    int scale = 1;\r
-                    boolean recycle = false;\r
-                    if (width >= 2048 || height >= 2048) {\r
-                        scale = (int) (Math.ceil(Math.max(height, width) / 2048.));\r
-                        options.inSampleSize = scale;\r
-                        recycle = true;\r
-                    }\r
-                    Display display = getActivity().getWindowManager().getDefaultDisplay();\r
-                    Point size = new Point();\r
-                    int screenwidth;\r
-                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {\r
-                        display.getSize(size);\r
-                        screenwidth = size.x;\r
-                    } else {\r
-                        screenwidth = display.getWidth();\r
-                    }\r
+                Log.e("ASD", "W " + width + " SW " + screenwidth);\r
 \r
-                    Log.e("ASD", "W " + width + " SW " + screenwidth);\r
+                if (width > screenwidth) {\r
+                    scale = (int) Math.ceil((Math.ceil(Math.max(height, width) / screenwidth)));\r
+                    options.inSampleSize = scale;\r
+                }\r
 \r
-                    if (width > screenwidth) {\r
-                        scale = (int) (Math.ceil(Math.max(height, width) / screenwidth));\r
-                        options.inSampleSize = scale;\r
-                        recycle = true;\r
-                    }\r
+                result = BitmapFactory.decodeFile(storagePath, options);\r
 \r
-                    if (recycle)\r
-                        result.recycle();\r
-                    result = BitmapFactory.decodeFile(storagePath, options);\r
-                }\r
+                Log.e("ASD", "W " + options.outWidth + " SW " + options.outHeight);\r
 \r
             } catch (OutOfMemoryError e) {\r
                 result = null;\r