package com.vondear.rxtools.view.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.vondear.rxtools.R;
import com.vondear.rxtools.view.scaleimage.ImageSource;
import com.vondear.rxtools.view.scaleimage.RxScaleImageView;


/**
 * @author vondear
 * @date 2016/7/19
 * 查看图片并支持手势缩放
 */
public class RxDialogScaleView extends RxDialog {

    private RxScaleImageView mRxScaleImageView;
    private String filePath;
    private Uri fileUri;
    private String fileAssetName;
    private Bitmap fileBitmap;
    private int resId;

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

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


    public RxDialogScaleView(Context context,String filePath,boolean isAssets) {
        super(context);
        initView();
        setImage(filePath,isAssets);
    }

    public RxDialogScaleView(Context context,Uri uri) {
        super(context);
        initView();
        setImage(uri);
    }

    public RxDialogScaleView(Context context,int resId,boolean isResId) {
        super(context);
        initView();
        if (isResId) {
            setImage(resId);
        }
    }

    public RxDialogScaleView(Context context,Bitmap bitmap) {
        super(context);
        initView();
        setImage(bitmap);
    }

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

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


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

    public RxScaleImageView getRxScaleImageView() {
        return mRxScaleImageView;
    }

    public void setImage(String filePath,boolean isAssets) {
        this.filePath = filePath;
        if (isAssets) {
            mRxScaleImageView.setImage(ImageSource.asset(filePath));
        }else {
            mRxScaleImageView.setImage(ImageSource.uri(filePath));
        }
    }

    public void setImage(Uri uri) {
        this.fileUri = uri;
        mRxScaleImageView.setImage(ImageSource.uri(uri));
    }

    public void setImage(int resId) {
        this.resId = resId;
        mRxScaleImageView.setImage(ImageSource.resource(resId));
    }

    public void setImage(Bitmap bitmap) {
        this.fileBitmap = bitmap;
        mRxScaleImageView.setImage(ImageSource.bitmap(fileBitmap));
    }

    private void initView() {
        View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_scaleview, null);
        mRxScaleImageView = (RxScaleImageView) dialogView.findViewById(R.id.rx_scale_view);
        mRxScaleImageView.setMaxScale(20);
        ImageView ivClose = (ImageView) dialogView.findViewById(R.id.iv_close);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cancel();
            }
        });
        setFullScreen();
        setContentView(dialogView);
    }

}

@@ -2140,57 +2140,71 @@
     
-this.filePath = filePath;%0A        if (isAssets) %7B
+if (isAssets) %7B%0A            this.fileAssetName = fileAssetName;
 %0A   
@@ -2261,32 +2261,32 @@
 set(filePath));%0A
-
         %7Delse %7B%0A
@@ -2285,16 +2285,54 @@
 %7Delse %7B%0A
+            this.filePath = filePath;%0A
         
@@ -3419,10 +3419,341 @@
 %0A    %7D%0A%0A
+    public String getFilePath() %7B%0A        return filePath;%0A    %7D%0A%0A    public Uri getFileUri() %7B%0A        return fileUri;%0A    %7D%0A%0A    public String getFileAssetName() %7B%0A        return fileAssetName;%0A    %7D%0A%0A    public Bitmap getFileBitmap() %7B%0A        return fileBitmap;%0A    %7D%0A%0A    public int getResId() %7B%0A        return resId;%0A    %7D%0A%0A%0A
 %7D%0A

update RxDialogScaleView.