private void setImageBitmap(Bitmap bt, boolean withAnim) { if (bt == null) { this.setImageDrawable(mDefaultSrc); return; } Drawable preDrawable = getDrawable(); BitmapDrawable btDrawable = null; if (preDrawable instanceof BitmapDrawable) { btDrawable = (BitmapDrawable) preDrawable; } RoundRectDrawable rDrawable = new RoundRectDrawable(getResources(), bt); rDrawable.setConerRadius(mCornerRadius); rDrawable.setUseCanvasClip(this.getScaleType() == ScaleType.CENTER_CROP); if (DEBUG) { System.out.println( "[[WebImageView::setImageBitmap]] drawable obj = " + rDrawable + " corner = " + mCornerRadius + " >>>"); } super.setImageDrawable(rDrawable); if (mHasAnimation) { this.clearAnimation(); if ((Build.VERSION.SDK_INT >= 14) && withAnim && ((bt != null && btDrawable == null) || (bt != null && btDrawable != null && btDrawable.getBitmap() != bt))) { this.startAnimation(mAnimation); } } }
public void setConerRadius(float coner) { if (coner != mCornerRadius) { float density = getContext().getResources().getDisplayMetrics().density; mCornerRadius = coner * density; if (DEBUG) { System.out.println( "[[init]] coner in XML = " + coner + " coner radius = " + mCornerRadius + " >>>::::::::::::: + obj = " + this); } mDefaultSrc = this.getDrawable(); if (mDefaultSrc != null && (mDefaultSrc instanceof BitmapDrawable) && ((BitmapDrawable) mDefaultSrc).getBitmap() != null) { RoundRectDrawable rDrawable = new RoundRectDrawable(getResources(), ((BitmapDrawable) mDefaultSrc).getBitmap()); rDrawable.setConerRadius(mCornerRadius); rDrawable.setUseCanvasClip(this.getScaleType() == ScaleType.CENTER_CROP); mDefaultSrc = rDrawable; this.setImageDrawable(mDefaultSrc); } } }
private void init(Context context, AttributeSet attrs, int defStyle) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WebImageView, defStyle, 0); int res = a.getResourceId(R.styleable.WebImageView_network_animation, -1); float coner = a.getDimension(R.styleable.WebImageView_conerRadius, 0); int cate = a.getInt(R.styleable.WebImageView_category, 0); switch (cate) { case 1: mImageCategory = CustomImageCategory.THUMBNAIL_CATEGORY; mBitmapOperationListener = new ThumnbailBitmapOperation(); break; case 2: mImageCategory = CustomImageCategory.SMALL_CATEGORY; mBitmapOperationListener = new SmallBitmapOperation(); break; default: mImageCategory = CustomImageCategory.DEFAULT_CATEGORY; mBitmapOperationListener = null; break; } float density = context.getResources().getDisplayMetrics().density; mCornerRadius = coner * density; if (DEBUG) { System.out.println( "[[init]] coner in XML = " + coner + " coner radius = " + mCornerRadius + " >>>::::::::::::: + obj = " + this); } if (res > 0) { mAnimation = AnimationUtils.loadAnimation(context.getApplicationContext(), res); if (mAnimation != null) { mHasAnimation = true; } } a.recycle(); mImageCache = (ICacheManager<Bitmap>) CacheFactory.getCacheManager(CacheFactory.TYPE_CACHE.TYPE_IMAGE); mImageDownloaer = ImageDownloader.getInstance(context.getApplicationContext()); mCategory = mImageCategory.toString(); mDefaultSrc = this.getDrawable(); if (mDefaultSrc != null && (mDefaultSrc instanceof BitmapDrawable) && ((BitmapDrawable) mDefaultSrc).getBitmap() != null) { RoundRectDrawable rDrawable = new RoundRectDrawable(getResources(), ((BitmapDrawable) mDefaultSrc).getBitmap()); rDrawable.setConerRadius(mCornerRadius); rDrawable.setUseCanvasClip(this.getScaleType() == ScaleType.CENTER_CROP); mDefaultSrc = rDrawable; this.setImageDrawable(mDefaultSrc); } }
public void setDefaultSrc(int res) { if (res > 0) { this.setImageResource(res); mDefaultSrc = this.getDrawable(); if (mDefaultSrc != null && (mDefaultSrc instanceof BitmapDrawable) && ((BitmapDrawable) mDefaultSrc).getBitmap() != null) { RoundRectDrawable rDrawable = new RoundRectDrawable(getResources(), ((BitmapDrawable) mDefaultSrc).getBitmap()); rDrawable.setConerRadius(mCornerRadius); rDrawable.setUseCanvasClip(this.getScaleType() == ScaleType.CENTER_CROP); mDefaultSrc = rDrawable; this.setImageDrawable(mDefaultSrc); } } }