diff options
author | 2022-09-07 23:23:32 +0000 | |
---|---|---|
committer | 2022-09-12 18:00:55 +0000 | |
commit | aabdce2242a22af99e3433686a28e4df177c616c (patch) | |
tree | 1f0abf17e228f39e02caf2eb82f1d84c2406d162 /WifiDialog/src | |
parent | 1b80f4f1c36050db1652a2e6cdf9384774dc34b1 (diff) |
Add countdown message to P2P Invitation Received dialog
Add a countdown message "Accept in XX seconds." to the P2P Invitation
Received dialog if a timeout is specified.
Updated-Overlayable: TRUE
Bug: 242681450
Test: adb shell cmd wifi launch-dialog-p2p-invitation-received with
timeout, verify countdown message appears.
Change-Id: Ia16d5191f53ba50506985023787701817364c43f
Diffstat (limited to 'WifiDialog/src')
-rw-r--r-- | WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java index 0489ea28ff..62b7227f03 100644 --- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java +++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java @@ -25,6 +25,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; +import android.icu.text.MessageFormat; import android.media.AudioManager; import android.media.Ringtone; import android.media.RingtoneManager; @@ -350,7 +351,7 @@ public class WifiDialogActivity extends Activity { if (!WifiManager.ACTION_LAUNCH_DIALOG.equals(action)) { return false; } - AlertDialog dialog = null; + final AlertDialog dialog; int dialogType = intent.getIntExtra( WifiManager.EXTRA_DIALOG_TYPE, WifiManager.DIALOG_TYPE_UNKNOWN); switch (dialogType) { @@ -383,7 +384,7 @@ public class WifiDialogActivity extends Activity { Log.v(TAG, "Could not create dialog with id= " + dialogId + " for unknown type: " + dialogType); } - break; + return false; } if (dialog == null) { return false; @@ -401,10 +402,6 @@ public class WifiDialogActivity extends Activity { dialog.getWindow().setGravity(mGravity); } mActiveDialogsPerId.put(dialogId, dialog); - dialog.show(); - if (mIsVerboseLoggingEnabled) { - Log.v(TAG, "Showing dialog " + dialogId); - } long timeoutMs = intent.getLongExtra(WifiManager.EXTRA_DIALOG_TIMEOUT_MS, 0); if (timeoutMs > 0) { // Use the original expiration time in case we've reloaded this dialog after a @@ -419,10 +416,19 @@ public class WifiDialogActivity extends Activity { intent.putExtra( EXTRA_DIALOG_EXPIRATION_TIME_MS, SystemClock.uptimeMillis() + timeoutMs); } - CountDownTimer countDownTimer = new CountDownTimer(timeoutMs, timeoutMs) { + CountDownTimer countDownTimer = new CountDownTimer(timeoutMs, 100) { @Override public void onTick(long millisUntilFinished) { - // Do nothing. + if (dialogType == WifiManager.DIALOG_TYPE_P2P_INVITATION_RECEIVED) { + int secondsRemaining = (int) millisUntilFinished / 1000; + if (millisUntilFinished % 1000 != 0) { + // Round up to the nearest whole second. + secondsRemaining++; + } + dialog.setMessage(MessageFormat.format( + getString(getStringId("wifi_p2p_invitation_seconds_remaining")), + secondsRemaining)); + } } @Override @@ -431,6 +437,15 @@ public class WifiDialogActivity extends Activity { } }.start(); mActiveCountDownTimersPerId.put(dialogId, countDownTimer); + } else { + if (dialogType == WifiManager.DIALOG_TYPE_P2P_INVITATION_RECEIVED) { + // Set the message back to null if we aren't using a timeout. + dialog.setMessage(null); + } + } + dialog.show(); + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "Showing dialog " + dialogId); } // Allow message URLs to be clickable. TextView messageView = dialog.findViewById(android.R.id.message); @@ -621,6 +636,8 @@ public class WifiDialogActivity extends Activity { AlertDialog dialog = new AlertDialog.Builder(this, getStyleId("wifi_p2p_invitation_received_dialog")) .setTitle(getString(getStringId("wifi_p2p_invitation_to_connect_title"))) + // Set the message to "" to allow us to modify it after building (b/36913966). + .setMessage("") .setView(textEntryView) .setPositiveButton(getStringId("accept"), (dialogPositive, which) -> { String pin = null; |