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);
}
}
Aggregations