package com.cwbuyer.code;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Bitmap.CompressFormat;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.cwbuyer.format.DefaultData;
import com.cwbuyer.format.EMode;
import com.cwbuyer.format.IDialog;
import com.cwbuyer.format.TypeData;
import com.cwbuyer.lib.Calculator;
import com.cwbuyer.lib.DBCloud;
import com.cwbuyer.lib.DBUtil;
import com.cwbuyer.lib.DateUtil;
import com.cwbuyer.lib.DialogUtilis;
import com.cwbuyer.lib.TbName;
import com.cwbuyer.lib.Utilis;
import com.pwbuyer.main.R;

@SuppressLint("InflateParams")
public class AddCategory extends Activity{

	private int COUNTRY_CODE = 1001;
	private int CAPTURE = 1010;
	private final int TPICTURE = 1009;
	private static int nPicDegree =0;
	private int mMode = 0;
	private int mID = 0;
	private int rotationInDegrees=0;
	String edpic="";
	TypeData mData = null;
	
	//	0單機 1On_line 2.Off_line
	int of_line=Utilis.toInt(Utilis.getIni(AddCategory.this, "SYS", "IMPORT", 3));
	String mUid=Utilis.getIni(AddCategory.this, "SYS", "IMPORT", 2);  //ex:3g001
	
	private ArrayList<Integer> mCountryId = new ArrayList<Integer>();
	private ArrayList<String> mCountryList = new ArrayList<String>();
	private ArrayList<String> mCountryIcon = new ArrayList<String>();
	private String[] mSeason = new String[]{"春天","夏天","秋天","冬天","四季"};
	
	private int mSpinnerPos1 = 0;
	
	ImageView OutPhoto = null;
	Uri mImageCaptureUri = null;
	private String mImagePath = null;
	
