Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d939d3b4 authored by Jeff DeCew's avatar Jeff DeCew Committed by Automerger Merge Worker
Browse files

Merge changes from topic "remote_input_a11y" into sc-dev am: f0ec6471

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14624271

Change-Id: Ic8007aba375287214b4e5593993b1cd6b70b5fe7
parents 639a7a0a f0ec6471
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -16,6 +16,6 @@
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true" android:color="?android:attr/colorAccent" />
    <item android:color="?android:attr/colorAccent" android:alpha=".3" />
    <item android:state_enabled="false" android:color="?android:attr/colorAccent" android:alpha=".3" />
    <item android:color="?android:attr/colorAccent" />
</selector>
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -16,6 +16,6 @@
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true" android:color="?android:attr/textColorPrimary" />
    <item android:color="?android:attr/textColorPrimary" android:alpha=".6" />
    <item android:state_enabled="false" android:color="?android:attr/textColorPrimary" android:alpha=".6" />
    <item android:color="?android:attr/textColorPrimary" />
</selector>
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@
        android:width="@dimen/remote_input_view_text_stroke"
        android:color="?android:attr/colorAccent"/>
    <padding
        android:bottom="12dp"
        android:bottom="0dp"
        android:left="12dp"
        android:right="12dp"
        android:top="12dp"/>
        android:top="0dp"/>

    <corners android:radius="24dp" />

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

    <FrameLayout
            android:layout_width="wrap_content"
            android:layout_width="56dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical">

+55 −56
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.graphics.BlendMode;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Bundle;
@@ -187,6 +186,16 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        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
     * 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;
        mTint = backgroundColor;
        final int editBgColor;
        final int alternateBgColor;
        final int alternateTextColor;
        final int accentColor;
        final int textColor;
        final int hintTextColor;
        final int stroke = mContext.getResources().getDimensionPixelSize(
                R.dimen.remote_input_view_text_stroke);
        final int deleteBgColor;
        final int deleteFgColor;
        final ColorStateList accentColor;
        final ColorStateList textColor;
        final int hintColor;
        final int stroke = colorized ? mContext.getResources().getDimensionPixelSize(
                R.dimen.remote_input_view_text_stroke) : 0;
        if (colorized) {
            final boolean dark = !ContrastColorUtil.isColorLight(backgroundColor);
            final int foregroundColor = dark ? Color.WHITE : Color.BLACK;
            final int inverseColor = dark ? Color.BLACK : Color.WHITE;
            editBgColor = backgroundColor;
            accentColor = foregroundColor;
            alternateBgColor = foregroundColor;
            alternateTextColor = backgroundColor;
            textColor = foregroundColor;
            hintTextColor = ColorUtils.setAlphaComponent(foregroundColor, 0x99);
            deleteBgColor = foregroundColor;
            deleteFgColor = inverseColor;
            accentColor = colorStateListWithDisabledAlpha(foregroundColor, 0x4D); // 30%
            textColor = colorStateListWithDisabledAlpha(foregroundColor, 0x99); // 60%
            hintColor = ColorUtils.setAlphaComponent(foregroundColor, 0x99);
        } else {
            textColor = mContext.getColor(R.color.remote_input_text);
            hintTextColor = mContext.getColor(R.color.remote_input_hint);
            accentColor = mContext.getColorStateList(R.color.remote_input_send);
            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[]{
                    com.android.internal.R.attr.colorAccent,
                    com.android.internal.R.attr.colorSurface,
                    com.android.internal.R.attr.colorSurfaceVariant,
                    com.android.internal.R.attr.textColorPrimary
                    com.android.internal.R.attr.colorSurfaceHighlight,
                    com.android.internal.R.attr.colorSurfaceVariant
            })) {
                accentColor = ta.getColor(0, textColor);
                editBgColor = ta.getColor(1, backgroundColor);
                alternateBgColor = ta.getColor(2, textColor);
                alternateTextColor = ta.getColor(3, backgroundColor);
                editBgColor = ta.getColor(0, backgroundColor);
                deleteBgColor = ta.getColor(1, Color.GRAY);
            }
        }
        mEditText.setAllColors(backgroundColor, editBgColor,
                accentColor, textColor, hintTextColor);
        final ColorStateList accentTint = new ColorStateList(new int[][]{
                new int[]{com.android.internal.R.attr.state_enabled},
                new int[]{},
        }, new int[]{
                accentColor,
                accentColor & 0x4DFFFFFF // %30 opacity
        });

        mEditText.setTextColor(textColor);
        mEditText.setHintTextColor(hintColor);
        mEditText.getTextCursorDrawable().setColorFilter(
                accentColor.getDefaultColor(), PorterDuff.Mode.SRC_IN);
        mContentBackground.setColor(editBgColor);
        mContentBackground.setStroke(stroke, accentTint);
        mDelete.setImageTintList(ColorStateList.valueOf(alternateTextColor));
        mDeleteBg.setImageTintList(ColorStateList.valueOf(alternateBgColor));
        mSendButton.setImageTintList(accentTint);
        mProgressBar.setProgressTintList(accentTint);
        mProgressBar.setIndeterminateTintList(accentTint);
        mProgressBar.setSecondaryProgressTintList(accentTint);
        setBackgroundColor(editBgColor);
        mContentBackground.setStroke(stroke, accentColor);
        mDelete.setImageTintList(ColorStateList.valueOf(deleteFgColor));
        mDeleteBg.setImageTintList(ColorStateList.valueOf(deleteBgColor));
        mSendButton.setImageTintList(accentColor);
        mProgressBar.setProgressTintList(accentColor);
        mProgressBar.setIndeterminateTintList(accentColor);
        mProgressBar.setSecondaryProgressTintList(accentColor);
        setBackgroundColor(backgroundColor);
    }

    @Override
