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, int themeResId) {
        super(context, themeResId);
        initView();
    }

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

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

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

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

    public RxScaleImageView getRxScaleImageView() {
        return mRxScaleImageView;
    }

    public void setImagePath(String filePath) {
        this.filePath = filePath;
        mRxScaleImageView.setImage(ImageSource.uri(filePath));
    }

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

    public void setImageAssets(String assetName) {
        this.fileAssetName = assetName;
        mRxScaleImageView.setImage(ImageSource.asset(assetName));
    }

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

    public void setImageBitmap(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);
    }

}

@@ -748,24 +748,108 @@
 text
-, int themeResId
+) %7B%0A        super(context);%0A        initView();%0A    %7D%0A%0A    public RxDialogScaleView(Activity context
 ) %7B%0A
@@ -873,20 +873,8 @@
 text
-, themeResId
 );%0A 
@@ -891,32 +891,33 @@
 tView();%0A    %7D%0A%0A
+%0A
     public RxDia
@@ -949,133 +949,578 @@
 ext,
- boolean cancelable, OnCancelListener cancelListener) %7B%0A        super(context, cancelable, cancelListener);%0A        initView(
+String filePath,boolean isAssets) %7B%0A        super(context);%0A        initView();%0A        setImage(filePath,isAssets);%0A    %7D%0A%0A    public RxDialogScaleView(Context context,Uri uri) %7B%0A        super(context);%0A        initView();%0A        setImage(uri);%0A    %7D%0A%0A    public RxDialogScaleView(Context context,int resId,boolean isResId) %7B%0A        super(context);%0A        initView();%0A        if (isResId) %7B%0A            setImage(resId);%0A        %7D%0A    %7D%0A%0A    public RxDialogScaleView(Context context,Bitmap bitmap) %7B%0A        super(context);%0A        initView();%0A        setImage(bitmap
 );%0A 
@@ -1561,32 +1561,48 @@
 (Context context
+, int themeResId
 ) %7B%0A        supe
@@ -1602,32 +1602,44 @@
    super(context
+, themeResId
 );%0A        initV
@@ -1685,49 +1685,129 @@
 iew(
-Activity context) %7B%0A        super(context
+Context context, boolean cancelable, OnCancelListener cancelListener) %7B%0A        super(context, cancelable, cancelListener
 );%0A 
@@ -1824,32 +1824,33 @@
 tView();%0A    %7D%0A%0A
+%0A
     public RxDia
@@ -2091,20 +2091,16 @@
 setImage
-Path
 (String 
@@ -2107,16 +2107,33 @@
 filePath
+,boolean isAssets
 ) %7B%0A    
@@ -2158,24 +2158,52 @@
 = filePath;%0A
+        if (isAssets) %7B%0A    
         mRxS
@@ -2237,19 +2237,21 @@
 eSource.
-uri
+asset
 (filePat
@@ -2263,78 +2263,24 @@
     
-%7D%0A%0A
     
-public void setImageUri(Uri uri) %7B%0A        this.fileUri = uri;%0A
+%7Delse %7B%0A    
     
@@ -2330,14 +2330,29 @@
 uri(
-uri));
+filePath));%0A        %7D
 %0A   
@@ -2383,73 +2383,46 @@
 mage
-Assets(String assetName) %7B%0A        this.fileAssetName = assetName
+(Uri uri) %7B%0A        this.fileUri = uri
 ;%0A  
@@ -2470,23 +2470,15 @@
 rce.
-asset(assetName
+uri(uri
 ));%0A
@@ -2508,19 +2508,16 @@
 setImage
-Res
 (int res
@@ -2646,22 +2646,16 @@
 setImage
-Bitmap
 (Bitmap 

update RxDialogScaleView.