	final String filepath=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+Utilis.getIni(this, "SYS", "YEAR", 8);
	public final  String SAVE_FOLDER = filepath + File.separator;
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		String OutPhotoURI;
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == COUNTRY_CODE) {
			if (resultCode == RESULT_OK) {
				int id = data.getIntExtra("country_id", 0);
				String pid = data.getStringExtra("country_pic");
				String name = data.getStringExtra("country_name");
				try{
					mData.nCountry = id;
					((ImageView)findViewById(R.id.img_country)).setImageDrawable(Utilis.getResourceImage(AddCategory.this, pid));
					((EditText)findViewById(R.id.edit_country)).setText(name);
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}  
		else if ((requestCode == CAPTURE) && (resultCode == RESULT_OK)) // 相本
		{
			

 	    		edpic=filepath +File.separator+"Cate_"+ String.valueOf(DateUtil.getSystemTime())+ ".jpg";
	    		
	    		Bitmap mBitmap=null;Bitmap bitmap=null;
	            Uri selectedImageUri = data.getData();
	            
	            if (Build.VERSION.SDK_INT < 19) {
	            	OutPhotoURI = getPath(selectedImageUri);
	            	mBitmap = Utilis.getScaleBitmap(OutPhotoURI, 210, 280);
					try {
						ExifInterface exif = new ExifInterface(OutPhotoURI);
						int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
						rotationInDegrees = exifToDegrees(rotation);
						Matrix matrix = new Matrix();
						matrix.preRotate(rotationInDegrees);
						bitmap = Bitmap.createBitmap(mBitmap, 0, 0, 210, 280, matrix, true);
						
	    		        FileOutputStream fos = null;
	    				try {
	    						fos = new FileOutputStream(edpic);
	   	    					bitmap.compress(CompressFormat.JPEG, 100, fos);
	   	    					fos.close();
	   	    					mBitmap=bitmap;	
	    				} catch (FileNotFoundException e) {
	    					// TODO Auto-generated catch block
	    					e.printStackTrace();
	    				}
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
	            }
	            else
	            {
	                ParcelFileDescriptor parcelFileDescriptor;
	                try {
	                    parcelFileDescriptor = getContentResolver().openFileDescriptor(selectedImageUri, "r");
	                    FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
	                    bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor);
	                    parcelFileDescriptor.close();

	    				ByteArrayOutputStream stream = new ByteArrayOutputStream();
	    				bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);// (0 - 100)压缩文件
	    		        FileOutputStream fos = null;
	    				try {
	    						fos = new FileOutputStream(edpic);
	    				} catch (FileNotFoundException e) {
	    					// TODO Auto-generated catch block
	    					e.printStackTrace();
	    				}
	    				try {
	    					bitmap.compress(CompressFormat.JPEG, 100, fos);
	    					fos.close();
	    					mBitmap = Utilis.getScaleBitmap(edpic, 210, 280);
	    	                //mBitmap = BitmapFactory.decodeFile(OutPhotoURI);
	    					
	    					try {
	    						ExifInterface exif = new ExifInterface(edpic);
	    						int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
	    						rotationInDegrees = exifToDegrees(rotation);
	    						Matrix matrix = new Matrix();
	    						matrix.preRotate(rotationInDegrees);
	    						bitmap = Bitmap.createBitmap(mBitmap, 0, 0, 210, 280, matrix, true);

	    						try {
	    	    						fos = new FileOutputStream(edpic);
	    	   	    					bitmap.compress(CompressFormat.JPEG, 100, fos);
	    	   	    					fos.close();
	    	   	    					mBitmap=bitmap;	
	    	    				} catch (FileNotFoundException e) {
	    	    					// TODO Auto-generated catch block
	    	    					e.printStackTrace();
	    	    				}

	    					} catch (IOException e) {
	    						// TODO Auto-generated catch block
	    						e.printStackTrace();
	    					}
	    					
	    					
	    				} catch (IOException e) {
	    					// TODO Auto-generated catch block
	    					e.printStackTrace();
	    				}
	                    
	                } catch (FileNotFoundException e) {
	                    e.printStackTrace();
	                } catch (IOException e) {

	                    e.printStackTrace();
	                }
	            }
				if (mBitmap!=null && mBitmap.getHeight()>0 )
				{
					mImagePath = edpic;
					OutPhoto.setImageBitmap(mBitmap);
				}
		}else if ((requestCode == TPICTURE) && (resultCode == RESULT_OK)) // 照相
		{
			//ContentResolver cr = this.getContentResolver();
			if (data != null) {
				try {
					Bundle extras = data.getExtras();
					if (extras != null) {
						OutPhotoURI = mImageCaptureUri.getPath();
						Bitmap bitmap=null;
						OutPhotoURI = mImageCaptureUri.getPath();
						bitmap = Utilis.getLimitBitmap(
						mImageCaptureUri.getPath(), 80,80);
						if (bitmap != null) {
							ExifInterface exif = new ExifInterface(OutPhotoURI);
							int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
							int rotationInDegrees = exifToDegrees(rotation);
							Matrix matrix = new Matrix();
							matrix.preRotate(rotationInDegrees);
							Bitmap adjustedBitmap = Bitmap.createBitmap(bitmap, 0, 0, 80, 80, matrix, true);
							mImagePath = OutPhotoURI;
							//OutPhoto.setScaleType(ScaleType.FIT_XY);
							OutPhoto.setImageBitmap(adjustedBitmap);
						}
					}
				} catch (Exception e) {

				}
			} else {
				try {
					OutPhotoURI = mImageCaptureUri.getPath();
					Bitmap bitmap = Utilis
							.getLimitBitmap(OutPhotoURI, 80, 80);
					if (bitmap != null) {
						Matrix matrix = new Matrix();
						ExifInterface exif = new ExifInterface(OutPhotoURI);
						int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
						int rotationInDegrees = exifToDegrees(rotation);
						
						matrix.preRotate(rotationInDegrees);
						Bitmap adjustedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
							mImagePath = OutPhotoURI;
							//OutPhoto.setScaleType(ScaleType.FIT_XY);
							OutPhoto.setImageBitmap(adjustedBitmap);
						ByteArrayOutputStream stream = new ByteArrayOutputStream();
						adjustedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);// (0 - 100)压缩文件

				        FileOutputStream fos = null;
						try {
								fos = new FileOutputStream(mImagePath);
						} catch (FileNotFoundException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
						try {
							adjustedBitmap.compress(CompressFormat.JPEG, 100, fos);
							fos.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				} catch (Exception e) {
				}
				
				try {
					OutPhotoURI = mImageCaptureUri.getPath();
					Bitmap bitmap = Utilis.getLimitBitmap(
							mImageCaptureUri.getPath(), 80, 80);
					if (bitmap != null) {
						mImagePath = OutPhotoURI;
						//OutPhoto.setScaleType(ScaleType.FIT_XY);
						OutPhoto.setImageBitmap(bitmap);
					}
				} catch (Exception e) {
				}
			}
		}
	}
	
	private static int exifToDegrees(int exifOrientation) {        
	    if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; } 
	    else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {  return 180; } 
	    else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {  return 270; }            
	    return nPicDegree;    
	 }

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_category);
		setTitle("商品類別資料編輯");
		
		mID = getIntent().getIntExtra("id", 0);
		mMode = getIntent().getIntExtra("mode", EMode.ADD);
		nPicDegree =Utilis.toInt(Utilis.getIni(this, "SYS", "BACKOUT", 8)); // 帳戶		
		
		OutPhoto = (ImageView)findViewById(R.id.img_icon);
		if(mMode == EMode.ADD){
			getCountryData(this);
			
			// 新增的情況下帶入 預設參數的國家&季節
			DefaultData defaultData = DBUtil.Default.getDefaultData(this);
			
			mData = new TypeData();
//			OutPhoto.setBackgroundResource(R.drawable.keypad_photo);
			if(defaultData != null){
				mData.nCountry = defaultData.nCountry;
				mData.country = defaultData.country; 
				int index = mCountryId.indexOf(mData.nCountry);
				if(index >= 0){
					((ImageView)findViewById(R.id.img_country)).setImageDrawable(Utilis.getResourceImage(this, mCountryIcon.get(index)));
				}
				mData.nSeason = defaultData.nSeason;
				mData.season = mSeason[mData.nSeason];
			}else{
				mData.country = mCountryList.get(0);
				mData.nCountry = mCountryId.get(0);
				mData.season = "春天";
				mData.nSeason = 0;
				((ImageView)findViewById(R.id.img_country)).setImageDrawable(Utilis.getResourceImage(this, mCountryIcon.get(0)));
			}
			
			((EditText)findViewById(R.id.edit_season)).setText("" + mData.season);
			((EditText)findViewById(R.id.edit_country)).setText("" + mData.country);
		}else{
			getData(mID);
			if(mData != null){
				OutPhoto.setImageDrawable(Utilis.getResourceImage(this, mData.icon));
				((ImageView)findViewById(R.id.img_country)).setImageDrawable(Utilis.getResourceImage(this, mCountryIcon.get(mData.nCountry - 1)));
				((EditText)findViewById(R.id.edit_desc)).setText(mData.desc);
				((EditText)findViewById(R.id.edit_season)).setText("" + mData.season);
				((EditText)findViewById(R.id.edit_country)).setText("" + mData.country);
				((EditText)findViewById(R.id.edit_addcost)).setText("" + mData.nAddcost);
				mSpinnerPos1 = mData.nSeason;
				mImagePath = mData.icon;
			}
		}
		
		OutPhoto = (ImageView)findViewById(R.id.img_icon);
		OutPhoto.setOnClickListener(new MenuClick());
		((EditText)findViewById(R.id.edit_addcost)).setOnClickListener(new NumberClick());
		((EditText)findViewById(R.id.edit_country)).setOnClickListener(new MenuClick());
		((EditText)findViewById(R.id.edit_season)).setOnClickListener(new MenuClick());
		((Button)findViewById(R.id.btn_save)).setOnClickListener(new MenuClick());
		((Button)findViewById(R.id.btn_next)).setOnClickListener(new MenuClick());
		((Button)findViewById(R.id.btn_exit)).setOnClickListener(new MenuClick());
		
	}
	
	
	class NumberClick implements OnClickListener{
		@Override
		public void onClick(View v) {
			int id = v.getId();
			Utilis.runVibrate(AddCategory.this);
//			switch (id) {
//			}
			showComputer(id);
		}
	}
	
	class MenuClick implements OnClickListener{
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			int id = v.getId();
			Utilis.runVibrate(AddCategory.this);
			switch(id){
				case R.id.img_icon:
				{
					DialogUtilis.showDialog(AddCategory.this, "請選擇以下功能", -1, new String[]{"拍照","相本"}, new IDialog(){
						@Override
						public void onDialogFinish(int pos, String choice) {
							switch(pos){
								case 0: // 拍照
									eventImgCapture();
									break;
								case 1: // 相本
									eventImgFile();
									break;
							}
						}
					});
					break;
				}
				case R.id.edit_country:
				{
					Intent intent = new Intent();
					intent.setClass(AddCategory.this, CodeList.class);
					intent.putExtra("code_mode", CodeMode.COUNTRY);
					intent.putExtra("edit_mode", 1);
					AddCategory.this.startActivityForResult(intent, COUNTRY_CODE);
					break;
				}
				case R.id.edit_season:
				{
					DialogUtilis.showDialog(AddCategory.this, "請選擇季節", mSpinnerPos1, mSeason, new IDialog(){
						public void onDialogFinish(int nPos, String choice) {
							mSpinnerPos1 = nPos;
							mData.nSeason = nPos;
							((EditText)findViewById(R.id.edit_season)).setText(choice);
						}
					});
					break;
				}
				case R.id.btn_next:
				{
					if(saveData() == true){
						mMode = EMode.ADD;
						mID=0; //複製一筆資料
						Toast.makeText(AddCategory.this, "下一筆資料記錄開始", Toast.LENGTH_SHORT).show();
					}
					break;
				}
				case R.id.btn_save:
					if(saveData() == true){
						finish();
					}
					break;
				case R.id.btn_exit:
					finish();
					break;
			}
		}
	}
	
	@SuppressWarnings("unused")
	private void showComputer(final int vid){
		AlertDialog.Builder dialog = new AlertDialog.Builder(this);
		final View root = this.getLayoutInflater().inflate(R.layout.dlg_computer, null);
		Calculator calu = new Calculator(AddCategory.this, root);
		final TextView print = (TextView)root.findViewById(R.id.text_print);
		dialog.setView(root);
		dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
	          public void onClick(DialogInterface dialog, int which) {
	        	  EditText edit = (EditText)AddCategory.this.findViewById(vid);
	        	  try{
	        		  String result = print.getText().toString();
	        		  if(result == null || result.length() <=0){
	        			  print.setText("0");
	        		  }else if(result.indexOf("+") > 0){
	        			  print.setText("0");
	        		  }else if(result.indexOf("-") > 0){
	        			  print.setText("0");
	        		  }else if(result.indexOf("×") > 0){
	        			  print.setText("0");
	        		  }else if(result.indexOf("÷") > 0){
	        			  print.setText("0");
	        		  }
	        		  edit.setText(print.getText().toString());
	        	  }catch(Exception e){
	        		  
	        	  }
	          }
		});
		dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
	          public void onClick(DialogInterface dialog, int which) {
	          }
			});
		dialog.show();
	}

	public String getPath(Uri uri) {
        if( uri == null ) {
            return null;
        }
        String[] projection = { MediaStore.Images.Media.DATA };
        @SuppressWarnings("deprecation")
		Cursor cursor = managedQuery(uri, projection, null, null, null);
        if( cursor != null ){
            int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        return uri.getPath();
}

	
	private boolean saveData(){
		String desc = DBCloud.chkStr(((EditText)findViewById(R.id.edit_desc)).getText().toString().trim());
		String addcost = ((EditText)findViewById(R.id.edit_addcost)).getText().toString();
		boolean succed=true;
		
		if(desc == null || desc.length() <= 0){
			Toast.makeText(this, "請輸入描述", Toast.LENGTH_SHORT).show();
			return false;
		}
		if(addcost == null || addcost.length() <= 0 ){
			Toast.makeText(this, "請輸入管銷", Toast.LENGTH_SHORT).show();
			return false;
		}
		
        if (mImagePath==null || mImagePath.length()<=0){
        	mImagePath=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+"/cwbuyer/para/img_additem.png";
		}
		
		ContentValues value = new ContentValues();
    	value.put("GOODTYPE", desc);
    	value.put("COUNTRY", mData.nCountry);
    	value.put("SEASON", mData.nSeason);
    	value.put("ADDCOST", addcost);
    	value.put("PIC", Utilis.makeSPics(this,mImagePath));
    	
		if (Utilis.haveInternet(this) && of_line!=0){  //有網路的狀態且非單機,優先雲端運算,再行Hander維護Client端
			StringBuffer bfstr = new StringBuffer();
			StringBuffer bfstrF = new StringBuffer();
					bfstr.append(mUid).append(";");
					bfstrF.append("UID").append(";");
					bfstr.append(mID).append(";");
					bfstrF.append("_ID").append(";");
					bfstr.append(mID).append(";");
					bfstrF.append("ID").append(";");
					bfstr.append(desc).append(";");
					bfstrF.append("GOODTYPE").append(";");
					bfstr.append(mData.nCountry).append(";");
					bfstrF.append("COUNTRY").append(";");
					bfstr.append(mData.nSeason).append(";");
					bfstrF.append("SEASON").append(";");
					bfstr.append(addcost).append(";");
					bfstrF.append("ADDCOST").append(";");
					bfstr.append(mImagePath);
					bfstrF.append("PIC");
				Toast.makeText(AddCategory.this, "正前往雲端編輯_商品類別中,請稍候....", Toast.LENGTH_SHORT).show();
				Thread t = new Thread(new DBCloud.sendPostRunnableQC(AddCategory.this,bfstr.toString(),bfstrF.toString(),2));
				t.start();
    	}else if(mMode == EMode.ADD){
    		SQLiteDatabase db = Utilis.getDB(this);
	    	long result = db.insert(TbName.QC_TYPE, null, value);
	    	if(result > 0){
	    		Toast.makeText(this, "存取資料成功", Toast.LENGTH_SHORT).show();
	    	}else{
	    		Toast.makeText(this, "存取資料失敗", Toast.LENGTH_SHORT).show();
	    		succed =false;
	    	}
	    	db.close();
    	}else{  // EDIT
    		SQLiteDatabase db = Utilis.getDB(this);
    		String[] args = {String.valueOf(mID)};
			int success = db.update(com.cwbuyer.lib.TbName.QC_TYPE, value,
					"_ID=?", args);
			if(success > 0){
				Toast.makeText(this, "修改資料成功", Toast.LENGTH_SHORT).show();
			}else{
				Toast.makeText(this, "修改資料失敗", Toast.LENGTH_SHORT).show();
	    		succed =false;
			}
			db.close();
    	}
		value.clear();
		return succed;
	}

	public void getData(int id){
		getCountryData(this);
		SQLiteDatabase db = Utilis.getDB(this);
		Cursor cursor = db.rawQuery("select * from qc_type where _ID="+id, null);
		if(cursor != null){
			try{
				if(cursor.getCount() > 0){
					cursor.moveToFirst();
						mData = new TypeData();
						mData.id = cursor.getInt(cursor.getColumnIndex("_ID"));
						mData.icon = cursor.getString(cursor.getColumnIndex("PIC"));
						mData.desc = cursor.getString(cursor.getColumnIndex("GOODTYPE"));
						mData.nCountry = cursor.getInt(cursor.getColumnIndex("COUNTRY"));
						mData.country = mCountryList.get(mData.nCountry - 1);
						mData.nSeason = cursor.getInt(cursor.getColumnIndex("SEASON"));
						mData.season = mSeason[mData.nSeason];
						mData.nAddcost = cursor.getInt(cursor.getColumnIndex("ADDCOST"));
					}
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				cursor.close();
				cursor = null;
			}
		}
		db.close();
		db = null;
	}
	
	
	public void getCountryData(Context context){
		if(mCountryList != null){
			mCountryList.clear();
		}
		SQLiteDatabase db = Utilis.getDB(context);
		Cursor cursor = db.rawQuery("select _ID,NAME,PIC from qc_country order by _ID", null);
		if(cursor != null){
			try{
				if(cursor.getCount() > 0){
					cursor.moveToFirst();
					for(int i = 0; i < cursor.getCount(); i++){
						String name = cursor.getString(cursor.getColumnIndex("NAME"));
						String pic = cursor.getString(cursor.getColumnIndex("PIC"));
						int id = cursor.getInt(cursor.getColumnIndex("_ID"));
						mCountryId.add(id);
						mCountryIcon.add(pic);
						mCountryList.add(name);
						cursor.moveToNext();
					}
				}
			}catch(Exception e){
				
			}finally{
				cursor.close();
				cursor = null;
			}
		}
		db.close();
		db = null;
	}
	

    private void eventImgCapture() {
		Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		// Wysie_Soh: Create path for temp file
		File folder = new File( SAVE_FOLDER );
		if(folder.exists() == false){
			folder.mkdirs();
		}
		File file = new File(SAVE_FOLDER ,"Cate_" + String.valueOf(System.currentTimeMillis())+ ".jpg");
		
		if(file.exists() == false){
			try{
				file.createNewFile();
			}catch(Exception e){
				
			}
		}
		mImageCaptureUri = Uri.fromFile(file);
		intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,mImageCaptureUri);

		try {
			intent.putExtra("return-data", true);
			startActivityForResult(intent, TPICTURE);
		} catch (ActivityNotFoundException e) {
			// Do nothing for now
		} catch (Exception e){
		}
	}
	
    // 相本
	private void eventImgFile(){
        Intent intent = new Intent(); 
        intent.setType("image/*"); 
        intent.setAction(Intent.ACTION_GET_CONTENT); 
        startActivityForResult(Intent.createChooser(intent,"Select Picture"),CAPTURE);
        //startActivityForResult(intent, CAPTURE);
	}
	
}
