ImgLoadManager

package com.cmb.zh.common.util;


import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.ImageView;


import com.cmb.zhsdk.magi.task.ICancelable;


public interface ImgLoadManager {
    interface LoadListener {
        void onSuccess(Bitmap bitmap);


        void onFailed(Throwable error);
    }


    interface ImgLoadReq {


        /**
         * 默認圖片
         *
         * @param placeholderResId 默認資源id
         * @return
         */
        ImgLoadReq placeholder(int placeholderResId);


        /**
         * 錯誤圖片
         *
         * @param errorResId 默認資源id
         * @return
         */
        ImgLoadReq error(int errorResId);


        /**
         * 設置tag,用於開啓或結束圖片加載
         *
         * @param tag
         * @return
         */
        ImgLoadReq tag(Object tag);


        /**
         * 重置圖片寬高
         *
         * @param width
         * @param height
         * @return
         */
        ImgLoadReq resize(int width, int height);




        /**
         * CenterInside()是一種尺度圖像的裁剪技術,這樣兩個尺寸等於或小於請求的ImageView的界限。圖像將顯示完全,但可能不會填滿整個ImageView
         *
         * @return
         */
        ImgLoadReq centerInside();


        /**
         * CenterCrop()是一種尺度圖像的裁剪技術,填補了ImageView的要求範圍,然後修剪其餘的範圍。ImageView將被完全填滿,但整個圖像可能不會顯示
         *
         * @return
         */
        ImgLoadReq centerCrop();


        /**
         * 圖片旋轉
         *
         * @param degrees 旋轉的角度
         * @return
         */
        ImgLoadReq rotate(float degrees);




        /**
         * 加載圖片至imageView控件
         *
         * @param imgView
         */
        ICancelable into(ImageView imgView);


        ICancelable into(LoadListener listener);


        /**
         * 自適應控件寬高設置圖片(wrap_content 無法計算)
         *
         * @return
         */
        ImgLoadReq fit();
    }




    /**
     * 加載
     *
     * @param path 可以是 url 或 本地路徑(本地路徑時需完全路徑file://...,否則無法正常顯示)
     * @return
     */
    ImgLoadReq load(String path);


    /**
     * 加載資源文件
     *
     * @param resourceId 資源id
     * @return
     */
    ImgLoadReq load(int resourceId);


    ImgLoadReq load(Uri path);


    /**
     * 加載本地圖片
     *
     * @param path 圖片本地路徑
     * @return
     */
    ImgLoadReq loadFile(String path);


    /**
     * 關閉請求
     *
     * @param tag
     */
    void pauseLoadByTag(Object tag);


    /**
     * 開啓請求
     *
     * @param tag
     */
    void resumeLoadByTag(Object tag);
}
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章