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) {
super
.onActivityResult(requestCode, resultCode, data);
ImageView imageView = (ImageView)findViewById(R.id.imgView);
photoUri = data.getData();
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();
}
}
}