package com.chaoran.listener;

import java.io.File;
import java.io.IOException;

import com.chaoran.entiry.PhotographUi;
import com.activity.chaoran.DjActivity;
import com.util.DialogUtil;
import com.util.SysUtil;

import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;

public class PzClickListener implements OnClickListener {
	private DjActivity activity;

	public PzClickListener(DjActivity activity) {
		this.activity = activity;
	}

	@Override
	public void onClick(View v) {
		if (SysUtil.isHasSdcard()) {
			activity.photographUi=(PhotographUi) v.getParent();
			String root=android.os.Environment
					.getExternalStorageDirectory().getAbsolutePath();
			Intent intent = new Intent();
			activity.pzImgPath = root+"/DCIM/Camera/pz.jpg";
			File dir = new File(root+"/DCIM/Camera");
			if (!dir.exists()) {
				dir.mkdirs();
			}
			File mPhotoFile = new File(activity.pzImgPath);
			if (!mPhotoFile.exists()) {
				try {
					mPhotoFile.createNewFile();
				} catch (IOException e) {
					DialogUtil.builder(activity, "提示信息",
							"创建文件失败：" + e.toString(),0);
				}
			}
			intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPhotoFile));
			intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
			activity.startActivityForResult(intent,8888);
		} else {
			DialogUtil.builder(activity, "提示信息", "请插入存储卡！",0);
		}
	}

}
