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

Commit 437245c6 authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge changes from topic "211506329"

* changes:
  Show bouncer over dream.
  Add dream overlay state callback.
  Add snapToGuide for complications.
parents acdb2f28 436101dc
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -20,6 +20,30 @@
    android:id="@+id/dream_overlay_complications_layer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/complication_top_guide"
        app:layout_constraintGuide_percent="@dimen/dream_overlay_complication_guide_top_percent"
        android:orientation="horizontal"/>
    <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/complication_end_guide"
        app:layout_constraintGuide_percent="@dimen/dream_overlay_complication_guide_end_percent"
        android:orientation="vertical"/>
    <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/complication_bottom_guide"
        app:layout_constraintGuide_percent="@dimen/dream_overlay_complication_guide_bottom_percent"
        android:orientation="horizontal"/>
    <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/complication_start_guide"
        app:layout_constraintGuide_percent="@dimen/dream_overlay_complication_guide_start_percent"
        android:orientation="vertical"/>
    <TextClock
        android:id="@+id/time_view"
        android:layout_width="wrap_content"
+33 −0
Original line number Diff line number Diff line
@@ -1344,4 +1344,37 @@
    <!-- Height of the area at the top of the dream overlay to allow dragging down the notifications
         shade. -->
    <dimen name="dream_overlay_notifications_drag_area_height">100dp</dimen>

    <!-- The position of the end guide, which dream overlay complications can align their start with
         if their end is aligned with the parent end. Represented as the percentage over from the
         start of the parent container. -->
    <item name="dream_overlay_complication_guide_end_percent" format="float" type="dimen">
        0.75
    </item>

    <!-- The position of the start guide, which dream overlay complications can align their end to
         if their start is aligned with the parent start. Represented as the percentage over from
         the start of the parent container. -->
    <item name="dream_overlay_complication_guide_start_percent" format="float" type="dimen">
        0.25
    </item>

    <!-- The position of the bottom guide, which dream overlay complications can align their top to
         if their bottom is aligned with the parent bottom. Represented as the percentage over from
         the top of the parent container. -->
    <item name="dream_overlay_complication_guide_bottom_percent" format="float" type="dimen">
        0.90
    </item>

    <!-- The position of the top guide, which dream overlay complications can align their bottom to
     if their top is aligned with the parent top. Represented as the percentage over from
     the top of the parent container. -->
    <item name="dream_overlay_complication_guide_top_percent" format="float" type="dimen">
        0.10
    </item>

    <!-- The percentage of the screen from which a swipe can start to reveal the bouncer. -->
    <item name="dream_overlay_bouncer_start_region_screen_percentage" format="float" type="dimen">
        .2
    </item>
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -88,16 +88,20 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
                }
            };

    private DreamOverlayStateController mStateController;

    @Inject
    public DreamOverlayService(
            Context context,
            @Main Executor executor,
            DreamOverlayComponent.Factory dreamOverlayComponentFactory,
            DreamOverlayStateController stateController,
            KeyguardUpdateMonitor keyguardUpdateMonitor) {
        mContext = context;
        mExecutor = executor;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mKeyguardUpdateMonitor.registerCallback(mKeyguardCallback);
        mStateController = stateController;

        final DreamOverlayComponent component =
                dreamOverlayComponentFactory.create(mViewModelStore, mHost);
@@ -118,6 +122,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        setCurrentState(Lifecycle.State.DESTROYED);
        final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
        windowManager.removeView(mWindow.getDecorView());
        mStateController.setOverlayActive(false);
        super.onDestroy();
    }

@@ -127,6 +132,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        mExecutor.execute(() -> {
            addOverlayWindowLocked(layoutParams);
            setCurrentState(Lifecycle.State.RESUMED);
            mStateController.setOverlayActive(true);
        });
    }

+63 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.dreams;

import android.util.Log;

import androidx.annotation.NonNull;

import com.android.internal.annotations.VisibleForTesting;
@@ -30,6 +32,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

import javax.inject.Inject;

@@ -41,6 +44,16 @@ import javax.inject.Inject;
@SysUISingleton
public class DreamOverlayStateController implements
        CallbackController<DreamOverlayStateController.Callback> {
    private static final String TAG = "DreamOverlayStateCtlr";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    public static final int STATE_DREAM_OVERLAY_ACTIVE = 1 << 0;

    private static final int OP_CLEAR_STATE = 1;
    private static final int OP_SET_STATE = 2;

    private int mState;

    /**
     * Callback for dream overlay events.
     */
@@ -50,6 +63,12 @@ public class DreamOverlayStateController implements
         */
        default void onComplicationsChanged() {
        }

        /**
         * Called when the dream overlay state changes.
         */
        default void onStateChanged() {
        }
    }

    private final Executor mExecutor;
