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

Commit 480405c5 authored by Merissa Mitchell's avatar Merissa Mitchell Committed by Android (Google) Code Review
Browse files

Merge changes I14b726e9,I84244b34,I9d21f576 into main

* changes:
  [PIP2] Hide PiP menu when PiP is moved or resized.
  [PIP2] Hook up expand icon to PipScheduler#scheduleExitPipViaExpand.
  [PIP2] Attach PiP menu to leash.
parents 22237bdd 875547e9
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2024 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.
-->
<com.android.wm.shell.pip2.phone.PipMenuActionView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/pip_action_size"
    android:layout_height="@dimen/pip_action_size"
    android:background="?android:selectableItemBackgroundBorderless"
    android:forceHasOverlappingRendering="false">

    <ImageView
        android:id="@+id/custom_close_bg"
        android:layout_width="@dimen/pip_custom_close_bg_size"
        android:layout_height="@dimen/pip_custom_close_bg_size"
        android:layout_gravity="center"
        android:src="@drawable/pip_custom_close_bg"
        android:visibility="gone"/>

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/pip_action_inner_size"
        android:layout_height="@dimen/pip_action_inner_size"
        android:layout_gravity="center"
        android:scaleType="fitXY"/>

</com.android.wm.shell.pip2.phone.PipMenuActionView>
+5 −4
Original line number Diff line number Diff line
@@ -127,11 +127,9 @@ public abstract class Pip2Module {
    @Provides
    static PipScheduler providePipScheduler(Context context,
            PipBoundsState pipBoundsState,
            PhonePipMenuController pipMenuController,
            @ShellMainThread ShellExecutor mainExecutor,
            PipTransitionState pipTransitionState) {
        return new PipScheduler(context, pipBoundsState, pipMenuController,
                mainExecutor, pipTransitionState);
        return new PipScheduler(context, pipBoundsState, mainExecutor, pipTransitionState);
    }

    @WMSingleton
@@ -140,10 +138,13 @@ public abstract class Pip2Module {
            PipBoundsState pipBoundsState, PipMediaController pipMediaController,
            SystemWindows systemWindows,
            PipUiEventLogger pipUiEventLogger,
            PipTaskListener pipTaskListener,
            @NonNull PipTransitionState pipTransitionState,
            @ShellMainThread ShellExecutor mainExecutor,
            @ShellMainThread Handler mainHandler) {
        return new PhonePipMenuController(context, pipBoundsState, pipMediaController,
                systemWindows, pipUiEventLogger, mainExecutor, mainHandler);
                systemWindows, pipUiEventLogger, pipTaskListener, pipTransitionState, mainExecutor,
                mainHandler);
    }


+49 −7
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.wm.shell.pip2.phone;

import static android.view.WindowManager.SHELL_ROOT_LAYER_PIP;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.RemoteAction;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.os.RemoteException;
@@ -52,7 +54,8 @@ import java.util.List;
 * The current media session provides actions whenever there are no valid actions provided by the
 * current PiP activity. Otherwise, those actions always take precedence.
 */
