Example usage for android.app Dialog setOnKeyListener

List of usage examples for android.app Dialog setOnKeyListener

Introduction

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

Prototype

public void setOnKeyListener(@Nullable OnKeyListener onKeyListener) 

Source Link

Document

Sets the callback that will be called if a key is dispatched to the dialog.

Usage

From source file:cn.stj.fphealth.views.dialog.QrcodeDialog.java

/**
 * Set the dialog edit text and other attribute
 *///from   w w  w  .  j a  v  a2 s.c o m
@Override
public void onResume() {
    super.onResume();

    Dialog dialog = getDialog();
    dialog.setCanceledOnTouchOutside(false);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    dialog.setCancelable(false);
    dialog.setOnKeyListener(new QrcodeDialogKeyListener());
}

From source file:cn.stj.fphealth.views.dialog.DeviceBindDialog.java

/**
 * Set the dialog edit text and other attribute
 *//*from www. j a v  a2s .co  m*/
@Override
public void onResume() {
    super.onResume();

    Dialog dialog = getDialog();
    dialog.setCanceledOnTouchOutside(false);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    dialog.setOnKeyListener(new SaveDialogKeyListener());
}

From source file:at.wada811.android.dialogfragments.AbstractDialogFragment.java

protected void setOnKeyListener(Dialog dialog) {
    useOnKeyListener = true;//from   w  w  w  .ja v a  2  s.co m
    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            return bindKeyListener(keyCode, event);
        }
    });
}

From source file:jp.co.noxi.app.NXDialog.java

void setOnKeyListenerInternal(final OnKeyListener listener) {
    final Dialog dialog = getDialog();
    if ((listener == null) || (dialog == null)) {
        return;//w  w  w  .jav a  2  s . c om
    }

    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            return listener.onKey(NXDialog.this, keyCode, event);
        }
    });
}

From source file:butter.droid.fragments.dialog.EpisodeDialogFragment.java

@NonNull
@Override//ww w  . j av a 2  s . c o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                smoothDismiss();
            }
            return true;
        }
    });
    return dialog;
}

From source file:io.openkit.OKLoginFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setOnKeyListener(backButtonListener);
    return dialog;
}

From source file:org.dmfs.tasks.InputTextDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    // hides the actual dialog title, we have one already...
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    // we want to listen to clicks on back button
    dialog.setOnKeyListener(this);
    return dialog;
}

From source file:ca.frozen.curlingtv.activities.ScannerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // get the controls
    View view = inflater.inflate(R.layout.fragment_scanner, container, false);
    message = (TextView) view.findViewById(R.id.scanner_message);
    status = (TextView) view.findViewById(R.id.scanner_status);
    progress = (ProgressBar) view.findViewById(R.id.scanner_progress);
    cancelButton = (Button) view.findViewById(R.id.scanner_cancel);

    // configure the dialog
    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);//from   w  w w  .  j  a  v a2s .c o  m
        dialog.setCanceledOnTouchOutside(false);
        dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(android.content.DialogInterface dialog, int keyCode,
                    android.view.KeyEvent event) {
                if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
                    cancel();
                }
                return false;
            }
        });
    }

    // handle the cancel button
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            cancel();
            dismiss();
        }
    });

    // create the dismiss handler and runnable
    dismissHandler = new Handler();
    dismissRunner = new Runnable() {
        @Override
        public void run() {
            dismiss();
        }
    };

    // configure the view if we've already done the scan
    if (savedInstanceState != null) {
        DeviceScanner scanner = (scannerWeakRef != null) ? scannerWeakRef.get() : null;
        if (scanner != null) {
            boolean complete = scanner.isComplete();
            scanner.setStatus(complete);
            if (complete) {
                cancelButton.setText(App.getStr(R.string.done));
            }
        }
    }

    return view;
}

From source file:com.github.michalbednarski.intentslab.editor.FindComponentDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setTitle(R.string.find);//  w w w  .  ja  va2  s. c o  m
    dialog.setOnKeyListener(this);
    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());// www  . j  ava2  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;
}