Search in sources :

Example 1 with QAImageException

use of cn.jeesoft.qa.error.QAImageException in project QuickAndroid by ImKarl.

the class DefaultImage method createQAImageLoadingListener.

/**
     * 创建图片加载监听器
     * @param view
     * @param listener
     * @return
     */
@SuppressWarnings("rawtypes")
private QAImageLoadingListener createQAImageLoadingListener(View view, final QAImageCallback listener) {
    return new QAImageLoadingListener<View>(view) {

        @Override
        public void onLoadingCancelled(View view, String imageUri) {
            if (listener != null) {
                listener.onCancel(imageUri, view);
            }
        }

        @Override
        public void onLoadingComplete(View view, String imageUri, Bitmap loadedImage) {
            if (listener != null) {
                listener.onSuccess(imageUri, view, loadedImage);
            }
        }

        @Override
        public void onLoadingFailed(View view, String imageUri, FailReason failReason) {
            if (listener != null) {
                FailType type = failReason.getType();
                int code = QAException.CODE_UNKNOW;
                if (type == FailType.IO_ERROR) {
                    code = QAException.CODE_IO_FILE;
                } else if (type == FailType.DECODING_ERROR) {
                    code = QAException.CODE_DECODE;
                } else if (type == FailType.NETWORK_DENIED) {
                    code = QAException.CODE_NETWORK;
                } else if (type == FailType.OUT_OF_MEMORY) {
                    code = QAException.CODE_OOM;
                } else if (type == FailType.UNKNOWN) {
                    code = QAException.CODE_UNKNOW;
                }
                QAImageException exception = new QAImageException(code, failReason.getCause());
                listener.onFail(imageUri, view, exception);
            }
        }

        @Override
        public void onLoadingStarted(View view, String imageUri) {
            if (listener != null) {
                listener.onStart(imageUri, view);
            }
        }
    };
}
Also used : QAImageException(cn.jeesoft.qa.error.QAImageException) Bitmap(android.graphics.Bitmap) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) FailType(com.nostra13.universalimageloader.core.assist.FailReason.FailType)

Aggregations

Bitmap (android.graphics.Bitmap)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 QAImageException (cn.jeesoft.qa.error.QAImageException)1 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)1 FailType (com.nostra13.universalimageloader.core.assist.FailReason.FailType)1