com.lidroid.xutils.BitmapUtils Java Examples

The following examples show how to use com.lidroid.xutils.BitmapUtils. 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: BitMapFragment.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater,
		@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
	View view = inflater.inflate(R.layout.bitmap_fragment_view, container,
			false);
	ViewUtils.inject(this, view);
	adapter = new MyAdapter(getActivity());
	listView.setAdapter(adapter);
	
	bitmapUtils = new BitmapUtils(getActivity());
	bitmapUtils.configDefaultLoadingImage(R.drawable.ic_launcher);
       bitmapUtils.configDefaultLoadFailedImage(R.drawable.down);
       bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565);
       
       loadImgList("http://www.22mm.cc/");
	return view;
}
 
Example #2
Source File: ImageShowActivity.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
/**
	 * 初始化BitmapUtils
	 */
	private void initBitmapUtils() {
		mBitmapUtils = new BitmapUtils(this);
//		mBitmapUtils.configDefaultLoadingImage(R.drawable.p_ic_imgloading);
//		mBitmapUtils.configDefaultLoadFailedImage(R.drawable.p_ic_imgloading_fail);
		mBitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565);
		mBitmapUtils.configMemoryCacheEnabled(true);
		mBitmapUtils.configDiskCacheEnabled(true);
	}
 
Example #3
Source File: IndexFragment.java    From miappstore with Apache License 2.0 5 votes vote down vote up
private void initTopView() {
    final BitmapUtils bitmapUtils = BitmapHelper.getBitmapUtils();
    iv_top1 = (ImageView) index_top.findViewById(R.id.iv_top1);
    iv_top2 = (ImageView) index_top.findViewById(R.id.iv_top2);
    iv_top3 = (ImageView) index_top.findViewById(R.id.iv_top3);
    iv_top4 = (ImageView) index_top.findViewById(R.id.iv_top4);
    final List<ImageView> imageViews = new ArrayList<ImageView>();
    imageViews.add(iv_top1);
    imageViews.add(iv_top2);
    imageViews.add(iv_top3);
    imageViews.add(iv_top4);
    //请求网络数据
    ThreadManager.getInstance().createLongPool().execute(new Runnable() {
        @Override
        public void run(){
            IndexTopProtocal indexTopProtocal = new IndexTopProtocal();
            final List<IndexTop> load = indexTopProtocal.load(0);
            //在主线程刷新界面
            UiUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    for (int i=0;i<load.size();i++){
                        IndexTop indexTop = load.get(i);
                        bitmapUtils.display(imageViews.get(i),indexTop.getHost()+indexTop.getMticon());
                    }
                }
            });
        }
    });
}
 
Example #4
Source File: AsyncDrawable.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public AsyncDrawable(Drawable drawable, BitmapUtils.BitmapLoadTask<T> bitmapWorkerTask) {
    if (bitmapWorkerTask == null) {
        throw new IllegalArgumentException("bitmapWorkerTask may not be null");
    }
    baseDrawable = drawable;
    bitmapLoadTaskReference = new WeakReference<BitmapUtils.BitmapLoadTask<T>>(bitmapWorkerTask);
}
 
Example #5
Source File: BaseActivity.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
private void initBitmapUtils() {
	bitmapUtils = new BitmapUtils(this);
	bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565);
	bitmapUtils.configMemoryCacheEnabled(true);
	bitmapUtils.configDiskCacheEnabled(true);
}
 
Example #6
Source File: XUtils2ImageLoader.java    From GalleryFinal with Apache License 2.0 4 votes vote down vote up
public XUtils2ImageLoader(Context context) {
    bitmapUtils = new BitmapUtils(context);
}
 
Example #7
Source File: DefaultDownloader.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
/**
 * Download bitmap to outputStream by uri.
 *
 * @param uri          file path, assets path(assets/xxx) or http url.
 * @param outputStream
 * @param task
 * @return The expiry time stamp or -1 if failed to download.
 */
@Override
public long downloadToStream(String uri, OutputStream outputStream, final BitmapUtils.BitmapLoadTask<?> task) {

    if (task == null || task.isCancelled() || task.getTargetContainer() == null) return -1;

    URLConnection urlConnection = null;
    BufferedInputStream bis = null;

    OtherUtils.trustAllHttpsURLConnection();

    long result = -1;
    long fileLen = 0;
    long currCount = 0;  
    try {
    	//分三种方式获取图片
        if (uri.startsWith("/")) { 
        	//sd卡获取
            FileInputStream fileInputStream = new FileInputStream(uri);
            fileLen = fileInputStream.available();
            bis = new BufferedInputStream(fileInputStream);
            result = System.currentTimeMillis() + this.getDefaultExpiry();
        } else if (uri.startsWith("assets/")) { 
        	//资产文件夹
            InputStream inputStream = this.getContext().getAssets().open(uri.substring(7, uri.length()));
            fileLen = inputStream.available();
            bis = new BufferedInputStream(inputStream);
            result = Long.MAX_VALUE;
        } else {  
        	//网络
            final URL url = new URL(uri);
            urlConnection = url.openConnection();
            urlConnection.setConnectTimeout(this.getDefaultConnectTimeout());
            urlConnection.setReadTimeout(this.getDefaultReadTimeout());
            bis = new BufferedInputStream(urlConnection.getInputStream());
            result = urlConnection.getExpiration();
            result = result < System.currentTimeMillis() ? System.currentTimeMillis() + this.getDefaultExpiry() : result;
            fileLen = urlConnection.getContentLength();
        }

        if (task.isCancelled() || task.getTargetContainer() == null) return -1;

        byte[] buffer = new byte[4096];
        int len = 0;
        BufferedOutputStream out = new BufferedOutputStream(outputStream);
        while ((len = bis.read(buffer)) != -1) {
            out.write(buffer, 0, len);
            currCount += len;
            if (task.isCancelled() || task.getTargetContainer() == null) return -1;
            task.updateProgress(fileLen, currCount);     //回调
        }
        out.flush();
    } catch (Throwable e) {
        result = -1;
        LogUtils.e(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(bis);
    }
    return result;
}
 
Example #8
Source File: AsyncDrawable.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public BitmapUtils.BitmapLoadTask<T> getBitmapWorkerTask() {
    return bitmapLoadTaskReference.get();
}
 
Example #9
Source File: Downloader.java    From android-open-project-demo with Apache License 2.0 2 votes vote down vote up
/**
 * Download bitmap to outputStream by uri.
 *
 * @param uri
 * @param outputStream
 * @return The expiry time stamp or -1 if failed to download.
 */
public abstract long downloadToStream(String uri, OutputStream outputStream, final BitmapUtils.BitmapLoadTask<?> task);