1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.quickstep 18 19 import android.content.Intent 20 import android.provider.Settings 21 import android.view.View 22 import androidx.core.net.toUri 23 import com.android.launcher3.AbstractFloatingViewHelper 24 import com.android.launcher3.R 25 import com.android.launcher3.logging.StatsLogManager.LauncherEvent 26 import com.android.launcher3.popup.SystemShortcut 27 import com.android.quickstep.views.RecentsViewContainer 28 import com.android.quickstep.views.TaskContainer 29 import com.android.window.flags.Flags.universalResizableByDefault 30 31 /** 32 * System shortcut to change the application's aspect ratio compatibility mode. 33 * 34 * This shows up only on screens that are not compact, ie. shortest-width greater than {@link 35 * com.android.launcher3.util.window.WindowManagerProxy#MIN_TABLET_WIDTH}. 36 */ 37 class AspectRatioSystemShortcut( 38 viewContainer: RecentsViewContainer, 39 taskContainer: TaskContainer, 40 abstractFloatingViewHelper: AbstractFloatingViewHelper, 41 ) : 42 SystemShortcut<RecentsViewContainer>( 43 R.drawable.ic_aspect_ratio, 44 R.string.recent_task_option_aspect_ratio, 45 viewContainer, 46 taskContainer.itemInfo, 47 taskContainer.taskView, 48 abstractFloatingViewHelper, 49 ) { onClicknull50 override fun onClick(view: View) { 51 dismissTaskMenuView() 52 53 val intent = 54 Intent(Settings.ACTION_MANAGE_USER_ASPECT_RATIO_SETTINGS) 55 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) 56 if (mItemInfo.targetPackage != null) { 57 intent.setData(("package:" + mItemInfo.targetPackage).toUri()) 58 } 59 60 mTarget.startActivitySafely(view, intent, mItemInfo) 61 mTarget 62 .statsLogManager 63 .logger() 64 .withItemInfo(mItemInfo) 65 .log(LauncherEvent.LAUNCHER_ASPECT_RATIO_SETTINGS_SYSTEM_SHORTCUT_TAP) 66 } 67 68 companion object { 69 /** Optionally create a factory for the aspect ratio system shortcut. */ 70 @JvmOverloads createFactorynull71 fun createFactory( 72 abstractFloatingViewHelper: AbstractFloatingViewHelper = AbstractFloatingViewHelper() 73 ): TaskShortcutFactory { 74 return object : TaskShortcutFactory { 75 override fun getShortcuts( 76 viewContainer: RecentsViewContainer, 77 taskContainer: TaskContainer, 78 ): List<AspectRatioSystemShortcut>? { 79 return when { 80 // Only available when the feature flag is on. 81 !universalResizableByDefault() -> null 82 83 // The option is only shown on sw600dp+ screens (checked by isTablet) 84 !viewContainer.deviceProfile.isTablet -> null 85 86 else -> { 87 listOf( 88 AspectRatioSystemShortcut( 89 viewContainer, 90 taskContainer, 91 abstractFloatingViewHelper, 92 ) 93 ) 94 } 95 } 96 } 97 } 98 } 99 } 100 } 101