Search in sources :

Example 1 with MyDrawable

use of org.aisen.android.component.bitmaploader.view.MyDrawable in project AisenWeiBo by wangdan.

the class VideoHintImageView method display.

public void display(BitmapOwner owner, UrlBean urlBean) {
    setOnClickListener(null);
    this.urlBean = urlBean;
    if (videoBean != null && !TextUtils.isEmpty(videoBean.getShortUrl()) && videoBean.getShortUrl().equals(urlBean.getUrl_short())) {
    } else {
        videoBean = null;
    }
    ImageConfig config = new ImageConfig();
    config.setCompressCacheEnable(false);
    config.setDownloaderClass(VideoDownloader.class);
    config.setBitmapCompress(VideoCompress.class);
    config.setLoadingRes(R.drawable.bg_timeline_loading);
    MyBitmap myBitmap = BitmapLoader.getInstance().getMyBitmapFromMemory(urlBean.getUrl_short(), config);
    // 内存缓存存在图片,且未释放
    if (myBitmap != null) {
        setImageDrawable(new MyDrawable(getResources(), myBitmap, config, null));
    } else {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams();
        if (params != null && params.height != minHeight) {
            params.height = minHeight;
        }
        setLayoutParams(params);
        BitmapLoader.getInstance().display(owner, urlBean.getUrl_short(), this, config);
    }
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) LinearLayout(android.widget.LinearLayout)

Example 2 with MyDrawable

use of org.aisen.android.component.bitmaploader.view.MyDrawable in project AisenWeiBo by wangdan.

the class VideoHintImageView method setImageDrawable.

@Override
public void setImageDrawable(Drawable drawable) {
    super.setImageDrawable(drawable);
    MyDrawable myDrawable = null;
    if (drawable instanceof MyDrawable) {
        myDrawable = (MyDrawable) drawable;
    } else if (drawable instanceof TransitionDrawable) {
        myDrawable = (MyDrawable) ((TransitionDrawable) drawable).getDrawable(1);
    }
    if (myDrawable != null) {
        MyBitmap myBitmap = myDrawable.getMyBitmap();
        if (myBitmap instanceof VideoBitmap) {
            setOnClickListener(this);
            videoBean = ((VideoBitmap) myBitmap).getVideoBean();
            if (getWidth() > 0) {
                int width = myBitmap.getBitmap().getWidth();
                int height = myBitmap.getBitmap().getHeight();
                float scale = getWidth() * 1.0f / width;
                height = (int) (height * scale);
                if (height > getWidth() * 4 / 5) {
                    height = getWidth() * 4 / 5;
                }
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams();
                if (params != null) {
                    params.height = height;
                } else {
                    params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
                }
                setLayoutParams(params);
            }
            Logger.d(VideoHintImageView.class.getSimpleName(), videoBean);
        }
    }
}
Also used : MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) Paint(android.graphics.Paint) LinearLayout(android.widget.LinearLayout)

Example 3 with MyDrawable

use of org.aisen.android.component.bitmaploader.view.MyDrawable in project AisenWeiBo by wangdan.

the class BitmapLoader method getLoadingDrawable.

public static Drawable getLoadingDrawable(Context context, ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    if (drawable != null && context != null) {
        if (drawable instanceof TransitionDrawable) {
            TransitionDrawable transitionDrawable = (TransitionDrawable) drawable;
            drawable = transitionDrawable.getDrawable(1);
        }
        if (drawable instanceof MyDrawable) {
            MyDrawable myDrawable = (MyDrawable) drawable;
            ImageConfig config = myDrawable.getConfig();
            if (config != null) {
                if (config.getLoadingRes() > 0)
                    return new BitmapDrawable(context.getResources(), new MyBitmap(context, config.getLoadingRes()).getBitmap());
            }
        }
    }
    return new ColorDrawable(Color.parseColor("#fff2f2f2"));
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable)

Example 4 with MyDrawable

use of org.aisen.android.component.bitmaploader.view.MyDrawable in project AisenWeiBo by wangdan.

the class BitmapLoader method display.

public void display(BitmapOwner owner, String url, ImageView imageView, ImageConfig imageConfig) {
    if (TextUtils.isEmpty(url)) {
        setImageFaild(imageView, imageConfig);
        return;
    }
    if (bitmapHasBeenSet(imageView, url))
        return;
    MyBitmap myBitmap = mImageCache.getBitmapFromMemCache(url, imageConfig);
    // 内存缓存存在图片,且未释放
    if (myBitmap != null && imageView != null) {
        imageView.setImageDrawable(new MyDrawable(mContext.getResources(), myBitmap, imageConfig, null));
    } else // 开启线程拉取图片
    {
        // 线程不存在,获取已经存在的线程不是加载当前的url,如果存在线程,则停止之前存在的线程
        if (!checkTaskExistAndRunning(url, imageView, imageConfig)) {
            // 2014-08-29 修改为当视图在滚动的时候,不加载图片
            boolean canLoad = owner == null || owner.canDisplay() ? true : false;
            if (!canLoad) {
                Logger.d(TAG, "视图在滚动,显示默认图片");
                setImageLoading(imageView, null, imageConfig);
            } else {
                // 开启新的线程加载图片
                MyBitmapLoaderTask newTask = new MyBitmapLoaderTask(url, imageView, this, imageConfig);
                WeakReference<MyBitmapLoaderTask> taskReference = new WeakReference<MyBitmapLoaderTask>(newTask);
                taskCache.put(KeyGenerator.generateMD5(getKeyByConfig(url, imageConfig)), taskReference);
                setImageLoading(imageView, url, imageConfig);
                newTask.executrOnImageExecutor();
                // 添加到fragment当中,当fragment在Destory的时候,清除task列表
                if (owner != null)
                    getTaskCache(owner).add(new WeakReference<MyBitmapLoaderTask>(newTask));
                newTask = null;
            }
        }
    }
}
Also used : MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) WeakReference(java.lang.ref.WeakReference) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable)

Example 5 with MyDrawable

use of org.aisen.android.component.bitmaploader.view.MyDrawable in project AisenWeiBo by wangdan.

the class BitmapLoader method bitmapHasBeenSet.

/**
 * 当前加载的图片已经绑定在ImageView上了
 *
 * @param imageView
 * @param url
 * @return
 */
public boolean bitmapHasBeenSet(ImageView imageView, String url) {
    if (imageView != null) {
        Drawable drawable = imageView.getDrawable();
        if (drawable != null) {
            if (drawable instanceof TransitionDrawable) {
                TransitionDrawable transitionDrawable = (TransitionDrawable) drawable;
                drawable = transitionDrawable.getDrawable(1);
            }
            if (drawable instanceof MyDrawable) {
                MyDrawable myDrawable = (MyDrawable) drawable;
                if (myDrawable.getMyBitmap() != null && url.equals(myDrawable.getMyBitmap().getUrl())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable)

Aggregations

MyDrawable (org.aisen.android.component.bitmaploader.view.MyDrawable)5 MyBitmap (org.aisen.android.component.bitmaploader.core.MyBitmap)4 TransitionDrawable (android.graphics.drawable.TransitionDrawable)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 LinearLayout (android.widget.LinearLayout)2 ImageConfig (org.aisen.android.component.bitmaploader.core.ImageConfig)2 Paint (android.graphics.Paint)1 WeakReference (java.lang.ref.WeakReference)1