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

Commit 91974684 authored by Alex Mang's avatar Alex Mang
Browse files

Add notification feedback indicator icon.

This icon will be used to indicate an adjustment was made for this
notification and to solicit feedback. Currently it's not tappable. Will
add this in a later commit.

Test: manually on device
Change-Id: I730953a0d1286cd1ee2686fe4603f9642fa5d958
parent dead1a5b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -5153,6 +5153,7 @@ public class Notification implements Parcelable
            bindProfileBadge(contentView, p);
            bindAlertedIcon(contentView, p);
            bindActivePermissions(contentView, p);
            bindFeedbackIcon(contentView, p);
            bindExpandButton(contentView, p);
            mN.mUsesStandardHeader = true;
        }
@@ -5164,6 +5165,11 @@ public class Notification implements Parcelable
            contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP);
        }

        private void bindFeedbackIcon(RemoteViews contentView, StandardTemplateParams p) {
            int color = getNeutralColor(p);
            contentView.setDrawableTint(R.id.feedback, false, color, PorterDuff.Mode.SRC_ATOP);
        }

        private void bindExpandButton(RemoteViews contentView, StandardTemplateParams p) {
            int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p);
            contentView.setDrawableTint(R.id.expand_button, false, color,
+4 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class NotificationHeaderView extends ViewGroup {
    private CachingIconView mIcon;
    private View mProfileBadge;
    private View mAppOps;
    private View mFeedbackIcon;
    private boolean mExpanded;
    private boolean mShowExpandButtonAtEnd;
    private boolean mShowWorkBadgeAtEnd;
@@ -116,6 +117,7 @@ public class NotificationHeaderView extends ViewGroup {
        mIcon = findViewById(com.android.internal.R.id.icon);
        mProfileBadge = findViewById(com.android.internal.R.id.profile_badge);
        mAppOps = findViewById(com.android.internal.R.id.app_ops);
        mFeedbackIcon = findViewById(com.android.internal.R.id.feedback);
    }

    @Override
@@ -144,6 +146,7 @@ public class NotificationHeaderView extends ViewGroup {
            if ((child == mExpandButton && mShowExpandButtonAtEnd)
                    || child == mProfileBadge
                    || child == mAppOps
                    || child == mFeedbackIcon
                    || child == mTransferChip) {
                iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
            } else {
@@ -209,6 +212,7 @@ public class NotificationHeaderView extends ViewGroup {
            if ((child == mExpandButton && mShowExpandButtonAtEnd)
                    || child == mProfileBadge
                    || child == mAppOps
                    || child == mFeedbackIcon
                    || child == mTransferChip) {
                if (end == getMeasuredWidth()) {
                    layoutRight = end - mContentEndMargin;
+78 −8
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.RemotableViewMethod;
import android.view.TouchDelegate;
import android.view.View;
@@ -169,10 +170,13 @@ public class ConversationLayout extends FrameLayout
    private TextView mUnreadBadge;
    private ViewGroup mAppOps;
    private Rect mAppOpsTouchRect = new Rect();
    private View mFeedbackIcon;
    private float mMinTouchSize;
    private Icon mConversationIcon;
    private Icon mShortcutIcon;
    private View mAppNameDivider;
    private TouchDelegateComposite mTouchDelegate = new TouchDelegateComposite(this);
    private int mNotificationHeaderSeparatingMargin;

    public ConversationLayout(@NonNull Context context) {
        super(context);
@@ -212,6 +216,7 @@ public class ConversationLayout extends FrameLayout
        mConversationIconContainer = findViewById(R.id.conversation_icon_container);
        mIcon = findViewById(R.id.icon);
        mAppOps = findViewById(com.android.internal.R.id.app_ops);
        mFeedbackIcon = findViewById(com.android.internal.R.id.feedback);
        mMinTouchSize = 48 * getResources().getDisplayMetrics().density;
        mImportanceRingView = findViewById(R.id.conversation_icon_badge_ring);
        mConversationIconBadge = findViewById(R.id.conversation_icon_badge);
@@ -307,6 +312,8 @@ public class ConversationLayout extends FrameLayout
        mInternalButtonPadding
                = getResources().getDimensionPixelSize(R.dimen.button_padding_horizontal_material)
                + getResources().getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
        mNotificationHeaderSeparatingMargin = getResources().getDimensionPixelSize(
                R.dimen.notification_header_separating_margin);
    }

    private void animateViewForceHidden(CachingIconView view, boolean forceHidden) {
@@ -1160,6 +1167,7 @@ public class ConversationLayout extends FrameLayout
                }
            });
        }
        mTouchDelegate.clear();
        if (mAppOps.getWidth() > 0) {

            // Let's increase the touch size of the app ops view if it's here
@@ -1191,16 +1199,49 @@ public class ConversationLayout extends FrameLayout
            }
            mAppOpsTouchRect.inset(0, -heightIncrease);

            // Let's adjust the hitrect since app ops isn't a direct child
            ViewGroup viewGroup = (ViewGroup) mAppOps.getParent();
            getRelativeTouchRect(mAppOpsTouchRect, mAppOps);

            // Extend the size of the app opps to be at least 48dp
            mTouchDelegate.add(new TouchDelegate(mAppOpsTouchRect, mAppOps));

        }
        if (mFeedbackIcon.getVisibility() == VISIBLE) {
            updateFeedbackIconMargins();
            float width = Math.max(mMinTouchSize, mFeedbackIcon.getWidth());
            float height = Math.max(mMinTouchSize, mFeedbackIcon.getHeight());
            final Rect feedbackTouchRect = new Rect();
            feedbackTouchRect.left = (int) ((mFeedbackIcon.getLeft() + mFeedbackIcon.getRight())
                    / 2.0f - width / 2.0f);
            feedbackTouchRect.top = (int) ((mFeedbackIcon.getTop() + mFeedbackIcon.getBottom())
                    / 2.0f - height / 2.0f);
            feedbackTouchRect.bottom = (int) (feedbackTouchRect.top + height);
            feedbackTouchRect.right = (int) (feedbackTouchRect.left + width);

            getRelativeTouchRect(feedbackTouchRect, mFeedbackIcon);
            mTouchDelegate.add(new TouchDelegate(feedbackTouchRect, mFeedbackIcon));
        }

        setTouchDelegate(mTouchDelegate);
    }

    private void getRelativeTouchRect(Rect touchRect, View view) {
        ViewGroup viewGroup = (ViewGroup) view.getParent();
        while (viewGroup != this) {
                mAppOpsTouchRect.offset(viewGroup.getLeft(), viewGroup.getTop());
            touchRect.offset(viewGroup.getLeft(), viewGroup.getTop());
            viewGroup = (ViewGroup) viewGroup.getParent();
        }
            //
            // Extend the size of the app opps to be at least 48dp
            setTouchDelegate(new TouchDelegate(mAppOpsTouchRect, mAppOps));
    }

    private void updateFeedbackIconMargins() {
        MarginLayoutParams lp = (MarginLayoutParams) mFeedbackIcon.getLayoutParams();
        if (mAppOps.getWidth() == 0) {
            lp.setMarginStart(mNotificationHeaderSeparatingMargin);
        } else {
            float width = Math.max(mMinTouchSize, mFeedbackIcon.getWidth());
            int horizontalMargin = (int) ((width - mFeedbackIcon.getWidth()) / 2);
            lp.setMarginStart(horizontalMargin);
        }
        mFeedbackIcon.setLayoutParams(lp);
    }

    public MessagingLinearLayout getMessagingLinearLayout() {
@@ -1347,4 +1388,33 @@ public class ConversationLayout extends FrameLayout
    public Icon getConversationIcon() {
        return mConversationIcon;
    }

    private static class TouchDelegateComposite extends TouchDelegate {
        private final ArrayList<TouchDelegate> mDelegates = new ArrayList<>();

        private TouchDelegateComposite(View view) {
            super(new Rect(), view);
        }

        public void add(TouchDelegate delegate) {
            mDelegates.add(delegate);
        }

        public void clear() {
            mDelegates.clear();
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            float x = event.getX();
            float y = event.getY();
            for (TouchDelegate delegate: mDelegates) {
                event.setLocation(x, y);
                if (delegate.onTouchEvent(event)) {
                    return true;
                }
            }
            return false;
        }
    }
}
+24 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2020 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24">
    <path
        android:fillColor="@android:color/white"
        android:pathData="M15.6 0L4 13.88h8.75L10.04 24L21 10.35h-8.25z" />
</vector>
+14 −0
Original line number Diff line number Diff line
@@ -135,6 +135,20 @@
        android:contentDescription="@string/notification_alerted_content_description"
        android:src="@drawable/ic_notifications_alerted"
    />
    <ImageButton
        android:id="@+id/feedback"
        android:layout_width="@dimen/notification_feedback_size"
        android:layout_height="@dimen/notification_feedback_size"
        android:layout_marginStart="6dp"
        android:layout_marginEnd="6dp"
        android:paddingTop="2dp"
        android:layout_gravity="center"
        android:scaleType="fitCenter"
        android:src="@drawable/ic_feedback_indicator"
        android:background="?android:selectableItemBackgroundBorderless"
        android:visibility="gone"
        android:contentDescription="@string/notification_feedback_indicator"
    />
    <ImageView
        android:id="@+id/profile_badge"
        android:layout_width="@dimen/notification_badge_size"
Loading