import android.graphics.Bitmap;\r
import android.graphics.BitmapFactory;\r
import android.graphics.BitmapFactory.Options;\r
+import android.graphics.drawable.BitmapDrawable;\r
+import android.graphics.drawable.Drawable;\r
import android.net.Uri;\r
import android.os.Bundle;\r
import android.util.Log;\r
\r
import eu.alefzero.owncloud.DisplayUtils;\r
import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
import eu.alefzero.owncloud.datamodel.OCFile;\r
import eu.alefzero.owncloud.files.services.FileDownloader;\r
-import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
\r
/**\r
* This Fragment is used to display the details about a file.\r
getActivity().startService(i);\r
}\r
\r
+\r
+ /**\r
+ * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.\r
+ * \r
+ * @return True when the fragment was created with the empty layout.\r
+ */\r
+ public boolean isEmpty() {\r
+ return mLayout == R.layout.file_details_empty;\r
+ }\r
+\r
+ \r
/**\r
* Can be used to get the file that is currently being displayed.\r
* @return The file on the screen.\r
*/\r
public void updateFileDetails() {\r
\r
- if (mFile != null && mLayout == R.layout.file_details_fragment) {\r
+ if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) {\r
+ \r
Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
// set file details\r
setFilename(mFile.getFileName());\r
\r
setTimeModified(mFile.getModificationTimestamp());\r
\r
- // Update preview\r
if (mFile.getStoragePath() != null) {\r
+ // Update preview\r
ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);\r
try {\r
if (mFile.getMimetype().startsWith("image/")) {\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
+ if (bmp != null) {\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
+ bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+ }\r
+ }\r
+ if (bmp != null) {\r
+ preview.setImageBitmap(bmp);\r
}\r
- preview.setImageBitmap(bmp);\r
}\r
} catch (OutOfMemoryError e) {\r
preview.setVisibility(View.INVISIBLE);\r
preview.setVisibility(View.INVISIBLE);\r
Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t);\r
}\r
+ \r
+ // Change download button to open button\r
downloadButton.setText(R.string.filedetails_open);\r
downloadButton.setOnClickListener(new OnClickListener() {\r
@Override\r
try {\r
Intent i = new Intent(Intent.ACTION_VIEW);\r
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));\r
- if (mimeType != mFile.getMimetype()) {\r
+ if (mimeType != null && !mimeType.equals(mFile.getMimetype())) {\r
i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType);\r
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
startActivity(i);\r
}\r
}\r
\r
+ \r
/**\r
* Updates the filename in view\r
* @param filename to set\r
\r
}\r
\r
-\r
}\r