當前位置: 首頁>>代碼示例>>Java>>正文


Java GifDrawable類代碼示例

本文整理匯總了Java中pl.droidsonroids.gif.GifDrawable的典型用法代碼示例。如果您正苦於以下問題:Java GifDrawable類的具體用法?Java GifDrawable怎麽用?Java GifDrawable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GifDrawable類屬於pl.droidsonroids.gif包,在下文中一共展示了GifDrawable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
@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);

    mGifImageView = (GifImageView) findViewById(R.id.gif_image_view);
    try {
        GifDrawable drawable = new GifDrawable(Config.GIF_SAVE_PATH);
        drawable.start();
        drawable.setLoopCount(10);
        mGifImageView.setBackground(drawable);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:pili-engineering,項目名稱:PLDroidShortVideo,代碼行數:23,代碼來源:ShowGIFActivity.java

示例2: onMergedEvent

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMergedEvent(EventMergeFinish mergeService) {
    ProgressBarHelper.getInstance(true).dismiss();
    try {
        mViewDrawableOverlay.setVisibility(View.GONE);
        ViewAnimator.animate(mGifImageView).fadeIn().accelerate().duration(600).start();
        mGifImageView.setVisibility(View.VISIBLE);
        GifDrawable gifFromBytes = new GifDrawable(mergeService.getGifPath());
        gifFromBytes.setLoopCount(0xFFFF);
        mGifImageView.setImageDrawable(gifFromBytes);
        mStickerTextDownLoadDialog.dismiss();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String mergePath = mergeService.getGifPath();
    EventBus.getDefault().post(new EventStartNewThread(true, mergePath));
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:18,代碼來源:VoiceMainActivity.java

示例3: decodeGifWrapper

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
private ImageWrapper decodeGifWrapper(InputStream bis, int width, int height) throws IOException {
    ImageWrapper result = null;
    Resource<GifDrawable> gifResource = gifDecoder.decode(bis, width, height);
    if (gifResource != null) {
        GifDrawable drawable = gifResource.get();
        // We can more efficiently hold Bitmaps in memory, so for static GIFs, try to return Bitmaps
        // instead. Returning a Bitmap incurs the cost of allocating the GifDrawable as well as the normal
        // Bitmap allocation, but since we can encode the Bitmap out as a JPEG, future decodes will be
        // efficient.
        if (drawable.getNumberOfFrames() > 1) {
            result = new ImageWrapper(null /*bitmapResource*/, gifResource);
        } else {
            Resource<Bitmap> bitmapResource = new BitmapResource(drawable.getCurrentFrame(), bitmapPool);
            result = new ImageWrapper(bitmapResource, null /*gifResource*/);
        }
    }
    return result;
}
 
開發者ID:dengyuhan,項目名稱:GlidePlus,代碼行數:19,代碼來源:ImageWrapperResourceDecoder.java

示例4: setImageUrl

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
public void setImageUrl(String iid, String url, boolean cache) {
    if (!webImageCache.containsKey(iid)) {
        if (!reqIids.contains(iid)) {
            //if (!MiscStatics.canRequest(getContext())) return;    //may we ignore this here? I mean opening a index page on the browser laods about 70 thumbnails at once
            reqIids.add(iid);
            Logger.getLogger("a621").info("Downloading " + iid);
            DownloadTask task = new DownloadTask();
            task.execute(iid, url, (cache ? getContext().getCacheDir().getAbsolutePath() : null)); //have at least 16 MiB RAM for the app to cache
            cleanUp(getContext());
        }
    } else {
        Logger.getLogger("a621").info("Using cache for " + iid);
        uUsage(iid);    //update timestamp for this image
        Drawable resource = webImageCache.get(iid);
        setImageDrawable(webImageCache.get(iid));
        updateDisplay();
        if (resource instanceof GifDrawable) ((GifDrawable)resource).start();
    }
}
 
開發者ID:rebane621,項目名稱:e621-android,代碼行數:20,代碼來源:WebImageView.java

示例5: onPostExecute

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
@Override
protected void onPostExecute(Drawable result) {
    if (result != null) {
        if (sUseCache) {
            Logger.getLogger("a621").info("Storing " + iid + "...");
            WebImageView.webImageCache.put(iid, result);
            WebImageView.webImageUsage.put(iid, System.currentTimeMillis()/1000);
        }
        WebImageView.this.setImageDrawable(result);
        if (gif && cacheDir != null) {  //if cachedir is null we can't have a gif at hand, see code above
            GifDrawable rr = (GifDrawable) result;
            rr.setLoopCount(0);
            rr.start();
        }
        //WebImageView.this.postInvalidate();
        updateDisplay();

        if (reqIids.contains(iid)) reqIids.remove(iid);

        if (wil != null) wil.onImageLoaded();
    } else {
        Logger.getLogger("a621").info("Could not download " + iid);
    }
}
 
開發者ID:rebane621,項目名稱:e621-android,代碼行數:25,代碼來源:WebImageView.java

示例6: onDestroy

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
@Override
    protected void onDestroy() {
        super.onDestroy();

//        WebView webView = (WebView) findViewById(R.id.webViewGif);
//        if (webView.getVisibility() == View.VISIBLE) {
//            webView.removeAllViews();
//            webView.clearCache(true);
//            webView.destroy();
//            webView = null;
//        }
        if (gifImageView != null && gifImageView.getDrawable() != null) {
            GifDrawable drawable = (GifDrawable) gifImageView.getDrawable();
            drawable.recycle();
        }
        if (attacher != null) {
            attacher.cleanup();
            attacher = null;
        }
    }
 
開發者ID:EuphoriaDev,項目名稱:euphoria-vk-client,代碼行數:21,代碼來源:PhotoViewerActivity.java

示例7: doInBackground

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
@Override
protected GifDrawable doInBackground(String... strings) {
    try {
        URLConnection urlConnection = new URL(logoUrl).openConnection();
        urlConnection.connect();
        final int contentLength = urlConnection.getContentLength();
        ByteBuffer buffer = ByteBuffer.allocateDirect(contentLength);
        ReadableByteChannel channel = Channels.newChannel(urlConnection.getInputStream());
        while (buffer.remaining() > 0){
            channel.read(buffer);
        }
        channel.close();
        return new GifDrawable(buffer);

    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

}
 
開發者ID:Galarzaa90,項目名稱:TibiaCompendium,代碼行數:21,代碼來源:GuildFragment.java

示例8: onCreate

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    test_gif = (GifImageView) findViewById(R.id.test_gif);
    //設置圖片數據
    test_gif.setImageResource(R.drawable.ui_bg_03);
    final android.widget.MediaController mediaController = new android.widget.MediaController(this);
    mediaController.setMediaPlayer((GifDrawable) test_gif.getDrawable());
    test_gif.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mediaController.show();
            //Snackbar.make(test_gif, "可以點擊哦", Snackbar.LENGTH_LONG).show();
        }
    });
}
 
