package com.fxy.baselibrary.views.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.fxy.baselibrary.R;


/**
 * Created by vondear on 2016/7/19.
 * Mainly used for confirmation and cancel.
 */
public class RxDialogZoomImageView extends RxDialog {

    private ZoomImageView mZoomImageView;

    public RxDialogZoomImageView(Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public RxDialogZoomImageView(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    public RxDialogZoomImageView(Context context) {
        super(context);
        initView();
    }

    public RxDialogZoomImageView(Activity context) {
        super(context);
        initView();
    }

    public RxDialogZoomImageView(Context context, float alpha, int gravity) {
        super(context, alpha, gravity);
        initView();
    }

    public ZoomImageView getRxScaleImageView() {
        return mZoomImageView;
    }

    public void setImagePath(String filePath) {
        Glide.with(mContext)
                .load(filePath)
                .into(mZoomImageView);
    }

    public void setImageUri(Uri uri) {
        Glide.with(mContext)
                .load(uri)
                .into(mZoomImageView);
    }

    public void setImageRes(int resId) {
        Glide.with(mContext)
                .load(resId)
                .into(mZoomImageView);
    }

    public void setImageBitmap(Bitmap bitmap) {
        Glide.with(mContext)
                .load(bitmap)
                .into(mZoomImageView);
    }

    private void initView() {
        View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_zoom_imageview, null);
        mZoomImageView = (ZoomImageView) dialogView.findViewById(R.id.rx_zoom_imageview);
        ImageView ivClose = (ImageView) dialogView.findViewById(R.id.iv_close);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cancel();
            }
        });
        setFullScreen();
        setContentView(dialogView);
    }

}
