Skip to content

Commit

Permalink
Freaking GIF playing like hell YEAH! only missing "play" icon in album
Browse files Browse the repository at this point in the history
  • Loading branch information
ferminho committed Mar 10, 2015
1 parent e73fd79 commit cb50821
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.DragEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;

Expand All @@ -29,6 +28,8 @@ public class GifDialog extends DialogFragment implements AnimatedGifDrawable.Upd
private ImageView mImageView;
private AnimatedGifDrawable mDrawable;

private boolean isPlaying = true;

public GifDialog() {
}

Expand All @@ -50,11 +51,33 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
return view;
}

@Override
public void onDestroy() {
super.onDestroy();
if (mDrawable != null) {
mDrawable.stop();
}
}

private View createDialog() {
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = inflater.inflate(R.layout.gif_view, null);
mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
mImageView = (ImageView) view.findViewById(R.id.imageViewGif);
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDrawable != null) {
if (isPlaying) {
mDrawable.stop();
isPlaying = false;
} else {
mDrawable.start();
isPlaying = true;
}
}
}
});

mDialog = getDialog();
mDialog.setCancelable(true);
Expand All @@ -70,6 +93,7 @@ protected Void doInBackground(Void... params) {
try {
is = new FileInputStream(mGifPath);
mDrawable = new AnimatedGifDrawable(is, GifDialog.this, 1);
mDrawable.setOneShot(false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Expand All @@ -83,6 +107,7 @@ protected void onPostExecute(Void aVoid) {
mProgressBar.setVisibility(View.INVISIBLE);
if (mDrawable != null) {
mImageView.setImageDrawable(mDrawable);
mDrawable.start();
} else {
mImageView.setImageResource(android.R.drawable.stat_notify_error);
}
Expand Down

0 comments on commit cb50821

Please sign in to comment.