package com.ruiwenliu.wrapper.util;

import android.graphics.Bitmap;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.request.target.ImageViewTarget;

public class TransformationUtil3 extends ImageViewTarget<Bitmap> {

    private ImageView target;

    public TransformationUtil3(ImageView target) {
        super(target);
        this.target = target;
    }

    @Override
    protected void setResource(Bitmap resource) {
        target.setImageBitmap(resource);

        if (resource == null) return;
        //获取原图的宽高
        int width = resource.getWidth();
        int height = resource.getHeight();

        //获取imageView的宽
        int imageViewWidth = target.getWidth();
        int imageViewHeight = 0;
        if ((width * 0.1f) / (height * 0.1f) < 0.75) {
            //计算图片等比例放大后的高
            imageViewHeight = (int) (1.5f * imageViewWidth);
        } else {
            imageViewHeight = imageViewWidth;
        }

        ViewGroup.LayoutParams params = target.getLayoutParams();
        params.height = imageViewHeight;
        target.setLayoutParams(params);
    }
}