Merge "Fix bug with app pairs appearing in wrong orientation in pinned Taskbar" into main
diff --git a/src/com/android/launcher3/apppairs/AppPairIcon.java b/src/com/android/launcher3/apppairs/AppPairIcon.java
index c11193a..13fefc4 100644
--- a/src/com/android/launcher3/apppairs/AppPairIcon.java
+++ b/src/com/android/launcher3/apppairs/AppPairIcon.java
@@ -101,7 +101,7 @@
// 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();
diff --git a/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt b/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt
index c12aa0c..777831b 100644
--- a/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt
+++ b/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt
@@ -25,17 +25,19 @@
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 @@
// 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 @@
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 @@
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