Example usage for android.app Dialog setOnShowListener

List of usage examples for android.app Dialog setOnShowListener

Introduction

In this page you can find the example usage for android.app Dialog setOnShowListener.

Prototype

public void setOnShowListener(@Nullable OnShowListener listener) 

Source Link

Document

Sets a listener to be invoked when the dialog is shown.

Usage

From source file:hku.fyp14017.blencode.ui.dialogs.MultiLineTextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity())
            .inflate(hku.fyp14017.blencode.R.layout.dialog_text_multiline_dialog, null);
    input = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_EditMultiLineText);

    if (getHint() != null) {
        input.setHint(getHint());/*from  ww w.ja  v a 2 s. c  om*/
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

/**
 * Dialog//from   www  .jav  a 2s.co m
 *
 * @param mContext
 * @return
 */
private Dialog showInputPasswordDialog(final Context mContext) {
    View convertView = LayoutInflater.from(mContext).inflate(R.layout.fragment_right_control, null);
    tv_forget_psw = (TextView) convertView.findViewById(R.id.tv_forget_psw);
    tv_forget_psw.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mContext.startActivity(new Intent(mContext, MyModifyPasswordActivity.class));
        }
    });
    inputView = (GridPasswordView) convertView.findViewById(R.id.pswView);
    inputView.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
        @Override
        public void onChanged(String psw) {

        }

        @Override
        public void onMaxLength(String psw) {
            if (onPasswordDialogClickListener != null) {
                onPasswordDialogClickListener.getPassword(psw);
            }
        }
    });

    final Dialog dialog = new Dialog(mContext, R.style.CustomDialog);
    //        dialog.setCanceledOnTouchOutside(false);//??
    dialog.setContentView(convertView);

    dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style);
    //dialog 
    dialog.setOnShowListener(new android.content.DialogInterface.OnShowListener() {
        @Override
        public void onShow(final android.content.DialogInterface dialog) {

            new AsyncTask<Integer, Void, Void>() {
                @Override
                protected Void doInBackground(Integer... params) {
                    try {
                        Thread.sleep(params[0]);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void value) {
                    super.onPostExecute(value);
                    if (outerDialog.isShowing())
                        if (inputView != null) {
                            inputView.requestFocus();
                            InputMethodManager imm = (InputMethodManager) inputView.getContext()
                                    .getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
                        }
                }
            }.execute(600);
        }
    });

    outerDialog = dialog;
    return dialog;
}

From source file:org.catrobat.catroid.ui.dialogs.OverwriteRenameDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_overwrite_project, null);

    replaceButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_project_radio_replace);
    replaceButton.setOnClickListener(this);
    renameButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_project_radio_rename);
    renameButton.setOnClickListener(this);
    projectText = (EditText) dialogView.findViewById(R.id.dialog_overwrite_project_edit);
    projectText.setText(programName);/*  w w  w. j a  v  a 2  s .  com*/
    projectTextView = (TextView) dialogView.findViewById(R.id.dialog_overwrite_project_edit_text);
    projectTextLine = dialogView.findViewById(R.id.dialog_overwrite_project_edit_line);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(R.string.overwrite_text)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ToastUtil.showError(context, R.string.notification_download_project_cancel);
                }
            }).create();

    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleOkButton();
                }
            });
        }
    });

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            } else if (keyCode == KeyEvent.KEYCODE_BACK) {
                ToastUtil.showError(context, R.string.notification_download_project_cancel);
                return true;
            }

            return false;
        }
    });

    return dialog;
}

From source file:com.app.blockydemo.ui.dialogs.ScriptNameDialog.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    final View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_script_editor_name,
            null);/*from w w w.  ja  va2s .c om*/

    final Dialog dialogNewVariable = new AlertDialog.Builder(getActivity()).setView(dialogView)
            .setTitle(R.string.formula_editor_script_name)
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).setPositiveButton(R.string.ok, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handleOkButton(dialogView);
                }
            }).create();

    dialogNewVariable.setCanceledOnTouchOutside(true);
    dialogNewVariable.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialogNewVariable.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            handleOnShow(dialogNewVariable);
        }
    });

    return dialogNewVariable;
}

