package
arabiannight.tistory.com.dialogattribute;
import
android.app.Activity;
import
android.app.Dialog;
import
android.content.DialogInterface;
import
android.content.DialogInterface.OnCancelListener;
import
android.content.DialogInterface.OnDismissListener;
import
android.content.DialogInterface.OnShowListener;
import
android.graphics.drawable.ColorDrawable;
import
android.os.Bundle;
import
android.view.View;
import
android.view.WindowManager;
import
android.widget.Toast;
public
class
MainActivity
extends
Activity {
private
Dialog mDialog =
null
;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createDialog();
}
public
void
onClick(View v) {
switch
(v.getId()) {
case
R.id.btn_click:
Toast.makeText(MainActivity.
this
,
"Activity Button 입니다."
,
Toast.LENGTH_SHORT).show();
case
R.id.btn_ok:
dismissDialog();
break
;
case
R.id.btn_cancle:
dismissDialog();
break
;
default
:
break
;
}
}
private
void
createDialog() {
final
View innerView = getLayoutInflater().inflate(R.layout.dialog,
null
);
mDialog =
new
Dialog(
this
);
mDialog.setTitle(
"Title"
);
mDialog.setContentView(innerView);
mDialog.setCancelable(
true
);
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
mDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
mDialog.setOnCancelListener(
new
OnCancelListener() {
@Override
public
void
onCancel(DialogInterface dialog) {
Toast.makeText(MainActivity.
this
,
"cancle listener"
,
Toast.LENGTH_SHORT).show();
}
});
mDialog.setOnShowListener(
new
OnShowListener() {
@Override
public
void
onShow(DialogInterface dialog) {
Toast.makeText(MainActivity.
this
,
"show listener"
,
Toast.LENGTH_SHORT).show();
}
});
mDialog.setOnDismissListener(
new
OnDismissListener() {
@Override
public
void
onDismiss(DialogInterface dialog) {
Toast.makeText(MainActivity.
this
,
"dismiss listener"
,
Toast.LENGTH_SHORT).show();
}
});
mDialog.show();
}
private
void
dismissDialog() {
if
(mDialog !=
null
&& mDialog.isShowing()) {
mDialog.dismiss();
}
}
}