Example usage for android.telecom DisconnectCause getLabel

List of usage examples for android.telecom DisconnectCause getLabel

Introduction

In this page you can find the example usage for android.telecom DisconnectCause getLabel.

Prototype

public CharSequence getLabel() 

Source Link

Document

Returns a short label which explains the reason for the disconnect cause and is for display in the user interface.

Usage

From source file:com.android.incallui.CallCardFragment.java

/**
 * Gets the call state label based on the state of the call or cause of disconnect.
 *
 * Additional labels are applied as follows:
 *         1. All outgoing calls with display "Calling via [Provider]".
 *         2. Ongoing calls will display the name of the provider.
 *         3. Incoming calls will only display "Incoming via..." for accounts.
 *         4. Video calls, and session modification states (eg. requesting video).
 *         5. Incoming and active Wi-Fi calls will show label provided by hint.
 *
 * TODO: Move this to the CallCardPresenter.
 *///from w w w.  ja  va2 s. com
private CallStateLabel getCallStateLabelFromState(int state, int videoState, int sessionModificationState,
        DisconnectCause disconnectCause, String label, boolean isGatewayCall, boolean isWifi,
        boolean isConference, boolean isWorkCall) {
    final Context context = getView().getContext();
    CharSequence callStateLabel = null; // Label to display as part of the call banner

    boolean hasSuggestedLabel = label != null;
    boolean isAccount = hasSuggestedLabel && !isGatewayCall;
    boolean isAutoDismissing = false;

    switch (state) {
    case Call.State.IDLE:
        // "Call state" is meaningless in this state.
        break;
    case Call.State.ACTIVE:
        // We normally don't show a "call state label" at all in this state
        // (but we can use the call state label to display the provider name).
        if ((isAccount || isWifi || isConference) && hasSuggestedLabel) {
            callStateLabel = label;
        } else if (sessionModificationState == Call.SessionModificationState.REQUEST_REJECTED) {
            callStateLabel = context.getString(R.string.card_title_video_call_rejected);
            isAutoDismissing = true;
        } else if (sessionModificationState == Call.SessionModificationState.REQUEST_FAILED) {
            callStateLabel = context.getString(R.string.card_title_video_call_error);
            isAutoDismissing = true;
        } else if (sessionModificationState == Call.SessionModificationState.WAITING_FOR_RESPONSE) {
            callStateLabel = context.getString(R.string.card_title_video_call_requesting);
        } else if (sessionModificationState == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
            callStateLabel = context.getString(R.string.card_title_video_call_requesting);
        } else if (VideoUtils.isVideoCall(videoState)) {
            callStateLabel = context.getString(R.string.card_title_video_call);
        }
        break;
    case Call.State.ONHOLD:
        callStateLabel = context.getString(R.string.card_title_on_hold);
        break;
    case Call.State.CONNECTING:
    case Call.State.DIALING:
        if (hasSuggestedLabel && !isWifi) {
            callStateLabel = context.getString(R.string.calling_via_template, label);
        } else {
            callStateLabel = context.getString(R.string.card_title_dialing);
        }
        break;
    case Call.State.REDIALING:
        callStateLabel = context.getString(R.string.card_title_redialing);
        break;
    case Call.State.INCOMING:
    case Call.State.CALL_WAITING:
        if (isWifi && hasSuggestedLabel) {
            callStateLabel = label;
        } else if (isAccount) {
            callStateLabel = context.getString(R.string.incoming_via_template, label);
        } else if (VideoUtils.isVideoCall(videoState)) {
            callStateLabel = context.getString(R.string.notification_incoming_video_call);
        } else {
            callStateLabel = context.getString(
                    isWorkCall ? R.string.card_title_incoming_work_call : R.string.card_title_incoming_call);
        }
        break;
    case Call.State.DISCONNECTING:
        // While in the DISCONNECTING state we display a "Hanging up"
        // message in order to make the UI feel more responsive.  (In
        // GSM it's normal to see a delay of a couple of seconds while
        // negotiating the disconnect with the network, so the "Hanging
        // up" state at least lets the user know that we're doing
        // something.  This state is currently not used with CDMA.)
        callStateLabel = context.getString(R.string.card_title_hanging_up);
        break;
    case Call.State.DISCONNECTED:
        callStateLabel = disconnectCause.getLabel();
        if (TextUtils.isEmpty(callStateLabel)) {
            callStateLabel = context.getString(R.string.card_title_call_ended);
        }
        break;
    case Call.State.CONFERENCED:
        callStateLabel = context.getString(R.string.card_title_conf_call);
        break;
    default:
        Log.wtf(this, "updateCallStateWidgets: unexpected call: " + state);
    }
    return new CallStateLabel(callStateLabel, isAutoDismissing);
}