brought back gif support

This commit is contained in:
Mariotaku Lee 2015-04-15 00:55:28 +08:00
parent 88cc7a8cce
commit 765d14312b
3 changed files with 44 additions and 38 deletions

View File

@ -76,6 +76,9 @@ import org.mariotaku.twidere.view.LinePageIndicator;
import java.io.File;
import pl.droidsonroids.gif.GifTextureView;
import pl.droidsonroids.gif.InputSource.FileSource;
public final class MediaViewerActivity extends ThemedActionBarActivity implements Constants, OnPageChangeListener {
@ -368,15 +371,19 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
implements DownloadListener, LoaderCallbacks<Result>, OnLayoutChangeListener, OnClickListener {
private SubsamplingScaleImageView mImageView;
private GifTextureView mGifImageView;
private ProgressWheel mProgressBar;
private boolean mLoaderInitialized;
private float mContentLength;
private SaveImageTask mSaveImageTask;
private File mImageFile;
@Override
public void onBaseViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onBaseViewCreated(view, savedInstanceState);
mImageView = (SubsamplingScaleImageView) view.findViewById(R.id.image_view);
mGifImageView = (GifTextureView) view.findViewById(R.id.gif_image_view);
mProgressBar = (ProgressWheel) view.findViewById(R.id.progress);
}
@ -405,29 +412,27 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
@Override
public void onLoadFinished(final Loader<TileImageLoader.Result> loader, final TileImageLoader.Result data) {
if (data.hasData()) {
mImageView.setVisibility(View.VISIBLE);
mImageView.setTag(data.file);
mImageFile = data.file;
if (data.useDecoder) {
mGifImageView.setVisibility(View.GONE);
mImageView.setVisibility(View.VISIBLE);
mImageView.setImage(ImageSource.uri(Uri.fromFile(data.file)));
} else if ("image/gif".equals(data.options.outMimeType)) {
// try {
// final FileDescriptor fd = new RandomAccessFile(data.file, "r").getFD();
// mImageView.setImageDrawable(new GifDrawable(fd));
// } catch (IOException e) {
// mImageView.setImage(null);
// mImageView.setTag(null);
// mImageView.setVisibility(View.GONE);
// Utils.showErrorMessage(getActivity(), null, e, true);
// }
mGifImageView.setVisibility(View.VISIBLE);
mImageView.setVisibility(View.GONE);
mGifImageView.setInputSource(new FileSource(data.file));
updateScaleLimit();
} else {
mGifImageView.setVisibility(View.GONE);
mImageView.setVisibility(View.VISIBLE);
mImageView.setImage(ImageSource.bitmap(data.bitmap));
updateScaleLimit();
}
} else {
mImageView.recycle();
mImageView.setTag(null);
mImageFile = null;
mImageView.setVisibility(View.GONE);
mGifImageView.setVisibility(View.GONE);
Utils.showErrorMessage(getActivity(), null, data.exception, true);
}
mProgressBar.setVisibility(View.GONE);
@ -451,16 +456,15 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
final Object imageTag = mImageView.getTag();
final File file = mImageFile;
final boolean isLoading = getLoaderManager().hasRunningLoaders();
final boolean hasImage = imageTag instanceof File;
final boolean hasImage = file != null && file.exists();
MenuUtils.setMenuItemAvailability(menu, R.id.refresh, !hasImage && !isLoading);
MenuUtils.setMenuItemAvailability(menu, R.id.share, hasImage && !isLoading);
MenuUtils.setMenuItemAvailability(menu, R.id.save, hasImage && !isLoading);
if (hasImage) {
if (!hasImage) return;
final MenuItem shareItem = menu.findItem(R.id.share);
final ShareActionProvider shareProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
final File file = (File) imageTag;
final Intent intent = new Intent(Intent.ACTION_SEND);
final Uri fileUri = Uri.fromFile(file);
intent.setDataAndType(fileUri, Utils.getImageMimeType(file));
@ -473,7 +477,6 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
}
shareProvider.setShareIntent(intent);
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
@ -501,14 +504,11 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
private void saveToGallery() {
if (mSaveImageTask != null && mSaveImageTask.getStatus() == Status.RUNNING) return;
final Object imageTag = mImageView.getTag();
final boolean hasImage = imageTag instanceof File;
if (hasImage) {
mSaveImageTask = new SaveImageTask(getActivity(), (File) imageTag);
final File file = mImageFile;
final boolean hasImage = file != null && file.exists();
if (!hasImage) return;
mSaveImageTask = new SaveImageTask(getActivity(), file);
mSaveImageTask.execute();
} else {
}
}
private void openInBrowser() {

View File

@ -154,7 +154,7 @@ public class TileImageLoader extends AsyncTaskLoader<TileImageLoader.Result> {
private void dump(final InputStream is, final OutputStream os) throws IOException {
final byte buffer[] = new byte[1024];
final byte buffer[] = new byte[128];
int rc = is.read(buffer, 0, buffer.length);
long downloaded = 0;
while (rc > 0) {

View File

@ -23,6 +23,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<pl.droidsonroids.gif.GifTextureView
android:id="@+id/gif_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_view"
android:layout_width="match_parent"