開發者ID:xmlxin,項目名稱:AndroidLogin,代碼行數:18,代碼來源:MainActivity.java

示例9: displayGif

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
/**
 * 加載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();
        }
    });
}
 
開發者ID:kymjs,項目名稱:KJGallery,代碼行數:21,代碼來源:SamplePagerAdapter.java

示例10: decodeByteArrayOrThrow

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
/**
 * Decodes image from byte array.
 * Returns {@link GifDrawable} if the image is an animated GIF.
 * Returns {@link BitmapDrawable} if the image is s valid static image {@link BitmapFactory}
 * can decode.
 * Returns null on error.
 *
 * @param res     Resources to use if creating a BitmapDrawable
 * @param data    byte array of compressed image data
 * @param options optional options if an image will be decoded to a Bitmap
 * @return decoded {@link Drawable}
 * @throws IOException          on error
 * @throws NullPointerException if the data byte array is null
 */
@NonNull
public static Drawable decodeByteArrayOrThrow(@Nullable final Resources res,
        final byte[] data,
        @Nullable final BitmapFactory.Options options) throws IOException {
    if (data == null) {
        throw new NullPointerException("data byte array must not be null");
    }
    final boolean animated = isAnimatedGif(
            new BufferedInputStream(new ByteArrayInputStream(data)));
    if (animated) {
        return new GifDrawable(data);
    } else {
        final Bitmap decoded = BitmapFactory.decodeByteArray(data, 0, data.length, options);
        if (decoded == null) {
            throw new IOException("BitmapFactory returned null");
        }
        return new BitmapDrawable(res, decoded);
    }
}
 
