Merge "Make the tap-to-edit behaviour configurable"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2d917da052
@@ -13835,6 +13835,7 @@ public final class Settings {
|
||||
* enabled (boolean)
|
||||
* requires_targeting_p (boolean)
|
||||
* max_squeeze_remeasure_attempts (int)
|
||||
* edit_choices_before_sending (boolean)
|
||||
* </pre>
|
||||
* @see com.android.systemui.statusbar.policy.SmartReplyConstants
|
||||
* @hide
|
||||
|
||||
@@ -449,6 +449,11 @@
|
||||
better (narrower) line-break for a double-line smart reply button. -->
|
||||
<integer name="config_smart_replies_in_notifications_max_squeeze_remeasure_attempts">3</integer>
|
||||
|
||||
<!-- Smart replies in notifications: Whether by default tapping on a choice should let the user
|
||||
edit the input before it is sent to the app. Developers can override this via
|
||||
RemoteInput.Builder.setEditChoicesBeforeSending. -->
|
||||
<bool name="config_smart_replies_in_notifications_edit_choices_before_sending">false</bool>
|
||||
|
||||
<!-- Screenshot editing default activity. Must handle ACTION_EDIT image/png intents.
|
||||
Blank sends the user to the Chooser first.
|
||||
This name is in the ComponentName flattened format (package/class) -->
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.policy;
|
||||
|
||||
import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;
|
||||
|
||||
import android.app.RemoteInput;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
@@ -42,14 +43,18 @@ public final class SmartReplyConstants extends ContentObserver {
|
||||
private static final String KEY_REQUIRES_TARGETING_P = "requires_targeting_p";
|
||||
private static final String KEY_MAX_SQUEEZE_REMEASURE_ATTEMPTS =
|
||||
"max_squeeze_remeasure_attempts";
|
||||
private static final String KEY_EDIT_CHOICES_BEFORE_SENDING =
|
||||
"edit_choices_before_sending";
|
||||
|
||||
private final boolean mDefaultEnabled;
|
||||
private final boolean mDefaultRequiresP;
|
||||
private final int mDefaultMaxSqueezeRemeasureAttempts;
|
||||
private final boolean mDefaultEditChoicesBeforeSending;
|
||||
|
||||
private boolean mEnabled;
|
||||
private boolean mRequiresTargetingP;
|
||||
private int mMaxSqueezeRemeasureAttempts;
|
||||
private boolean mEditChoicesBeforeSending;
|
||||
|
||||
private final Context mContext;
|
||||
private final KeyValueListParser mParser = new KeyValueListParser(',');
|
||||
@@ -66,6 +71,8 @@ public final class SmartReplyConstants extends ContentObserver {
|
||||
R.bool.config_smart_replies_in_notifications_requires_targeting_p);
|
||||
mDefaultMaxSqueezeRemeasureAttempts = resources.getInteger(
|
||||
R.integer.config_smart_replies_in_notifications_max_squeeze_remeasure_attempts);
|
||||
mDefaultEditChoicesBeforeSending = resources.getBoolean(
|
||||
R.bool.config_smart_replies_in_notifications_edit_choices_before_sending);
|
||||
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Global.getUriFor(Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS),
|
||||
@@ -90,6 +97,8 @@ public final class SmartReplyConstants extends ContentObserver {
|
||||
mRequiresTargetingP = mParser.getBoolean(KEY_REQUIRES_TARGETING_P, mDefaultRequiresP);
|
||||
mMaxSqueezeRemeasureAttempts = mParser.getInt(
|
||||
KEY_MAX_SQUEEZE_REMEASURE_ATTEMPTS, mDefaultMaxSqueezeRemeasureAttempts);
|
||||
mEditChoicesBeforeSending = mParser.getBoolean(
|
||||
KEY_EDIT_CHOICES_BEFORE_SENDING, mDefaultEditChoicesBeforeSending);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,4 +122,24 @@ public final class SmartReplyConstants extends ContentObserver {
|
||||
public int getMaxSqueezeRemeasureAttempts() {
|
||||
return mMaxSqueezeRemeasureAttempts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether by tapping on a choice should let the user edit the input before it
|
||||
* is sent to the app.
|
||||
*
|
||||
* @param remoteInputEditChoicesBeforeSending The value from
|
||||
* {@link RemoteInput#getEditChoicesBeforeSending()}
|
||||
*/
|
||||
public boolean getEffectiveEditChoicesBeforeSending(
|
||||
@RemoteInput.EditChoicesBeforeSending int remoteInputEditChoicesBeforeSending) {
|
||||
switch (remoteInputEditChoicesBeforeSending) {
|
||||
case RemoteInput.EDIT_CHOICES_BEFORE_SENDING_DISABLED:
|
||||
return false;
|
||||
case RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED:
|
||||
return true;
|
||||
case RemoteInput.EDIT_CHOICES_BEFORE_SENDING_AUTO:
|
||||
default:
|
||||
return mEditChoicesBeforeSending;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,9 +242,8 @@ public class SmartReplyView extends ViewGroup {
|
||||
b.setText(choice);
|
||||
|
||||
OnDismissAction action = () -> {
|
||||
// TODO(b/111437455): Also for EDIT_CHOICES_BEFORE_SENDING_AUTO, depending on flags.
|
||||
if (smartReplies.remoteInput.getEditChoicesBeforeSending()
|
||||
== RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED) {
|
||||
if (mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
smartReplies.remoteInput.getEditChoicesBeforeSending())) {
|
||||
entry.remoteInputText = choice;
|
||||
mRemoteInputManager.activateRemoteInput(b,
|
||||
new RemoteInput[] { smartReplies.remoteInput }, smartReplies.remoteInput,
|
||||
|
||||
@@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import android.app.RemoteInput;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
@@ -51,6 +52,8 @@ public class SmartReplyConstantsTest extends SysuiTestCase {
|
||||
resources.addOverride(R.bool.config_smart_replies_in_notifications_enabled, true);
|
||||
resources.addOverride(
|
||||
R.integer.config_smart_replies_in_notifications_max_squeeze_remeasure_attempts, 7);
|
||||
resources.addOverride(
|
||||
R.bool.config_smart_replies_in_notifications_edit_choices_before_sending, false);
|
||||
mConstants = new SmartReplyConstants(Handler.createAsync(Looper.myLooper()), mContext);
|
||||
}
|
||||
|
||||
@@ -104,6 +107,51 @@ public class SmartReplyConstantsTest extends SysuiTestCase {
|
||||
assertEquals(5, mConstants.getMaxSqueezeRemeasureAttempts());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEffectiveEditChoicesBeforeSendingWithNoConfig() {
|
||||
overrideSetting("enabled=true");
|
||||
triggerConstantsOnChange();
|
||||
assertFalse(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_AUTO));
|
||||
assertTrue(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED));
|
||||
assertFalse(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_DISABLED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEffectiveEditChoicesBeforeSendingWithEnabledConfig() {
|
||||
overrideSetting("enabled=true,edit_choices_before_sending=true");
|
||||
triggerConstantsOnChange();
|
||||
assertTrue(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_AUTO));
|
||||
assertTrue(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED));
|
||||
assertFalse(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_DISABLED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEffectiveEditChoicesBeforeSendingWithDisabledConfig() {
|
||||
overrideSetting("enabled=true,edit_choices_before_sending=false");
|
||||
triggerConstantsOnChange();
|
||||
assertFalse(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_AUTO));
|
||||
assertTrue(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED));
|
||||
assertFalse(
|
||||
mConstants.getEffectiveEditChoicesBeforeSending(
|
||||
RemoteInput.EDIT_CHOICES_BEFORE_SENDING_DISABLED));
|
||||
}
|
||||
|
||||
private void overrideSetting(String flags) {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS, flags);
|
||||
|
||||
Reference in New Issue
Block a user