Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46aa4a58 authored by Jeremy Sim's avatar Jeremy Sim Committed by Android (Google) Code Review
Browse files

Merge "Fix bug with app pairs appearing in wrong orientation in pinned Taskbar" into main

parents a61e05eb 999ab521
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,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);

        icon.checkDisabledState();

+31 −4
Original line number Diff line number Diff line
@@ -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.FastBitmapDrawable
import com.android.launcher3.icons.FastBitmapDrawable.getDisabledColorFilter
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 {
@@ -66,14 +68,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 lateinit var appIcon1: FastBitmapDrawable
    private lateinit var appIcon2: FastBitmapDrawable

    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
@@ -81,8 +86,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())
@@ -98,6 +103,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. */
    fun applyIcons() {
        val apps = parentIcon.info.contents