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

Commit b67ef4aa authored by Steve Elliott's avatar Steve Elliott
Browse files

Fix IME image insertion for RemoteInputView

Broken by ag/12830377

Bug: 163595585
Test: manual
Change-Id: I75700adca2796f7b70a0d840a470acdb2488546a
parent 1447bab5
Loading
Loading
Loading
Loading
+34 −36
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.policy;


import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.Notification;
import android.app.Notification;
@@ -75,6 +74,7 @@ import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewW
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import com.android.systemui.statusbar.phone.LightBarController;
import com.android.systemui.statusbar.phone.LightBarController;


import java.util.Collection;
import java.util.HashMap;
import java.util.HashMap;
import java.util.function.Consumer;
import java.util.function.Consumer;


@@ -315,8 +315,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        mRemoteInputs = remoteInputs;
        mRemoteInputs = remoteInputs;
        mRemoteInput = remoteInput;
        mRemoteInput = remoteInput;
        mEditText.setHint(mRemoteInput.getLabel());
        mEditText.setHint(mRemoteInput.getLabel());
        mEditText.mSupportedMimeTypes = (remoteInput.getAllowedDataTypes() == null) ? null
        mEditText.setSupportedMimeTypes(remoteInput.getAllowedDataTypes());
                : remoteInput.getAllowedDataTypes().toArray(new String[0]);


        mEntry.editedSuggestionInfo = editedSuggestionInfo;
        mEntry.editedSuggestionInfo = editedSuggestionInfo;
        if (editedSuggestionInfo != null) {
        if (editedSuggestionInfo != null) {
@@ -570,12 +569,13 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
     */
     */
    public static class RemoteEditText extends EditText {
    public static class RemoteEditText extends EditText {


        private final OnReceiveContentListener mOnReceiveContentListener = this::onReceiveContent;

        private final Drawable mBackground;
        private final Drawable mBackground;
        private RemoteInputView mRemoteInputView;
        private RemoteInputView mRemoteInputView;
        boolean mShowImeOnInputConnection;
        boolean mShowImeOnInputConnection;
        private LightBarController mLightBarController;
        private LightBarController mLightBarController;
        UserHandle mUser;
        UserHandle mUser;
        private String[] mSupportedMimeTypes;


        public RemoteEditText(Context context, AttributeSet attrs) {
        public RemoteEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
            super(context, attrs);
@@ -583,39 +583,14 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
            mLightBarController = Dependency.get(LightBarController.class);
            mLightBarController = Dependency.get(LightBarController.class);
        }
        }


        @Override
        void setSupportedMimeTypes(@Nullable Collection<String> mimeTypes) {
        protected void onFinishInflate() {
            String[] types = null;
            super.onFinishInflate();
            OnReceiveContentListener listener = null;
            if (mSupportedMimeTypes != null && mSupportedMimeTypes.length > 0) {
            if (mimeTypes != null && !mimeTypes.isEmpty()) {
                setOnReceiveContentListener(mSupportedMimeTypes,
                types = mimeTypes.toArray(new String[0]);
                        new OnReceiveContentListener() {
                listener = mOnReceiveContentListener;
                            @Override
                            @Nullable
                            public ContentInfo onReceiveContent(@NonNull View view,
                                    @NonNull ContentInfo payload) {
                                Pair<ContentInfo, ContentInfo> split = payload.partition(
                                        item -> item.getUri() != null);
                                ContentInfo uriContent = split.first;
                                ContentInfo remaining = split.second;
                                if (uriContent != null) {
                                    ClipData clip = uriContent.getClip();
                                    ClipDescription description = clip.getDescription();
                                    if (clip.getItemCount() > 1
                                            || description.getMimeTypeCount() < 1
                                            || remaining != null) {
                                        // TODO(b/172363500): Update to loop over all the items
                                        return payload;
                                    }
                                    Uri contentUri = clip.getItemAt(0).getUri();
                                    String mimeType = description.getMimeType(0);
                                    Intent dataIntent = mRemoteInputView
                                            .prepareRemoteInputFromData(mimeType, contentUri);
                                    mRemoteInputView.sendRemoteInput(dataIntent);
                                }
                                return remaining;
                            }
                        });
            }
            }
            setOnReceiveContentListener(types, listener);
        }
        }


        private void defocusIfNeeded(boolean animate) {
        private void defocusIfNeeded(boolean animate) {
@@ -759,5 +734,28 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
                setBackground(null);
                setBackground(null);
            }
            }
        }
        }

        private ContentInfo onReceiveContent(View view, ContentInfo payload) {
            Pair<ContentInfo, ContentInfo> split =
                    payload.partition(item -> item.getUri() != null);
            ContentInfo uriItems = split.first;
            ContentInfo remainingItems = split.second;
            if (uriItems != null) {
                ClipData clip = uriItems.getClip();
                ClipDescription description = clip.getDescription();
                if (clip.getItemCount() > 1
                        || description.getMimeTypeCount() < 1
                        || remainingItems != null) {
                    // TODO(b/172363500): Update to loop over all the items
                    return payload;
                }
                Uri contentUri = clip.getItemAt(0).getUri();
                String mimeType = description.getMimeType(0);
                Intent dataIntent =
                        mRemoteInputView.prepareRemoteInputFromData(mimeType, contentUri);
                mRemoteInputView.sendRemoteInput(dataIntent);
            }
            return remainingItems;
        }
    }
    }
}
}