@Override public void onClick(final View v) { if (v.equals(btnToggle)) { if (gifImageView.isAnimating()) gifImageView.stopAnimation(); else gifImageView.startAnimation(); } else if (v.equals(btnBlur)) { shouldBlur = !shouldBlur; } else { gifImageView.clear(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gifImageView = (GifImageView) findViewById(R.id.gifImageView); btnToggle = (Button) findViewById(R.id.btnToggle); btnBlur = (Button) findViewById(R.id.btnBlur); final Button btnClear = (Button) findViewById(R.id.btnClear); blur = Blur.newInstance(this); gifImageView.setOnFrameAvailableListener( new GifImageView.OnFrameAvailableListener() { @Override public Bitmap onFrameAvailable(Bitmap bitmap) { if (shouldBlur) { return blur.blur(bitmap); } return bitmap; } }); btnToggle.setOnClickListener(this); btnClear.setOnClickListener(this); btnBlur.setOnClickListener(this); new GifDataDownloader() { @Override protected void onPostExecute(final byte[] bytes) { gifImageView.setBytes(bytes); gifImageView.startAnimation(); Log.d(TAG, "GIF width is " + gifImageView.getGifWidth()); Log.d(TAG, "GIF height is " + gifImageView.getGifHeight()); } }.execute("http://katemobile.ru/tmp/sample3.gif"); }