package lee.hyeontae.AlertDialogEx;
import java.util.ArrayList;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class CustomAlertDialog extends Dialog implements
android.view.View.OnClickListener{
public final static int BUTTONTYPE_BLUETYPE = 0x0001;
public final static int BUTTONTYPE_GRAYTYPE = 0x0002;
private Context mContext = null;
private onClickCustomAlertButton mListener = null;
public EditText id_editText;
public EditText pass_editText;
public TextView textView = null;
private LinearLayout buttonBaseView = null;
private ArrayList<Button> buttonArray = null;
private String message = null;
public CustomAlertDialog(Context context, String message,
onClickCustomAlertButton listener) {
super(context);
setContentView(R.layout.alert_layout);
mContext = context.getApplicationContext();
this.message=message;
this.buttonArray = new ArrayList<Button>();
textView = (TextView)findViewById(R.id.alertMessage);
buttonBaseView = (LinearLayout)findViewById(R.id.buttonBaseView);
mListener = listener;
id_editText = (EditText)findViewById(R.id.id_editText);
pass_editText = (EditText)findViewById(R.id.pass_EditText);
textView.setText(this.message);
getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
}
@Override
public void onClick(View v) {
Button btn = (Button)v;
Log.d("dodo4989","onClick");
if(mListener != null) {
mListener.onClickAlertButton(buttonArray.indexOf(btn), btn);
}
if(id_editText.getVisibility()==0){
Log.d("dodo4989","TRUE");
} else {
Log.d("dodo4989","FALSE");
this.dismiss();
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_UP &&
event.getKeyCode() == KeyEvent.KEYCODE_BACK)
return false;
return super.dispatchKeyEvent(event);
}
public Button addButton(String title, int buttonType) {
Button tmpBtn = new Button(mContext);
tmpBtn.setBackgroundResource(buttonType==BUTTONTYPE_BLUETYPE?R.drawable.alert_button_type_1 : R.drawable.alert_button_type_2);
tmpBtn.setGravity(Gravity.CENTER);
tmpBtn.setText(title);
tmpBtn.setPadding(0, 0, 0, 0);
buttonBaseView.addView(tmpBtn);
tmpBtn.setOnClickListener(this);
LayoutParams lp =
(LayoutParams)tmpBtn.getLayoutParams();
lp.weight=1;
lp.height=LayoutParams.WRAP_CONTENT;
lp.width=LayoutParams.FILL_PARENT;
lp.leftMargin=5;
lp.rightMargin=5;
tmpBtn.setLayoutParams(lp);
buttonBaseView.invalidate();
buttonArray.add(tmpBtn);
return tmpBtn;
}
public interface onClickCustomAlertButton {
public void onClickAlertButton(int buttonIndex, Button
buttonView);
}
}