@@ -311,6 +315,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        } else {
            attachment.setVisibility(VISIBLE);
        }
        updateSendButton();
    }

    /**
@@ -332,6 +337,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
                results);

        mEntry.remoteInputText = mEditText.getText();
        // TODO(b/188646667): store attachment to entry
        mEntry.remoteInputUri = null;
        mEntry.remoteInputMimeType = null;

@@ -368,6 +374,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
                : "\"" + attachmentLabel + "\" " + mEditText.getText();

        mEntry.remoteInputText = fullText;
        // TODO(b/188646667): store attachment to entry
        mEntry.remoteInputMimeType = contentType;
        mEntry.remoteInputUri = data;

@@ -470,6 +477,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
    private void onDefocus(boolean animate, boolean logClose) {
        mController.removeRemoteInput(mEntry, mToken);
        mEntry.remoteInputText = mEditText.getText();
        // TODO(b/188646667): store attachment to entry

        // During removal, we get reattached and lose focus. Not hiding in that
        // case to prevent flicker.
@@ -557,6 +565,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        mEntry.editedSuggestionInfo = editedSuggestionInfo;
        if (editedSuggestionInfo != null) {
            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.mShowImeOnInputConnection = true;
        mEditText.setText(mEntry.remoteInputText);
        mEditText.setSelection(mEditText.getText().length());
        mEditText.setSelection(mEditText.length());
        mEditText.requestFocus();
        mController.addRemoteInput(mEntry, mToken);
        // TODO(b/188646667): restore attachment from entry

        mRemoteInputQuickSettingsDisabler.setRemoteInputActive(true);

@@ -621,6 +631,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
    private void reset() {
        mResetting = true;
        mEntry.remoteInputTextWhenReset = SpannedString.valueOf(mEditText.getText());
        // TODO(b/188646667): store attachment at time of reset to entry

        mEditText.getText().clear();
        mEditText.setEnabled(true);
@@ -629,6 +640,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        mController.removeSpinning(mEntry.getKey(), mToken);
        updateSendButton();
        onDefocus(false /* animate */, false /* logClose */);
        // TODO(b/188646667): clear attachment

        mResetting = false;
    }
@@ -645,7 +657,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
    }

    private void updateSendButton() {
        mSendButton.setEnabled(mEditText.getText().length() != 0);
        mSendButton.setEnabled(mEditText.length() != 0 || mAttachment != null);
    }

    public void close() {
@@ -875,7 +887,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        private final OnReceiveContentListener mOnReceiveContentListener = this::onReceiveContent;

        private RemoteInputView mRemoteInputView;
        private ColorDrawable mBackground;
        boolean mShowImeOnInputConnection;
        private LightBarController mLightBarController;
        private InputMethodManager mInputMethodManager;
@@ -885,8 +896,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        public RemoteEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
            mLightBarController = Dependency.get(LightBarController.class);

            mBackground = new ColorDrawable();
        }

        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.
                    if (mRemoteInputView != null) {
                        mRemoteInputView.mEntry.remoteInputText = getText();
                        // TODO(b/188646667): store attachment to entry
                    }
                }
                return;
@@ -1045,9 +1055,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene

            if (focusable) {
                requestFocus();
                setBackground(mBackground);
            } else {
                setBackground(null);
            }
        }

@@ -1062,13 +1069,5 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
            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);
        }
    }
}