Search in sources :

Example 1 with GifDrawableBuilder

use of pl.droidsonroids.gif.GifDrawableBuilder in project android-gif-drawable by koral--.

the class GifSourcesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final GifSourceItemHolder holder, int position) {
    final String[] descriptions = holder.itemView.getResources().getStringArray(R.array.sources);
    position %= descriptions.length;
    final GifDrawable existingOriginalDrawable = (GifDrawable) holder.gifImageViewOriginal.getDrawable();
    final GifDrawable existingSampledDrawable = (GifDrawable) holder.gifImageViewSampled.getDrawable();
    final GifDrawableBuilder builder = new GifDrawableBuilder().with(existingOriginalDrawable);
    try {
        mGifSourcesResolver.bindSource(position, builder);
        final GifDrawable fullSizeDrawable = builder.build();
        holder.gifImageViewOriginal.setImageDrawable(fullSizeDrawable);
        holder.gifImageViewOriginal.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (fullSizeDrawable.isPlaying())
                    fullSizeDrawable.stop();
                else
                    fullSizeDrawable.start();
            }
        });
        builder.with(existingSampledDrawable).sampleSize(3);
        mGifSourcesResolver.bindSource(position, builder);
        final GifDrawable subsampledDrawable = builder.build();
        final SpannableStringBuilder stringBuilder = new SpannableStringBuilder(descriptions[position] + '');
        stringBuilder.setSpan(new ImageSpan(subsampledDrawable), stringBuilder.length() - 1, stringBuilder.length(), 0);
        holder.descriptionTextView.setText(stringBuilder);
        holder.gifImageViewSampled.setImageDrawable(subsampledDrawable);
        subsampledDrawable.setCallback(holder.multiCallback);
        holder.multiCallback.addView(holder.gifImageViewSampled);
        holder.multiCallback.addView(holder.descriptionTextView);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : GifDrawableBuilder(pl.droidsonroids.gif.GifDrawableBuilder) GifDrawable(pl.droidsonroids.gif.GifDrawable) IOException(java.io.IOException) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ImageSpan (android.text.style.ImageSpan)1 View (android.view.View)1 IOException (java.io.IOException)1 GifDrawable (pl.droidsonroids.gif.GifDrawable)1 GifDrawableBuilder (pl.droidsonroids.gif.GifDrawableBuilder)1