Fix bug with app pairs appearing in wrong orientation in pinned Taskbar

This CL makes it so that app pairs do an orientation check in dispatchDraw() instead of only on init().

Previously we only checked orientation on AppPairIcon.inflateIcon(), and the issue was that orientation was not re-checked when pinned Taskbar was rotated to different sides of the screen. Added a DeviceProfileListener to update orientation when DP changes.

Fixes: 323288812
Flag: ACONFIG com.android.wm.shell.enable_app_pairs TRUNKFOOD
Test: Manual, app pair icon always has correct otientation on pinned taskbar
Change-Id: If2de1a4c7334fef1ba4c2edcca09bef9338bc73f
Merged-In: If2de1a4c7334fef1ba4c2edcca09bef9338bc73f
(cherry picked from commit 999ab5215a)
This commit is contained in:
Jeremy Sim
2024-02-28 18:32:00 -08:00
committed by Winson Chung
parent 7c8b31d2d7
commit eac4f16646
2 changed files with 32 additions and 5 deletions
@@ -103,7 +103,7 @@ public class AppPairIcon extends FrameLayout implements DraggableView, Reorderab
// Set up icon drawable area
icon.mIconGraphic = icon.findViewById(R.id.app_pair_icon_graphic);
icon.mIconGraphic.init(activity.getDeviceProfile(), icon);
icon.mIconGraphic.init(activity, icon);
// Set up app pair title
icon.mAppPairName = icon.findViewById(R.id.app_pair_icon_name);
@@ -25,17 +25,19 @@ import android.util.Log
import android.view.Gravity
import android.widget.FrameLayout
import com.android.launcher3.DeviceProfile
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener
import com.android.launcher3.icons.BitmapInfo
import com.android.launcher3.icons.PlaceHolderIconDrawable
import com.android.launcher3.model.data.WorkspaceItemInfo
import com.android.launcher3.util.Themes
import com.android.launcher3.views.ActivityContext
/**
* A FrameLayout marking the area on an [AppPairIcon] where the visual icon will be drawn. One of
* two child UI elements on an [AppPairIcon], along with a BubbleTextView holding the text title.
*/
class AppPairIconGraphic @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
FrameLayout(context, attrs) {
FrameLayout(context, attrs), OnDeviceProfileChangeListener {
private val TAG = "AppPairIconGraphic"
companion object {
@@ -69,14 +71,17 @@ class AppPairIconGraphic @JvmOverloads constructor(context: Context, attrs: Attr
// The app pairs icon appears differently in portrait and landscape.
var isLeftRightSplit = false
private lateinit var activityContext: ActivityContext
private lateinit var parentIcon: AppPairIcon
private lateinit var appPairBackground: Drawable
private var appIcon1: Drawable? = null
private var appIcon2: Drawable? = null
fun init(grid: DeviceProfile, icon: AppPairIcon) {
fun init(activity: ActivityContext, icon: AppPairIcon) {
activityContext = activity
// Calculate device-specific measurements
val defaultIconSize = grid.iconSizePx
val defaultIconSize = activity.deviceProfile.iconSizePx
outerPadding = OUTER_PADDING_SCALE * defaultIconSize
innerPadding = INNER_PADDING_SCALE * defaultIconSize
backgroundSize = defaultIconSize - outerPadding * 2
@@ -84,8 +89,8 @@ class AppPairIconGraphic @JvmOverloads constructor(context: Context, attrs: Attr
centerChannelSize = CENTER_CHANNEL_SCALE * defaultIconSize
bigRadius = BIG_RADIUS_SCALE * defaultIconSize
smallRadius = SMALL_RADIUS_SCALE * defaultIconSize
isLeftRightSplit = grid.isLeftRightSplit
parentIcon = icon
updateOrientation()
appPairBackground = AppPairIconBackground(context, this)
appPairBackground.setBounds(0, 0, backgroundSize.toInt(), backgroundSize.toInt())
@@ -100,6 +105,28 @@ class AppPairIconGraphic @JvmOverloads constructor(context: Context, attrs: Attr
layoutParams = lp
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
activityContext.addOnDeviceProfileChangeListener(this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
activityContext.removeOnDeviceProfileChangeListener(this)
}
/** Checks the device orientation and updates isLeftRightSplit accordingly. */
private fun updateOrientation() {
val activity: ActivityContext = ActivityContext.lookupContext(context)
isLeftRightSplit = activity.deviceProfile.isLeftRightSplit
}
/** When device profile changes, update orientation */
override fun onDeviceProfileChanged(dp: DeviceProfile?) {
updateOrientation()
invalidate()
}
/** Sets up app pair member icons for drawing. */
private fun applyIcons(contents: ArrayList<WorkspaceItemInfo>) {
// App pair should always contain 2 members; if not 2, return to avoid a crash loop