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 setCategory(int category) { switch (category) { 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; } mCategory = mImageCategory.toString(); }