Search in sources :

Example 6 with OnKeyListener

use of android.content.DialogInterface.OnKeyListener in project android_packages_apps_Dialer by MoKee.

the class InCallLowBatteryListener method displayLowBatteryAlert.

/*
     * This method displays one of below alert dialogs when UE is in low battery
     * For Active Video Calls:
     *     1. hangup alert dialog in absence of voice capabilities
     *     2. downgrade to voice call alert dialog in the presence of voice
     *        capabilities
     * For MT Video calls wherein user decided to accept the call as Video and for MO Video Calls:
     *     1. alert dialog asking user confirmation to convert the video call to voice call or
     *        to continue the call as video call
     * For MO Video calls, seek user confirmation to continue the video call as is or convert the
     * video call to voice call
     */
private void displayLowBatteryAlert(final Call call) {
    // if low battery dialog is already visible to user, dismiss it
    dismissPendingDialogs();
    final InCallActivity inCallActivity = InCallPresenter.getInstance().getActivity();
    if (inCallActivity == null) {
        Log.w(this, "displayLowBatteryAlert inCallActivity is NULL");
        return;
    }
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(inCallActivity);
    alertDialog.setTitle(R.string.low_battery);
    alertDialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(final DialogInterface dialog) {
        }
    });
    if (VideoUtils.isIncomingVideoCall(call)) {
        alertDialog.setNegativeButton(R.string.low_battery_convert, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.d(this, "displayLowBatteryAlert answer as Voice Call");
                TelecomAdapter.getInstance().answerCall(call.getId(), VideoProfile.STATE_AUDIO_ONLY);
            }
        });
        alertDialog.setMessage(R.string.low_battery_msg);
        alertDialog.setPositiveButton(android.R.string.yes, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.d(this, "displayLowBatteryAlert answer as Video Call");
                TelecomAdapter.getInstance().answerCall(call.getId(), VideoProfile.STATE_BIDIRECTIONAL);
            }
        });
    } else if (VideoUtils.isOutgoingVideoCall(call)) {
        alertDialog.setNegativeButton(R.string.low_battery_convert, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.d(this, "displayLowBatteryAlert place Voice Call");
                // Change the audio route to earpiece
                InCallAudioManager.getInstance().onModifyCallClicked(call, VideoProfile.STATE_AUDIO_ONLY);
                try {
                    QtiImsExtManager.getInstance().resumePendingCall(VideoProfile.STATE_AUDIO_ONLY);
                } catch (QtiImsException e) {
                    Log.e(this, "resumePendingCall exception " + e);
                }
            }
        });
        alertDialog.setMessage(R.string.low_battery_msg);
        alertDialog.setPositiveButton(android.R.string.yes, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.d(this, "displayLowBatteryAlert place Video Call");
                try {
                    QtiImsExtManager.getInstance().resumePendingCall(VideoProfile.STATE_BIDIRECTIONAL);
                } catch (QtiImsException e) {
                    Log.e(this, "resumePendingCall exception " + e);
                }
            }
        });
    } else if (isActiveUnPausedVideoCall(call)) {
        if (QtiCallUtils.hasVoiceCapabilities(call)) {
            // active video call can be downgraded to voice
            alertDialog.setMessage(R.string.low_battery_msg);
            alertDialog.setPositiveButton(android.R.string.yes, null);
            alertDialog.setNegativeButton(R.string.low_battery_convert, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.d(this, "displayLowBatteryAlert downgrading to voice call");
                    QtiCallUtils.downgradeToVoiceCall(call);
                }
            });
        } else {
            /* video call doesn't have downgrade capabilities, so alert the user
                   with a hangup dialog*/
            alertDialog.setMessage(R.string.low_battery_hangup_msg);
            alertDialog.setNegativeButton(android.R.string.no, null);
            alertDialog.setPositiveButton(android.R.string.yes, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.d(this, "displayLowBatteryAlert hanging up the call: " + call);
                    call.setState(Call.State.DISCONNECTING);
                    CallList.getInstance().onUpdate(call);
                    TelecomAdapter.getInstance().disconnectCall(call.getId());
                }
            });
        }
    }
    mAlert = alertDialog.create();
    mAlert.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            Log.d(this, "on Alert displayLowBattery keyCode = " + keyCode);
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                // On Back key press, disconnect MO low battery video call
                // that is waiting for user input
                maybeDisconnectMoCall(call);
                return true;
            }
            return false;
        }
    });
    mAlert.setCanceledOnTouchOutside(false);
    mAlert.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    mAlert.show();
}
Also used : AlertDialog(android.app.AlertDialog) KeyEvent(android.view.KeyEvent) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) QtiImsException(org.codeaurora.ims.QtiImsException) OnClickListener(android.content.DialogInterface.OnClickListener) OnKeyListener(android.content.DialogInterface.OnKeyListener)