From source file:org.catrobat.catroid.ui.dialogs.OverwriteRenameMediaDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_overwrite_media, null);

    replaceButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_media_radio_replace);
    replaceButton.setOnClickListener(this);
    renameButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_media_radio_rename);
    renameButton.setOnClickListener(this);
    mediaText = (EditText) dialogView.findViewById(R.id.dialog_overwrite_media_edit);
    mediaText.setText(mediaName);//from   w  w  w .ja  va2  s  .c o m
    mediaTextView = (TextView) dialogView.findViewById(R.id.dialog_overwrite_media_edit_text);
    mediaTextLine = dialogView.findViewById(R.id.dialog_overwrite_media_edit_line);

    final int header;
    final int replaceText;
    final int renameText;
    final int renameHeaderText;
    switch (mediaType) {
    case Constants.MEDIA_TYPE_LOOK:
        header = R.string.look_rename_overwrite;
        replaceText = R.string.overwrite_replace_look;
        renameText = R.string.overwrite_rename_look;
        renameHeaderText = R.string.new_look_name;
        break;
    case Constants.MEDIA_TYPE_SOUND:
        header = R.string.rename_sound_overwrite;
        replaceText = R.string.overwrite_replace_sound;
        renameText = R.string.overwrite_rename_sound;
        renameHeaderText = R.string.new_sound_name;
        break;
    default:
        header = R.string.rename_sprite_dialog;
        replaceText = R.string.overwrite_replace_default;
        renameText = R.string.overwrite_rename_default;
        renameHeaderText = R.string.new_sound_name;
    }

    replaceButton.setText(replaceText);
    renameButton.setText(renameText);
    mediaTextView.setText(renameHeaderText);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(header)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).create();

    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleOkButton();
                }
            });
        }
    });

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                if (!okButtonResult) {
                    return false;
                } else {
                    dismiss();
                }
                return okButtonResult;
            } else if (keyCode == KeyEvent.KEYCODE_BACK) {
                dismiss();
                return true;
            }
            return false;
        }
    });

    return dialog;
}

From source file:com.app.blockydemo.ui.dialogs.NewVariableDialog.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    final View dialogView = LayoutInflater.from(getActivity())
            .inflate(R.layout.dialog_formula_editor_variable_name, null);

    final Dialog dialogNewVariable = new AlertDialog.Builder(getActivity()).setView(dialogView)
            .setTitle(R.string.formula_editor_variable_dialog_title)
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override//from   ww w  .  j a v  a 2s.  co  m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).setPositiveButton(R.string.ok, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handleOkButton(dialogView);
                }
            }).create();

    dialogNewVariable.setCanceledOnTouchOutside(true);
    dialogNewVariable.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialogNewVariable.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            handleOnShow(dialogNewVariable);
        }
    });

    return dialogNewVariable;
}

From source file:org.catrobat.catroid.ui.dialogs.UploadProjectDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_upload_project, null);

    projectRename = (TextView) dialogView.findViewById(R.id.tv_project_rename);
    projectDescriptionField = (EditText) dialogView.findViewById(R.id.project_description_upload);
    projectUploadName = (EditText) dialogView.findViewById(R.id.project_upload_name);
    sizeOfProject = (TextView) dialogView.findViewById(R.id.dialog_upload_size_of_project);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView)
            .setTitle(R.string.upload_project_dialog_title)
            .setPositiveButton(R.string.upload_button, new DialogInterface.OnClickListener() {
                @Override//  w  w  w.j av a2  s .  co  m
                public void onClick(DialogInterface dialog, int which) {
                    handleUploadButtonClick();
                }
            }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handleCancelButtonClick();
                }
            }).create();

    dialog.setCanceledOnTouchOutside(true);
    dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            initListeners();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(projectUploadName, InputMethodManager.SHOW_IMPLICIT);
        }
    });

    initControls();

    return dialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.OverwriteRenameDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(context)
            .inflate(hku.fyp14017.blencode.R.layout.dialog_overwrite_project, null);

    replaceButton = (RadioButton) dialogView
            .findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_radio_replace);
    replaceButton.setOnClickListener(this);
    renameButton = (RadioButton) dialogView
            .findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_radio_rename);
    renameButton.setOnClickListener(this);
    projectText = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_edit);
    projectText.setText(programName);//from   ww  w.j  a v  a 2s .c om
    projectTextView = (TextView) dialogView
            .findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_edit_text);
    projectTextLine = dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_edit_line);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView)
            .setTitle(hku.fyp14017.blencode.R.string.overwrite_text)
            .setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(context,
                                    hku.fyp14017.blencode.R.string.notification_download_project_cancel,
                                    Toast.LENGTH_SHORT).show();
                        }
                    })
            .create();

    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleOkButton();
                }
            });
        }
    });

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            } else if (keyCode == KeyEvent.KEYCODE_BACK) {
                Toast.makeText(context, hku.fyp14017.blencode.R.string.notification_download_project_cancel,
                        Toast.LENGTH_SHORT).show();
                return true;
            }

            return false;
        }
    });

    return dialog;
}

From source file:com.app.blockydemo.ui.dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());//from   w ww  .j a va2 s. c o m
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener(dialog);

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

From source file:org.catrobat.catroid.ui.dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());//from   ww w .j ava 2  s  .com
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}