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

Commit d79d5c9b authored by Kenny Guy's avatar Kenny Guy Committed by android-build-merger
Browse files

Merge "Add spinner for smart replies." into pi-dev am: 5f18904a

am: 06c4122c

Change-Id: I5a2d775500b0a43eea281592f2325add233e7de1
parents 9311b2af 06c4122c
Loading
Loading
Loading
Loading
+75 −1
Original line number Diff line number Diff line
@@ -971,6 +971,18 @@ public class Notification implements Parcelable
     */
    public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory";

    /**
     * {@link #extras} key: boolean as supplied to
     * {@link Builder#setShowRemoteInputSpinner(boolean)}.
     *
     * If set to true, then the view displaying the remote input history from
     * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner.
     *
     * @see Builder#setShowRemoteInputSpinner(boolean)
     * @hide
     */
    public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner";

    /**
     * {@link #extras} key: this is a small piece of additional text as supplied to
     * {@link Builder#setContentInfo(CharSequence)}.
@@ -3536,6 +3548,15 @@ public class Notification implements Parcelable
            return this;
        }

        /**
         * Sets whether remote history entries view should have a spinner.
         * @hide
         */
        public Builder setShowRemoteInputSpinner(boolean showSpinner) {
            mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner);
            return this;
        }

        /**
         * Sets the number of items this notification represents. May be displayed as a badge count
         * for Launchers that support badging.
@@ -4760,6 +4781,8 @@ public class Notification implements Parcelable

            big.setViewVisibility(R.id.notification_material_reply_container, View.GONE);
            big.setTextViewText(R.id.notification_material_reply_text_1, null);
            big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE);
            big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE);

            big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE);
            big.setTextViewText(R.id.notification_material_reply_text_2, null);
@@ -4810,10 +4833,19 @@ public class Notification implements Parcelable
            CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY);
            if (!p.ambient && validRemoteInput && replyText != null
                    && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) {
                boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER);
                big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE);
                big.setViewVisibility(R.id.notification_material_reply_text_1_container,
                        View.VISIBLE);
                big.setTextViewText(R.id.notification_material_reply_text_1,
                        processTextSpans(replyText[0]));
                setTextViewColorSecondary(big, R.id.notification_material_reply_text_1);
                big.setViewVisibility(R.id.notification_material_reply_progress,
                        showSpinner ? View.VISIBLE : View.GONE);
                big.setProgressIndeterminateTintList(
                        R.id.notification_material_reply_progress,
                        ColorStateList.valueOf(
                                isColorized() ? getPrimaryTextColor() : resolveContrastColor()));

                if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) {
                    big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE);
@@ -6958,11 +6990,16 @@ public class Notification implements Parcelable
            static final String KEY_DATA_MIME_TYPE = "type";
            static final String KEY_DATA_URI= "uri";
            static final String KEY_EXTRAS_BUNDLE = "extras";
            static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history";

            private final CharSequence mText;
            private final long mTimestamp;
            @Nullable
            private final Person mSender;
            /** True if this message was generated from the extra
             *  {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}
             */
            private final boolean mRemoteInputHistory;

            private Bundle mExtras = new Bundle();
            private String mDataMimeType;
@@ -7001,9 +7038,33 @@ public class Notification implements Parcelable
             * </p>
             */
            public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) {
                this(text, timestamp, sender, false /* remoteHistory */);
            }

            /**
             * Constructor
             * @param text A {@link CharSequence} to be displayed as the message content
             * @param timestamp Time at which the message arrived
             * @param sender The {@link Person} who sent the message.
             * Should be <code>null</code> for messages by the current user, in which case
             * the platform will insert the user set in {@code MessagingStyle(Person)}.
             * @param remoteInputHistory True if the messages was generated from the extra
             * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}.
             * <p>
             * The person provided should contain an Icon, set with
             * {@link Person.Builder#setIcon(Icon)} and also have a name provided
             * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same
             * name, consider providing a key with {@link Person.Builder#setKey(String)} in order
             * to differentiate between the different users.
             * </p>
             * @hide
             */
            public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender,
                    boolean remoteInputHistory) {
                mText = text;
                mTimestamp = timestamp;
                mSender = sender;
                mRemoteInputHistory = remoteInputHistory;
            }

            /**
@@ -7093,6 +7154,15 @@ public class Notification implements Parcelable
                return mDataUri;
            }

            /**
             * @return True if the message was generated from
             * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}.
             * @hide
             */
            public boolean isRemoteInputHistory() {
                return mRemoteInputHistory;
            }

            private Bundle toBundle() {
                Bundle bundle = new Bundle();
                if (mText != null) {
@@ -7113,6 +7183,9 @@ public class Notification implements Parcelable
                if (mExtras != null) {
                    bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras);
                }
                if (mRemoteInputHistory) {
                    bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory);
                }
                return bundle;
            }

