Merge "Use different pip shadow for each tv pip menu mode" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
35f013904a
@@ -19,10 +19,11 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
<View
|
<View
|
||||||
|
android:id="@+id/background_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_margin="@dimen/pip_menu_outer_space_frame"
|
android:layout_margin="@dimen/pip_menu_outer_space_frame"
|
||||||
android:background="@drawable/tv_pip_menu_background"
|
android:background="@drawable/tv_pip_menu_background"
|
||||||
android:elevation="@dimen/pip_menu_elevation"/>
|
android:elevation="@dimen/pip_menu_elevation_no_menu"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,9 @@
|
|||||||
<dimen name="pip_menu_arrow_size">24dp</dimen>
|
<dimen name="pip_menu_arrow_size">24dp</dimen>
|
||||||
<dimen name="pip_menu_arrow_elevation">5dp</dimen>
|
<dimen name="pip_menu_arrow_elevation">5dp</dimen>
|
||||||
|
|
||||||
<dimen name="pip_menu_elevation">1dp</dimen>
|
<dimen name="pip_menu_elevation_no_menu">1dp</dimen>
|
||||||
|
<dimen name="pip_menu_elevation_move_menu">7dp</dimen>
|
||||||
|
<dimen name="pip_menu_elevation_all_actions_menu">4dp</dimen>
|
||||||
|
|
||||||
<dimen name="pip_menu_edu_text_view_height">24dp</dimen>
|
<dimen name="pip_menu_edu_text_view_height">24dp</dimen>
|
||||||
<dimen name="pip_menu_edu_text_home_icon">9sp</dimen>
|
<dimen name="pip_menu_edu_text_home_icon">9sp</dimen>
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.wm.shell.pip.tv;
|
||||||
|
|
||||||
|
import static com.android.wm.shell.pip.tv.TvPipMenuController.MODE_ALL_ACTIONS_MENU;
|
||||||
|
import static com.android.wm.shell.pip.tv.TvPipMenuController.MODE_MOVE_MENU;
|
||||||
|
import static com.android.wm.shell.pip.tv.TvPipMenuController.MODE_NO_MENU;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.animation.Interpolator;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.android.internal.protolog.common.ProtoLog;
|
||||||
|
import com.android.wm.shell.R;
|
||||||
|
import com.android.wm.shell.protolog.ShellProtoLogGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This view is part of the Tv PiP menu. It is drawn behind the PiP surface and serves as a
|
||||||
|
* background behind the PiP content. If the PiP content is translucent, this view is visible
|
||||||
|
* behind it.
|
||||||
|
* It is also used to draw the shadow behind the Tv PiP menu. The shadow intensity is determined
|
||||||
|
* by the menu mode that the Tv PiP menu is in. See {@link TvPipMenuController.TvPipMenuMode}.
|
||||||
|
*/
|
||||||
|
class TvPipBackgroundView extends FrameLayout {
|
||||||
|
private static final String TAG = "TvPipBackgroundView";
|
||||||
|
|
||||||
|
private final View mBackgroundView;
|
||||||
|
private final int mElevationNoMenu;
|
||||||
|
private final int mElevationMoveMenu;
|
||||||
|
private final int mElevationAllActionsMenu;
|
||||||
|
private final int mPipMenuFadeAnimationDuration;
|
||||||
|
|
||||||
|
private @TvPipMenuController.TvPipMenuMode int mCurrentMenuMode = MODE_NO_MENU;
|
||||||
|
|
||||||
|
TvPipBackgroundView(@NonNull Context context) {
|
||||||
|
super(context, null, 0, 0);
|
||||||
|
inflate(context, R.layout.tv_pip_menu_background, this);
|
||||||
|
|
||||||
|
mBackgroundView = findViewById(R.id.background_view);
|
||||||
|
|
||||||
|
final Resources res = mContext.getResources();
|
||||||
|
mElevationNoMenu = res.getDimensionPixelSize(R.dimen.pip_menu_elevation_no_menu);
|
||||||
|
mElevationMoveMenu = res.getDimensionPixelSize(R.dimen.pip_menu_elevation_move_menu);
|
||||||
|
mElevationAllActionsMenu =
|
||||||
|
res.getDimensionPixelSize(R.dimen.pip_menu_elevation_all_actions_menu);
|
||||||
|
mPipMenuFadeAnimationDuration =
|
||||||
|
res.getInteger(R.integer.tv_window_menu_fade_animation_duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
void transitionToMenuMode(@TvPipMenuController.TvPipMenuMode int pipMenuMode) {
|
||||||
|
ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
|
||||||
|
"%s: transitionToMenuMode(), old menu mode = %s, new menu mode = %s",
|
||||||
|
TAG, TvPipMenuController.getMenuModeString(mCurrentMenuMode),
|
||||||
|
TvPipMenuController.getMenuModeString(pipMenuMode));
|
||||||
|
|
||||||
|
if (mCurrentMenuMode == pipMenuMode) return;
|
||||||
|
|
||||||
|
int elevation = mElevationNoMenu;
|
||||||
|
Interpolator interpolator = TvPipInterpolators.ENTER;
|
||||||
|
switch(pipMenuMode) {
|
||||||
|
case MODE_NO_MENU:
|
||||||
|
elevation = mElevationNoMenu;
|
||||||
|
interpolator = TvPipInterpolators.EXIT;
|
||||||
|
break;
|
||||||
|
case MODE_MOVE_MENU:
|
||||||
|
elevation = mElevationMoveMenu;
|
||||||
|
break;
|
||||||
|
case MODE_ALL_ACTIONS_MENU:
|
||||||
|
elevation = mElevationAllActionsMenu;
|
||||||
|
if (mCurrentMenuMode == MODE_MOVE_MENU) {
|
||||||
|
interpolator = TvPipInterpolators.EXIT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Unknown TV PiP menu mode: " + pipMenuMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
mBackgroundView.animate()
|
||||||
|
.translationZ(elevation)
|
||||||
|
.setInterpolator(interpolator)
|
||||||
|
.setDuration(mPipMenuFadeAnimationDuration)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
mCurrentMenuMode = pipMenuMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ import android.content.IntentFilter;
|
|||||||
import android.graphics.Insets;
|
import android.graphics.Insets;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.SurfaceControl;
|
import android.view.SurfaceControl;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewRootImpl;
|
import android.view.ViewRootImpl;
|
||||||
@@ -61,7 +60,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
|
|||||||
private Delegate mDelegate;
|
private Delegate mDelegate;
|
||||||
private SurfaceControl mLeash;
|
private SurfaceControl mLeash;
|
||||||
private TvPipMenuView mPipMenuView;
|
private TvPipMenuView mPipMenuView;
|
||||||
private View mPipBackgroundView;
|
private TvPipBackgroundView mPipBackgroundView;
|
||||||
private boolean mMenuIsFocused;
|
private boolean mMenuIsFocused;
|
||||||
|
|
||||||
@TvPipMenuMode
|
@TvPipMenuMode
|
||||||
@@ -178,12 +177,16 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void attachPipBackgroundView() {
|
private void attachPipBackgroundView() {
|
||||||
mPipBackgroundView = LayoutInflater.from(mContext)
|
mPipBackgroundView = createTvPipBackgroundView();
|
||||||
.inflate(R.layout.tv_pip_menu_background, null);
|
|
||||||
setUpViewSurfaceZOrder(mPipBackgroundView, -1);
|
setUpViewSurfaceZOrder(mPipBackgroundView, -1);
|
||||||
addPipMenuViewToSystemWindows(mPipBackgroundView, BACKGROUND_WINDOW_TITLE);
|
addPipMenuViewToSystemWindows(mPipBackgroundView, BACKGROUND_WINDOW_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
TvPipBackgroundView createTvPipBackgroundView() {
|
||||||
|
return new TvPipBackgroundView(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
private void setUpViewSurfaceZOrder(View v, int zOrderRelativeToPip) {
|
private void setUpViewSurfaceZOrder(View v, int zOrderRelativeToPip) {
|
||||||
v.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
v.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -415,10 +418,11 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateUiOnNewMenuModeRequest(boolean resetMenu) {
|
private void updateUiOnNewMenuModeRequest(boolean resetMenu) {
|
||||||
if (mPipMenuView == null) return;
|
if (mPipMenuView == null || mPipBackgroundView == null) return;
|
||||||
|
|
||||||
mPipMenuView.setPipGravity(mTvPipBoundsState.getTvPipGravity());
|
mPipMenuView.setPipGravity(mTvPipBoundsState.getTvPipGravity());
|
||||||
mPipMenuView.transitionToMenuMode(mCurrentMenuMode, resetMenu);
|
mPipMenuView.transitionToMenuMode(mCurrentMenuMode, resetMenu);
|
||||||
|
mPipBackgroundView.transitionToMenuMode(mCurrentMenuMode);
|
||||||
grantPipMenuFocus(mCurrentMenuMode != MODE_NO_MENU);
|
grantPipMenuFocus(mCurrentMenuMode != MODE_NO_MENU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public class TvPipMenuControllerTest extends ShellTestCase {
|
|||||||
private TvPipActionsProvider mMockActionsProvider;
|
private TvPipActionsProvider mMockActionsProvider;
|
||||||
@Mock
|
@Mock
|
||||||
private TvPipMenuView mMockTvPipMenuView;
|
private TvPipMenuView mMockTvPipMenuView;
|
||||||
|
@Mock
|
||||||
|
private TvPipBackgroundView mMockTvPipBackgroundView;
|
||||||
|
|
||||||
private TvPipMenuController mTvPipMenuController;
|
private TvPipMenuController mTvPipMenuController;
|
||||||
|
|
||||||
@@ -173,6 +175,7 @@ public class TvPipMenuControllerTest extends ShellTestCase {
|
|||||||
assertMenuIsInAllActionsMode();
|
assertMenuIsInAllActionsMode();
|
||||||
verify(mMockDelegate, times(2)).onInMoveModeChanged();
|
verify(mMockDelegate, times(2)).onInMoveModeChanged();
|
||||||
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU), eq(false));
|
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU), eq(false));
|
||||||
|
verify(mMockTvPipBackgroundView, times(2)).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -215,6 +218,7 @@ public class TvPipMenuControllerTest extends ShellTestCase {
|
|||||||
assertMenuIsInAllActionsMode();
|
assertMenuIsInAllActionsMode();
|
||||||
verify(mMockDelegate, times(2)).onInMoveModeChanged();
|
verify(mMockDelegate, times(2)).onInMoveModeChanged();
|
||||||
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU), eq(false));
|
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU), eq(false));
|
||||||
|
verify(mMockTvPipBackgroundView, times(2)).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU));
|
||||||
|
|
||||||
pressBackAndAssertMenuClosed();
|
pressBackAndAssertMenuClosed();
|
||||||
}
|
}
|
||||||
@@ -262,12 +266,14 @@ public class TvPipMenuControllerTest extends ShellTestCase {
|
|||||||
assertMenuIsInMoveMode();
|
assertMenuIsInMoveMode();
|
||||||
verify(mMockDelegate).onInMoveModeChanged();
|
verify(mMockDelegate).onInMoveModeChanged();
|
||||||
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_MOVE_MENU), eq(false));
|
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_MOVE_MENU), eq(false));
|
||||||
|
verify(mMockTvPipBackgroundView).transitionToMenuMode(eq(MODE_MOVE_MENU));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAndAssertAllActionsMenu() {
|
private void showAndAssertAllActionsMenu() {
|
||||||
mTvPipMenuController.showMenu();
|
mTvPipMenuController.showMenu();
|
||||||
assertMenuIsInAllActionsMode();
|
assertMenuIsInAllActionsMode();
|
||||||
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU), eq(true));
|
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU), eq(true));
|
||||||
|
verify(mMockTvPipBackgroundView).transitionToMenuMode(eq(MODE_ALL_ACTIONS_MENU));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeMenuAndAssertMenuClosed() {
|
private void closeMenuAndAssertMenuClosed() {
|
||||||
@@ -284,6 +290,7 @@ public class TvPipMenuControllerTest extends ShellTestCase {
|
|||||||
assertMenuIsOpen(false);
|
assertMenuIsOpen(false);
|
||||||
verify(mMockDelegate).onMenuClosed();
|
verify(mMockDelegate).onMenuClosed();
|
||||||
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_NO_MENU), eq(false));
|
verify(mMockTvPipMenuView).transitionToMenuMode(eq(MODE_NO_MENU), eq(false));
|
||||||
|
verify(mMockTvPipBackgroundView).transitionToMenuMode(eq(MODE_NO_MENU));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertMenuIsOpen(boolean open) {
|
private void assertMenuIsOpen(boolean open) {
|
||||||
@@ -320,5 +327,10 @@ public class TvPipMenuControllerTest extends ShellTestCase {
|
|||||||
TvPipMenuView createTvPipMenuView() {
|
TvPipMenuView createTvPipMenuView() {
|
||||||
return mMockTvPipMenuView;
|
return mMockTvPipMenuView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
TvPipBackgroundView createTvPipBackgroundView() {
|
||||||
|
return mMockTvPipBackgroundView;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user