Better file opening; new ownCloud logo in account settings page
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / FileDetailFragment.java
index ee69555..6b2aa86 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
 import android.app.ActionBar.LayoutParams;\r
+import android.content.ActivityNotFoundException;\r
 import android.content.BroadcastReceiver;\r
 import android.content.Context;\r
 import android.content.Intent;\r
@@ -203,9 +204,13 @@ public class FileDetailFragment extends SherlockFragment implements
                     if (mFile.getMimetype().startsWith("image/")) {\r
                         BitmapFactory.Options options = new Options();\r
                         options.inScaled = true;\r
-                        options.inMutable = false;\r
-                        options.inPreferQualityOverSpeed = false;\r
                         options.inPurgeable = true;\r
+                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {\r
+                            options.inPreferQualityOverSpeed = false;\r
+                        }\r
+                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {\r
+                            options.inMutable = false;\r
+                        }\r
 \r
                         Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
 \r
@@ -224,6 +229,14 @@ public class FileDetailFragment extends SherlockFragment implements
                 } catch (OutOfMemoryError e) {\r
                     preview.setVisibility(View.INVISIBLE);\r
                     Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength());\r
+                    \r
+                } catch (NoSuchFieldError e) {\r
+                    preview.setVisibility(View.INVISIBLE);\r
+                    Log.e(TAG, "Error from access to unexisting field despite protection " + mFile.getFileLength());\r
+                    \r
+                } catch (Throwable t) {\r
+                    preview.setVisibility(View.INVISIBLE);\r
+                    Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength());\r
                 }\r
                 downloadButton.setText(R.string.filedetails_open);\r
                 downloadButton.setOnClickListener(new OnClickListener() {\r
@@ -231,10 +244,11 @@ public class FileDetailFragment extends SherlockFragment implements
                     public void onClick(View v) {\r
                         Intent i = new Intent(Intent.ACTION_VIEW);\r
                         i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype());\r
-                        List list = getActivity().getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY);\r
-                        if (list.size() > 0) {\r
+                        i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
+                        try {\r
                             startActivity(i);\r
-                        } else {\r
+                            \r
+                        } catch (ActivityNotFoundException e) {\r
                             Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();\r
                         }\r
                     }\r