開發者ID:Doctoror,項目名稱:ImageFactory,代碼行數:34,代碼來源:ImageFactory.java

示例11: testLoopOnceAnimatedGifAsAssetInputStream

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
public void testLoopOnceAnimatedGifAsAssetInputStream() throws Throwable {
    final Context context = getInstrumentation().getContext();
    final InputStream is1 = context.getAssets()
            .open("loop_once.gif", AssetManager.ACCESS_RANDOM);
    try {
        assertTrue(ImageFactory.isAnimatedGif(new BufferedInputStream(is1)));
    } finally {
        is1.close();
    }

    final InputStream is = context.getAssets()
            .open("loop_once.gif", AssetManager.ACCESS_RANDOM);
    final Drawable result;
    try {
        result = ImageFactory.decodeStreamOrThrow(context.getResources(), is, null, null);
    } finally {
        is.close();
    }
    assertTrue(result instanceof GifDrawable);
    assertTrue(((GifDrawable) result).getLoopCount() == 1);
}
 
開發者ID:Doctoror,項目名稱:ImageFactory,代碼行數:22,代碼來源:ImageFactoryTest.java

示例12: testLoopOnceAnimatedGifAsByteArray

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
public void testLoopOnceAnimatedGifAsByteArray() throws Throwable {
    final Context context = getInstrumentation().getContext();
    final InputStream is1 = context.getAssets()
            .open("loop_once.gif", AssetManager.ACCESS_RANDOM);
    final byte[] data;
    try {
        data = toByteArray(is1);
    } finally {
        is1.close();
    }

    assertTrue(ImageFactory
            .isAnimatedGif(new BufferedInputStream(new ByteArrayInputStream(data))));
    final Drawable result = ImageFactory.decodeByteArray(context.getResources(), data);
    assertTrue(result instanceof GifDrawable);
    assertTrue(((GifDrawable) result).getLoopCount() == 1);
}
 
開發者ID:Doctoror,項目名稱:ImageFactory,代碼行數:18,代碼來源:ImageFactoryTest.java

示例13: testLoopedAnimatedGifAsAssetInputStream

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
public void testLoopedAnimatedGifAsAssetInputStream() throws Throwable {
    final Context context = getInstrumentation().getContext();
    final InputStream is1 = context.getAssets()
            .open("w3c_home_animation.gif", AssetManager.ACCESS_RANDOM);
    try {
        assertTrue(ImageFactory.isAnimatedGif(new BufferedInputStream(is1)));
    } finally {
        is1.close();
    }

    final InputStream is = context.getAssets()
            .open("w3c_home_animation.gif", AssetManager.ACCESS_RANDOM);
    final Drawable result;
    try {
        result = ImageFactory.decodeStream(context.getResources(), is);
    } finally {
        is.close();
    }
    assertTrue(result instanceof GifDrawable);
    assertTrue(((GifDrawable) result).getLoopCount() == 0);
}
 
開發者ID:Doctoror,項目名稱:ImageFactory,代碼行數:22,代碼來源:ImageFactoryTest.java

示例14: testLoopedAnimatedGifAsByteArray

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
public void testLoopedAnimatedGifAsByteArray() throws Throwable {
    final Context context = getInstrumentation().getContext();
    final InputStream is1 = context.getAssets()
            .open("w3c_home_animation.gif", AssetManager.ACCESS_RANDOM);
    final byte[] data;
    try {
        data = toByteArray(is1);
    } finally {
        is1.close();
    }

    assertTrue(ImageFactory
            .isAnimatedGif(new BufferedInputStream(new ByteArrayInputStream(data))));

    final Drawable result = ImageFactory.decodeByteArray(context.getResources(), data);
    assertTrue(result instanceof GifDrawable);
    assertTrue(((GifDrawable) result).getLoopCount() == 0);
}
 
開發者ID:Doctoror,項目名稱:ImageFactory,代碼行數:19,代碼來源:ImageFactoryTest.java

示例15: setFace

import pl.droidsonroids.gif.GifDrawable; //導入依賴的package包/類
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);
    }

}
 
開發者ID:fei-ke,項目名稱:ChipHellClient,代碼行數:18,代碼來源:FastReplyFragment.java


注:本文中的pl.droidsonroids.gif.GifDrawable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。