/**
* Copyright 2016 bingoogolapple
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.bingoogolapple.photopicker.imageloader;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.widget.ImageView;
import org.xutils.common.Callback;
import org.xutils.image.ImageOptions;
import org.xutils.x;
import cn.bingoogolapple.photopicker.util.BGAPhotoPickerUtil;
/**
* 作者:王浩 邮件:bingoogolapple@gmail.com
* 创建时间:16/6/25 下午6:03
* 描述:
*/
public class BGAXUtilsImageLoader extends BGAImageLoader {
@Override
public void display(final ImageView imageView, String path, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final DisplayDelegate delegate) {
x.Ext.init(BGAPhotoPickerUtil.sApp);
ImageOptions options = new ImageOptions.Builder()
.setLoadingDrawableId(loadingResId)
.setFailureDrawableId(failResId)
.setSize(width, height)
.build();
final String finalPath = getPath(path);
x.image().bind(imageView, finalPath, options, new Callback.CommonCallback<Drawable>() {
@Override
public void onSuccess(Drawable result) {
if (delegate != null) {
delegate.onSuccess(imageView, finalPath);
}
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
}
@Override
public void onCancelled(CancelledException cex) {
}
@Override
public void onFinished() {
}
});
}
@Override
public void download(String path, final DownloadDelegate delegate) {
x.Ext.init(BGAPhotoPickerUtil.sApp);
final String finalPath = getPath(path);
x.image().loadDrawable(finalPath, new ImageOptions.Builder().build(), new Callback.CommonCallback<Drawable>() {
@Override
public void onSuccess(Drawable result) {
if (delegate != null) {
delegate.onSuccess(finalPath, ((BitmapDrawable) result).getBitmap());
}
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
if (delegate != null) {
delegate.onFailed(finalPath);
}
}
@Override
public void onCancelled(CancelledException cex) {
}
@Override
public void onFinished() {
}
});
}
@Override
public void pause(Activity activity) {
}
@Override
public void resume(Activity activity) {
}
}