diff options
8 files changed, 117 insertions, 7 deletions
diff --git a/res/flag(com.android.documentsui.flags.use_material3)/color/nav_rail_burger_icon_ripple_color.xml b/res/flag(com.android.documentsui.flags.use_material3)/color/nav_rail_burger_icon_ripple_color.xml new file mode 100644 index 000000000..19c657b29 --- /dev/null +++ b/res/flag(com.android.documentsui.flags.use_material3)/color/nav_rail_burger_icon_ripple_color.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2025 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:alpha="@dimen/ripple_overlay_alpha" android:color="?attr/colorOnSurfaceVariant" /> +</selector> diff --git a/res/flag(com.android.documentsui.flags.use_material3)/drawable/ic_hamburger.xml b/res/flag(com.android.documentsui.flags.use_material3)/drawable/ic_hamburger.xml index 1d3990887..5a3e42d5e 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/drawable/ic_hamburger.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/drawable/ic_hamburger.xml @@ -20,6 +20,6 @@ android:viewportWidth="24" android:viewportHeight="24"> <path - android:fillColor="?android:attr/colorControlNormal" + android:fillColor="?attr/colorOnSurface" android:pathData="M3,18h18v-2H3V18zM3,13h18v-2H3V13zM3,6v2h18V6H3z"/> </vector>
\ No newline at end of file diff --git a/res/flag(com.android.documentsui.flags.use_material3)/drawable/nav_rail_burger_icon_background.xml b/res/flag(com.android.documentsui.flags.use_material3)/drawable/nav_rail_burger_icon_background.xml new file mode 100644 index 000000000..0957d36bb --- /dev/null +++ b/res/flag(com.android.documentsui.flags.use_material3)/drawable/nav_rail_burger_icon_background.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2025 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="?attr/colorOnSurfaceVariant" + android:alpha="@dimen/hover_overlay_alpha" /> + <item android:state_hovered="true" + android:color="?attr/colorOnSurfaceVariant" + android:alpha="@dimen/hover_overlay_alpha" /> + <item android:color="@android:color/transparent" /> +</selector> diff --git a/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml b/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml index 618aa7f14..a014d8866 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml @@ -18,6 +18,7 @@ floating action buttons) to operate correctly. --> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout"> @@ -39,11 +40,35 @@ android:background="?attr/colorSurfaceContainer"> <!-- Navigation rail: left hand side. --> - <FrameLayout - android:id="@+id/nav_rail_container_roots" + <LinearLayout + android:id="@+id/nav_rail_container" android:layout_width="144dp" android:layout_height="match_parent" - /> + android:orientation="vertical" + android:gravity="center_horizontal"> + + <com.google.android.material.button.MaterialButton + style="?attr/materialIconButtonStyle" + android:id="@+id/nav_rail_burger_menu" + android:layout_width="@dimen/nav_rail_burger_icon_size" + android:layout_height="@dimen/nav_rail_burger_icon_size" + android:layout_marginBottom="24dp" + app:iconPadding="0dp" + app:iconGravity="textStart" + app:iconTint="?attr/colorOnSurfaceVariant" + app:backgroundTint="@drawable/nav_rail_burger_icon_background" + app:rippleColor="@color/nav_rail_burger_icon_ripple_color" + app:strokeColor="?attr/colorPrimary" + android:contentDescription="@string/drawer_open" + app:icon="@drawable/ic_hamburger" /> + + <FrameLayout + android:id="@+id/nav_rail_container_roots" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" /> + + </LinearLayout> <!-- Main container for the right hand side. --> <LinearLayout diff --git a/res/flag(com.android.documentsui.flags.use_material3)/values-w600dp/dimens.xml b/res/flag(com.android.documentsui.flags.use_material3)/values-w600dp/dimens.xml index 2781026e9..4707991f6 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/values-w600dp/dimens.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/values-w600dp/dimens.xml @@ -23,7 +23,7 @@ we zero here, to avoid pushing the title further. --> <dimen name="search_bar_text_margin_start">0dp</dimen> - <dimen name="toolbar_padding_start">@dimen/space_small_3</dimen> + <dimen name="toolbar_padding_start">@dimen/main_container_padding_start</dimen> <dimen name="list_container_padding">@dimen/space_extra_small_6</dimen> </resources> diff --git a/res/flag(com.android.documentsui.flags.use_material3)/values/dimens.xml b/res/flag(com.android.documentsui.flags.use_material3)/values/dimens.xml index f8edfac9e..1ba7b00cd 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/values/dimens.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/values/dimens.xml @@ -91,6 +91,7 @@ <dimen name="nav_rail_item_icon_bg_radius">16dp</dimen> <dimen name="nav_rail_item_icon_bg_width">56dp</dimen> <dimen name="nav_rail_item_icon_bg_height">32dp</dimen> + <dimen name="nav_rail_burger_icon_size">56dp</dimen> <dimen name="drag_shadow_width">176dp</dimen> <dimen name="drag_shadow_height">64dp</dimen> diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java index 41fc5182f..e450326f4 100644 --- a/src/com/android/documentsui/BaseActivity.java +++ b/src/com/android/documentsui/BaseActivity.java @@ -79,6 +79,7 @@ import com.android.documentsui.sorting.SortModel; import com.android.modules.utils.build.SdkLevel; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.button.MaterialButton; import com.google.android.material.color.DynamicColors; import java.util.ArrayList; @@ -204,6 +205,16 @@ public abstract class BaseActivity mDrawer = DrawerController.create(this, mInjector.config); Metrics.logActivityLaunch(mState, intent); + if (useMaterial3()) { + View navRailRoots = findViewById(R.id.nav_rail_container_roots); + if (navRailRoots != null) { + // Bind event listener for the burger menu on nav rail. + MaterialButton burgerMenu = findViewById(R.id.nav_rail_burger_menu); + burgerMenu.setOnClickListener(v -> mDrawer.setOpen(true)); + burgerMenu.setOnFocusChangeListener(this::onBurgerMenuFocusChange); + } + } + mProviders = DocumentsApplication.getProvidersCache(this); mDocs = DocumentsAccess.create(this, mState); @@ -1117,4 +1128,19 @@ public abstract class BaseActivity } setRecentsScreenshotEnabled(!mUserManagerState.areHiddenInQuietModeProfilesPresent()); } + + /** + * When the burger menu is focused, adding a focus ring indicator using Stroke. + * TODO(b/381957932): Remove this once Material Button supports focus ring. + */ + private void onBurgerMenuFocusChange(View v, boolean hasFocus) { + MaterialButton burgerMenu = (MaterialButton) v; + if (hasFocus) { + final int focusRingWidth = getResources() + .getDimensionPixelSize(R.dimen.focus_ring_width); + burgerMenu.setStrokeWidth(focusRingWidth); + } else { + burgerMenu.setStrokeWidth(0); + } + } } diff --git a/src/com/android/documentsui/NavigationViewManager.java b/src/com/android/documentsui/NavigationViewManager.java index c376c86db..01239eb9d 100644 --- a/src/com/android/documentsui/NavigationViewManager.java +++ b/src/com/android/documentsui/NavigationViewManager.java @@ -17,6 +17,7 @@ package com.android.documentsui; import static com.android.documentsui.base.SharedMinimal.VERBOSE; +import static com.android.documentsui.flags.Flags.useMaterial3; import android.content.res.Resources; import android.content.res.TypedArray; @@ -264,8 +265,19 @@ public class NavigationViewManager implements AppBarLayout.OnOffsetChangedListen mDrawer.setTitle(mEnv.getDrawerTitle()); - mToolbar.setNavigationIcon(getActionBarIcon()); - mToolbar.setNavigationContentDescription(R.string.drawer_open); + boolean showBurgerMenuOnToolbar = true; + if (useMaterial3()) { + View navRailRoots = mActivity.findViewById(R.id.nav_rail_container_roots); + if (navRailRoots != null) { + // If nav rail exists, burger menu will show on the nav rail instead. + showBurgerMenuOnToolbar = false; + } + } + + if (showBurgerMenuOnToolbar) { + mToolbar.setNavigationIcon(getActionBarIcon()); + mToolbar.setNavigationContentDescription(R.string.drawer_open); + } if (shouldShowSearchBar()) { mBreadcrumb.show(false); |