pl.droidsonroids.gif.GifDrawable Java Examples
The following examples show how to use
pl.droidsonroids.gif.GifDrawable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GifWithTextItem.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onLoadThumbnailFromLocal(final ViewHolder holder, final String tag, final String localPath, LocalFileType fileType) { super.onLoadThumbnailFromLocal(holder, tag, localPath, fileType); if (holder.image != null && holder.image.getTag() != null && holder.image.getTag().equals(tag)) { holder.image.setImageURI(Uri.fromFile(new File(localPath))); if (fileType == LocalFileType.FILE) { SharedPreferences sharedPreferences = holder.itemView.getContext().getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); if (sharedPreferences.getInt(SHP_SETTING.KEY_AUTOPLAY_GIFS, SHP_SETTING.Defaults.KEY_AUTOPLAY_GIFS) == 1) { holder.itemView.findViewById(R.id.progress).setVisibility(View.GONE); } else { if (holder.image.getDrawable() instanceof GifDrawable) { GifDrawable gifDrawable = (GifDrawable) holder.image.getDrawable(); // to get first frame gifDrawable.stop(); holder.itemView.findViewById(R.id.progress).setVisibility(View.VISIBLE); } } } } }
Example #2
Source File: FastReplyFragment.java From ChipHellClient with Apache License 2.0 | 6 votes |
private void setFace(SpannableStringBuilder spb, String smileName, int length) { String path = SmileTable.get(smileName); try { int height = (int) editTextFastReply.getTextSize() * 2; GifDrawable drawable = new GifDrawable(ChhApplication.getInstance().getAssets(), path); // Drawable drawable = Drawable.createFromStream(getResources().getAssets().open(path), smileName); drawable.setBounds(0, 0, height, height); ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE); SpannableString spanStr = new SpannableString(smileName); spanStr.setSpan(imageSpan, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spb.append(spanStr); } catch (IOException e) { e.printStackTrace(); spb.append(smileName); } }
Example #3
Source File: GifProcessor.java From Markwon with Apache License 2.0 | 6 votes |
private static void addGifClickSpan( @NonNull TextView textView, @NonNull AsyncDrawableSpan span, @NonNull GifAwareAsyncDrawable drawable) { // important thing here is to obtain new spannable from textView // as with each `setText()` new spannable is created and keeping reference // to an older one won't affect textView final Spannable spannable = spannable(textView); if (spannable == null) { return; } final int start = spannable.getSpanStart(span); final int end = spannable.getSpanEnd(span); if (start < 0 || end < 0) { return; } final GifDrawable gifDrawable = (GifDrawable) drawable.getResult(); spannable.setSpan(new GifToggleClickableSpan(gifDrawable), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example #4
Source File: GifWithTextItem.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onPlayPauseGIF(ViewHolder holder, String localPath) throws ClassCastException { super.onPlayPauseGIF(holder, localPath); MessageProgress progress = (MessageProgress) holder.itemView.findViewById(R.id.progress); AppUtils.setProgresColor(progress.progressBar); progress.withDrawable(R.mipmap.photogif, true); GifDrawable gifDrawable = (GifDrawable) holder.image.getDrawable(); if (gifDrawable != null) { if (gifDrawable.isPlaying()) { gifDrawable.pause(); holder.itemView.findViewById(R.id.progress).setVisibility(View.VISIBLE); } else { gifDrawable.start(); holder.itemView.findViewById(R.id.progress).setVisibility(View.GONE); } } }
Example #5
Source File: GifItem.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onLoadThumbnailFromLocal(final ViewHolder holder, final String tag, final String localPath, LocalFileType fileType) { super.onLoadThumbnailFromLocal(holder, tag, localPath, fileType); if (holder.image != null && holder.image.getTag() != null && holder.image.getTag().equals(tag)) { holder.image.setImageURI(Uri.fromFile(new File(localPath))); if (fileType == LocalFileType.FILE) { SharedPreferences sharedPreferences = holder.itemView.getContext().getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); if (sharedPreferences.getInt(SHP_SETTING.KEY_AUTOPLAY_GIFS, SHP_SETTING.Defaults.KEY_AUTOPLAY_GIFS) == 1) { holder.itemView.findViewById(R.id.progress).setVisibility(View.GONE); } else { if (holder.image.getDrawable() instanceof GifDrawable) { GifDrawable gifDrawable = (GifDrawable) holder.image.getDrawable(); // to get first frame gifDrawable.stop(); holder.itemView.findViewById(R.id.progress).setVisibility(View.VISIBLE); } } } } }
Example #6
Source File: SamplePagerAdapter.java From KJGallery with Apache License 2.0 | 6 votes |
/** * 加载gif图片 */ private void displayGif(final GifImageView gifView, byte[] res) { gifView.setVisibility(View.VISIBLE); try { GifDrawable gifFromBytes = new GifDrawable(res); gifView.setImageDrawable(gifFromBytes); } catch (IOException e) { gifView.setImageResource(R.mipmap.default_img_rect); } gifView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { aty.finish(); } }); }
Example #7
Source File: GifItem.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onPlayPauseGIF(ViewHolder holder, String localPath) throws ClassCastException { super.onPlayPauseGIF(holder, localPath); MessageProgress progress = (MessageProgress) holder.itemView.findViewById(R.id.progress); AppUtils.setProgresColor(progress.progressBar); progress.withDrawable(R.drawable.photogif, true); GifDrawable gifDrawable = (GifDrawable) holder.image.getDrawable(); if (gifDrawable != null) { if (gifDrawable.isPlaying()) { gifDrawable.pause(); holder.itemView.findViewById(R.id.progress).setVisibility(View.VISIBLE); } else { gifDrawable.start(); holder.itemView.findViewById(R.id.progress).setVisibility(View.GONE); } } }
Example #8
Source File: ReadImageTask.java From DaVinci with Apache License 2.0 | 5 votes |
final void execute(String requestBody) { if ( mImageUrl == null || mImageUrl.isEmpty() || Util.generateKey(mImageUrl).isEmpty() ) { mImageView.setImageDrawable(mContext.getResources().getDrawable(mErrorImage)); return; } String rawKey = mImageUrl; if ( mKeyMode != 0 && mMaxSize != 0 ) rawKey += mMaxSize; ImageEntity entity = mImageCache.getBitmap(Util.generateKey(rawKey)); if ( entity != null ) { VinciLog.d("Load image from cache, key = " + Util.generateKey(rawKey)); // if it's gif, show as gif if ( entity.isGif() ) { try { GifDrawable gifDrawable = new GifDrawable(entity.getBytes()); mImageView.setImageDrawable(gifDrawable); } catch (Throwable e) { VinciLog.w("pl.droidsonroids.gif.GifDrawable not found"); } } else { mImageView.setImageBitmap(entity.getBitmap()); } } else if ( mImageUrl.startsWith("http") ) { VolleyImageListener listener = new VolleyImageListener(mContext, mImageView, mImageCache); listener.setDefaultImage(mLoadingImage, mErrorImage); listener.setMaxSize(mMaxSize, mKeyMode); VinciLog.d("Load image from web, url = " + mImageUrl ); mImageLoader.get(mImageUrl, requestBody, listener); } else { mImageView.setImageDrawable(mContext.getResources().getDrawable(mErrorImage)); } }
Example #9
Source File: PullToRefreshLayout.java From PullToRefresh with Apache License 2.0 | 5 votes |
/** * 设置下拉刷新gif动画头 * * @param headGifDrawable */ public void setGifRefreshView(GifDrawable headGifDrawable) { // 设置下拉头 GifHeadView headView = new GifHeadView(getContext()); headView.setGifAnim(headGifDrawable); setCustomRefreshView(headView); setOnRefreshProcessListener(new GifOnPullProcessListener( headView.getDrawable())); }
Example #10
Source File: PullToRefreshLayout.java From PullToRefresh with Apache License 2.0 | 5 votes |
/** * 设置上拉加载更多gif动画头 * * @param footGifDrawable */ public void setGifLoadmoreView(GifDrawable footGifDrawable) { // 设置上拉头 GifHeadView footView = new GifHeadView(getContext()); footView.setGifAnim(footGifDrawable); setCustomLoadmoreView(footView); setOnLoadmoreProcessListener(new GifOnPullProcessListener( footView.getDrawable())); }
Example #11
Source File: GifDrawableBytesTranscoder.java From MoeGallery with GNU General Public License v3.0 | 5 votes |
@Override public Resource<GifDrawable> transcode(Resource<byte[]> toTranscode) { try { return new GifDrawableResource(new GifDrawable(toTranscode.get())); } catch (IOException ex) { Log.e("GifDrawable", "Cannot decode bytes", ex); return null; } }
Example #12
Source File: ImageFragment.java From MoeGallery with GNU General Public License v3.0 | 5 votes |
private void loadImage(Image image, LazyHeaders.Builder header) { if (mUri != null && mUri.toLowerCase().endsWith("gif")) { mGifRequestBuilder.load(new GlideUrl(image.getFileUrl(), header.build())) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .listener(new MediaRequestListener<GlideUrl, GifDrawable>()) .into(mPhotoView); } else { mRequestManager.load(new GlideUrl(image.getFileUrl(), header.build())) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .listener(new MediaRequestListener<GlideUrl, GlideDrawable>()) .into(mPhotoView); } }
Example #13
Source File: MainModule.java From MoeGallery with GNU General Public License v3.0 | 5 votes |
@Singleton @Provides GenericRequestBuilder<GlideUrl, InputStream, byte[], GifDrawable> provideGifRequestBuilder( RequestManager requestManager, OkHttpClient okHttpClient) { return requestManager.using(new OkHttpUrlLoader(okHttpClient), InputStream.class) .from(GlideUrl.class) .as(byte[].class) .transcode(new GifDrawableBytesTranscoder(), GifDrawable.class) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .decoder(new StreamByteArrayResourceDecoder()) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>(new StreamByteArrayResourceDecoder())); }
Example #14
Source File: GifHeadView.java From PullToRefresh with Apache License 2.0 | 5 votes |
/** * 设置gif动画资源 * * @param gifDrawable */ public void setGifAnim(GifDrawable gifDrawable) { gifImageView.setImageDrawable(gifDrawable); // 停止自动播放 gifDrawable.stop(); }
Example #15
Source File: Util.java From DaVinci with Apache License 2.0 | 5 votes |
public static boolean doGif(ImageView imageView, byte[] data) { if ( isGif( data ) ) { try { GifDrawable gifDrawable = new GifDrawable(data); imageView.setImageDrawable(gifDrawable); return true; } catch (Throwable e) { VinciLog.w("pl.droidsonroids.gif.GifDrawable not found"); } } return false; }
Example #16
Source File: FeedbackFragment.java From ifican with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { GifDrawable drawable = (GifDrawable) ((GifImageView) v).getDrawable(); if (drawable.isPlaying()) drawable.stop(); else drawable.start(); }
Example #17
Source File: TransitionsExampleFragment.java From ifican with Apache License 2.0 | 5 votes |
@OnClick({R.id.gif1, R.id.gif2}) public void onGifClick(GifImageView view) { GifDrawable drawable = (GifDrawable) view.getDrawable(); if (drawable.isPlaying()) drawable.stop(); else drawable.start(); }
Example #18
Source File: AtentionFragment.java From ifican with Apache License 2.0 | 5 votes |
@OnClick({R.id.gif1, R.id.gif2, R.id.gif3}) public void onGifClick(GifImageView view) { GifDrawable drawable = (GifDrawable) view.getDrawable(); if (drawable.isPlaying()) drawable.stop(); else drawable.start(); }
Example #19
Source File: ContextFragment.java From ifican with Apache License 2.0 | 5 votes |
@OnClick(R.id.gif1) public void onGifClick(GifImageView view) { GifDrawable drawable = (GifDrawable) view.getDrawable(); if (drawable.isPlaying()) drawable.stop(); else drawable.start(); }
Example #20
Source File: Utils.java From ifican with Apache License 2.0 | 5 votes |
public static void startGif(GifImageView view) { GifDrawable drawable = (GifDrawable) view.getDrawable(); if (!drawable.isPlaying()) { drawable.reset(); drawable.start(); } }
Example #21
Source File: ChatItemView.java From meatspace-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
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); } } }
Example #22
Source File: EmptyLayout.java From CoreModule with Apache License 2.0 | 5 votes |
public void setErrorType(int i) { setVisibility(View.VISIBLE); switch (i) { case NETWORK_ERROR: mErrorState = NETWORK_ERROR; tv.setText(R.string.emptyview_load_again); img.setImageResource(R.mipmap.emptyview_icon_network); setVisibility(View.VISIBLE); clickEnable = true; break; case NETWORK_LOADING: mErrorState = NETWORK_LOADING; try { AssetManager assetManager = getResources().getAssets(); String[] loadingList = assetManager.list(LOADING_IMAGE_FOLDER_NAME); String imageName = loadingList[((int) (loadingList.length * Math.random()))]; String absoluteImageName = LOADING_IMAGE_FOLDER_NAME + File.separator + imageName; loadingDrawable = new GifDrawable(assetManager, absoluteImageName); img.setImageDrawable(loadingDrawable); } catch (Exception e) { } tv.setText(R.string.emptyview_loading); clickEnable = false; setVisibility(View.VISIBLE); break; case NODATA: mErrorState = NODATA; img.setImageResource(R.mipmap.emptyview_icon_empty); setTvNoDataContent(); clickEnable = true; setVisibility(View.VISIBLE); break; case HIDE_LAYOUT: dismiss(); break; default: break; } }
Example #23
Source File: ShowGIFActivity.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_gif); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); } setTitle(R.string.title_show_gif); String gifFilePath = getIntent().getStringExtra(GIF_PATH); if (gifFilePath == null) { return; } mGifImageView = (GifImageView) findViewById(R.id.gif_image_view); try { GifDrawable drawable = new GifDrawable(gifFilePath); drawable.start(); drawable.setLoopCount(10); mGifImageView.setBackground(drawable); } catch (IOException e) { e.printStackTrace(); } }
Example #24
Source File: BigImageView.java From ImageLoader with Apache License 2.0 | 5 votes |
@Override public void showContent(File image) { if ("gif".equals(MyUtil.getRealType(image))) { try { GifDrawable gif = new GifDrawable(image.getAbsolutePath()); placeHolder.setVisibility(VISIBLE); gifView.setVisibility(VISIBLE); llLoading.setVisibility(GONE); gifView.setImageDrawable(gif); } catch (IOException e) { e.printStackTrace(); showError(); } } else { mImageView.setVisibility(VISIBLE); if (image != null) mImageView.setImage(ImageSource.uri(Uri.fromFile(image))); Log.d("BigImageView", "mImageView.setImage: " + image.getAbsolutePath()); if (placeHolder != null) { placeHolder.setVisibility(GONE); } } currentState = STATE_CONTENT; if (progressView != null) progressView.setVisibility(GONE); if (mThumbnailView != null) mThumbnailView.setVisibility(GONE); if (errorView != null) errorView.setVisibility(GONE); }
Example #25
Source File: SplashScreenActivity.java From microbit with Apache License 2.0 | 5 votes |
/** * Prepares gif image view before it's started. * * @param isPortrait Checks if device is in portrait view. */ private void prepareGif(final boolean isPortrait) { mGifDrawable = (GifDrawable) mGifImage.getDrawable(); mGifDrawable.stop(); mGifDrawable.addAnimationListener(mGifAnimListener); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mGifImageLayout.getLayoutParams(); int halfOfScreen; //Change size of the gif image. if(isPortrait) { final int screenHeight = getResources().getDisplayMetrics().heightPixels; halfOfScreen = screenHeight / 2; params.height = halfOfScreen; mGifImageLayout.setTranslationY(screenHeight); } else { final int screenWidth = getResources().getDisplayMetrics().widthPixels; halfOfScreen = screenWidth / 2; params.width = halfOfScreen; mGifImageLayout.setTranslationX(screenWidth); mGifImageLayout.setPadding(0, 0, 0, 0); } mGifImageLayout.setLayoutParams(params); }
Example #26
Source File: GifAwareAsyncDrawable.java From Markwon with Apache License 2.0 | 5 votes |
@Override public void setResult(@NonNull Drawable result) { super.setResult(result); isGif = result instanceof GifDrawable; if (isGif && onGifResultListener != null) { onGifResultListener.onGifResult(this); } }
Example #27
Source File: GifAwareAsyncDrawable.java From Markwon with Apache License 2.0 | 5 votes |
@Override public void draw(@NonNull Canvas canvas) { super.draw(canvas); if (isGif) { final GifDrawable drawable = (GifDrawable) getResult(); if (!drawable.isPlaying()) { gifPlaceholder.setBounds(drawable.getBounds()); gifPlaceholder.draw(canvas); } } }
Example #28
Source File: FragmentShearedMedia.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void playAndPusGif(int position, RecyclerView.ViewHolder holder) { final GifAdapter.ViewHolder vh = (GifAdapter.ViewHolder) holder; GifDrawable gifDrawable = vh.gifDrawable; if (gifDrawable != null) { if (gifDrawable.isPlaying()) { gifDrawable.pause(); vh.messageProgress.setVisibility(View.VISIBLE); } else { gifDrawable.start(); vh.messageProgress.setVisibility(View.GONE); } } else { File file = new File(vh.filePath); if (file.exists()) { vh.gifView.setImageURI(Uri.fromFile(file)); vh.gifDrawable = (GifDrawable) vh.gifView.getDrawable(); vh.messageProgress.withDrawable(R.drawable.ic_play, true); vh.messageProgress.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (vh.gifDrawable != null) { vh.gifDrawable.start(); vh.messageProgress.setVisibility(View.GONE); } } }); vh.gifDrawable.start(); vh.messageProgress.setVisibility(View.GONE); } } }
Example #29
Source File: Matchers.java From redux-android-sample with Apache License 2.0 | 5 votes |
public static Matcher<View> withPlayingGifDrawable() { return new BoundedMatcher<View, View>(View.class) { @Override public boolean matchesSafely(View view) { GifImageView gifImageView = (GifImageView) view.findViewById(R.id.gif_image); return ((GifDrawable) gifImageView.getDrawable()).isPlaying(); } @Override public void describeTo(Description description) { description.appendText("with gif image view playing"); } }; }
Example #30
Source File: GifDrawableBytesTranscoder.java From MoeGallery with GNU General Public License v3.0 | 4 votes |
GifDrawableResource(GifDrawable drawable) { gifDrawable = drawable; }