@@ -7164,7 +7237,8 @@ public class Notification implements Parcelable
                        }
                        Message message = new Message(bundle.getCharSequence(KEY_TEXT),
                                bundle.getLong(KEY_TIMESTAMP),
                                senderPerson);
                                senderPerson,
                                bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false));
                        if (bundle.containsKey(KEY_DATA_MIME_TYPE) &&
                                bundle.containsKey(KEY_DATA_URI)) {
                            message.setData(bundle.getString(KEY_DATA_MIME_TYPE),
+46 −4
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.annotation.Nullable;
import android.annotation.StyleRes;
import android.app.Person;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Icon;
@@ -29,6 +31,7 @@ import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Pools;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -36,6 +39,7 @@ import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RemoteViews;

import com.android.internal.R;
@@ -58,6 +62,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    private CharSequence mAvatarName = "";
    private Icon mAvatarIcon;
    private int mTextColor;
    private int mSendingTextColor;
    private List<MessagingMessage> mMessages;
    private ArrayList<MessagingMessage> mAddedMessages = new ArrayList<>();
    private boolean mFirstLayout;
@@ -69,6 +74,8 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    private MessagingImageMessage mIsolatedMessage;
    private boolean mTransformingImages;
    private Point mDisplaySize = new Point();
    private ProgressBar mSendingSpinner;
    private View mSendingSpinnerContainer;

    public MessagingGroup(@NonNull Context context) {
        super(context);
@@ -96,6 +103,8 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        mSenderName.addOnLayoutChangeListener(MessagingLayout.MESSAGING_PROPERTY_ANIMATOR);
        mAvatarView = findViewById(R.id.message_icon);
        mImageContainer = findViewById(R.id.messaging_group_icon_container);
        mSendingSpinner = findViewById(R.id.messaging_group_sending_progress);
        mSendingSpinnerContainer = findViewById(R.id.messaging_group_sending_progress_container);
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        mDisplaySize.x = displayMetrics.widthPixels;
        mDisplaySize.y = displayMetrics.heightPixels;
@@ -139,17 +148,37 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        mAvatarView.setVisibility(VISIBLE);
        mSenderName.setVisibility(VISIBLE);
        mTextColor = getNormalTextColor();
        mSendingTextColor = calculateSendingTextColor();
    }

    public void setSending(boolean sending) {
        int visibility = sending ? View.VISIBLE : View.GONE;
        if (mSendingSpinnerContainer.getVisibility() != visibility) {
            mSendingSpinnerContainer.setVisibility(visibility);
            updateMessageColor();
        }
    }

    private int getNormalTextColor() {
        return mContext.getColor(R.color.notification_secondary_text_color_light);
    }

    private int calculateSendingTextColor() {
        TypedValue alphaValue = new TypedValue();
        mContext.getResources().getValue(
                R.dimen.notification_secondary_text_disabled_alpha, alphaValue, true);
        float alpha = alphaValue.getFloat();
        return Color.valueOf(
                Color.red(mTextColor),
                Color.green(mTextColor),
                Color.blue(mTextColor),
                alpha).toArgb();
    }

    public void setAvatar(Icon icon) {
        mAvatarIcon = icon;
        mAvatarView.setImageIcon(icon);
        mAvatarSymbol = "";
        mLayoutColor = 0;
        mAvatarName = "";
    }

@@ -321,13 +350,26 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
                || layoutColor != mLayoutColor) {
            setAvatar(cachedIcon);
            mAvatarSymbol = avatarSymbol;
            mLayoutColor = layoutColor;
            setLayoutColor(layoutColor);
            mAvatarName = avatarName;
        }
    }

    public void setLayoutColor(int layoutColor) {
        if (layoutColor != mLayoutColor){
            mLayoutColor = layoutColor;
            mSendingSpinner.setIndeterminateTintList(ColorStateList.valueOf(mLayoutColor));
        }
    }

    private void updateMessageColor() {
        if (mMessages != null) {
            int color = mSendingSpinnerContainer.getVisibility() == View.VISIBLE
                    ? mSendingTextColor : mTextColor;
            for (MessagingMessage message : mMessages) {
                message.setColor(message.getMessage().isRemoteInputHistory() ? color : mTextColor);
            }
        }
    }

    public void setMessages(List<MessagingMessage> group) {
@@ -336,7 +378,6 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        MessagingImageMessage isolatedMessage = null;
        for (int messageIndex = 0; messageIndex < group.size(); messageIndex++) {
            MessagingMessage message = group.get(messageIndex);
            message.setColor(mTextColor);
            if (message.getGroup() != this) {
                message.setMessagingGroup(this);
                mAddedMessages.add(message);
@@ -376,6 +417,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        }
        mIsolatedMessage = isolatedMessage;
        mMessages = group;
        updateMessageColor();
    }

    /**
+11 −7
Original line number Diff line number Diff line
@@ -149,7 +149,9 @@ public class MessagingLayout extends FrameLayout {
        }
        addRemoteInputHistoryToMessages(newMessages,
                extras.getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY));
        bind(newMessages, newHistoricMessages);
        boolean showSpinner =
                extras.getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false);
        bind(newMessages, newHistoricMessages, showSpinner);
    }

    private void addRemoteInputHistoryToMessages(
@@ -161,17 +163,18 @@ public class MessagingLayout extends FrameLayout {
        for (int i = remoteInputHistory.length - 1; i >= 0; i--) {
            CharSequence message = remoteInputHistory[i];
            newMessages.add(new Notification.MessagingStyle.Message(
                    message, 0, (Person) null));
                    message, 0, (Person) null, true /* remoteHistory */));
        }
    }

    private void bind(List<Notification.MessagingStyle.Message> newMessages,
            List<Notification.MessagingStyle.Message> newHistoricMessages) {
            List<Notification.MessagingStyle.Message> newHistoricMessages,
            boolean showSpinner) {

        List<MessagingMessage> historicMessages = createMessages(newHistoricMessages,
                true /* isHistoric */);
        List<MessagingMessage> messages = createMessages(newMessages, false /* isHistoric */);
        addMessagesToGroups(historicMessages, messages);
        addMessagesToGroups(historicMessages, messages, showSpinner);

        // Let's remove the remaining messages
        mMessages.forEach(REMOVE_MESSAGE);
@@ -308,7 +311,7 @@ public class MessagingLayout extends FrameLayout {
    }

    private void addMessagesToGroups(List<MessagingMessage> historicMessages,
            List<MessagingMessage> messages) {
            List<MessagingMessage> messages, boolean showSpinner) {
        // Let's first find our groups!
        List<List<MessagingMessage>> groups = new ArrayList<>();
        List<Person> senders = new ArrayList<>();
@@ -317,11 +320,11 @@ public class MessagingLayout extends FrameLayout {
        findGroups(historicMessages, messages, groups, senders);

        // Let's now create the views and reorder them accordingly
        createGroupViews(groups, senders);
        createGroupViews(groups, senders, showSpinner);
    }

    private void createGroupViews(List<List<MessagingMessage>> groups,
            List<Person> senders) {
            List<Person> senders, boolean showSpinner) {
        mGroups.clear();
        for (int groupIndex = 0; groupIndex < groups.size(); groupIndex++) {
            List<MessagingMessage> group = groups.get(groupIndex);
@@ -346,6 +349,7 @@ public class MessagingLayout extends FrameLayout {
                nameOverride = mNameReplacement;
            }
            newGroup.setSender(sender, nameOverride);
            newGroup.setSending(groupIndex == (groups.size() - 1) && showSpinner);
            mGroups.add(newGroup);

            if (mMessagingLinearLayout.indexOfChild(newGroup) != groupIndex) {
+3 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ public interface MessagingMessage extends MessagingLinearLayout.MessagingChild {
        if (!Objects.equals(message.getDataUri(), ownMessage.getDataUri())) {
            return false;
        }
        if (message.isRemoteInputHistory() != ownMessage.isRemoteInputHistory()) {
            return false;
        }
        return true;
    }

+24 −4
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
            android:id="@+id/action_divider"
            android:layout_marginTop="@dimen/notification_content_margin"
            android:layout_marginBottom="@dimen/notification_content_margin"
            android:layout_marginEnd="@dimen/notification_content_margin_end"
            android:background="@drawable/notification_template_divider" />

    <TextView
@@ -50,12 +51,31 @@
            android:textAppearance="@style/TextAppearance.Material.Notification.Reply"
            android:singleLine="true" />

    <LinearLayout
            android:id="@+id/notification_material_reply_text_1_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginStart="@dimen/notification_content_margin_start"
            android:layout_marginEnd="@dimen/notification_content_margin_end">
        <TextView
                android:id="@+id/notification_material_reply_text_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginEnd="@dimen/notification_content_margin_end"
                android:layout_gravity="center"
                android:textAppearance="@style/TextAppearance.Material.Notification.Reply"
                android:singleLine="true" />
        <ProgressBar
            android:id="@+id/notification_material_reply_progress"
            android:layout_height="@dimen/messaging_group_sending_progress_size"
            android:layout_width="@dimen/messaging_group_sending_progress_size"
            android:layout_marginStart="@dimen/notification_content_margin_start"
            android:layout_marginEnd="@dimen/notification_content_margin_end"
            android:layout_gravity="center"
            android:indeterminate="true"
            style="?android:attr/progressBarStyleSmall" />
    </LinearLayout>

</LinearLayout>
Loading