Search in sources :

Example 1 with QtiImsException

use of org.codeaurora.ims.QtiImsException 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)

Aggregations

AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 OnKeyListener (android.content.DialogInterface.OnKeyListener)1 KeyEvent (android.view.KeyEvent)1 QtiImsException (org.codeaurora.ims.QtiImsException)1