diff options
author | 2024-03-07 11:20:04 -0800 | |
---|---|---|
committer | 2024-03-29 12:09:23 -0700 | |
commit | ff8ba2c432aaded40e47379f93ea695675faed8e (patch) | |
tree | 8c6033efab3d5efa49debf4a6d3619b54c9a9f0d | |
parent | 70437b59364ac570c1622867fcea23c39726ead9 (diff) |
Update maximize menu to new specs
Applies the following changes:
1. Adds text below menu options
2. Edits coloring and menu design
3. Adds onHover animations
4. Moving the maximize menu to be centered relative to the maximize
window button in the caption.
Bug: 327421788
Test: Manual testing
Change-Id: I1b487ce187570d3b52d2a6ff8f6dbe4f0dff8bfe
12 files changed, 215 insertions, 101 deletions
diff --git a/libs/WindowManager/Shell/res/color/desktop_mode_maximize_menu_button_color_selector.xml b/libs/WindowManager/Shell/res/color/desktop_mode_maximize_menu_button_color_selector.xml index 65f5239737b2..640d184e641c 100644 --- a/libs/WindowManager/Shell/res/color/desktop_mode_maximize_menu_button_color_selector.xml +++ b/libs/WindowManager/Shell/res/color/desktop_mode_maximize_menu_button_color_selector.xml @@ -14,15 +14,13 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> - -<selector xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"> <item android:state_pressed="true" - android:color="@color/desktop_mode_maximize_menu_button_on_hover"/> - <item android:state_hovered="true" - android:color="@color/desktop_mode_maximize_menu_button_on_hover"/> + android:color="?androidprv:attr/colorAccentPrimary"/> <item android:state_focused="true" - android:color="@color/desktop_mode_maximize_menu_button_on_hover"/> + android:color="?androidprv:attr/colorAccentPrimary"/> <item android:state_selected="true" - android:color="@color/desktop_mode_maximize_menu_button_on_hover"/> - <item android:color="@color/desktop_mode_maximize_menu_button"/> + android:color="?androidprv:attr/colorAccentPrimary"/> + <item android:color="?androidprv:attr/materialColorOutlineVariant"/> </selector>
\ No newline at end of file diff --git a/libs/WindowManager/Shell/res/color/desktop_mode_maximize_menu_button_outline_color_selector.xml b/libs/WindowManager/Shell/res/color/desktop_mode_maximize_menu_button_outline_color_selector.xml deleted file mode 100644 index 86679af5428b..000000000000 --- a/libs/WindowManager/Shell/res/color/desktop_mode_maximize_menu_button_outline_color_selector.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - ~ 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 ---> - -<selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_pressed="true" - android:color="@color/desktop_mode_maximize_menu_button_outline_on_hover"/> - <item android:state_hovered="true" - android:color="@color/desktop_mode_maximize_menu_button_outline_on_hover"/> - <item android:state_focused="true" - android:color="@color/desktop_mode_maximize_menu_button_outline_on_hover"/> - <item android:state_selected="true" - android:color="@color/desktop_mode_maximize_menu_button_outline_on_hover"/> - <item android:color="@color/desktop_mode_maximize_menu_button_outline"/> -</selector>
\ No newline at end of file diff --git a/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_maximize_button_background.xml b/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_button_background.xml index bfb0dd7f3100..ed51498dfe24 100644 --- a/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_maximize_button_background.xml +++ b/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_button_background.xml @@ -19,6 +19,5 @@ android:shape="rectangle"> <solid android:color="@color/desktop_mode_maximize_menu_button_color_selector"/> <corners - android:radius="@dimen/desktop_mode_maximize_menu_buttons_large_corner_radius"/> - <stroke android:width="1dp" android:color="@color/desktop_mode_maximize_menu_button_outline_color_selector"/> + android:radius="@dimen/desktop_mode_maximize_menu_buttons_radius"/> </shape>
\ No newline at end of file diff --git a/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_snap_left_button_background.xml b/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_layout_background.xml index 6630fcab4794..04ad572e046f 100644 --- a/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_snap_left_button_background.xml +++ b/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_layout_background.xml @@ -1,5 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> - <!-- ~ Copyright (C) 2023 The Android Open Source Project ~ @@ -17,12 +16,9 @@ --> <shape xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" android:shape="rectangle"> - <solid android:color="@color/desktop_mode_maximize_menu_button_color_selector"/> <corners - android:topLeftRadius="@dimen/desktop_mode_maximize_menu_buttons_large_corner_radius" - android:topRightRadius="@dimen/desktop_mode_maximize_menu_buttons_small_corner_radius" - android:bottomLeftRadius="@dimen/desktop_mode_maximize_menu_buttons_large_corner_radius" - android:bottomRightRadius="@dimen/desktop_mode_maximize_menu_buttons_small_corner_radius"/> - <stroke android:width="1dp" android:color="@color/desktop_mode_maximize_menu_button_outline_color_selector"/> + android:radius="@dimen/desktop_mode_maximize_menu_buttons_outline_radius"/> + <stroke android:width="1dp" android:color="?androidprv:attr/materialColorOutlineVariant"/> </shape>
\ No newline at end of file diff --git a/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_snap_right_button_background.xml b/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_layout_background_on_hover.xml index 7bd6e9981c12..86da9feacc49 100644 --- a/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_snap_right_button_background.xml +++ b/libs/WindowManager/Shell/res/drawable/desktop_mode_maximize_menu_layout_background_on_hover.xml @@ -1,5 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> - <!-- ~ Copyright (C) 2023 The Android Open Source Project ~ @@ -17,12 +16,9 @@ --> <shape xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" android:shape="rectangle"> - <solid android:color="@color/desktop_mode_maximize_menu_button_color_selector"/> <corners - android:topLeftRadius="@dimen/desktop_mode_maximize_menu_buttons_small_corner_radius" - android:topRightRadius="@dimen/desktop_mode_maximize_menu_buttons_large_corner_radius" - android:bottomLeftRadius="@dimen/desktop_mode_maximize_menu_buttons_small_corner_radius" - android:bottomRightRadius="@dimen/desktop_mode_maximize_menu_buttons_large_corner_radius"/> - <stroke android:width="1dp" android:color="@color/desktop_mode_maximize_menu_button_outline_color_selector"/> + android:radius="@dimen/desktop_mode_maximize_menu_buttons_outline_radius"/> + <stroke android:width="1dp" android:color="?androidprv:attr/colorAccentPrimary"/> </shape>
\ No newline at end of file diff --git a/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_maximize_menu.xml b/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_maximize_menu.xml index dbfd6e5d8d94..9f0a425a82f8 100644 --- a/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_maximize_menu.xml +++ b/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_maximize_menu.xml @@ -15,41 +15,87 @@ ~ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" android:id="@+id/maximize_menu" style="?android:attr/buttonBarStyle" android:layout_width="@dimen/desktop_mode_maximize_menu_width" android:layout_height="@dimen/desktop_mode_maximize_menu_height" android:orientation="horizontal" android:gravity="center" + android:padding="16dp" android:background="@drawable/desktop_mode_maximize_menu_background"> + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> - <Button - android:id="@+id/maximize_menu_maximize_button" - style="?android:attr/buttonBarButtonStyle" - android:layout_width="120dp" - android:layout_height="80dp" - android:layout_marginRight="15dp" - android:color="@color/desktop_mode_maximize_menu_button" - android:background="@drawable/desktop_mode_maximize_menu_maximize_button_background" - android:stateListAnimator="@null"/> + <FrameLayout + android:id="@+id/maximize_menu_maximize_button_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@drawable/desktop_mode_maximize_menu_layout_background" + android:padding="4dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="4dp"> + <Button + android:id="@+id/maximize_menu_maximize_button" + style="?android:attr/buttonBarButtonStyle" + android:layout_width="86dp" + android:layout_height="@dimen/desktop_mode_maximize_menu_button_height" + android:background="@drawable/desktop_mode_maximize_menu_button_background" + android:stateListAnimator="@null"/> + </FrameLayout> - <Button - android:id="@+id/maximize_menu_snap_left_button" - style="?android:attr/buttonBarButtonStyle" - android:layout_width="58dp" - android:layout_height="80dp" - android:layout_marginRight="6dp" - android:color="@color/desktop_mode_maximize_menu_button" - android:background="@drawable/desktop_mode_maximize_menu_snap_left_button_background" - android:stateListAnimator="@null"/> + <TextView + android:layout_width="94dp" + android:layout_height="18dp" + android:textSize="11sp" + android:layout_marginBottom="76dp" + android:gravity="center" + android:fontFamily="google-sans-text" + android:text="@string/desktop_mode_maximize_menu_maximize_text" + android:textColor="?androidprv:attr/materialColorOnSurface"/> + </LinearLayout> - <Button - android:id="@+id/maximize_menu_snap_right_button" - style="?android:attr/buttonBarButtonStyle" - android:layout_width="58dp" - android:layout_height="80dp" - android:color="@color/desktop_mode_maximize_menu_button" - android:background="@drawable/desktop_mode_maximize_menu_snap_right_button_background" - android:stateListAnimator="@null"/> + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + <LinearLayout + android:id="@+id/maximize_menu_snap_menu_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:padding="4dp" + android:background="@drawable/desktop_mode_maximize_menu_layout_background" + android:layout_marginBottom="4dp"> + <Button + android:id="@+id/maximize_menu_snap_left_button" + style="?android:attr/buttonBarButtonStyle" + android:layout_width="41dp" + android:layout_height="@dimen/desktop_mode_maximize_menu_button_height" + android:layout_marginRight="4dp" + android:background="@drawable/desktop_mode_maximize_menu_button_background" + android:stateListAnimator="@null"/> + + <Button + android:id="@+id/maximize_menu_snap_right_button" + style="?android:attr/buttonBarButtonStyle" + android:layout_width="41dp" + android:layout_height="@dimen/desktop_mode_maximize_menu_button_height" + android:background="@drawable/desktop_mode_maximize_menu_button_background" + android:stateListAnimator="@null"/> + </LinearLayout> + <TextView + android:layout_width="94dp" + android:layout_height="18dp" + android:textSize="11sp" + android:layout_marginBottom="76dp" + android:layout_gravity="center" + android:gravity="center" + android:fontFamily="google-sans-text" + android:text="@string/desktop_mode_maximize_menu_snap_text" + android:textColor="?androidprv:attr/materialColorOnSurface"/> + </LinearLayout> </LinearLayout>
\ No newline at end of file diff --git a/libs/WindowManager/Shell/res/values/colors.xml b/libs/WindowManager/Shell/res/values/colors.xml index 758dbfd5f3c5..cf18da6e7463 100644 --- a/libs/WindowManager/Shell/res/values/colors.xml +++ b/libs/WindowManager/Shell/res/values/colors.xml @@ -62,10 +62,6 @@ <color name="desktop_mode_caption_handle_bar_dark">#1C1C17</color> <color name="desktop_mode_resize_veil_light">#EFF1F2</color> <color name="desktop_mode_resize_veil_dark">#1C1C17</color> - <color name="desktop_mode_maximize_menu_button">#DDDACD</color> - <color name="desktop_mode_maximize_menu_button_outline">#797869</color> - <color name="desktop_mode_maximize_menu_button_outline_on_hover">#606219</color> - <color name="desktop_mode_maximize_menu_button_on_hover">#E7E790</color> <color name="desktop_mode_maximize_menu_progress_light">#33000000</color> <color name="desktop_mode_maximize_menu_progress_dark">#33FFFFFF</color> <color name="desktop_mode_caption_button_on_hover_light">#11000000</color> diff --git a/libs/WindowManager/Shell/res/values/dimen.xml b/libs/WindowManager/Shell/res/values/dimen.xml index 70371f6b18fc..39dd4d3af98d 100644 --- a/libs/WindowManager/Shell/res/values/dimen.xml +++ b/libs/WindowManager/Shell/res/values/dimen.xml @@ -456,16 +456,19 @@ <dimen name="desktop_mode_customizable_caption_margin_end">152dp</dimen> <!-- The width of the maximize menu in desktop mode. --> - <dimen name="desktop_mode_maximize_menu_width">287dp</dimen> + <dimen name="desktop_mode_maximize_menu_width">228dp</dimen> <!-- The height of the maximize menu in desktop mode. --> - <dimen name="desktop_mode_maximize_menu_height">112dp</dimen> + <dimen name="desktop_mode_maximize_menu_height">114dp</dimen> - <!-- The larger of the two corner radii of the maximize menu buttons. --> - <dimen name="desktop_mode_maximize_menu_buttons_large_corner_radius">4dp</dimen> + <!-- The height of the buttons in the maximize menu. --> + <dimen name="desktop_mode_maximize_menu_button_height">52dp</dimen> - <!-- The smaller of the two corner radii of the maximize menu buttons. --> - <dimen name="desktop_mode_maximize_menu_buttons_small_corner_radius">2dp</dimen> + <!-- The radius of the maximize menu buttons. --> + <dimen name="desktop_mode_maximize_menu_buttons_radius">4dp</dimen> + + <!-- The radius of the layout outline around the maximize menu buttons. --> + <dimen name="desktop_mode_maximize_menu_buttons_outline_radius">6dp</dimen> <!-- The corner radius of the maximize menu. --> <dimen name="desktop_mode_maximize_menu_corner_radius">8dp</dimen> diff --git a/libs/WindowManager/Shell/res/values/strings.xml b/libs/WindowManager/Shell/res/values/strings.xml index 812a81ba33d1..fa6dd3914ddd 100644 --- a/libs/WindowManager/Shell/res/values/strings.xml +++ b/libs/WindowManager/Shell/res/values/strings.xml @@ -280,4 +280,8 @@ <string name="collapse_menu_text">Close Menu</string> <!-- Accessibility text for the handle menu open menu button [CHAR LIMIT=NONE] --> <string name="expand_menu_text">Open Menu</string> + <!-- Maximize menu maximize button string. --> + <string name="desktop_mode_maximize_menu_maximize_text">Maximize Screen</string> + <!-- Maximize menu maximize button string. --> + <string name="desktop_mode_maximize_menu_snap_text">Snap Screen</string> </resources> diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java index dd09bb91d425..ce8d69f03392 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java @@ -25,6 +25,7 @@ import static android.view.InputDevice.SOURCE_TOUCHSCREEN; import static android.view.MotionEvent.ACTION_CANCEL; import static android.view.MotionEvent.ACTION_HOVER_ENTER; import static android.view.MotionEvent.ACTION_HOVER_EXIT; +import static android.view.MotionEvent.ACTION_HOVER_MOVE; import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_UP; import static android.view.WindowInsets.Type.statusBars; @@ -365,7 +366,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { private class DesktopModeTouchEventListener extends GestureDetector.SimpleOnGestureListener implements View.OnClickListener, View.OnTouchListener, View.OnLongClickListener, - View.OnGenericMotionListener , DragDetector.MotionEventHandler { + View.OnGenericMotionListener, DragDetector.MotionEventHandler { private static final int CLOSE_MAXIMIZE_MENU_DELAY_MS = 150; private final int mTaskId; @@ -558,8 +559,14 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { // Re-hovering over any of the maximize menu views should keep the menu open by // cancelling any attempts to close the menu. mMainHandler.removeCallbacks(mCloseMaximizeWindowRunnable); + if (id != R.id.maximize_window) { + decoration.onMaximizeMenuHoverEnter(id, ev); + } } return true; + } else if (ev.getAction() == ACTION_HOVER_MOVE + && MaximizeMenu.Companion.isMaximizeMenuView(id)) { + decoration.onMaximizeMenuHoverMove(id, ev); } else if (ev.getAction() == ACTION_HOVER_EXIT) { if (!decoration.isMaximizeMenuActive() && id == R.id.maximize_window) { decoration.onMaximizeWindowHoverExit(); @@ -569,6 +576,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { // menu view to another. mMainHandler.postDelayed(mCloseMaximizeWindowRunnable, CLOSE_MAXIMIZE_MENU_DELAY_MS); + } else if (MaximizeMenu.Companion.isMaximizeMenuView(id)) { + decoration.onMaximizeMenuHoverExit(id, ev); } return true; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index c21f8f686be5..660ff022ec97 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -401,7 +401,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin final int menuHeight = loadDimensionPixelSize( resources, R.dimen.desktop_mode_maximize_menu_height); - float menuLeft = (mPositionInParent.x + maximizeButtonLocation[0]); + float menuLeft = (mPositionInParent.x + maximizeButtonLocation[0] - ((float) (menuWidth + - maximizeWindowButton.getWidth()) / 2)); float menuTop = (mPositionInParent.y + captionHeight); final float menuRight = menuLeft + menuWidth; final float menuBottom = menuTop + menuHeight; @@ -808,16 +809,34 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin .setAnimatingTaskResize(animatingTaskResize); } + /** Called when there is a {@Link ACTION_HOVER_EXIT} on the maximize window button. */ void onMaximizeWindowHoverExit() { ((DesktopModeAppControlsWindowDecorationViewHolder) mWindowDecorViewHolder) .onMaximizeWindowHoverExit(); } + /** Called when there is a {@Link ACTION_HOVER_ENTER} on the maximize window button. */ void onMaximizeWindowHoverEnter() { ((DesktopModeAppControlsWindowDecorationViewHolder) mWindowDecorViewHolder) .onMaximizeWindowHoverEnter(); } + /** Called when there is a {@Link ACTION_HOVER_ENTER} on a view in the maximize menu. */ + void onMaximizeMenuHoverEnter(int id, MotionEvent ev) { + mMaximizeMenu.onMaximizeMenuHoverEnter(id, ev); + } + + /** Called when there is a {@Link ACTION_HOVER_MOVE} on a view in the maximize menu. */ + void onMaximizeMenuHoverMove(int id, MotionEvent ev) { + mMaximizeMenu.onMaximizeMenuHoverMove(id, ev); + } + + /** Called when there is a {@Link ACTION_HOVER_EXIT} on a view in the maximize menu. */ + void onMaximizeMenuHoverExit(int id, MotionEvent ev) { + mMaximizeMenu.onMaximizeMenuHoverExit(id, ev); + } + + @Override public String toString() { return "{" diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/MaximizeMenu.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/MaximizeMenu.kt index b82f7ca47ef3..899b7cc0ea0d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/MaximizeMenu.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/MaximizeMenu.kt @@ -33,7 +33,11 @@ import android.view.View.OnTouchListener import android.view.WindowManager import android.view.WindowlessWindowManager import android.widget.Button +import android.widget.FrameLayout +import android.widget.LinearLayout import android.window.TaskConstants +import androidx.core.content.withStyledAttributes +import com.android.internal.R.attr.colorAccentPrimary import com.android.wm.shell.R import com.android.wm.shell.RootTaskDisplayAreaOrganizer import com.android.wm.shell.common.DisplayController @@ -70,6 +74,12 @@ class MaximizeMenu( private val menuWidth = loadDimensionPixelSize(R.dimen.desktop_mode_maximize_menu_width) private val menuHeight = loadDimensionPixelSize(R.dimen.desktop_mode_maximize_menu_height) + private lateinit var snapRightButton: Button + private lateinit var snapLeftButton: Button + private lateinit var maximizeButton: Button + private lateinit var maximizeButtonLayout: FrameLayout + private lateinit var snapButtonsLayout: LinearLayout + /** Position the menu relative to the caption's position. */ fun positionMenu(position: PointF, t: Transaction) { menuPosition.set(position) @@ -150,23 +160,23 @@ class MaximizeMenu( maximizeMenuView.setOnGenericMotionListener(onGenericMotionListener) maximizeMenuView.setOnTouchListener(onTouchListener) - val maximizeButton = maximizeMenuView.requireViewById<Button>( - R.id.maximize_menu_maximize_button - ) + maximizeButtonLayout = maximizeMenuView.requireViewById( + R.id.maximize_menu_maximize_button_layout) + + maximizeButton = maximizeMenuView.requireViewById(R.id.maximize_menu_maximize_button) maximizeButton.setOnClickListener(onClickListener) maximizeButton.setOnGenericMotionListener(onGenericMotionListener) - val snapRightButton = maximizeMenuView.requireViewById<Button>( - R.id.maximize_menu_snap_right_button - ) + snapRightButton = maximizeMenuView.requireViewById(R.id.maximize_menu_snap_right_button) snapRightButton.setOnClickListener(onClickListener) snapRightButton.setOnGenericMotionListener(onGenericMotionListener) - val snapLeftButton = maximizeMenuView.requireViewById<Button>( - R.id.maximize_menu_snap_left_button - ) + snapLeftButton = maximizeMenuView.requireViewById(R.id.maximize_menu_snap_left_button) snapLeftButton.setOnClickListener(onClickListener) snapLeftButton.setOnGenericMotionListener(onGenericMotionListener) + + snapButtonsLayout = maximizeMenuView.requireViewById(R.id.maximize_menu_snap_menu_layout) + snapButtonsLayout.setOnGenericMotionListener(onGenericMotionListener) } /** @@ -190,11 +200,77 @@ class MaximizeMenu( return maximizeMenu?.mWindowViewHost?.view?.isLaidOut ?: false } + fun onMaximizeMenuHoverEnter(viewId: Int, ev: MotionEvent) { + setSnapButtonsColorOnHover(viewId, ev) + } + + fun onMaximizeMenuHoverMove(viewId: Int, ev: MotionEvent) { + setSnapButtonsColorOnHover(viewId, ev) + } + + fun onMaximizeMenuHoverExit(id: Int, ev: MotionEvent) { + val inSnapMenuBounds = ev.x >= 0 && ev.x <= snapButtonsLayout.width && + ev.y >= 0 && ev.y <= snapButtonsLayout.height + val colorList = decorWindowContext.getColorStateList( + R.color.desktop_mode_maximize_menu_button_color_selector) + + if (id == R.id.maximize_menu_maximize_button) { + maximizeButton.background?.setTintList(colorList) + maximizeButtonLayout.setBackgroundResource( + R.drawable.desktop_mode_maximize_menu_layout_background) + } else if (id == R.id.maximize_menu_snap_menu_layout && !inSnapMenuBounds) { + // After exiting the snap menu layout area, checks to see that user is not still + // hovering within the snap menu layout bounds which would indicate that the user is + // hovering over a snap button within the snap menu layout rather than having exited. + snapLeftButton.background?.setTintList(colorList) + snapLeftButton.background?.alpha = 255 + snapRightButton.background?.setTintList(colorList) + snapRightButton.background?.alpha = 255 + snapButtonsLayout.setBackgroundResource( + R.drawable.desktop_mode_maximize_menu_layout_background) + } + } + + private fun setSnapButtonsColorOnHover(viewId: Int, ev: MotionEvent) { + decorWindowContext.withStyledAttributes(null, intArrayOf(colorAccentPrimary), 0, 0) { + val materialColor = getColor(0, 0) + val snapMenuCenter = snapButtonsLayout.width / 2 + if (viewId == R.id.maximize_menu_maximize_button) { + // Highlight snap maximize window button + maximizeButton.background?.setTint(materialColor) + maximizeButtonLayout.setBackgroundResource( + R.drawable.desktop_mode_maximize_menu_layout_background_on_hover) + } else if (viewId == R.id.maximize_menu_snap_left_button || + (viewId == R.id.maximize_menu_snap_menu_layout && ev.x <= snapMenuCenter)) { + // Highlight snap left button + snapRightButton.background?.setTint(materialColor) + snapLeftButton.background?.setTint(materialColor) + snapButtonsLayout.setBackgroundResource( + R.drawable.desktop_mode_maximize_menu_layout_background_on_hover) + snapRightButton.background?.alpha = 102 + snapLeftButton.background?.alpha = 255 + } else if (viewId == R.id.maximize_menu_snap_right_button || + (viewId == R.id.maximize_menu_snap_menu_layout && ev.x > snapMenuCenter)) { + // Highlight snap right button + snapRightButton.background?.setTint(materialColor) + snapLeftButton.background?.setTint(materialColor) + snapButtonsLayout.setBackgroundResource( + R.drawable.desktop_mode_maximize_menu_layout_background_on_hover) + snapRightButton.background?.alpha = 255 + snapLeftButton.background?.alpha = 102 + } + } + } + companion object { fun isMaximizeMenuView(@IdRes viewId: Int): Boolean { - return viewId == R.id.maximize_menu || viewId == R.id.maximize_menu_maximize_button || + return viewId == R.id.maximize_menu || + viewId == R.id.maximize_menu_maximize_button || + viewId == R.id.maximize_menu_maximize_button_layout || viewId == R.id.maximize_menu_snap_left_button || - viewId == R.id.maximize_menu_snap_right_button + viewId == R.id.maximize_menu_snap_right_button || + viewId == R.id.maximize_menu_snap_menu_layout || + viewId == R.id.maximize_menu_snap_menu_layout } } } |