use of pl.droidsonroids.gif.GifDrawable in project android-gif-drawable by koral--.
the class ImageSpanFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mTextView = new TextView(getActivity());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mTextView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mTextView.setTextIsSelectable(true);
}
final GifDrawable gifDrawable = GifDrawable.createFromResource(getResources(), R.drawable.anim_flag_england);
final SpannableStringBuilder ssb = new SpannableStringBuilder("test");
assert gifDrawable != null;
gifDrawable.setBounds(0, 0, gifDrawable.getIntrinsicWidth(), gifDrawable.getIntrinsicHeight());
gifDrawable.setCallback(this);
ssb.setSpan(new ImageSpan(gifDrawable), ssb.length() - 1, ssb.length(), 0);
mTextView.setText(ssb);
return mTextView;
}
use of pl.droidsonroids.gif.GifDrawable 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);
}
}
use of pl.droidsonroids.gif.GifDrawable in project weiciyuan by qii.
the class GifPictureFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.gallery_gif_layout, container, false);
gifImageView = (PhotoView) view.findViewById(R.id.gif);
if (SettingUtility.allowClickToCloseGallery()) {
gifImageView.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {
@Override
public void onViewTap(View view, float x, float y) {
getActivity().onBackPressed();
}
});
}
LongClickListener longClickListener = ((ContainerFragment) getParentFragment()).getLongClickListener();
gifImageView.setOnLongClickListener(longClickListener);
String path = getArguments().getString("path");
boolean animateIn = getArguments().getBoolean("animationIn");
final AnimationRect rect = getArguments().getParcelable("rect");
File gifFile = new File(path);
try {
GifDrawable gifFromFile = new GifDrawable(gifFile);
gifImageView.setImageDrawable(gifFromFile);
} catch (IOException e) {
e.printStackTrace();
}
final ClipImageView photoView = (ClipImageView) view.findViewById(R.id.cover);
Bitmap bitmap = ImageUtility.decodeBitmapFromSDCard(path, IMAGEVIEW_SOFT_LAYER_MAX_WIDTH, IMAGEVIEW_SOFT_LAYER_MAX_HEIGHT);
photoView.setImageBitmap(bitmap);
if (!animateIn) {
photoView.setVisibility(View.INVISIBLE);
return view;
}
gifImageView.setVisibility(View.INVISIBLE);
final Runnable endAction = new Runnable() {
@Override
public void run() {
Bundle bundle = getArguments();
bundle.putBoolean("animationIn", false);
photoView.setVisibility(View.INVISIBLE);
gifImageView.setVisibility(View.VISIBLE);
}
};
photoView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (rect == null) {
photoView.getViewTreeObserver().removeOnPreDrawListener(this);
endAction.run();
return true;
}
final Rect startBounds = new Rect(rect.scaledBitmapRect);
final Rect finalBounds = AnimationUtility.getBitmapRectFromImageView(photoView);
if (finalBounds == null) {
photoView.getViewTreeObserver().removeOnPreDrawListener(this);
endAction.run();
return true;
}
float startScale = (float) finalBounds.width() / startBounds.width();
if (startScale * startBounds.height() > finalBounds.height()) {
startScale = (float) finalBounds.height() / startBounds.height();
}
int oriBitmapScaledWidth = (int) (finalBounds.width() / startScale);
int oriBitmapScaledHeight = (int) (finalBounds.height() / startScale);
int thumbnailAndOriDeltaRightSize = Math.abs(rect.scaledBitmapRect.width() - oriBitmapScaledWidth);
int thumbnailAndOriDeltaBottomSize = Math.abs(rect.scaledBitmapRect.height() - oriBitmapScaledHeight);
float thumbnailAndOriDeltaWidth = (float) thumbnailAndOriDeltaRightSize / (float) oriBitmapScaledWidth;
float thumbnailAndOriDeltaHeight = (float) thumbnailAndOriDeltaBottomSize / (float) oriBitmapScaledHeight;
int deltaTop = startBounds.top - finalBounds.top;
int deltaLeft = startBounds.left - finalBounds.left;
photoView.setPivotY((photoView.getHeight() - finalBounds.height()) / 2);
photoView.setPivotX((photoView.getWidth() - finalBounds.width()) / 2);
photoView.setScaleX(1 / startScale);
photoView.setScaleY(1 / startScale);
photoView.setTranslationX(deltaLeft);
photoView.setTranslationY(deltaTop);
photoView.animate().translationY(0).translationX(0).scaleY(1).scaleX(1).setDuration(ANIMATION_DURATION).setInterpolator(new AccelerateDecelerateInterpolator()).withEndAction(endAction);
if (rect.type == AnimationRect.TYPE_EXTEND_V || rect.type == AnimationRect.TYPE_EXTEND_H) {
AnimatorSet animationSet = new AnimatorSet();
animationSet.setDuration(ANIMATION_DURATION);
animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipBottom", thumbnailAndOriDeltaHeight, 0));
animationSet.start();
} else {
AnimatorSet animationSet = new AnimatorSet();
animationSet.setDuration(ANIMATION_DURATION);
animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
float clipRectH = ((float) (oriBitmapScaledWidth - oriBitmapScaledWidth * thumbnailAndOriDeltaWidth - rect.widgetWidth) / 2) / (float) oriBitmapScaledWidth;
float clipRectV = ((float) (oriBitmapScaledHeight - oriBitmapScaledHeight * thumbnailAndOriDeltaHeight - rect.widgetHeight) / 2) / (float) oriBitmapScaledHeight;
animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipHorizontal", clipRectH, 0));
animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipVertical", clipRectV, 0));
animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipBottom", thumbnailAndOriDeltaHeight, 0));
animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipRight", thumbnailAndOriDeltaWidth, 0));
animationSet.start();
}
photoView.getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
});
return view;
}
use of pl.droidsonroids.gif.GifDrawable in project meatspace-android by RomainPiel.
the class ChatItemView method bind.
public void bind(final Chat chat) {
if (chat != null) {
Chat.Value value = chat.getValue();
try {
ByteArrayInputStream in = new ByteArrayInputStream(value.getMedia().getBytes());
GifDrawable gifFromStream = new GifDrawable(in);
gif.setImageDrawable(gifFromStream);
gif.setVisibility(VISIBLE);
} catch (Exception e) {
Debug.out(e);
gif.setVisibility(INVISIBLE);
}
Date date = new Date(value.getCreated());
timestamp.setText(com.romainpiel.lib.utils.DateUtils.formatTime(getContext(), date));
message.setText(value.getMessage());
if (!chat.getValue().isFromMe()) {
menuButton.setVisibility(VISIBLE);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_card_mute && onMuteClickListener != null) {
onMuteClickListener.onMenuClick(chat);
}
return true;
}
});
} else {
menuButton.setVisibility(INVISIBLE);
}
}
}
Aggregations