diff options
author | 2025-02-04 14:27:19 +0100 | |
---|---|---|
committer | 2025-03-24 06:56:05 +0100 | |
commit | 116eafb95c2d4538fb8b59c95a828823a2fe4148 (patch) | |
tree | 5a35f06ba420ccfbba6f4f58f19653713508e387 /quickstep/src | |
parent | 88b2f23a83252572a53cae7dbf4d27de54592553 (diff) |
Add "change aspect ratio" to Recents/Overview
This shows up if the launcher is in a sw600dp-or-greater configuration.
Test: AspectRatioSystemShortcutTests
Test: OverviewMenuImageTest
Test: Manual check on phone, tablet, and inner/outer fold screens.
Flag: com.android.window.flags.universal_resizable_by_default
Bug: 357141415
Change-Id: I1bcbf9299d28ce68cccd636d92ed7195d64736eb
Diffstat (limited to 'quickstep/src')
-rw-r--r-- | quickstep/src/com/android/quickstep/AspectRatioSystemShortcut.kt | 100 | ||||
-rw-r--r-- | quickstep/src/com/android/quickstep/TaskOverlayFactory.java | 1 |
2 files changed, 101 insertions, 0 deletions
diff --git a/quickstep/src/com/android/quickstep/AspectRatioSystemShortcut.kt b/quickstep/src/com/android/quickstep/AspectRatioSystemShortcut.kt new file mode 100644 index 0000000000..68860ac91b --- /dev/null +++ b/quickstep/src/com/android/quickstep/AspectRatioSystemShortcut.kt @@ -0,0 +1,100 @@ +/* + * 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. + */ + +package com.android.quickstep + +import android.content.Intent +import android.provider.Settings +import android.view.View +import androidx.core.net.toUri +import com.android.launcher3.AbstractFloatingViewHelper +import com.android.launcher3.R +import com.android.launcher3.logging.StatsLogManager.LauncherEvent +import com.android.launcher3.popup.SystemShortcut +import com.android.quickstep.views.RecentsViewContainer +import com.android.quickstep.views.TaskContainer +import com.android.window.flags.Flags.universalResizableByDefault + +/** + * System shortcut to change the application's aspect ratio compatibility mode. + * + * This shows up only on screens that are not compact, ie. shortest-width greater than {@link + * com.android.launcher3.util.window.WindowManagerProxy#MIN_TABLET_WIDTH}. + */ +class AspectRatioSystemShortcut( + viewContainer: RecentsViewContainer, + taskContainer: TaskContainer, + abstractFloatingViewHelper: AbstractFloatingViewHelper, +) : + SystemShortcut<RecentsViewContainer>( + R.drawable.ic_aspect_ratio, + R.string.recent_task_option_aspect_ratio, + viewContainer, + taskContainer.itemInfo, + taskContainer.taskView, + abstractFloatingViewHelper, + ) { + override fun onClick(view: View) { + dismissTaskMenuView() + + val intent = + Intent(Settings.ACTION_MANAGE_USER_ASPECT_RATIO_SETTINGS) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) + if (mItemInfo.targetPackage != null) { + intent.setData(("package:" + mItemInfo.targetPackage).toUri()) + } + + mTarget.startActivitySafely(view, intent, mItemInfo) + mTarget + .statsLogManager + .logger() + .withItemInfo(mItemInfo) + .log(LauncherEvent.LAUNCHER_ASPECT_RATIO_SETTINGS_SYSTEM_SHORTCUT_TAP) + } + + companion object { + /** Optionally create a factory for the aspect ratio system shortcut. */ + @JvmOverloads + fun createFactory( + abstractFloatingViewHelper: AbstractFloatingViewHelper = AbstractFloatingViewHelper() + ): TaskShortcutFactory { + return object : TaskShortcutFactory { + override fun getShortcuts( + viewContainer: RecentsViewContainer, + taskContainer: TaskContainer, + ): List<AspectRatioSystemShortcut>? { + return when { + // Only available when the feature flag is on. + !universalResizableByDefault() -> null + + // The option is only shown on sw600dp+ screens (checked by isTablet) + !viewContainer.deviceProfile.isTablet -> null + + else -> { + listOf( + AspectRatioSystemShortcut( + viewContainer, + taskContainer, + abstractFloatingViewHelper, + ) + ) + } + } + } + } + } + } +} diff --git a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java index ae6bfbc517..5bf4451fad 100644 --- a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java +++ b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java @@ -118,6 +118,7 @@ public class TaskOverlayFactory implements ResourceBasedOverride { TaskShortcutFactory.FREE_FORM, DesktopSystemShortcut.Companion.createFactory(), ExternalDisplaySystemShortcut.Companion.createFactory(), + AspectRatioSystemShortcut.Companion.createFactory(), TaskShortcutFactory.WELLBEING, TaskShortcutFactory.SAVE_APP_PAIR, TaskShortcutFactory.SCREENSHOT, |