X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/3727806652d401fbac7e4137af51fd0c38422402..6d6a5c3a20a75a3c3a11c275bcab3ffface6ad0e:/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 e4b33f12..7d10ebac 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -17,14 +17,15 @@ */ package eu.alefzero.owncloud.ui.fragment; -import android.app.FragmentTransaction; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.net.Uri; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -52,33 +53,44 @@ public class FileDetailFragment extends SherlockFragment implements public static final String FILE = "FILE"; - private Intent mIntent; - //private View mView; private DownloadFinishReceiver mDownloadFinishReceiver; - private OCFile mFile; - + private Intent mIntent; private int mLayout; - private boolean mEmptyLayout; + private View mView; + private OCFile mFile; + private static final String TAG = "FileDetailFragment"; /** - * Default constructor. When inflated by android -> display empty layout + * Default constructor - contains real layout + */ + public FileDetailFragment(){ + mLayout = R.layout.file_details_fragment; + } + + /** + * Creates a dummy layout. For use if the user never has + * tapped on a file before + * + * @param useEmptyView If true, use empty layout */ - public FileDetailFragment() { - mLayout = R.layout.file_details_empty; - mEmptyLayout = true; + public FileDetailFragment(boolean useEmptyView){ + if(useEmptyView){ + mLayout = R.layout.file_details_empty; + } else { + mLayout = R.layout.file_details_fragment; + } } - + /** - * Custom construtor. Use with a {@link FragmentTransaction}. The intent has - * to contain {@link FileDetailFragment#FILE} with an OCFile and also - * {@link FileDownloader#EXTRA_ACCOUNT} with the account. + * Use this when creating the fragment and display + * a file at the same time * - * @param intent Intent with an account and a file in it for rendering + * @param showDetailsIntent The Intent with the required parameters + * @see FileDetailFragment#updateFileDetails(Intent) */ - public FileDetailFragment(Intent intent) { + public FileDetailFragment(Intent showDetailsIntent) { + mIntent = showDetailsIntent; mLayout = R.layout.file_details_fragment; - mIntent = intent; - mEmptyLayout = false; } @Override @@ -115,6 +127,7 @@ public class FileDetailFragment extends SherlockFragment implements private void updateFileDetails() { mFile = mIntent.getParcelableExtra(FILE); + Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); if (mFile != null) { // set file details @@ -122,47 +135,34 @@ public class FileDetailFragment extends SherlockFragment implements setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile .getMimetype())); setFilesize(mFile.getFileLength()); - // Update preview if (mFile.getStoragePath() != null) { - if (mFile.getMimetype().startsWith("image/")) { - ImageView preview = (ImageView) getView().findViewById( - R.id.fdPreview); - Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath()); - preview.setImageBitmap(bmp); + try { + if (mFile.getMimetype().startsWith("image/")) { + ImageView preview = (ImageView) getView().findViewById( + R.id.fdPreview); + Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath()); + preview.setImageBitmap(bmp); + } + } catch (OutOfMemoryError e) { + Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength()); } + downloadButton.setText("Open file"); + downloadButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype()); + startActivity(i); + } + }); + } else { + // Make download button effective + downloadButton.setOnClickListener(this); } - - // Make download button effective - Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - downloadButton.setOnClickListener(this); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = null; - view = inflater.inflate(mLayout, container, false); - return view; - } - - @Override - public void onStart() { - super.onStart(); - - // Fill in required information about file displaying - if(mIntent == null){ - mIntent = getActivity().getIntent(); - } - - // Fill in the details if the layout is not empty - if(!mEmptyLayout){ - updateFileDetails(); } - } - + private void setFilename(String filename) { TextView tv = (TextView) getView().findViewById(R.id.fdFilename); if (tv != null) @@ -181,20 +181,28 @@ public class FileDetailFragment extends SherlockFragment implements tv.setText(DisplayUtils.bitsToHumanReadable(filesize)); } - /** - * Use this to check if the correct layout is loaded. When android - * instanciates this class using the default constructor, the layout will be - * empty. - * - * Once a user touches a file for the first time, you must instanciate a new - * Fragment with the new FileDetailFragment(true) to inflate the actual - * details - * - * @return If the layout is empty, this method will return true, otherwise - * false - */ - public boolean isEmptyLayout() { - return mEmptyLayout; + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = null; + view = inflater.inflate(mLayout, container, false); + mView = view; + if(mLayout == R.layout.file_details_fragment){ + // Phones will launch an activity with this intent + if(mIntent == null){ + mIntent = getActivity().getIntent(); + } + updateFileDetails(); + } + + return view; + } + + + + @Override + public View getView() { + return super.getView() == null ? mView : super.getView(); } @Override