@@ -92,6 +111,14 @@ public class DreamOverlayStateController implements
        return Collections.unmodifiableCollection(mComplications);
    }

    private void notifyCallbacks(Consumer<Callback> callbackConsumer) {
        mExecutor.execute(() -> {
            for (Callback callback : mCallbacks) {
                callbackConsumer.accept(callback);
            }
        });
    }

    @Override
    public void addCallback(@NonNull Callback callback) {
        mExecutor.execute(() -> {
@@ -117,4 +144,40 @@ public class DreamOverlayStateController implements
            mCallbacks.remove(callback);
        });
    }

    /**
     * Returns whether the overlay is active.
     * @return {@code true} if overlay is active, {@code false} otherwise.
     */
    public boolean isOverlayActive() {
        return containsState(STATE_DREAM_OVERLAY_ACTIVE);
    }

    private boolean containsState(int state) {
        return (mState & state) != 0;
    }

    private void modifyState(int op, int state) {
        final int existingState = mState;
        switch (op) {
            case OP_CLEAR_STATE:
                mState &= ~state;
                break;
            case OP_SET_STATE:
                mState |= state;
                break;
        }

        if (existingState != mState) {
            notifyCallbacks(callback -> callback.onStateChanged());
        }
    }

    /**
     * Sets whether the overlay is active.
     * @param active {@code true} if overlay is active, {@code false} otherwise.
     */
    public void setOverlayActive(boolean active) {
        modifyState(active ? OP_SET_STATE : OP_CLEAR_STATE, STATE_DREAM_OVERLAY_ACTIVE);
    }
}
+35 −0
Original line number Diff line number Diff line
@@ -25,10 +25,13 @@ import android.view.ViewGroup;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Constraints;

import com.android.systemui.R;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.function.Consumer;

import javax.inject.Inject;
import javax.inject.Named;
@@ -102,6 +105,8 @@ public class ComplicationLayoutEngine {

            final int direction = getLayoutParams().getDirection();

            final boolean snapsToGuide = getLayoutParams().snapsToGuide();

            // If no parent, view is the anchor. In this case, it is given the highest priority for
            // alignment. All alignment preferences are done in relation to the parent container.
            final boolean isRoot = head == mView;
@@ -125,6 +130,11 @@ public class ComplicationLayoutEngine {
                        } else {
                            params.startToEnd = head.getId();
                        }
                        if (snapsToGuide
                                && (direction == ComplicationLayoutParams.DIRECTION_DOWN
                                || direction == ComplicationLayoutParams.DIRECTION_UP)) {
                            params.endToStart = R.id.complication_start_guide;
                        }
                        break;
                    case ComplicationLayoutParams.POSITION_TOP:
                        if (isRoot || direction != ComplicationLayoutParams.DIRECTION_DOWN) {
@@ -132,6 +142,11 @@ public class ComplicationLayoutEngine {
                        } else {
                            params.topToBottom = head.getId();
                        }
                        if (snapsToGuide
                                && (direction == ComplicationLayoutParams.DIRECTION_END
                                || direction == ComplicationLayoutParams.DIRECTION_START)) {
                            params.endToStart = R.id.complication_top_guide;
                        }
                        break;
                    case ComplicationLayoutParams.POSITION_BOTTOM:
                        if (isRoot || direction != ComplicationLayoutParams.DIRECTION_UP) {
@@ -139,6 +154,11 @@ public class ComplicationLayoutEngine {
                        } else {
                            params.bottomToTop = head.getId();
                        }
                        if (snapsToGuide
                                && (direction == ComplicationLayoutParams.DIRECTION_END
                                || direction == ComplicationLayoutParams.DIRECTION_START)) {
                            params.topToBottom = R.id.complication_bottom_guide;
                        }
                        break;
                    case ComplicationLayoutParams.POSITION_END:
                        if (isRoot || direction != ComplicationLayoutParams.DIRECTION_START) {
@@ -146,6 +166,11 @@ public class ComplicationLayoutEngine {
                        } else {
                            params.endToStart = head.getId();
                        }
                        if (snapsToGuide
                                && (direction == ComplicationLayoutParams.DIRECTION_UP
                                || direction == ComplicationLayoutParams.DIRECTION_DOWN)) {
                            params.startToEnd = R.id.complication_end_guide;
                        }
                        break;
                }
            });
@@ -153,6 +178,16 @@ public class ComplicationLayoutEngine {
            mView.setLayoutParams(params);
        }

        private void setGuide(ConstraintLayout.LayoutParams lp, int validDirections,
                Consumer<ConstraintLayout.LayoutParams> consumer) {
            final ComplicationLayoutParams layoutParams = getLayoutParams();
            if (!layoutParams.snapsToGuide()) {
                return;
            }

            consumer.accept(lp);
        }

        /**
         * Informs the {@link ViewEntry}'s parent entity to remove the {@link ViewEntry} from
         * being shown further.
Loading