
// Photo Button
public void imgOnClick(View v){
builder.setView(linear)
.setPositiveButton("앨범",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ImageView imgView = (ImageView)linear.findViewById(R.id.dialogImgView);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
startActivityForResult(intent, requestCode1);
}
}
)
.setNegativeButton("카메라",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
startActivityForResult(intent, requestCode2);
}
}
);
mPopupDlg = builder.show();
}
// 이문제 인줄 알고 햇는데 ㅡㅡ 안됨 .. 해결 방법을없을까요??
// 앨범, 카메라 선택시 도중에 종료 할경우 다이얼로그 종료시킴.
@Override
public void onBackPressed() {
super.onBackPressed();
mPopupDlg.dismiss();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
ImageView imageView = (ImageView)findViewById(R.id.imgView);
photoUri = data.getData(); // Uri 주소값을 받아온다.
if(data != null){
if(requestCode == requestCode1 && resultCode == RESULT_OK){ //앨범 이미지 선택시
try{
profileBitmap = Images.Media.getBitmap(getContentResolver(), photoUri);
profileBitmap = Bitmap.createScaledBitmap(profileBitmap, profileBitmap.getWidth(), profileBitmap.getHeight(), true);
imageView.setBackgroundResource(0);
imageView.setImageBitmap(profileBitmap);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
System.out.println("앨범 이미지 선택시");
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}else if(requestCode == requestCode2 && resultCode == RESULT_OK){ //카메라 선택시
try{
profileBitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(profileBitmap);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
System.out.println("카메라 선택시");
}catch(Exception e){
e.printStackTrace();
}
}else{
Toast toast = Toast.makeText(this, "이미지 선택 취소", Toast.LENGTH_LONG);
toast.show();
}
}
}