Example 7 with OnKeyListener

use of android.content.DialogInterface.OnKeyListener in project ignition by mttkay.

the class IgnitedDialogs method newProgressDialog.

/**
 * Creates a new ProgressDialog
 *
 * @param activity
 * @param progressDialogTitleId
 *            The resource id for the title. If this is less than or equal to 0, a default title
 *            is used.
 * @param progressDialogMsgId
 *            The resource id for the message. If this is less than or equal to 0, a default
 *            message is used.
 * @return The new dialog
 */
public static ProgressDialog newProgressDialog(final Activity activity, int progressDialogTitleId, int progressDialogMsgId) {
    ProgressDialog progressDialog = new ProgressDialog(activity);
    if (progressDialogTitleId <= 0) {
        progressDialogTitleId = R.string.ign_progress_dialog_title;
    }
    progressDialog.setTitle(progressDialogTitleId);
    if (progressDialogMsgId <= 0) {
        progressDialogMsgId = R.string.ign_progress_dialog_msg;
    }
    progressDialog.setMessage(activity.getString(progressDialogMsgId));
    progressDialog.setIndeterminate(true);
    progressDialog.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            activity.onKeyDown(keyCode, event);
            return false;
        }
    });
    return progressDialog;
}
Also used : KeyEvent(android.view.KeyEvent) DialogInterface(android.content.DialogInterface) OnKeyListener(android.content.DialogInterface.OnKeyListener) ProgressDialog(android.app.ProgressDialog)

Example 8 with OnKeyListener

use of android.content.DialogInterface.OnKeyListener in project smartmodule by carozhu.

the class MyWebChromeHelper method onJsAlert.

/**
 * 覆盖默认的window.alert展示界面,避免title里显示为“:来自file:////”
 */
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
    builder.setTitle("消息提示").setMessage(message).setPositiveButton("确定", null);
    // 不需要绑定按键事件
    // 屏蔽keycode等于84之类的按键
    builder.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            Log.v("onJsAlert", "keyCode==" + keyCode + "event=" + event);
            return true;
        }
    });
    // 禁止响应按back键的事件
    builder.setCancelable(false);
    AlertDialog dialog = builder.create();
    dialog.show();
    // 因为没有绑定事件,需要强行confirm,否则页面会变黑显示不了内容。
    result.confirm();
    return true;
}
Also used : AlertDialog(android.app.AlertDialog) KeyEvent(android.view.KeyEvent) DialogInterface(android.content.DialogInterface) OnKeyListener(android.content.DialogInterface.OnKeyListener)

Example 9 with OnKeyListener

use of android.content.DialogInterface.OnKeyListener in project Android-DialogFragments by wada811.

the class AbstractDialogFragment method setOnKeyListener.

protected void setOnKeyListener(Dialog dialog) {
    useOnKeyListener = true;
    dialog.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            return bindKeyListener(keyCode, event);
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) DialogInterface(android.content.DialogInterface) OnKeyListener(android.content.DialogInterface.OnKeyListener)

Aggregations

DialogInterface (android.content.DialogInterface)9 OnKeyListener (android.content.DialogInterface.OnKeyListener)9 KeyEvent (android.view.KeyEvent)9 AlertDialog (android.app.AlertDialog)4 OnClickListener (android.content.DialogInterface.OnClickListener)3 ProgressDialog (android.app.ProgressDialog)2 SuppressLint (android.annotation.SuppressLint)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 IntentFilter (android.content.IntentFilter)1 EditText (android.widget.EditText)1 ProgressBar (android.widget.ProgressBar)1 AddContactFriendsAdapter (com.lingtuan.firefly.contact.adapter.AddContactFriendsAdapter)1 QtiImsException (org.codeaurora.ims.QtiImsException)1