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

Commit cb189d46 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Improve RemoteViews to simplify notification view hierarchy.

Test: manual
Change-Id: Iab1579a3e992a53f1e44ff7236511d1093de048f
parent d9e18369
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -6701,8 +6701,7 @@ public class Notification implements Parcelable
            customContent = customContent.clone();
            customContent = customContent.clone();
            if (p.mHeaderless) {
            if (p.mHeaderless) {
                if (decorationType <= DevFlags.DECORATION_PARTIAL) {
                if (decorationType <= DevFlags.DECORATION_PARTIAL) {
                    template.removeAllViewsExceptId(R.id.notification_top_line_container,
                    template.removeFromParent(R.id.notification_top_line);
                            R.id.notification_main_column);
                }
                }
                if (decorationType != DevFlags.DECORATION_FULL_COMPATIBLE) {
                if (decorationType != DevFlags.DECORATION_FULL_COMPATIBLE) {
                    // Change the max content size from 60dp (the compatible size) to 48dp
                    // Change the max content size from 60dp (the compatible size) to 48dp
+102 −0
Original line number Original line Diff line number Diff line
@@ -73,6 +73,8 @@ import android.view.RemotableViewMethod;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewManager;
import android.view.ViewParent;
import android.view.ViewStub;
import android.view.ViewStub;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemClickListener;


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


    /** @hide **/
    /** @hide **/
    @IntDef(prefix = "MARGIN_", value = {
    @IntDef(prefix = "MARGIN_", value = {
@@ -1826,6 +1829,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
     * Helper action to set compound drawables on a TextView. Supports relative
     * (s/t/e/b) or cardinal (l/t/r/b) arrangement.
     * (s/t/e/b) or cardinal (l/t/r/b) arrangement.
@@ -2531,6 +2603,8 @@ public class RemoteViews implements Parcelable, Filter {
                return new SetRippleDrawableColor(parcel);
                return new SetRippleDrawableColor(parcel);
            case SET_INT_TAG_TAG:
            case SET_INT_TAG_TAG:
                return new SetIntTagAction(parcel);
                return new SetIntTagAction(parcel);
            case REMOVE_FROM_PARENT_ACTION_TAG:
                return new RemoveFromParentAction(parcel);
            default:
            default:
                throw new ActionException("Tag " + tag + " not found");
                throw new ActionException("Tag " + tag + " not found");
        }
        }
@@ -2668,6 +2742,18 @@ public class RemoteViews implements Parcelable, Filter {
        addAction(new ViewGroupActionRemove(viewId, viewIdToKeep));
        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()}
     * Equivalent to calling {@link AdapterViewAnimator#showNext()}
     *
     *
@@ -4013,6 +4099,22 @@ public class RemoteViews implements Parcelable, Filter {
            return null;
            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) {
        public void replaceView(View v) {
            mRoot = v;
            mRoot = v;
            mChildren = null;
            mChildren = null;
+28 −41
Original line number Original line Diff line number Diff line
@@ -109,17 +109,6 @@
            android:layout_weight="1"
            android:layout_weight="1"
            />
            />


        <!--
        Because RemoteViews doesn't allow us to remove specific views, this container allows us
        to remove the NotificationTopLineView without removing other padding items.
        -->
        <FrameLayout
            android:id="@+id/notification_top_line_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="false"
            >

        <!-- extends ViewGroup -->
        <!-- extends ViewGroup -->
        <NotificationTopLineView
        <NotificationTopLineView
            android:id="@+id/notification_top_line"
            android:id="@+id/notification_top_line"
@@ -153,8 +142,6 @@


        </NotificationTopLineView>
        </NotificationTopLineView>


        </FrameLayout>

        <LinearLayout
        <LinearLayout
            android:id="@+id/notification_main_column"
            android:id="@+id/notification_main_column"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
+0 −1
Original line number Original line Diff line number Diff line
@@ -2876,7 +2876,6 @@
  <java-symbol type="id" name="alternate_expand_target" />
  <java-symbol type="id" name="alternate_expand_target" />
  <java-symbol type="id" name="notification_header" />
  <java-symbol type="id" name="notification_header" />
  <java-symbol type="id" name="notification_top_line" />
  <java-symbol type="id" name="notification_top_line" />
  <java-symbol type="id" name="notification_top_line_container" />
  <java-symbol type="id" name="notification_headerless_margin_extra_top" />
  <java-symbol type="id" name="notification_headerless_margin_extra_top" />
  <java-symbol type="id" name="notification_headerless_margin_extra_bottom" />
  <java-symbol type="id" name="notification_headerless_margin_extra_bottom" />
  <java-symbol type="id" name="time_divider" />
  <java-symbol type="id" name="time_divider" />