private ProgressBar mProgressWheel;
public Bitmap mBitmap = null;
-
+
private static final String TAG = PreviewImageFragment.class.getSimpleName();
private boolean mIgnoreFirstSavedState;
-
+
private LoadBitmapTask mLoadBitmapTask = null;
return frag;
}
-
+
/**
* Creates an empty fragment for image previews.
public PreviewImageFragment() {
mIgnoreFirstSavedState = false;
}
-
-
+
+
/**
* {@inheritDoc}
*/
mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST);
setHasOptionsMenu(true);
}
-
+
/**
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
+ Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.preview_image_fragment, container, false);
mImageView = (TouchImageViewCustom) view.findViewById(R.id.image);
throw new IllegalStateException("There is no local file to preview");
}
}
-
+
/**
* {@inheritDoc}
super.onSaveInstanceState(outState);
outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile());
}
-
+
@Override
public void onStart() {
mLoadBitmapTask.execute(getFile());
}
}
-
-
+
+
@Override
public void onStop() {
Log_OC.d(TAG, "onStop starts");
}
super.onStop();
}
-
+
/**
* {@inheritDoc}
*/
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
-
+
if (mContainerActivity.getStorageManager() != null) {
// Update the file
setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId()));
-
+
FileMenuFilter mf = new FileMenuFilter(
getFile(),
mContainerActivity.getStorageManager().getAccount(),
);
mf.filter(menu);
}
-
+
// additional restriction for this fragment
// TODO allow renaming in PreviewImageFragment
MenuItem item = menu.findItem(R.id.action_rename_file);
item.setVisible(false);
item.setEnabled(false);
}
-
+
// additional restriction for this fragment
// TODO allow refresh file in PreviewImageFragment
item = menu.findItem(R.id.action_sync_file);
item.setVisible(false);
item.setEnabled(false);
}
-
+
+ // additional restriction for this fragment
+ item = menu.findItem(R.id.action_copy);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+
}
-
-
+
/**
* {@inheritDoc}
*/
return false;
}
}
-
+
private void seeDetails() {
- mContainerActivity.showDetails(getFile());
+ mContainerActivity.showDetails(getFile());
}
super.onDestroy();
}
-
+
/**
* Opens the previewed image with an external application.
*/
mContainerActivity.getFileOperationsHelper().openFile(getFile());
finish();
}
-
+
private class LoadBitmapTask extends AsyncTask<OCFile, Void, LoadImage> {
*/
private final WeakReference<TextView> mMessageViewRef;
-
+
/**
* Weak reference to the target {@link ProgressBar} shown while the load is in progress.
*
*/
private final WeakReference<ProgressBar> mProgressWheelRef;
-
+
/**
- * Error message to show when a load fails
+ * Error message to show when a load fails
*/
private int mErrorMessageId;
-
-
+
+
/**
* Constructor.
- *
- * @param imageView Target {@link ImageView} where the bitmap will be loaded into.
+ *
+ * @param imageView Target {@link ImageView} where the bitmap will be loaded into.
*/
public LoadBitmapTask(ImageViewCustom imageView, TextView messageView,
ProgressBar progressWheel) {
mMessageViewRef = new WeakReference<TextView>(messageView);
mProgressWheelRef = new WeakReference<ProgressBar>(progressWheel);
}
-
+
@Override
protected LoadImage doInBackground(OCFile... params) {
Bitmap result = null;
} catch (NoSuchFieldError e) {
mErrorMessageId = R.string.common_error_unknown;
- Log_OC.e(TAG, "Error from access to unexisting field despite protection; file "
- + storagePath, e);
-
+ Log_OC.e(TAG, "Error from access to unexisting field despite protection; file "
+ + storagePath, e);
+
} catch (Throwable t) {
mErrorMessageId = R.string.common_error_unknown;
Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t);
-
+
}
+
return new LoadImage(result, ocFile);
}
-
+
@Override
protected void onCancelled(LoadImage result) {
- if (result.bitmap != null) {
+ if (result != null && result.bitmap != null) {
result.bitmap.recycle();
}
}
hideProgressWheel();
if (result.bitmap != null) {
showLoadedImage(result);
- } else {
+ }
+ else {
showErrorMessage();
}
if (result.bitmap != null && mBitmap != result.bitmap) {
result.bitmap.recycle();
}
}
-
+
@SuppressLint("InlinedApi")
private void showLoadedImage(LoadImage result) {
final ImageViewCustom imageView = mImageViewRef.get();
imageView.setBackground(backrepeat);
}
- imageView.setImageBitmap(bitmap);
+ if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")){
+ imageView.setGifImage(result.ocFile);
+ } else {
+ imageView.setImageBitmap(bitmap);
+ }
+
imageView.setVisibility(View.VISIBLE);
mBitmap = bitmap; // needs to be kept for recycling when not useful
}
messageView.setVisibility(View.GONE);
} // else , silently finish, the fragment was destroyed
}
-
+
private void showErrorMessage() {
final ImageView imageView = mImageViewRef.get();
if (imageView != null) {
messageView.setVisibility(View.VISIBLE);
} // else , silently finish, the fragment was destroyed
}
-
+
private void hideProgressWheel() {
final ProgressBar progressWheel = mProgressWheelRef.get();
if (progressWheel != null) {
progressWheel.setVisibility(View.GONE);
}
}
-
+
}
/**
return (file != null && file.isImage());
}
-
+
/**
* Finishes the preview
*/
Activity container = getActivity();
container.finish();
}
-
+
public TouchImageViewCustom getImageView() {
return mImageView;
}