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

Commit 14e81630 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Initial commit for rotation contextual button

Bug: 180046394
Test: Events successfully passed through to launcher
Change-Id: I84c60dc89f560fdaf76afdbed8b5f9ec23b38856
parent 08bcd0e8
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -77,8 +77,24 @@ oneway interface IOverviewProxy {
    void onSplitScreenSecondaryBoundsChanged(in Rect bounds, in Rect insets) = 17;

    /**
     * Sent IME status changes
     * Sent when IME status changes
     */
    void onImeWindowStatusChanged(int displayId, IBinder token, int vis, int backDisposition,
                         boolean showImeSwitcher) = 18;

    /**
     * Sent when suggested rotation button could be shown
     */
    void onRotationProposal(int rotation, boolean isValid) = 19;


    /**
     * Sent when disable flags change
     */
    void disable(int displayId, int state1, int state2, boolean animate) = 20;

    /**
     * Sent when behavior changes. See WindowInsetsController#@Behavior
     */
    void onSystemBarAttributesChanged(int displayId, int behavior) = 21;
}
+19 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.systemui.shared.recents.utilities;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.view.Surface;
import android.view.View;

/* Common code */
public class Utilities {
@@ -31,6 +33,23 @@ public class Utilities {
        h.sendMessageAtFrontOfQueue(msg);
    }

    public static boolean isRotationAnimationCCW(int from, int to) {
        // All 180deg WM rotation animations are CCW, match that
        if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false;
        if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW
        if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true;
        if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true;
        if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false;
        if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW
        if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW
        if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true;
        if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false;
        if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false;
        if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW
        if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true;
        return false; // Default
    }

    /** Calculates the constrast between two colors, using the algorithm provided by the WCAG v2. */
    public static float computeContrastBetweenColors(int bg, int fg) {
        float bgR = Color.red(bg) / 255f;
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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.
 */

package com.android.systemui.shared.recents.utilities;

import android.view.View;

/**
 * Shows view ripples by toggling the provided Views "pressed" state.
 * Ripples 4 times.
 */
public class ViewRippler {
    private static final int RIPPLE_OFFSET_MS = 50;
    private static final int RIPPLE_INTERVAL_MS = 2000;
    private View mRoot;

    public void start(View root) {
        stop(); // Stop any pending ripple animations

        mRoot = root;

        // Schedule pending ripples, offset the 1st to avoid problems with visibility change
        mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
        mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
        mRoot.postOnAnimationDelayed(mRipple, 2 * RIPPLE_INTERVAL_MS);
        mRoot.postOnAnimationDelayed(mRipple, 3 * RIPPLE_INTERVAL_MS);
        mRoot.postOnAnimationDelayed(mRipple, 4 * RIPPLE_INTERVAL_MS);
    }

    public void stop() {
        if (mRoot != null) mRoot.removeCallbacks(mRipple);
    }

    private final Runnable mRipple = new Runnable() {
        @Override
        public void run() { // Cause the ripple to fire via false presses
            if (!mRoot.isAttachedToWindow()) return;
            mRoot.setPressed(true /* pressed */);
            mRoot.setPressed(false /* pressed */);
        }
    };
}
 No newline at end of file
+3 −50
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.navigationbar.buttons.KeyButtonDrawable;
import com.android.systemui.shared.recents.utilities.Utilities;
import com.android.systemui.shared.recents.utilities.ViewRippler;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.TaskStackChangeListener;
import com.android.systemui.shared.system.TaskStackChangeListeners;
@@ -311,7 +313,7 @@ public class RotationButtonController {

        // Prepare to show the navbar icon by updating the icon style to change anim params
        mLastRotationSuggestion = rotation; // Remember rotation for click
        final boolean rotationCCW = isRotationAnimationCCW(windowRotation, rotation);
        final boolean rotationCCW = Utilities.isRotationAnimationCCW(windowRotation, rotation);
        if (windowRotation == Surface.ROTATION_0 || windowRotation == Surface.ROTATION_180) {
            mIconResId = rotationCCW
                    ? R.drawable.ic_sysbar_rotate_button_ccw_start_90
@@ -431,23 +433,6 @@ public class RotationButtonController {
        return rotation == NATURAL_ROTATION;
    }

    private boolean isRotationAnimationCCW(int from, int to) {
        // All 180deg WM rotation animations are CCW, match that
        if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false;
        if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW
        if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true;
        if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true;
        if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false;
        if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW
        if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW
        if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true;
        if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false;
        if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false;
        if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW
        if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true;
        return false; // Default
    }

    private void rescheduleRotationTimeout(final boolean reasonHover) {
        // May be called due to a new rotation proposal or a change in hover state
        if (reasonHover) {
@@ -520,38 +505,6 @@ public class RotationButtonController {
        }
    }

    private class ViewRippler {
        private static final int RIPPLE_OFFSET_MS = 50;
        private static final int RIPPLE_INTERVAL_MS = 2000;
        private View mRoot;

        public void start(View root) {
            stop(); // Stop any pending ripple animations

            mRoot = root;

            // Schedule pending ripples, offset the 1st to avoid problems with visibility change
            mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
            mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
            mRoot.postOnAnimationDelayed(mRipple, 2 * RIPPLE_INTERVAL_MS);
            mRoot.postOnAnimationDelayed(mRipple, 3 * RIPPLE_INTERVAL_MS);
            mRoot.postOnAnimationDelayed(mRipple, 4 * RIPPLE_INTERVAL_MS);
        }

        public void stop() {
            if (mRoot != null) mRoot.removeCallbacks(mRipple);
        }

        private final Runnable mRipple = new Runnable() {
            @Override
            public void run() { // Cause the ripple to fire via false presses
                if (!mRoot.isAttachedToWindow()) return;
                mRoot.setPressed(true /* pressed */);
                mRoot.setPressed(false /* pressed */);
            }
        };
    }

    enum RotationButtonEvent implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "The rotation button was shown")
        ROTATION_SUGGESTION_SHOWN(206),
+18 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.navigationbar;

import android.os.IBinder;

import com.android.internal.view.AppearanceRegion;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.statusbar.CommandQueue;

@@ -35,4 +36,21 @@ public class TaskbarDelegate implements CommandQueue.Callbacks {
        mOverviewProxyService.notifyImeWindowStatus(displayId, token, vis, backDisposition,
                showImeSwitcher);
    }

    @Override
    public void onRotationProposal(int rotation, boolean isValid) {
        mOverviewProxyService.onRotationProposal(rotation, isValid);
    }

    @Override
    public void disable(int displayId, int state1, int state2, boolean animate) {
        mOverviewProxyService.disable(displayId, state1, state2, animate);
    }

    @Override
    public void onSystemBarAttributesChanged(int displayId, int appearance,
            AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme, int behavior,
            boolean isFullscreen) {
        mOverviewProxyService.onSystemBarAttributesChanged(displayId, behavior);
    }
}
Loading