Merge changes from topic "remote_input_a11y" into sc-dev

* changes:
  Fix colors to match the spec, and resolve contrast issues.
  Allow sending inline reply of just an image
  Fix size of RemoteInputView to for a11y
This commit is contained in:
Jeff DeCew
2021-05-21 13:43:10 +00:00
committed by Android (Google) Code Review
5 changed files with 78 additions and 77 deletions

View File

@@ -16,6 +16,6 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:color="?android:attr/colorAccent" /> <item android:state_enabled="false" android:color="?android:attr/colorAccent" android:alpha=".3" />
<item android:color="?android:attr/colorAccent" android:alpha=".3" /> <item android:color="?android:attr/colorAccent" />
</selector> </selector>

View File

@@ -16,6 +16,6 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:color="?android:attr/textColorPrimary" /> <item android:state_enabled="false" android:color="?android:attr/textColorPrimary" android:alpha=".6" />
<item android:color="?android:attr/textColorPrimary" android:alpha=".6" /> <item android:color="?android:attr/textColorPrimary" />
</selector> </selector>

View File

@@ -21,10 +21,10 @@
android:width="@dimen/remote_input_view_text_stroke" android:width="@dimen/remote_input_view_text_stroke"
android:color="?android:attr/colorAccent"/> android:color="?android:attr/colorAccent"/>
<padding <padding
android:bottom="12dp" android:bottom="0dp"
android:left="12dp" android:left="12dp"
android:right="12dp" android:right="12dp"
android:top="12dp"/> android:top="0dp"/>
<corners android:radius="24dp" /> <corners android:radius="24dp" />

View File

@@ -28,18 +28,18 @@
android:id="@+id/remote_input_content" android:id="@+id/remote_input_content"
android:orientation="vertical" android:orientation="vertical"
android:clipToPadding="false" android:clipToPadding="false"
android:layout_marginEnd="20dp" android:layout_marginEnd="0dp"
android:layout_marginStart="20dp" android:layout_marginStart="16dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:layout_weight="1"> android:layout_weight="1">
<FrameLayout <FrameLayout
android:id="@+id/remote_input_content_container" android:id="@+id/remote_input_content_container"
android:layout_marginTop="-6dp" android:layout_height="66dp"
android:layout_height="60dp" android:layout_width="66dp"
android:layout_width="60dp" android:layout_marginTop="0dp"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:layout_marginBottom="12dp" android:layout_marginBottom="0dp"
android:visibility="gone" android:visibility="gone"
android:layout_gravity="center_vertical"> android:layout_gravity="center_vertical">
<ImageView <ImageView
@@ -52,18 +52,20 @@
android:scaleType="centerCrop" /> android:scaleType="centerCrop" />
<ImageView <ImageView
android:id="@+id/remote_input_delete_bg" android:id="@+id/remote_input_delete_bg"
android:paddingStart="24dp" android:paddingTop="6dp"
android:paddingBottom="24dp" android:paddingEnd="6dp"
android:paddingStart="18dp"
android:paddingBottom="18dp"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="end|top" android:layout_gravity="end|top"
android:src="@drawable/thumbnail_delete_btn_bg"/> android:src="@drawable/thumbnail_delete_btn_bg"/>
<ImageView <ImageView
android:id="@+id/remote_input_delete" android:id="@+id/remote_input_delete"
android:paddingTop="3dp" android:paddingTop="9dp"
android:paddingEnd="3dp" android:paddingEnd="9dp"
android:paddingStart="27dp" android:paddingStart="21dp"
android:paddingBottom="27dp" android:paddingBottom="21dp"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="end|top" android:layout_gravity="end|top"
@@ -76,9 +78,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:paddingTop="2dp" android:paddingTop="14dp"
android:paddingStart="4dp" android:paddingStart="4dp"
android:paddingBottom="4dp" android:paddingBottom="16dp"
android:paddingEnd="12dp" android:paddingEnd="12dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
android:textAppearance="?android:attr/textAppearance" android:textAppearance="?android:attr/textAppearance"
@@ -93,7 +95,7 @@
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout
android:layout_width="wrap_content" android:layout_width="56dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_vertical"> android:layout_gravity="center_vertical">

