X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ba6eafccb81f6761ae90c2e1f53833a02b119a2e..fb8194b7ebcc386a6749bf81ec498445ef851f13:/src/com/owncloud/android/ui/fragment/FileDetailFragment.java diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index f37c6094..eca461c5 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -18,6 +18,7 @@ package com.owncloud.android.ui.fragment; import java.io.File; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -65,10 +66,12 @@ import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.webkit.MimeTypeMap; +import android.webkit.WebView.FindListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.MediaController; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import android.widget.VideoView; @@ -105,6 +108,8 @@ import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener; import com.owncloud.android.utils.OwnCloudVersion; import com.owncloud.android.R; + +import eu.alefzero.webdav.OnDatatransferProgressListener; import eu.alefzero.webdav.WebdavClient; import eu.alefzero.webdav.WebdavUtils; @@ -115,27 +120,26 @@ import eu.alefzero.webdav.WebdavUtils; * @author David A. Velasco */ public class FileDetailFragment extends SherlockFragment implements - OnClickListener, OnTouchListener, - ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener { + OnClickListener, + ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener, + FileFragment { public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; - private FileDetailFragment.ContainerActivity mContainerActivity; + private FileFragment.ContainerActivity mContainerActivity; private int mLayout; private View mView; private OCFile mFile; private Account mAccount; private FileDataStorageManager mStorageManager; - private ImageView mPreview; private DownloadFinishReceiver mDownloadFinishReceiver; private UploadFinishReceiver mUploadFinishReceiver; private Handler mHandler; private RemoteOperation mLastRemoteOperation; - private DialogFragment mCurrentDialog; private MediaServiceBinder mMediaServiceBinder = null; private MediaController mMediaController = null; @@ -207,8 +211,6 @@ public class FileDetailFragment extends SherlockFragment implements mView.findViewById(R.id.fdOpenBtn).setOnClickListener(this); mView.findViewById(R.id.fdRemoveBtn).setOnClickListener(this); //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this); - mPreview = (ImageView)mView.findViewById(R.id.fdPreview); - mPreview.setOnTouchListener(this); } updateFileDetails(false); @@ -274,8 +276,6 @@ public class FileDetailFragment extends SherlockFragment implements filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE); getActivity().registerReceiver(mUploadFinishReceiver, filter); - mPreview = (ImageView)mView.findViewById(R.id.fdPreview); // this is here just because it is nullified in onPause() - } @@ -289,10 +289,6 @@ public class FileDetailFragment extends SherlockFragment implements getActivity().unregisterReceiver(mUploadFinishReceiver); mUploadFinishReceiver = null; - if (mPreview != null) { // why? - mPreview = null; - } - } @@ -403,8 +399,7 @@ public class FileDetailFragment extends SherlockFragment implements mFile.isDown() ? R.string.confirmation_remove_local : -1, R.string.common_cancel); confDialog.setOnConfirmationListener(this); - mCurrentDialog = confDialog; - mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION); + confDialog.show(getFragmentManager(), FTAG_CONFIRMATION); break; } case R.id.fdOpenBtn: { @@ -422,38 +417,6 @@ public class FileDetailFragment extends SherlockFragment implements } - @Override - public boolean onTouch(View v, MotionEvent event) { - if (v == mPreview && event.getAction() == MotionEvent.ACTION_DOWN && mFile != null && mFile.isDown()) { - if (mFile.isAudio()) { - if (!mMediaServiceBinder.isPlaying(mFile)) { - Log.d(TAG, "starting playback of " + mFile.getStoragePath()); - mMediaServiceBinder.start(mAccount, mFile); - // this is a patch; need to synchronize this with the onPrepared() coming from MediaPlayer in the MediaService - /* - mMediaController.postDelayed(new Runnable() { - @Override - public void run() { - mMediaController.show(0); - } - } , 300); - */ - } else { - if (mMediaController.isShowing()) { - mMediaController.hide(); - } else { - mMediaController.show(MediaService.MEDIA_CONTROL_LIFE); - } - } - - } else if (mFile.isVideo()) { - startVideoActivity(); - } - } - return false; - } - - private void startVideoActivity() { Intent i = new Intent(getActivity(), VideoActivity.class); i.putExtra(VideoActivity.EXTRA_FILE, mFile); @@ -584,8 +547,6 @@ public class FileDetailFragment extends SherlockFragment implements getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } } - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @Override @@ -597,15 +558,11 @@ public class FileDetailFragment extends SherlockFragment implements mStorageManager.saveFile(mFile); updateFileDetails(mFile, mAccount); } - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @Override public void onCancel(String callerTag) { Log.d(TAG, "REMOVAL CANCELED"); - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @@ -620,10 +577,9 @@ public class FileDetailFragment extends SherlockFragment implements /** - * Can be used to get the file that is currently being displayed. - * @return The file on the screen. + * {@inheritDoc} */ - public OCFile getDisplayedFile(){ + public OCFile getFile(){ return mFile; } @@ -682,11 +638,6 @@ public class FileDetailFragment extends SherlockFragment implements setButtonsForTransferring(); } else if (mFile.isDown()) { - // Update preview - if (mFile.getMimetype().startsWith("image/")) { - BitmapLoader bl = new BitmapLoader(); - bl.execute(new String[]{mFile.getStoragePath()}); - } setButtonsForDown(); @@ -785,9 +736,23 @@ public class FileDetailFragment extends SherlockFragment implements ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false); ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false); getView().findViewById(R.id.fdKeepInSync).setEnabled(false); + + // show the progress bar for the transfer + ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar); + progressBar.setVisibility(View.VISIBLE); + TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText); + progressText.setVisibility(View.VISIBLE); + FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); + if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { + progressText.setText(R.string.downloader_download_in_progress_ticker); + } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) { + progressText.setText(R.string.uploader_upload_in_progress_ticker); + } } } + /** * Enables or disables buttons for a file locally available */ @@ -800,6 +765,10 @@ public class FileDetailFragment extends SherlockFragment implements ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true); getView().findViewById(R.id.fdKeepInSync).setEnabled(true); + + // hides the progress bar + ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar); + progressBar.setVisibility(View.GONE); } } @@ -815,6 +784,10 @@ public class FileDetailFragment extends SherlockFragment implements ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true); getView().findViewById(R.id.fdKeepInSync).setEnabled(true); + + // hides the progress bar + ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar); + progressBar.setVisibility(View.GONE); } } @@ -840,30 +813,6 @@ public class FileDetailFragment extends SherlockFragment implements /** - * Interface to implement by any Activity that includes some instance of FileDetailFragment - * - * @author David A. Velasco - */ - public interface ContainerActivity extends TransferServiceGetter { - - /** - * Callback method invoked when the detail fragment wants to notice its container - * activity about a relevant state the file shown by the fragment. - * - * Added to notify to FileDisplayActivity about the need of refresh the files list. - * - * Currently called when: - * - a download is started; - * - a rename is completed; - * - a deletion is completed; - * - the 'inSync' flag is changed; - */ - public void onFileStateChanged(); - - } - - - /** * Once the file download has finished -> update view * @author Bartek Przybylski */ @@ -1043,80 +992,6 @@ public class FileDetailFragment extends SherlockFragment implements } - class BitmapLoader extends AsyncTask { - @SuppressLint({ "NewApi", "NewApi", "NewApi" }) // to avoid Lint errors since Android SDK r20 - @Override - protected Bitmap doInBackground(String... params) { - Bitmap result = null; - if (params.length != 1) return result; - String storagePath = params[0]; - try { - - BitmapFactory.Options options = new Options(); - options.inScaled = true; - options.inPurgeable = true; - options.inJustDecodeBounds = true; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - options.inPreferQualityOverSpeed = false; - } - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { - options.inMutable = false; - } - - result = BitmapFactory.decodeFile(storagePath, options); - options.inJustDecodeBounds = false; - - int width = options.outWidth; - int height = options.outHeight; - int scale = 1; - if (width >= 2048 || height >= 2048) { - scale = (int) Math.ceil((Math.ceil(Math.max(height, width) / 2048.))); - options.inSampleSize = scale; - } - Display display = getActivity().getWindowManager().getDefaultDisplay(); - Point size = new Point(); - int screenwidth; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { - display.getSize(size); - screenwidth = size.x; - } else { - screenwidth = display.getWidth(); - } - - Log.e("ASD", "W " + width + " SW " + screenwidth); - - if (width > screenwidth) { - scale = (int) Math.ceil((float)width / screenwidth); - options.inSampleSize = scale; - } - - result = BitmapFactory.decodeFile(storagePath, options); - - Log.e("ASD", "W " + options.outWidth + " SW " + options.outHeight); - - } catch (OutOfMemoryError e) { - result = null; - Log.e(TAG, "Out of memory occured for file with size " + storagePath); - - } catch (NoSuchFieldError e) { - result = null; - Log.e(TAG, "Error from access to unexisting field despite protection " + storagePath); - - } catch (Throwable t) { - result = null; - Log.e(TAG, "Unexpected error while creating image preview " + storagePath, t); - } - return result; - } - @Override - protected void onPostExecute(Bitmap result) { - if (result != null && mPreview != null) { - mPreview.setImageBitmap(result); - } - } - - } - /** * {@inheritDoc} */ @@ -1226,4 +1101,14 @@ public class FileDetailFragment extends SherlockFragment implements } + public ProgressBar getProgressBar() { + View v = getView(); + if (v != null) { + return (ProgressBar) v.findViewById(R.id.fdProgressBar); + } else { + return null; + } + } + + }