Merge "Controls UI - Handle 'not found' better" into rvc-dev

This commit is contained in:
Matt Pietal
2020-06-04 23:22:54 +00:00
committed by Android (Google) Code Review
4 changed files with 89 additions and 10 deletions

View File

@@ -73,25 +73,37 @@ public final class Control implements Parcelable {
})
public @interface Status {};
/**
* Reserved for use with the {@link StatelessBuilder}, and while loading. When state is
* requested via {@link ControlsProviderService#createPublisherFor}, use other status codes
* to indicate the proper device state.
*/
public static final int STATUS_UNKNOWN = 0;
/**
* The device corresponding to the {@link Control} is responding correctly.
* Used to indicate that the state of the device was successfully retrieved. This includes
* all scenarios where the device may have a warning for the user, such as "Lock jammed",
* or "Vacuum stuck". Any information for the user should be set through
* {@link StatefulBuilder#setStatusText}.
*/
public static final int STATUS_OK = 1;
/**
* The device corresponding to the {@link Control} cannot be found or was removed.
* The device corresponding to the {@link Control} cannot be found or was removed. The user
* will be alerted and directed to the application to resolve.
*/
public static final int STATUS_NOT_FOUND = 2;
/**
* The device corresponding to the {@link Control} is in an error state.
* Used to indicate that there was a temporary error while loading the device state. A default
* error message will be displayed in place of any custom text that was set through
* {@link StatefulBuilder#setStatusText}.
*/
public static final int STATUS_ERROR = 3;
/**
* The {@link Control} is currently disabled.
* The {@link Control} is currently disabled. A default error message will be displayed in
* place of any custom text that was set through {@link StatefulBuilder#setStatusText}.
*/
public static final int STATUS_DISABLED = 4;

View File

@@ -2790,7 +2790,13 @@
a retry will be attempted [CHAR LIMIT=30] -->
<string name="controls_error_retryable">Error, retrying\u2026</string>
<!-- Error message indicating that the control is no longer available in the application [CHAR LIMIT=30] -->
<string name="controls_error_removed">Device removed</string>
<string name="controls_error_removed">Not found</string>
<!-- Title for dialog indicating that the control is no longer available in the application [CHAR LIMIT=30] -->
<string name="controls_error_removed_title">Control is unavailable</string>
<!-- Message body for dialog indicating that the control is no longer available in the application [CHAR LIMIT=NONE] -->
<string name="controls_error_removed_message">Couldn\u2019t access <xliff:g id="device" example="Backdoor lock">%1$s</xliff:g>. Check the <xliff:g id="application" example="Google Home">%2$s</xliff:g> app to make sure the control is still available and that the app settings haven\u2019t changed.</string>
<!-- Text for button to open the corresponding application [CHAR_LIMIT=20] -->
<string name="controls_open_app">Open app</string>
<!-- Error message indicating that an unspecified error occurred while getting the status [CHAR LIMIT=30] -->
<string name="controls_error_generic">Can\u2019t load status</string>
<!-- Error message indicating that a control action failed [CHAR_LIMIT=30] -->

View File

@@ -118,6 +118,7 @@ class ControlViewHolder(
var behavior: Behavior? = null
var lastAction: ControlAction? = null
var isLoading = false
var visibleDialog: Dialog? = null
private var lastChallengeDialog: Dialog? = null
private val onDialogCancel: () -> Unit = { lastChallengeDialog = null }
@@ -197,18 +198,24 @@ class ControlViewHolder(
fun dismiss() {
lastChallengeDialog?.dismiss()
lastChallengeDialog = null
visibleDialog?.dismiss()
visibleDialog = null
}
fun setTransientStatus(tempStatus: String) {
val previousText = status.getText()
cancelUpdate = uiExecutor.executeDelayed({
setStatusText(previousText)
updateContentDescription()
animateStatusChange(/* animated */ true, {
setStatusText(previousText, /* immediately */ true)
updateContentDescription()
})
}, UPDATE_DELAY_IN_MILLIS)
setStatusText(tempStatus)
updateContentDescription()
animateStatusChange(/* animated */ true, {
setStatusText(tempStatus, /* immediately */ true)
updateContentDescription()
})
}
private fun updateContentDescription() =

View File

@@ -16,7 +16,13 @@
package com.android.systemui.controls.ui
import android.app.AlertDialog
import android.app.PendingIntent
import android.content.DialogInterface
import android.content.pm.PackageManager
import android.service.controls.Control
import android.view.View
import android.view.WindowManager
import com.android.systemui.R
@@ -31,7 +37,17 @@ class StatusBehavior : Behavior {
val status = cws.control?.status ?: Control.STATUS_UNKNOWN
val msg = when (status) {
Control.STATUS_ERROR -> R.string.controls_error_generic
Control.STATUS_NOT_FOUND -> R.string.controls_error_removed
Control.STATUS_DISABLED -> R.string.controls_error_timeout
Control.STATUS_NOT_FOUND -> {
cvh.layout.setOnClickListener(View.OnClickListener() {
showNotFoundDialog(cvh, cws)
})
cvh.layout.setOnLongClickListener(View.OnLongClickListener() {
showNotFoundDialog(cvh, cws)
true
})
R.string.controls_error_removed
}
else -> {
cvh.isLoading = true
com.android.internal.R.string.loading
@@ -40,4 +56,42 @@ class StatusBehavior : Behavior {
cvh.setStatusText(cvh.context.getString(msg))
cvh.applyRenderInfo(false, colorOffset)
}
private fun showNotFoundDialog(cvh: ControlViewHolder, cws: ControlWithState) {
val pm = cvh.context.getPackageManager()
val ai = pm.getApplicationInfo(cws.componentName.packageName, PackageManager.GET_META_DATA)
val appLabel = pm.getApplicationLabel(ai)
val builder = AlertDialog.Builder(
cvh.context,
android.R.style.Theme_DeviceDefault_Dialog_Alert
).apply {
val res = cvh.context.resources
setTitle(res.getString(R.string.controls_error_removed_title))
setMessage(res.getString(
R.string.controls_error_removed_message, cvh.title.getText(), appLabel))
setPositiveButton(
R.string.controls_open_app,
DialogInterface.OnClickListener { dialog, _ ->
try {
cws.control?.getAppIntent()?.send()
} catch (e: PendingIntent.CanceledException) {
cvh.setTransientStatus(
cvh.context.resources.getString(R.string.controls_error_failed))
}
dialog.dismiss()
})
setNegativeButton(
android.R.string.cancel,
DialogInterface.OnClickListener { dialog, _ ->
dialog.cancel()
}
)
}
cvh.visibleDialog = builder.create().apply {
getWindow().apply {
setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY)
show()
}
}
}
}