Example usage for android.app AlertDialog.Builder setOnKeyListener

List of usage examples for android.app AlertDialog.Builder setOnKeyListener

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder 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:com.microsoft.rightsmanagement.ui.CustomerExperienceDataConsentDialogFragment.java

/**
 * Instantiate the fragment views./*from   w ww .  j  av a2s .c o  m*/
 * 
 * @param savedInstanceState the saved instance state
 * @return the dialog
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Logger.ms(TAG, "onCreateDialog");
    super.onCreateDialog(savedInstanceState);

    // initialize the field for cases when fragment is recreated by OS
    // During recreation, OS would use default constructor and set the state
    Bundle arguments = getArguments();
    if (arguments != null && arguments.containsKey(REQUEST_CALLBACK_ID)) {
        mRequestCallbackId = getArguments().getInt(REQUEST_CALLBACK_ID);
    }

    LayoutInflater inflater = LayoutInflater.from(getActivity().getApplicationContext());
    View view = inflater.inflate(R.layout.customer_experience_data_consent_dialog_fragment, null);
    Button positiveButton = (Button) view
            .findViewById(R.id.customer_experience_data_consent_dialog_positive_button);
    positiveButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Logger.d(TAG, "onClick listener called on yes button");
            mDialogState = DialogState.UserResponded;
            storeDebugLogPreference(true);
            dismiss();
        }
    });
    Button negativeButton = (Button) view
            .findViewById(R.id.customer_experience_data_consent_dialog_negative_button);
    negativeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Logger.d(TAG, "onClick listener called on no button");
            mDialogState = DialogState.UserResponded;
            storeDebugLogPreference(false);
            dismiss();
        }
    });
    Button neutralButton = (Button) view
            .findViewById(R.id.customer_experience_data_consent_dialog_neutral_button);
    neutralButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Logger.d(TAG, "onClick listener called on learn more");
            Intent internetIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(getString(R.string.learn_more_uri)));
            startActivity(internetIntent);
        }
    });

    OnKeyListener backKeyListener = new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                Logger.d(TAG, "onback press");
                mDialogState = DialogState.UserCancelled;
                // onback press dismiss dialog and assume no thanks
                storeDebugLogPreference(false);
                dismiss();
                return true;
            }
            return false;
        }
    };

    AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(getActivity());
    dialogbuilder.setView(view);
    dialogbuilder.setOnKeyListener(backKeyListener);
    AlertDialog dialog = dialogbuilder.create();
    Logger.me(TAG, "onCreateDialog");
    return dialog;
}

From source file:jp.co.rakuten.rakutenvideoplayer.base.BaseActivity.java

/**
 * Show dialog error//from  www.  j a v  a2  s .  c  o  m
 * @param errStr
 */
public void showDialogError(String errStr) {
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setIcon(R.drawable.icon);
    adb.setTitle(R.string.str_ErrPlay_Title);
    adb.setMessage(errStr);
    adb.setPositiveButton(R.string.str_OK, new OnClickListener() {
        public void onClick(DialogInterface a0, int a1) {
            finish();
        }
    });
    adb.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

            if (keyCode == KeyEvent.KEYCODE_BACK) {
                dialog.dismiss();
                finish();

                return true;
            }

            return false;
        }

    });

    AlertDialog ad = adb.create();
    ad.show();
}

From source file:org.hfoss.posit.android.functionplugin.reminder.SetReminder.java

private void showAddrPickerDialog() {
    // Set the current dialog
    currentDialog = ADDRESS_PICKER_DIALOG_ID;

    // Set the options in Address Picker Dialog
    final CharSequence[] items = { "Use Current Location", "Use Find's Location",
            "Enter Location Name / Landmark Address " };

    // Build Address Picker Dialog
    AlertDialog.Builder addrPickerBuilder = new AlertDialog.Builder(this);
    addrPickerBuilder.setTitle("Step 2: Choose an address");
    addrPickerBuilder.setItems(items, mAddrPickerOnClickListener);

    // Set Listeners
    addrPickerBuilder.setOnKeyListener(mBackKeyListener);
    // Finish the activity when the user presses cancel
    addrPickerBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            setResult(RESULT_OK);/*from  w ww  . jav  a2  s. com*/
            finish();
        }
    });

    // Show Address Picker Dialog
    addrPickerDialog = addrPickerBuilder.create();
    addrPickerDialog.show();
}

From source file:org.apache.cordova.engine.crosswalk.XWalkCordovaChromeClient.java

/**
 * Tell the client to display a javascript alert dialog.
 *
 * @param view/*from ww w  . jav a2  s .com*/
 * @param url
 * @param message
 * @param result
 */
private boolean onJsAlert(XWalkView view, String url, String message, final XWalkJavascriptResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Alert");
    //Don't let alerts break the back button
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.confirm();
                return false;
            } else
                return true;
        }
    });
    dlg.create();
    dlg.show();
    return true;
}

From source file:org.apache.cordova.CordovaChromeClient.java

/**
 * Tell the client to display a javascript alert dialog.
 *
 * @param view/*  w w  w. ja v a  2s. com*/
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Alert");
    //Don't let alerts break the back button
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.confirm();
                return false;
            } else
                return true;
        }
    });
    dlg.show();
    return true;
}

From source file:org.apache.cordova.AndroidChromeClient.java

/**
 * Tell the client to display a javascript alert dialog.
 *
 * @param view/*from  w ww . j  a  v a 2 s . co  m*/
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Alert");
    //Don't let alerts break the back button
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.confirm();
                return false;
            } else
                return true;
        }
    });
    dlg.create();
    dlg.show();
    return true;
}

From source file:org.skt.runtime.RuntimeChromeClient.java

/**
 * Tell the client to display a javascript alert dialog.
 * /*from   w ww  .j  av  a2  s  . c  o  m*/
 * @param view
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
    dlg.setMessage(message);
    dlg.setTitle("Alert");
    //Don't let alerts break the back button
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.confirm();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.confirm();
                return false;
            } else
                return true;
        }
    });
    dlg.create();
    dlg.show();
    return true;
}

From source file:org.apache.cordova.engine.crosswalk.XWalkCordovaChromeClient.java

/**
 * Tell the client to display a confirm dialog to the user.
 *
 * @param view//from  w w  w . j av a2 s.c o  m
 * @param url
 * @param message
 * @param result
 */
private boolean onJsConfirm(XWalkView view, String url, String message, final XWalkJavascriptResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Confirm");
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.cancel();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.cancel();
                return false;
            } else
                return true;
        }
    });
    dlg.create();
    dlg.show();
    return true;
}

From source file:org.apache.cordova.CordovaChromeClient.java

/**
 * Tell the client to display a confirm dialog to the user.
 *
 * @param view// ww w  . j  av  a 2 s.c  om
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Confirm");
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.cancel();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.cancel();
                return false;
            } else
                return true;
        }
    });
    dlg.show();
    return true;
}

From source file:org.apache.cordova.AndroidChromeClient.java

/**
 * Tell the client to display a confirm dialog to the user.
 *
 * @param view//from   w  w w.j  a va2s  .  co  m
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Confirm");
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.cancel();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.cancel();
                return false;
            } else
                return true;
        }
    });
    dlg.create();
    dlg.show();
    return true;
}