/** * 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.content.Context; import android.content.ContextWrapper; import android.graphics.Bitmap; import android.support.annotation.DrawableRes; import android.view.View; import android.widget.ImageView; /** * 作者:王浩 邮件:bingoogolapple@gmail.com * 创建时间:16/6/25 下午4:30 * 描述: */ public abstract class BGAImageLoader { protected String getPath(String path) { if (path == null) { path = ""; } if (!path.startsWith("http") && !path.startsWith("file")) { path = "file://" + path; } return path; } protected Activity getActivity(View view) { Context context = view.getContext(); while (context instanceof ContextWrapper) { if (context instanceof Activity) { return (Activity) context; } context = ((ContextWrapper) context).getBaseContext(); } return null; } public abstract void display(ImageView imageView, String path, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, DisplayDelegate delegate); public abstract void download(String path, DownloadDelegate delegate); public abstract void pause(Activity activity); public abstract void resume(Activity activity); public interface DisplayDelegate { void onSuccess(View view, String path); } public interface DownloadDelegate { void onSuccess(String path, Bitmap bitmap); void onFailed(String path); } }