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

Commit b1e9252d authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge changes from topic "decorate_custom_notifs"

* changes:
  Improve RemoteViews to simplify notification view hierarchy.
  Fully custom view notifications now receive minimal decoration when targeting S.
parents 19d37240 cb189d46
Loading
Loading
Loading
Loading
+312 −61

File changed.

Preview size limit exceeded, changes collapsed.

+28 −0
Original line number Diff line number Diff line
@@ -14629,6 +14629,34 @@ public final class Settings {
         */
        public static final String BACKPORT_S_NOTIF_RULES = "backport_s_notif_rules";
        /**
         * The decoration to put on fully custom views that target S.
         *
         * <p>Values are:
         * <br>0: DECORATION_NONE: no decorations.
         * <br>1: DECORATION_MINIMAL: most minimal template; just the icon and the expander.
         * <br>2: DECORATION_PARTIAL: basic template without the top line.
         * <br>3: DECORATION_FULL_COMPATIBLE: basic template with the top line; 40dp of height.
         * <br>4: DECORATION_FULL_CONSTRAINED: basic template with the top line;  28dp of height.
         * <p>See {@link android.app.Notification.DevFlags} for more details.
         * @hide
         */
        public static final String FULLY_CUSTOM_VIEW_NOTIF_DECORATION =
                "fully_custom_view_notif_decoration";
        /**
         * The decoration to put on decorated custom views that target S.
         *
         * <p>Values are:
         * <br>2: DECORATION_PARTIAL: basic template without the top line.
         * <br>3: DECORATION_FULL_COMPATIBLE: basic template with the top line; 40dp of height.
         * <br>4: DECORATION_FULL_CONSTRAINED: basic template with the top line;  28dp of height.
         * <p>See {@link android.app.Notification.DevFlags} for more details.
         * @hide
         */
        public static final String DECORATED_CUSTOM_VIEW_NOTIF_DECORATION =
                "decorated_custom_view_notif_decoration";
        /**
         * Block untrusted touches mode.
         *
+102 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ import android.view.RemotableViewMethod;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewManager;
import android.view.ViewParent;
import android.view.ViewStub;
import android.widget.AdapterView.OnItemClickListener;

@@ -177,6 +179,7 @@ public class RemoteViews implements Parcelable, Filter {
    private static final int OVERRIDE_TEXT_COLORS_TAG = 20;
    private static final int SET_RIPPLE_DRAWABLE_COLOR_TAG = 21;
    private static final int SET_INT_TAG_TAG = 22;
    private static final int REMOVE_FROM_PARENT_ACTION_TAG = 23;

    /** @hide **/
    @IntDef(prefix = "MARGIN_", value = {
@@ -1830,6 +1833,75 @@ public class RemoteViews implements Parcelable, Filter {
        }
    }

    /**
     * Action to remove a view from its parent.
     */
    private class RemoveFromParentAction extends Action {

        RemoveFromParentAction(@IdRes int viewId) {
            this.viewId = viewId;
        }

        RemoveFromParentAction(Parcel parcel) {
            viewId = parcel.readInt();
        }

        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(viewId);
        }

        @Override
        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
            final View target = root.findViewById(viewId);

            if (target == null || target == root) {
                return;
            }

            ViewParent parent = target.getParent();
            if (parent instanceof ViewManager) {
                ((ViewManager) parent).removeView(target);
            }
        }

        @Override
        public Action initActionAsync(ViewTree root, ViewGroup rootParent, OnClickHandler handler) {
            // In the async implementation, update the view tree so that subsequent calls to
            // findViewById return the correct view.
            root.createTree();
            ViewTree target = root.findViewTreeById(viewId);

            if (target == null || target == root) {
                return ACTION_NOOP;
            }

            ViewTree parent = root.findViewTreeParentOf(target);
            if (parent == null || !(parent.mRoot instanceof ViewManager)) {
                return ACTION_NOOP;
            }
            final ViewManager parentVg = (ViewManager) parent.mRoot;

            parent.mChildren.remove(target);
            return new RuntimeAction() {
                @Override
                public void apply(View root, ViewGroup rootParent, OnClickHandler handler)
                        throws ActionException {
                    parentVg.removeView(target.mRoot);
                }
            };
        }

        @Override
        public int getActionTag() {
            return REMOVE_FROM_PARENT_ACTION_TAG;
        }

        @Override
        public int mergeBehavior() {
            return MERGE_APPEND;
        }
    }

    /**
     * Helper action to set compound drawables on a TextView. Supports relative
     * (s/t/e/b) or cardinal (l/t/r/b) arrangement.
@@ -2537,6 +2609,8 @@ public class RemoteViews implements Parcelable, Filter {
                return new SetRippleDrawableColor(parcel);
            case SET_INT_TAG_TAG:
                return new SetIntTagAction(parcel);
            case REMOVE_FROM_PARENT_ACTION_TAG:
                return new RemoveFromParentAction(parcel);
            default:
                throw new ActionException("Tag " + tag + " not found");
        }
@@ -2674,6 +2748,18 @@ public class RemoteViews implements Parcelable, Filter {
        addAction(new ViewGroupActionRemove(viewId, viewIdToKeep));
    }

    /**
     * Removes the {@link View} specified by the {@code viewId} from its parent {@link ViewManager}.
     * This will do nothing if the viewId specifies the root view of this RemoteViews.
     *
     * @param viewId The id of the {@link View} to remove from its parent.
     *
     * @hide
     */
    public void removeFromParent(@IdRes int viewId) {
        addAction(new RemoveFromParentAction(viewId));
    }

    /**
     * Equivalent to calling {@link AdapterViewAnimator#showNext()}
     *
@@ -4025,6 +4111,22 @@ public class RemoteViews implements Parcelable, Filter {
            return null;
        }

        public ViewTree findViewTreeParentOf(ViewTree child) {
            if (mChildren == null) {
                return null;
            }
            for (ViewTree tree : mChildren) {
                if (tree == child) {
                    return this;
                }
                ViewTree result = tree.findViewTreeParentOf(child);
                if (result != null) {
                    return result;
                }
            }
            return null;
        }

        public void replaceView(View v) {
            mRoot = v;
            mChildren = null;
+41 −39
Original line number Diff line number Diff line
@@ -45,6 +45,45 @@
        android:padding="@dimen/notification_icon_circle_padding"
        />

    <ImageView
        android:id="@+id/right_icon"
        android:layout_width="@dimen/notification_right_icon_size"
        android:layout_height="@dimen/notification_right_icon_size"
        android:layout_gravity="center_vertical|end"
        android:layout_marginTop="@dimen/notification_right_icon_headerless_margin"
        android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin"
        android:layout_marginEnd="@dimen/notification_header_expand_icon_size"
        android:background="@drawable/notification_large_icon_outline"
        android:importantForAccessibility="no"
        android:scaleType="centerCrop"
        />

    <FrameLayout
        android:id="@+id/alternate_expand_target"
        android:layout_width="@dimen/notification_content_margin_start"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:importantForAccessibility="no"
        />

    <FrameLayout
        android:id="@+id/expand_button_touch_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end">

        <com.android.internal.widget.NotificationExpandButton
            android:id="@+id/expand_button"
            android:layout_width="@dimen/notification_header_expand_icon_size"
            android:layout_height="@dimen/notification_header_expand_icon_size"
            android:layout_gravity="center_vertical|end"
            android:contentDescription="@string/expand_button_content_description_collapsed"
            android:paddingTop="@dimen/notification_expand_button_padding_top"
            android:scaleType="center"
            />

    </FrameLayout>

    <LinearLayout
        android:id="@+id/notification_headerless_view_column"
        android:layout_width="match_parent"
@@ -64,6 +103,7 @@
        variant is 56dp and the 2- and 3-line variants are both 76dp.
        -->
        <FrameLayout
            android:id="@+id/notification_headerless_margin_extra_top"
            android:layout_width="match_parent"
            android:layout_height="@dimen/notification_headerless_margin_extra"
            android:layout_weight="1"
@@ -135,6 +175,7 @@
        variant is 56dp and the 2- and 3-line variants are both 76dp.
        -->
        <FrameLayout
            android:id="@+id/notification_headerless_margin_extra_bottom"
            android:layout_width="match_parent"
            android:layout_height="@dimen/notification_headerless_margin_extra"
            android:layout_weight="1"
@@ -142,43 +183,4 @@

    </LinearLayout>

    <ImageView
        android:id="@+id/right_icon"
        android:layout_width="@dimen/notification_right_icon_size"
        android:layout_height="@dimen/notification_right_icon_size"
        android:layout_gravity="center_vertical|end"
        android:layout_marginTop="@dimen/notification_right_icon_headerless_margin"
        android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin"
        android:layout_marginEnd="@dimen/notification_header_expand_icon_size"
        android:background="@drawable/notification_large_icon_outline"
        android:importantForAccessibility="no"
        android:scaleType="centerCrop"
        />

    <FrameLayout
        android:id="@+id/alternate_expand_target"
        android:layout_width="@dimen/notification_content_margin_start"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:importantForAccessibility="no"
        />

    <FrameLayout
        android:id="@+id/expand_button_touch_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end">

        <com.android.internal.widget.NotificationExpandButton
            android:id="@+id/expand_button"
            android:layout_width="@dimen/notification_header_expand_icon_size"
            android:layout_height="@dimen/notification_header_expand_icon_size"
            android:layout_gravity="center_vertical|end"
            android:contentDescription="@string/expand_button_content_description_collapsed"
            android:paddingTop="@dimen/notification_expand_button_padding_top"
            android:scaleType="center"
            />

    </FrameLayout>

</com.android.internal.widget.NotificationMaxHeightFrameLayout>
+8 −2
Original line number Diff line number Diff line
@@ -305,12 +305,18 @@
    <!-- The top padding for the notification expand button. -->
    <dimen name="notification_expand_button_padding_top">1dp</dimen>

    <!-- minimum vertical margin for the headerless notification content -->
    <!-- minimum vertical margin for the headerless notification content, when cap = 60dp -->
    <dimen name="notification_headerless_margin_minimum">8dp</dimen>

    <!-- extra vertical margin for the headerless notification content -->
    <!-- extra vertical margin for the headerless notification content, when cap = 60dp -->
    <dimen name="notification_headerless_margin_extra">10dp</dimen>

    <!-- minimum vertical margin for the headerless notification content, when cap = 48dp -->
    <dimen name="notification_headerless_margin_constrained_minimum">14dp</dimen>

    <!-- extra vertical margin for the headerless notification content, when cap = 48dp -->
    <dimen name="notification_headerless_margin_constrained_extra">4dp</dimen>

    <!-- The height of each of the 1 or 2 lines in the headerless notification template -->
    <dimen name="notification_headerless_line_height">20sp</dimen>

Loading