diff options
Diffstat (limited to 'java/com/android')
-rw-r--r-- | java/com/android/incallui/InCallActivity.java | 106 | ||||
-rw-r--r-- | java/com/android/incallui/InCallActivityCommon.java | 134 | ||||
-rw-r--r-- | java/com/android/incallui/InCallPresenter.java | 32 |
3 files changed, 118 insertions, 154 deletions
diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java index a55770c41..ed10ed0bb 100644 --- a/java/com/android/incallui/InCallActivity.java +++ b/java/com/android/incallui/InCallActivity.java @@ -16,6 +16,7 @@ package com.android.incallui; +import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.Intent; @@ -36,6 +37,8 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; +import android.widget.CheckBox; +import android.widget.Toast; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; @@ -62,6 +65,7 @@ import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory; import com.android.incallui.incall.protocol.InCallScreen; import com.android.incallui.incall.protocol.InCallScreenDelegate; import com.android.incallui.incall.protocol.InCallScreenDelegateFactory; +import com.android.incallui.incalluilock.InCallUiLock; import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment; import com.android.incallui.video.bindings.VideoBindings; import com.android.incallui.video.protocol.VideoCallScreen; @@ -458,8 +462,40 @@ public class InCallActivity extends TransactionSafeFragmentActivity common.showPostCharWaitDialog(callId, chars); } - public void maybeShowErrorDialogOnDisconnect(DisconnectMessage disconnectMessage) { - common.maybeShowErrorDialogOnDisconnect(disconnectMessage); + public void showDialogOrToastForDisconnectedCall(DisconnectMessage disconnectMessage) { + LogUtil.i( + "InCallActivity.showDialogOrToastForDisconnectedCall", + "disconnect cause: %s", + disconnectMessage); + + if (disconnectMessage.dialog == null || isFinishing()) { + return; + } + + dismissPendingDialogs(); + + // Show a toast if the app is in background when a dialog can't be visible. + if (!isVisible()) { + Toast.makeText(getApplicationContext(), disconnectMessage.toastMessage, Toast.LENGTH_LONG) + .show(); + return; + } + + // Show the dialog. + common.setErrorDialog(disconnectMessage.dialog); + InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog"); + disconnectMessage.dialog.setOnDismissListener( + dialogInterface -> { + lock.release(); + onDialogDismissed(); + }); + disconnectMessage.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); + disconnectMessage.dialog.show(); + } + + private void onDialogDismissed() { + common.setErrorDialog(null); + CallList.getInstance().onErrorDialogDismissed(); } public void dismissPendingDialogs() { @@ -578,17 +614,67 @@ public class InCallActivity extends TransactionSafeFragmentActivity Trace.endSection(); } - public void onWiFiToLteHandover(DialerCall call) { - common.showWifiToLteHandoverToast(call); - } + public void showToastForWiFiToLteHandover(DialerCall call) { + if (call.hasShownWiFiToLteHandoverToast()) { + return; + } - public void onHandoverToWifiFailed(DialerCall call) { - common.showWifiFailedDialog(call); + Toast.makeText(this, R.string.video_call_wifi_to_lte_handover_toast, Toast.LENGTH_LONG).show(); + call.setHasShownWiFiToLteHandoverToast(); } - public void onInternationalCallOnWifi(@NonNull DialerCall call) { - LogUtil.enterBlock("InCallActivity.onInternationalCallOnWifi"); - common.showInternationalCallOnWifiDialog(call); + public void showDialogOrToastForWifiHandoverFailure(DialerCall call) { + if (call.showWifiHandoverAlertAsToast()) { + Toast.makeText(this, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT) + .show(); + return; + } + + dismissPendingDialogs(); + + AlertDialog.Builder builder = + new AlertDialog.Builder(this).setTitle(R.string.video_call_lte_to_wifi_failed_title); + + // This allows us to use the theme of the dialog instead of the activity + View dialogCheckBoxView = + View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null /* root */); + CheckBox wifiHandoverFailureCheckbox = + (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox); + wifiHandoverFailureCheckbox.setChecked(false); + + InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog"); + Dialog errorDialog = + builder + .setView(dialogCheckBoxView) + .setMessage(R.string.video_call_lte_to_wifi_failed_message) + .setOnCancelListener(dialogInterface -> onDialogDismissed()) + .setPositiveButton( + android.R.string.ok, + (dialogInterface, id) -> { + call.setDoNotShowDialogForHandoffToWifiFailure( + wifiHandoverFailureCheckbox.isChecked()); + dialogInterface.cancel(); + onDialogDismissed(); + }) + .setOnDismissListener(dialogInterface -> lock.release()) + .create(); + + common.setErrorDialog(errorDialog); + errorDialog.show(); + } + + public void showDialogForInternationalCallOnWifi(@NonNull DialerCall call) { + if (!InternationalCallOnWifiDialogFragment.shouldShow(this)) { + LogUtil.i( + "InCallActivity.showDialogForInternationalCallOnWifi", + "InternationalCallOnWifiDialogFragment.shouldShow returned false"); + return; + } + + InternationalCallOnWifiDialogFragment fragment = + InternationalCallOnWifiDialogFragment.newInstance( + call.getId(), common.getCallbackForInternationalCallOnWifiDialog()); + fragment.show(getSupportFragmentManager(), TAG_INTERNATIONAL_CALL_ON_WIFI); } @Override diff --git a/java/com/android/incallui/InCallActivityCommon.java b/java/com/android/incallui/InCallActivityCommon.java index f92e78534..8f82295ed 100644 --- a/java/com/android/incallui/InCallActivityCommon.java +++ b/java/com/android/incallui/InCallActivityCommon.java @@ -19,12 +19,8 @@ package com.android.incallui; import android.app.ActivityManager; import android.app.ActivityManager.AppTask; import android.app.ActivityManager.TaskDescription; -import android.app.AlertDialog; import android.app.Dialog; import android.app.KeyguardManager; -import android.content.DialogInterface; -import android.content.DialogInterface.OnCancelListener; -import android.content.DialogInterface.OnDismissListener; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; @@ -46,8 +42,6 @@ import android.view.Window; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; -import android.widget.CheckBox; -import android.widget.Toast; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener; import com.android.dialer.animation.AnimUtils; @@ -63,8 +57,6 @@ import com.android.incallui.call.CallList; import com.android.incallui.call.DialerCall; import com.android.incallui.call.DialerCall.State; import com.android.incallui.call.TelecomAdapter; -import com.android.incallui.disconnectdialog.DisconnectMessage; -import com.android.incallui.incalluilock.InCallUiLock; import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment; import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment.Callback; import com.google.common.base.Optional; @@ -535,19 +527,6 @@ public class InCallActivityCommon { } } - public void maybeShowErrorDialogOnDisconnect(DisconnectMessage disconnectMessage) { - LogUtil.i( - "InCallActivityCommon.maybeShowErrorDialogOnDisconnect", - "disconnect cause: %s", - disconnectMessage); - - if (!inCallActivity.isFinishing()) { - if (disconnectMessage.dialog != null) { - showErrorDialog(disconnectMessage.dialog, disconnectMessage.toastMessage); - } - } - } - /** * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should * be shown on launch. @@ -569,36 +548,6 @@ public class InCallActivityCommon { } } - private void showErrorDialog(Dialog dialog, CharSequence message) { - LogUtil.i("InCallActivityCommon.showErrorDialog", "message: %s", message); - inCallActivity.dismissPendingDialogs(); - - // Show toast if apps is in background when dialog won't be visible. - if (!inCallActivity.isVisible()) { - Toast.makeText(inCallActivity.getApplicationContext(), message, Toast.LENGTH_LONG).show(); - return; - } - - this.errorDialog = dialog; - InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog"); - dialog.setOnDismissListener( - new OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - LogUtil.i("InCallActivityCommon.showErrorDialog", "dialog dismissed"); - lock.release(); - onDialogDismissed(); - } - }); - dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); - dialog.show(); - } - - private void onDialogDismissed() { - errorDialog = null; - CallList.getInstance().onErrorDialogDismissed(); - } - public void setExcludeFromRecents(boolean exclude) { List<AppTask> tasks = inCallActivity.getSystemService(ActivityManager.class).getAppTasks(); int taskId = inCallActivity.getTaskId(); @@ -617,83 +566,6 @@ public class InCallActivityCommon { } } - void showInternationalCallOnWifiDialog(@NonNull DialerCall call) { - LogUtil.enterBlock("InCallActivityCommon.showInternationalCallOnWifiDialog"); - if (!InternationalCallOnWifiDialogFragment.shouldShow(inCallActivity)) { - LogUtil.i( - "InCallActivityCommon.showInternationalCallOnWifiDialog", - "InternationalCallOnWifiDialogFragment.shouldShow returned false"); - return; - } - - InternationalCallOnWifiDialogFragment fragment = - InternationalCallOnWifiDialogFragment.newInstance( - call.getId(), internationalCallOnWifiCallback); - fragment.show(inCallActivity.getSupportFragmentManager(), TAG_INTERNATIONAL_CALL_ON_WIFI); - } - - public void showWifiToLteHandoverToast(DialerCall call) { - if (call.hasShownWiFiToLteHandoverToast()) { - return; - } - Toast.makeText( - inCallActivity, R.string.video_call_wifi_to_lte_handover_toast, Toast.LENGTH_LONG) - .show(); - call.setHasShownWiFiToLteHandoverToast(); - } - - public void showWifiFailedDialog(final DialerCall call) { - if (call.showWifiHandoverAlertAsToast()) { - LogUtil.i("InCallActivityCommon.showWifiFailedDialog", "as toast"); - Toast.makeText( - inCallActivity, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT) - .show(); - return; - } - - inCallActivity.dismissPendingDialogs(); - - AlertDialog.Builder builder = - new AlertDialog.Builder(inCallActivity) - .setTitle(R.string.video_call_lte_to_wifi_failed_title); - - // This allows us to use the theme of the dialog instead of the activity - View dialogCheckBoxView = - View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null); - final CheckBox wifiHandoverFailureCheckbox = - (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox); - wifiHandoverFailureCheckbox.setChecked(false); - - InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog"); - errorDialog = - builder - .setView(dialogCheckBoxView) - .setMessage(R.string.video_call_lte_to_wifi_failed_message) - .setOnCancelListener( - new OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - onDialogDismissed(); - } - }) - .setPositiveButton( - android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - call.setDoNotShowDialogForHandoffToWifiFailure( - wifiHandoverFailureCheckbox.isChecked()); - dialog.cancel(); - onDialogDismissed(); - } - }) - .setOnDismissListener((dialog) -> lock.release()) - .create(); - - LogUtil.i("InCallActivityCommon.showWifiFailedDialog", "as dialog"); - errorDialog.show(); - } - void updateNavigationBar(boolean isDialpadVisible) { if (!ActivityCompat.isInMultiWindowMode(inCallActivity)) { View navigationBarBackground = @@ -898,4 +770,10 @@ public class InCallActivityCommon { @Nullable SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment) { this.selectPhoneAccountDialogFragment = selectPhoneAccountDialogFragment; } + + /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ + @Deprecated + InternationalCallOnWifiDialogFragment.Callback getCallbackForInternationalCallOnWifiDialog() { + return internationalCallOnWifiCallback; + } } diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java index fc2f34efe..3ba2ccff6 100644 --- a/java/com/android/incallui/InCallPresenter.java +++ b/java/com/android/incallui/InCallPresenter.java @@ -467,7 +467,7 @@ public class InCallPresenter implements CallList.Listener, AudioModeProvider.Aud // By the time the UI finally comes up, the call may already be disconnected. // If that's the case, we may need to show an error dialog. if (mCallList != null && mCallList.getDisconnectedCall() != null) { - maybeShowErrorDialogOnDisconnect(mCallList.getDisconnectedCall()); + showDialogOrToastForDisconnectedCall(mCallList.getDisconnectedCall()); } // When the UI comes up, we need to first check the in-call state. @@ -681,14 +681,14 @@ public class InCallPresenter implements CallList.Listener, AudioModeProvider.Aud @Override public void onWiFiToLteHandover(DialerCall call) { if (mInCallActivity != null) { - mInCallActivity.onWiFiToLteHandover(call); + mInCallActivity.showToastForWiFiToLteHandover(call); } } @Override public void onHandoverToWifiFailed(DialerCall call) { if (mInCallActivity != null) { - mInCallActivity.onHandoverToWifiFailed(call); + mInCallActivity.showDialogOrToastForWifiHandoverFailure(call); } } @@ -696,7 +696,7 @@ public class InCallPresenter implements CallList.Listener, AudioModeProvider.Aud public void onInternationalCallOnWifi(@NonNull DialerCall call) { LogUtil.enterBlock("InCallPresenter.onInternationalCallOnWifi"); if (mInCallActivity != null) { - mInCallActivity.onInternationalCallOnWifi(call); + mInCallActivity.showDialogForInternationalCallOnWifi(call); } } @@ -832,7 +832,7 @@ public class InCallPresenter implements CallList.Listener, AudioModeProvider.Aud */ @Override public void onDisconnect(DialerCall call) { - maybeShowErrorDialogOnDisconnect(call); + showDialogOrToastForDisconnectedCall(call); // We need to do the run the same code as onCallListChange. onCallListChange(mCallList); @@ -1241,19 +1241,19 @@ public class InCallPresenter implements CallList.Listener, AudioModeProvider.Aud } } - /** - * For some disconnected causes, we show a dialog. This calls into the activity to show the dialog - * if appropriate for the call. - */ - private void maybeShowErrorDialogOnDisconnect(DialerCall call) { + /** Instruct the in-call activity to show an error dialog or toast for a disconnected call. */ + private void showDialogOrToastForDisconnectedCall(DialerCall call) { + if (!isActivityStarted() || call.getState() != DialerCall.State.DISCONNECTED) { + return; + } + // For newly disconnected calls, we may want to show a dialog on specific error conditions - if (isActivityStarted() && call.getState() == DialerCall.State.DISCONNECTED) { - if (call.getAccountHandle() == null && !call.isConferenceCall()) { - setDisconnectCauseForMissingAccounts(call); - } - mInCallActivity.maybeShowErrorDialogOnDisconnect( - new DisconnectMessage(mInCallActivity, call)); + if (call.getAccountHandle() == null && !call.isConferenceCall()) { + setDisconnectCauseForMissingAccounts(call); } + + mInCallActivity.showDialogOrToastForDisconnectedCall( + new DisconnectMessage(mInCallActivity, call)); } /** |