public class PhonePipMenuController implements PipMenuController {
public class PhonePipMenuController implements PipMenuController,
        PipTransitionState.PipTransitionStateChangedListener {

    private static final String TAG = "PhonePipMenuController";
    private static final boolean DEBUG = false;
@@ -113,6 +116,11 @@ public class PhonePipMenuController implements PipMenuController {

    private PipMenuView mPipMenuView;

    private final PipTaskListener mPipTaskListener;

    @NonNull
    private final PipTransitionState mPipTransitionState;

    private SurfaceControl mLeash;

    private ActionListener mMediaActionListener = new ActionListener() {
@@ -125,15 +133,27 @@ public class PhonePipMenuController implements PipMenuController {

    public PhonePipMenuController(Context context, PipBoundsState pipBoundsState,
            PipMediaController mediaController, SystemWindows systemWindows,
            PipUiEventLogger pipUiEventLogger,
            ShellExecutor mainExecutor, Handler mainHandler) {
            PipUiEventLogger pipUiEventLogger, PipTaskListener pipTaskListener,
            @NonNull PipTransitionState pipTransitionState, ShellExecutor mainExecutor,
            Handler mainHandler) {
        mContext = context;
        mPipBoundsState = pipBoundsState;
        mMediaController = mediaController;
        mSystemWindows = systemWindows;
        mPipTaskListener = pipTaskListener;
        mPipTransitionState = pipTransitionState;
        mMainExecutor = mainExecutor;
        mMainHandler = mainHandler;
        mPipUiEventLogger = pipUiEventLogger;

        mPipTransitionState.addPipTransitionStateChangedListener(this);

        mPipTaskListener.addParamsChangedListener(new PipTaskListener.PipParamsChangedCallback() {
            @Override
            public void onActionsChanged(List<RemoteAction> actions, RemoteAction closeAction) {
                setAppActions(actions, closeAction);
            }
        });
    }

    public boolean isMenuVisible() {
@@ -438,8 +458,7 @@ public class PhonePipMenuController implements PipMenuController {
     * Sets the menu actions to the actions provided by the current PiP menu.
     */
    @Override
    public void setAppActions(List<RemoteAction> appActions,
            RemoteAction closeAction) {
    public void setAppActions(List<RemoteAction> appActions, RemoteAction closeAction) {
        mAppActions = appActions;
        mCloseAction = closeAction;
        updateMenuActions();
@@ -468,8 +487,8 @@ public class PhonePipMenuController implements PipMenuController {
     */
    private void updateMenuActions() {
        if (mPipMenuView != null) {
            mPipMenuView.setActions(mPipBoundsState.getBounds(),
                    resolveMenuActions(), mCloseAction);
            mPipMenuView.setActions(mPipBoundsState.getBounds(), resolveMenuActions(),
                    mCloseAction);
        }
    }

@@ -567,6 +586,29 @@ public class PhonePipMenuController implements PipMenuController {
        }
    }

    @Override
    public void onPipTransitionStateChanged(@PipTransitionState.TransitionState int oldState,
            @PipTransitionState.TransitionState int newState, Bundle extra) {
        switch (newState) {
            case PipTransitionState.ENTERED_PIP:
                attach(mPipTransitionState.mPinnedTaskLeash);
                break;
            case PipTransitionState.EXITED_PIP:
                detach();
                break;
            case PipTransitionState.CHANGED_PIP_BOUNDS:
                updateMenuLayout(mPipBoundsState.getBounds());
                hideMenu();
                break;
            case PipTransitionState.CHANGING_PIP_BOUNDS:
                hideMenu();
                break;
            case PipTransitionState.SCHEDULED_BOUNDS_CHANGE:
                hideMenu();
                break;
        }
    }

    void dump(PrintWriter pw, String prefix) {
        final String innerPrefix = prefix + "  ";
        pw.println(prefix + TAG);
+1 −1
Original line number Diff line number Diff line
@@ -447,7 +447,7 @@ public class PipMenuView extends FrameLayout {
                final LayoutInflater inflater = LayoutInflater.from(mContext);
                while (mActionsGroup.getChildCount() < mActions.size()) {
                    final PipMenuActionView actionView = (PipMenuActionView) inflater.inflate(
                            R.layout.pip_menu_action, mActionsGroup, false);
                            R.layout.pip2_menu_action, mActionsGroup, false);
                    mActionsGroup.addView(actionView);
                }

+1 −1
Original line number Diff line number Diff line
@@ -336,7 +336,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        }
        cancelPhysicsAnimation();
        mMenuController.hideMenu(ANIM_TYPE_NONE, false /* resize */);
        // mPipTaskOrganizer.exitPip(skipAnimation ? 0 : LEAVE_PIP_DURATION, enterSplit);
        mPipScheduler.scheduleExitPipViaExpand();
    }

    /**
Loading