Android Open Source - glide-transformations Main Adapter






From Project

Back to project page glide-transformations.

License

The source code is released under:

Apache License

If you think the Android project glide-transformations listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jp.wasabeef.example.glide;
//from w  ww  .j a  va  2 s .  co  m
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PointF;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import jp.wasabeef.glide.transformations.CropSquareTransformation;
import jp.wasabeef.glide.transformations.CropTransformation;
import jp.wasabeef.glide.transformations.GrayscaleTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;

/**
 * Created by Wasabeef on 2015/01/11.
 */
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {

    private Context mContext;
    private List<Type> mDataSet;
    private BitmapPool mPool;

    enum Type {
        Crop,
        CropSquare,
        CropCircle,
        ColorFilter,
        Grayscale,
        RoundedCorners,
        Blur,
        Toon,
        Sepia,
        Contrast,
        Invert,
        Pixel,
        Sketch,
        Swirl,
        Brightness,
        Kuawahara,
        Vignette
    }

    public MainAdapter(Context context, List<Type> dataSet) {
        mContext = context;
        mDataSet = dataSet;
        mPool = Glide.get(mContext).getBitmapPool();
    }

    @Override
    public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mContext)
                .inflate(R.layout.layout_list_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
        Transformation<Bitmap> transformation = null;
        switch (mDataSet.get(position)) {
            case Crop:
                transformation = new CropTransformation(mPool, 300, 100);
                break;
            case CropSquare:
                transformation = new CropSquareTransformation(mPool);
                break;
            case CropCircle:
                transformation = new CropCircleTransformation(mPool);
                break;
            case ColorFilter:
                transformation = new ColorFilterTransformation(mPool, Color.argb(80, 255, 0, 0));
                break;
            case Grayscale:
                transformation = new GrayscaleTransformation(mPool);
                break;
            case RoundedCorners:
                transformation = new RoundedCornersTransformation(mPool, 100, 0);
                break;
            case Blur:
                transformation = new BlurTransformation(mContext, mPool, 10);
                break;
            case Toon:
                transformation = new ToonFilterTransformation(mContext, mPool);
                break;
            case Sepia:
                transformation = new SepiaFilterTransformation(mContext, mPool);
                break;
            case Contrast:
                transformation = new ContrastFilterTransformation(mContext, mPool, 2.0f);
                break;
            case Invert:
                transformation = new InvertFilterTransformation(mContext, mPool);
                break;
            case Pixel:
                transformation = new PixelationFilterTransformation(mContext, mPool, 20);
                break;
            case Sketch:
                transformation = new SketchFilterTransformation(mContext, mPool);
                break;
            case Swirl:
                transformation = new SwirlFilterTransformation(mContext, mPool,
                        0.5f, 1.0f, new PointF(0.5f, 0.5f));
                break;
            case Brightness:
                transformation = new BrightnessFilterTransformation(mContext, mPool, 0.5f);
                break;
            case Kuawahara:
                transformation = new KuwaharaFilterTransformation(mContext, mPool, 25);
                break;
            case Vignette:
                transformation = new VignetteFilterTransformation(mContext, mPool,
                        new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0f, 0.75f);
                break;
        }

        Glide.with(mContext).load(R.drawable.demo)
                .bitmapTransform(transformation).into(holder.image);
        holder.title.setText(mDataSet.get(position).name());
    }

    @Override
    public int getItemCount() {
        return mDataSet.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        public ImageView image;
        public TextView title;

        ViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.image);
            title = (TextView) itemView.findViewById(R.id.title);
        }
    }
}




Java Source Code List

jp.wasabeef.example.glide.MainActivity.java
jp.wasabeef.example.glide.MainAdapter.java
jp.wasabeef.glide.transformations.ApplicationTest.java
jp.wasabeef.glide.transformations.BlurTransformation.java
jp.wasabeef.glide.transformations.ColorFilterTransformation.java
jp.wasabeef.glide.transformations.CropCircleTransformation.java
jp.wasabeef.glide.transformations.CropSquareTransformation.java
jp.wasabeef.glide.transformations.CropTransformation.java
jp.wasabeef.glide.transformations.GrayscaleTransformation.java
jp.wasabeef.glide.transformations.RoundedCornersTransformation.java
jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation.java
jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation.java