View File

@@ -35,7 +35,6 @@ import android.graphics.BlendMode;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@@ -187,6 +186,16 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
ta.recycle(); ta.recycle();
} }
private ColorStateList colorStateListWithDisabledAlpha(int color, int disabledAlpha) {
return new ColorStateList(new int[][]{
new int[]{-com.android.internal.R.attr.state_enabled}, // disabled
new int[]{},
}, new int[]{
ColorUtils.setAlphaComponent(color, disabledAlpha),
color
});
}
/** /**
* The remote view needs to adapt to colorized notifications when set * The remote view needs to adapt to colorized notifications when set
* It overrides the background of itself as well as all of its childern * It overrides the background of itself as well as all of its childern
@@ -197,55 +206,50 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
mColorized = colorized; mColorized = colorized;
mTint = backgroundColor; mTint = backgroundColor;
final int editBgColor; final int editBgColor;
final int alternateBgColor; final int deleteBgColor;
final int alternateTextColor; final int deleteFgColor;
final int accentColor; final ColorStateList accentColor;
final int textColor; final ColorStateList textColor;
final int hintTextColor; final int hintColor;
final int stroke = mContext.getResources().getDimensionPixelSize( final int stroke = colorized ? mContext.getResources().getDimensionPixelSize(
R.dimen.remote_input_view_text_stroke); R.dimen.remote_input_view_text_stroke) : 0;
if (colorized) { if (colorized) {
final boolean dark = !ContrastColorUtil.isColorLight(backgroundColor); final boolean dark = !ContrastColorUtil.isColorLight(backgroundColor);
final int foregroundColor = dark ? Color.WHITE : Color.BLACK; final int foregroundColor = dark ? Color.WHITE : Color.BLACK;
final int inverseColor = dark ? Color.BLACK : Color.WHITE;
editBgColor = backgroundColor; editBgColor = backgroundColor;
accentColor = foregroundColor; deleteBgColor = foregroundColor;
alternateBgColor = foregroundColor; deleteFgColor = inverseColor;
alternateTextColor = backgroundColor; accentColor = colorStateListWithDisabledAlpha(foregroundColor, 0x4D); // 30%
textColor = foregroundColor; textColor = colorStateListWithDisabledAlpha(foregroundColor, 0x99); // 60%
hintTextColor = ColorUtils.setAlphaComponent(foregroundColor, 0x99); hintColor = ColorUtils.setAlphaComponent(foregroundColor, 0x99);
} else { } else {
textColor = mContext.getColor(R.color.remote_input_text); accentColor = mContext.getColorStateList(R.color.remote_input_send);
hintTextColor = mContext.getColor(R.color.remote_input_hint); textColor = mContext.getColorStateList(R.color.remote_input_text);
hintColor = mContext.getColor(R.color.remote_input_hint);
deleteFgColor = textColor.getDefaultColor();
try (TypedArray ta = getContext().getTheme().obtainStyledAttributes(new int[]{ try (TypedArray ta = getContext().getTheme().obtainStyledAttributes(new int[]{
com.android.internal.R.attr.colorAccent, com.android.internal.R.attr.colorSurfaceHighlight,
com.android.internal.R.attr.colorSurface, com.android.internal.R.attr.colorSurfaceVariant
com.android.internal.R.attr.colorSurfaceVariant,
com.android.internal.R.attr.textColorPrimary
})) { })) {
accentColor = ta.getColor(0, textColor); editBgColor = ta.getColor(0, backgroundColor);
editBgColor = ta.getColor(1, backgroundColor); deleteBgColor = ta.getColor(1, Color.GRAY);
alternateBgColor = ta.getColor(2, textColor);
alternateTextColor = ta.getColor(3, backgroundColor);
} }
} }
mEditText.setAllColors(backgroundColor, editBgColor,
accentColor, textColor, hintTextColor); mEditText.setTextColor(textColor);
final ColorStateList accentTint = new ColorStateList(new int[][]{ mEditText.setHintTextColor(hintColor);
new int[]{com.android.internal.R.attr.state_enabled}, mEditText.getTextCursorDrawable().setColorFilter(
new int[]{}, accentColor.getDefaultColor(), PorterDuff.Mode.SRC_IN);
}, new int[]{
accentColor,
accentColor & 0x4DFFFFFF // %30 opacity
});
mContentBackground.setColor(editBgColor); mContentBackground.setColor(editBgColor);
mContentBackground.setStroke(stroke, accentTint); mContentBackground.setStroke(stroke, accentColor);
mDelete.setImageTintList(ColorStateList.valueOf(alternateTextColor)); mDelete.setImageTintList(ColorStateList.valueOf(deleteFgColor));
mDeleteBg.setImageTintList(ColorStateList.valueOf(alternateBgColor)); mDeleteBg.setImageTintList(ColorStateList.valueOf(deleteBgColor));
mSendButton.setImageTintList(accentTint); mSendButton.setImageTintList(accentColor);
mProgressBar.setProgressTintList(accentTint); mProgressBar.setProgressTintList(accentColor);
mProgressBar.setIndeterminateTintList(accentTint); mProgressBar.setIndeterminateTintList(accentColor);
mProgressBar.setSecondaryProgressTintList(accentTint); mProgressBar.setSecondaryProgressTintList(accentColor);
setBackgroundColor(editBgColor); setBackgroundColor(backgroundColor);
} }
@Override @Override
@@ -311,6 +315,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
} else { } else {
attachment.setVisibility(VISIBLE); attachment.setVisibility(VISIBLE);
} }
updateSendButton();
} }
/** /**
@@ -332,6 +337,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
results); results);
mEntry.remoteInputText = mEditText.getText(); mEntry.remoteInputText = mEditText.getText();
// TODO(b/188646667): store attachment to entry
mEntry.remoteInputUri = null; mEntry.remoteInputUri = null;
mEntry.remoteInputMimeType = null; mEntry.remoteInputMimeType = null;
@@ -368,6 +374,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
: "\"" + attachmentLabel + "\" " + mEditText.getText(); : "\"" + attachmentLabel + "\" " + mEditText.getText();
mEntry.remoteInputText = fullText; mEntry.remoteInputText = fullText;
// TODO(b/188646667): store attachment to entry
mEntry.remoteInputMimeType = contentType; mEntry.remoteInputMimeType = contentType;
mEntry.remoteInputUri = data; mEntry.remoteInputUri = data;
@@ -470,6 +477,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
private void onDefocus(boolean animate, boolean logClose) { private void onDefocus(boolean animate, boolean logClose) {
mController.removeRemoteInput(mEntry, mToken); mController.removeRemoteInput(mEntry, mToken);
mEntry.remoteInputText = mEditText.getText(); mEntry.remoteInputText = mEditText.getText();
// TODO(b/188646667): store attachment to entry
// During removal, we get reattached and lose focus. Not hiding in that // During removal, we get reattached and lose focus. Not hiding in that
// case to prevent flicker. // case to prevent flicker.
@@ -557,6 +565,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
mEntry.editedSuggestionInfo = editedSuggestionInfo; mEntry.editedSuggestionInfo = editedSuggestionInfo;
if (editedSuggestionInfo != null) { if (editedSuggestionInfo != null) {
mEntry.remoteInputText = editedSuggestionInfo.originalText; mEntry.remoteInputText = editedSuggestionInfo.originalText;
// TODO(b/188646667): store attachment to entry
} }
} }
@@ -596,9 +605,10 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
mEditText.setInnerFocusable(true); mEditText.setInnerFocusable(true);
mEditText.mShowImeOnInputConnection = true; mEditText.mShowImeOnInputConnection = true;
mEditText.setText(mEntry.remoteInputText); mEditText.setText(mEntry.remoteInputText);
mEditText.setSelection(mEditText.getText().length()); mEditText.setSelection(mEditText.length());
mEditText.requestFocus(); mEditText.requestFocus();
mController.addRemoteInput(mEntry, mToken); mController.addRemoteInput(mEntry, mToken);
// TODO(b/188646667): restore attachment from entry
mRemoteInputQuickSettingsDisabler.setRemoteInputActive(true); mRemoteInputQuickSettingsDisabler.setRemoteInputActive(true);
@@ -621,6 +631,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
private void reset() { private void reset() {
mResetting = true; mResetting = true;
mEntry.remoteInputTextWhenReset = SpannedString.valueOf(mEditText.getText()); mEntry.remoteInputTextWhenReset = SpannedString.valueOf(mEditText.getText());
// TODO(b/188646667): store attachment at time of reset to entry
mEditText.getText().clear(); mEditText.getText().clear();
mEditText.setEnabled(true); mEditText.setEnabled(true);
@@ -629,6 +640,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
mController.removeSpinning(mEntry.getKey(), mToken); mController.removeSpinning(mEntry.getKey(), mToken);
updateSendButton(); updateSendButton();
onDefocus(false /* animate */, false /* logClose */); onDefocus(false /* animate */, false /* logClose */);
// TODO(b/188646667): clear attachment
mResetting = false; mResetting = false;
} }
@@ -645,7 +657,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
} }
private void updateSendButton() { private void updateSendButton() {
mSendButton.setEnabled(mEditText.getText().length() != 0); mSendButton.setEnabled(mEditText.length() != 0 || mAttachment != null);
} }
public void close() { public void close() {
@@ -875,7 +887,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
private final OnReceiveContentListener mOnReceiveContentListener = this::onReceiveContent; private final OnReceiveContentListener mOnReceiveContentListener = this::onReceiveContent;
private RemoteInputView mRemoteInputView; private RemoteInputView mRemoteInputView;
private ColorDrawable mBackground;
boolean mShowImeOnInputConnection; boolean mShowImeOnInputConnection;
private LightBarController mLightBarController; private LightBarController mLightBarController;
private InputMethodManager mInputMethodManager; private InputMethodManager mInputMethodManager;
@@ -885,8 +896,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
public RemoteEditText(Context context, AttributeSet attrs) { public RemoteEditText(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mLightBarController = Dependency.get(LightBarController.class); mLightBarController = Dependency.get(LightBarController.class);
mBackground = new ColorDrawable();
} }
void setSupportedMimeTypes(@Nullable Collection<String> mimeTypes) { void setSupportedMimeTypes(@Nullable Collection<String> mimeTypes) {
@@ -915,6 +924,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
// our focus, so we'll need to save our text here. // our focus, so we'll need to save our text here.
if (mRemoteInputView != null) { if (mRemoteInputView != null) {
mRemoteInputView.mEntry.remoteInputText = getText(); mRemoteInputView.mEntry.remoteInputText = getText();
// TODO(b/188646667): store attachment to entry
} }
} }
return; return;
@@ -1045,9 +1055,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
if (focusable) { if (focusable) {
requestFocus(); requestFocus();
setBackground(mBackground);
} else {
setBackground(null);
} }
} }
@@ -1062,13 +1069,5 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
return remainingItems; return remainingItems;
} }
protected void setAllColors(int backgroundColor, int editBackgroundColor,
int accentColor, int textColor, int hintTextColor) {
setBackgroundColor(editBackgroundColor);
mBackground.setColor(editBackgroundColor);
setTextColor(textColor);
setHintTextColor(hintTextColor);
getTextCursorDrawable().setColorFilter(accentColor, PorterDuff.Mode.SRC_IN);
}
} }
} }