Merge "Controls UI - Support remaining confirmation dialogs" into rvc-dev

This commit is contained in:
Matt Pietal
2020-03-26 23:06:36 +00:00
committed by Android (Google) Code Review
3 changed files with 72 additions and 19 deletions

View File

@@ -136,7 +136,8 @@ public abstract class ControlAction {
/** /**
* Response code for the {@code consumer} in * Response code for the {@code consumer} in
* {@link ControlsProviderService#performControlAction} indicating that in order for the action * {@link ControlsProviderService#performControlAction} indicating that in order for the action
* to be performed, acknowledgment from the user is required. * to be performed, acknowledgment from the user is required. Any non-empty string returned
* from {@link #getChallengeValue} shall be treated as a positive acknowledgment.
*/ */
public static final @ResponseResult int RESPONSE_CHALLENGE_ACK = 3; public static final @ResponseResult int RESPONSE_CHALLENGE_ACK = 3;
/** /**

View File

@@ -34,24 +34,29 @@ import com.android.systemui.R
/** /**
* Creates all dialogs for challengeValues that can occur from a call to * Creates all dialogs for challengeValues that can occur from a call to
* {@link ControlsProviderService#performControlAction}. The types of challenge * [ControlsProviderService#performControlAction]. The types of challenge responses are listed in
* responses are listed in {@link ControlAction.ResponseResult}. * [ControlAction.ResponseResult].
*/ */
object ChallengeDialogs { object ChallengeDialogs {
fun createPinDialog(cvh: ControlViewHolder): Dialog? { private const val WINDOW_TYPE = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY
private const val STYLE = android.R.style.Theme_DeviceDefault_Dialog_Alert
/**
* AlertDialogs to handle [ControlAction#RESPONSE_CHALLENGE_PIN] and
* [ControlAction#RESPONSE_CHALLENGE_PIN] responses, decided by the useAlphaNumeric
* parameter.
*/
fun createPinDialog(cvh: ControlViewHolder, useAlphaNumeric: Boolean): Dialog? {
val lastAction = cvh.lastAction val lastAction = cvh.lastAction
if (lastAction == null) { if (lastAction == null) {
Log.e(ControlsUiController.TAG, Log.e(ControlsUiController.TAG,
"PIN Dialog attempted but no last action is set. Will not show") "PIN Dialog attempted but no last action is set. Will not show")
return null return null
} }
val builder = AlertDialog.Builder( val builder = AlertDialog.Builder(cvh.context, STYLE).apply {
cvh.context,
android.R.style.Theme_DeviceDefault_Dialog_Alert
).apply {
val res = cvh.context.resources val res = cvh.context.resources
setTitle(res.getString(R.string.controls_pin_verify, *arrayOf(cvh.title.getText()))) setTitle(res.getString(R.string.controls_pin_verify, cvh.title.getText()))
setView(R.layout.controls_dialog_pin) setView(R.layout.controls_dialog_pin)
setPositiveButton( setPositiveButton(
android.R.string.ok, android.R.string.ok,
@@ -71,13 +76,56 @@ object ChallengeDialogs {
} }
return builder.create().apply { return builder.create().apply {
getWindow().apply { getWindow().apply {
setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY) setType(WINDOW_TYPE)
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
} }
setOnShowListener(DialogInterface.OnShowListener { _ -> setOnShowListener(DialogInterface.OnShowListener { _ ->
val editText = requireViewById<EditText>(R.id.controls_pin_input) val editText = requireViewById<EditText>(R.id.controls_pin_input)
requireViewById<CheckBox>(R.id.controls_pin_use_alpha).setOnClickListener { v -> val useAlphaCheckBox = requireViewById<CheckBox>(R.id.controls_pin_use_alpha)
if ((v as CheckBox).isChecked) { useAlphaCheckBox.setChecked(useAlphaNumeric)
setInputType(editText, useAlphaCheckBox.isChecked())
requireViewById<CheckBox>(R.id.controls_pin_use_alpha).setOnClickListener { _ ->
setInputType(editText, useAlphaCheckBox.isChecked())
}
editText.requestFocus()
})
}
}
/**
* AlertDialogs to handle [ControlAction#RESPONSE_CHALLENGE_ACK] response type.
*/
fun createConfirmationDialog(cvh: ControlViewHolder): Dialog? {
val lastAction = cvh.lastAction
if (lastAction == null) {
Log.e(ControlsUiController.TAG,
"Confirmation Dialog attempted but no last action is set. Will not show")
return null
}
val builder = AlertDialog.Builder(cvh.context, STYLE).apply {
val res = cvh.context.resources
setMessage(res.getString(
R.string.controls_confirmation_message, cvh.title.getText()))
setPositiveButton(
android.R.string.ok,
DialogInterface.OnClickListener { dialog, _ ->
cvh.action(addChallengeValue(lastAction, "true"))
dialog.dismiss()
})
setNegativeButton(
android.R.string.cancel,
DialogInterface.OnClickListener { dialog, _ -> dialog.cancel() }
)
}
return builder.create().apply {
getWindow().apply {
setType(WINDOW_TYPE)
}
}
}
private fun setInputType(editText: EditText, useTextInput: Boolean) {
if (useTextInput) {
editText.setInputType( editText.setInputType(
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD) InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
} else { } else {
@@ -85,10 +133,6 @@ object ChallengeDialogs {
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD) InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD)
} }
} }
editText.requestFocus()
})
}
}
private fun addChallengeValue(action: ControlAction, challengeValue: String): ControlAction { private fun addChallengeValue(action: ControlAction, challengeValue: String): ControlAction {
val id = action.getTemplateId() val id = action.getTemplateId()

View File

@@ -442,7 +442,15 @@ class ControlsUiControllerImpl @Inject constructor (
controlViewsById.get(key)?.let { cvh -> controlViewsById.get(key)?.let { cvh ->
when (response) { when (response) {
ControlAction.RESPONSE_CHALLENGE_PIN -> { ControlAction.RESPONSE_CHALLENGE_PIN -> {
activeDialog = ChallengeDialogs.createPinDialog(cvh) activeDialog = ChallengeDialogs.createPinDialog(cvh, false)
activeDialog?.show()
}
ControlAction.RESPONSE_CHALLENGE_PASSPHRASE -> {
activeDialog = ChallengeDialogs.createPinDialog(cvh, true)
activeDialog?.show()
}
ControlAction.RESPONSE_CHALLENGE_ACK -> {
activeDialog = ChallengeDialogs.createConfirmationDialog(cvh)
activeDialog?.show() activeDialog?.show()
} }
else -> cvh.actionResponse(response) else -> cvh.actionResponse(response)