/** * 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.Bitmap; import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; import android.widget.ImageView; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.Target; import cn.bingoogolapple.photopicker.util.BGAPhotoPickerUtil; /** * 作者:王浩 邮件:bingoogolapple@gmail.com * 创建时间:16/6/25 下午4:45 * 描述: */ public class BGAPicassoImageLoader extends BGAImageLoader { @Override public void display(final ImageView imageView, String path, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final DisplayDelegate delegate) { final String finalPath = getPath(path); Activity activity = getActivity(imageView); Picasso.with(activity).load(finalPath).tag(activity).placeholder(loadingResId).error(failResId).resize(width, height).centerInside().into(imageView, new Callback.EmptyCallback() { @Override public void onSuccess() { if (delegate != null) { delegate.onSuccess(imageView, finalPath); } } }); } @Override public void download(String path, final DownloadDelegate delegate) { final String finalPath = getPath(path); Picasso.with(BGAPhotoPickerUtil.sApp).load(finalPath).into(new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { if (delegate != null) { delegate.onSuccess(finalPath, bitmap); } } @Override public void onBitmapFailed(Drawable errorDrawable) { if (delegate != null) { delegate.onFailed(finalPath); } } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }); } @Override public void pause(Activity activity) { Picasso.with(activity).pauseTag(activity); } @Override public void resume(Activity activity) { Picasso.with(activity).resumeTag(activity); } }