X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/7c2174d09e376ecc5ebd9a510a66dc7582b173f9..9b9b02c384b4453b3debd703c52e24b6136540f8:/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 627c26ab..505ff6c7 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -27,6 +27,8 @@ import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -44,10 +46,8 @@ import com.actionbarsherlock.app.SherlockFragment; import eu.alefzero.owncloud.DisplayUtils; import eu.alefzero.owncloud.R; -import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.files.services.FileDownloader; -import eu.alefzero.owncloud.utils.OwnCloudVersion; /** * This Fragment is used to display the details about a file. @@ -165,6 +165,17 @@ public class FileDetailFragment extends SherlockFragment implements getActivity().startService(i); } + + /** + * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced. + * + * @return True when the fragment was created with the empty layout. + */ + public boolean isEmpty() { + return mLayout == R.layout.file_details_empty; + } + + /** * Can be used to get the file that is currently being displayed. * @return The file on the screen. @@ -190,7 +201,8 @@ public class FileDetailFragment extends SherlockFragment implements */ public void updateFileDetails() { - if (mFile != null && mLayout == R.layout.file_details_fragment) { + if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) { + Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); // set file details setFilename(mFile.getFileName()); @@ -203,8 +215,8 @@ public class FileDetailFragment extends SherlockFragment implements setTimeModified(mFile.getModificationTimestamp()); - // Update preview if (mFile.getStoragePath() != null) { + // Update preview ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview); try { if (mFile.getMimetype().startsWith("image/")) { @@ -220,17 +232,21 @@ public class FileDetailFragment extends SherlockFragment implements 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(); + if (bmp != null) { + 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); + bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options); + } + } + if (bmp != null) { + preview.setImageBitmap(bmp); } - preview.setImageBitmap(bmp); } } catch (OutOfMemoryError e) { preview.setVisibility(View.INVISIBLE); @@ -244,6 +260,8 @@ public class FileDetailFragment extends SherlockFragment implements preview.setVisibility(View.INVISIBLE); Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t); } + + // Change download button to open button downloadButton.setText(R.string.filedetails_open); downloadButton.setOnClickListener(new OnClickListener() { @Override @@ -262,7 +280,7 @@ public class FileDetailFragment extends SherlockFragment implements try { Intent i = new Intent(Intent.ACTION_VIEW); mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); - if (mimeType != mFile.getMimetype()) { + if (mimeType != null && !mimeType.equals(mFile.getMimetype())) { i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); @@ -294,6 +312,7 @@ public class FileDetailFragment extends SherlockFragment implements } } + /** * Updates the filename in view * @param filename to set @@ -387,5 +406,4 @@ public class FileDetailFragment extends SherlockFragment implements } - }