GalleryFinal 接入

图片选择器使用场合比较多,第三方的框架也有不少,这个算是比较优秀的

接入方法:

gradle

compile 'cn.finalteam:galleryfinal:1.4.8.7'
compile 'com.android.support:support-v4:23.1.1'

application

private void initGalleryFinal(){

    ThemeConfig theme = new ThemeConfig.Builder()
            .setTitleBarBgColor(Color.rgb(0xFF, 0x57, 0x22))
            .setTitleBarTextColor(Color.BLACK)
            .setTitleBarIconColor(Color.BLACK)
            .setFabNornalColor(Color.RED)
            .setFabPressedColor(Color.BLUE)
            .setCheckNornalColor(Color.WHITE)
            .setCheckSelectedColor(Color.BLACK)
            .setIconBack(R.mipmap.ic_action_previous_item)
            .setIconRotate(R.mipmap.ic_action_repeat)
            .setIconCrop(R.mipmap.ic_action_crop)
            .setIconCamera(R.mipmap.ic_action_camera)
            .build();
    //配置功能
    FunctionConfig functionConfig = new FunctionConfig.Builder()
            .setEnableCamera(true)
            .setEnableEdit(false)
            .setEnableCrop(false)
            .setEnableRotate(true)
            .setCropSquare(true)
            .setEnablePreview(true)
            .build();

    initImageLoader(context);

    CoreConfig coreConfig = new CoreConfig.Builder(this, new UILImageLoader(), theme)
            .setFunctionConfig(functionConfig)
            .setPauseOnScrollListener(new UILPauseOnScrollListener(false, true))
            .build();
    GalleryFinal.init(coreConfig);
}

private void initImageLoader(Context context) {
    // This configuration tuning is custom. You can tune every option, you may tune some of them,
    // or you can create default configuration by
    //  ImageLoaderConfiguration.createDefault(this);
    // method.
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
    config.threadPriority(Thread.NORM_PRIORITY - 2);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
    config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    config.writeDebugLogs(); // Remove for release app

    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config.build());
}
项目中添加文件
import com.nostra13.universalimageloader.core.ImageLoader;

import cn.finalteam.galleryfinal.PauseOnScrollListener;

/**
 * Desction:
 * Author:pengjianbo
 * Date:2016/1/9 0009 18:47
 */
public class UILPauseOnScrollListener extends PauseOnScrollListener {

    public UILPauseOnScrollListener(boolean pauseOnScroll, boolean pauseOnFling) {
        super(pauseOnScroll, pauseOnFling);
    }

    @Override
    public void resume() {
        ImageLoader.getInstance().resume();
    }

    @Override
    public void pause() {
        ImageLoader.getInstance().pause();
    }
}

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;

import cn.finalteam.galleryfinal.widget.GFImageView;

/**
 * Desction:
 * Author:pengjianbo
 * Date:15/10/10 下午5:52
 */
public class UILImageLoader implements cn.finalteam.galleryfinal.ImageLoader {

    private Bitmap.Config mImageConfig;

    public UILImageLoader() {
        this(Bitmap.Config.RGB_565);
    }

    public UILImageLoader(Bitmap.Config config) {
        this.mImageConfig = config;
    }

    @Override
    public void displayImage(Activity activity, String path, GFImageView imageView, Drawable defaultDrawable, int width, int height) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .cacheOnDisk(false)
                .cacheInMemory(false)
                .bitmapConfig(mImageConfig)
                .build();
        ImageSize imageSize = new ImageSize(width, height);
        ImageLoader.getInstance().displayImage("file://" + path, new ImageViewAware(imageView), options, imageSize, null, null);
    }

    @Override
    public void clearMemoryCache() {

    }

}

 
  
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.weisj.fx.R;

import java.util.List;

import cn.finalteam.galleryfinal.model.PhotoInfo;
import cn.finalteam.toolsfinal.DeviceUtils;

/**
 * Desction:
 * Author:pengjianbo
 * Date:15/12/1 下午8:42
 */
public class ChoosePhotoListAdapter extends BaseAdapter {
    private List mList;
    private LayoutInflater mInflater;
    private int mScreenWidth;

    public ChoosePhotoListAdapter(Activity activity, List list) {
        this.mList = list;
        this.mInflater = LayoutInflater.from(activity);
        this.mScreenWidth = DeviceUtils.getScreenPix(activity).widthPixels;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnFail(R.mipmap.ic_gf_default_photo)
                .showImageForEmptyUri(R.mipmap.ic_gf_default_photo)
                .showImageOnLoading(R.mipmap.ic_gf_default_photo).build();

        ImageView ivPhoto = (ImageView) mInflater.inflate(R.layout.adapter_photo_list_item, null);
        setHeight(ivPhoto);

        PhotoInfo photoInfo = mList.get(position);
        ImageLoader.getInstance().displayImage("file:/" + photoInfo.getPhotoPath(), ivPhoto, options);
        return ivPhoto;
    }

    private void setHeight(final View convertView) {
        int height = mScreenWidth / 3 - 8;
        convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
    }
}

在使用的activity中调用
GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY, MAX_IMG, mOnHanlderResultCallback);
实现
private GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback = new GalleryFinal.OnHanlderResultCallback() {
    @Override
    public void onHanlderSuccess(int reqeustCode, 
   @Override
    public void onHanlderFailure(int requestCode, String errorMsg) {
        Toast.makeText(GoodEvaluateActivity.this, errorMsg, Toast.LENGTH_SHORT).show();
    }

参考文献

https://segmentfault.com/a/1190000004263541?_ea=554102



你可能感兴趣的:(GalleryFinal 接入)