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

Commit 640b589a authored by Fabian Kozynski's avatar Fabian Kozynski Committed by android-build-merger
Browse files

Merge "Fix RTL in QS Header Info" into qt-dev am: 769dd9f0

am: a8e40d37

Change-Id: I16d4653ed41dac861ef539885b6de649960c3f74
parents 43c48748 a8e40d37
Loading
Loading
Loading
Loading
+1 −4
Original line number Original line Diff line number Diff line
@@ -27,14 +27,12 @@
            android:id="@+id/status_container"
            android:id="@+id/status_container"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:layout_height="match_parent">
            android:gravity="start" >


            <LinearLayout
            <LinearLayout
                android:id = "@+id/alarm_container"
                android:id = "@+id/alarm_container"
                android:layout_width="wrap_content"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"
                android:gravity="center_vertical"
                android:focusable="true"
                android:focusable="true"
                android:clickable="true">
                android:clickable="true">
@@ -69,7 +67,6 @@
                android:id = "@+id/ringer_container"
                android:id = "@+id/ringer_container"
                android:layout_width="wrap_content"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"
                android:gravity="center_vertical"
                android:focusable="true"
                android:focusable="true"
                android:clickable="true">
                android:clickable="true">
+32 −24
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ class QSHeaderInfoLayout @JvmOverloads constructor(
    private lateinit var alarmContainer: View
    private lateinit var alarmContainer: View
    private lateinit var ringerContainer: View
    private lateinit var ringerContainer: View
    private lateinit var statusSeparator: View
    private lateinit var statusSeparator: View
    private val location = Location(0, 0)


    override fun onFinishInflate() {
    override fun onFinishInflate() {
        super.onFinishInflate()
        super.onFinishInflate()
@@ -53,31 +54,21 @@ class QSHeaderInfoLayout @JvmOverloads constructor(
        // At most one view is there
        // At most one view is there
        if (statusSeparator.visibility == View.GONE) super.onLayout(changed, l, t, r, b)
        if (statusSeparator.visibility == View.GONE) super.onLayout(changed, l, t, r, b)
        else {
        else {
            val alarmWidth = alarmContainer.measuredWidth
            val layoutRTL = isLayoutRtl
            val separatorWidth = statusSeparator.measuredWidth
            val width = r - l
            val ringerWidth = ringerContainer.measuredWidth
            val height = b - t
            val availableSpace = (r - l) - separatorWidth
            var offset = 0
            var left = l

            if (alarmWidth < availableSpace / 2) {
            offset += alarmContainer.layoutView(width, height, offset, layoutRTL)
                alarmContainer.layout(left, t, left + alarmWidth, b)
            offset += statusSeparator.layoutView(width, height, offset, layoutRTL)
                left += alarmWidth
            ringerContainer.layoutView(width, height, offset, layoutRTL)
                statusSeparator.layout(left, t, left + separatorWidth, b)
                left += separatorWidth
                ringerContainer.layout(left, t, left + Math.min(ringerWidth, r - left), b)
            } else if (ringerWidth < availableSpace / 2) {
                val alarmAllocation = Math.min(availableSpace - ringerWidth, alarmWidth)
                alarmContainer.layout(left, t, left + alarmAllocation, b)
                left += alarmWidth
                statusSeparator.layout(left, t, left + separatorWidth, b)
                left += separatorWidth
                ringerContainer.layout(left, t, left + ringerWidth, b)
            } else {
                alarmContainer.layout(left, t, left + availableSpace / 2, b)
                left += availableSpace / 2
                statusSeparator.layout(left, t, left + separatorWidth, b)
                ringerContainer.layout(r - availableSpace / 2, t, r, b)
        }
        }
    }
    }

    private fun View.layoutView(pWidth: Int, pHeight: Int, offset: Int, RTL: Boolean): Int {
        location.setLocationFromOffset(pWidth, offset, this.measuredWidth, RTL)
        layout(location.left, 0, location.right, pHeight)
        return this.measuredWidth
    }
    }


    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
@@ -120,4 +111,21 @@ class QSHeaderInfoLayout @JvmOverloads constructor(
        }
        }
        setMeasuredDimension(width, measuredHeight)
        setMeasuredDimension(width, measuredHeight)
    }
    }

    private data class Location(var left: Int, var right: Int) {
        /**
         * Sets the [left] and [right] with the correct values for laying out the child, respecting
         * RTL. Only set the variable through here to prevent concurrency issues.
         * This is done to prevent allocation of [Pair] in [onLayout].
         */
        fun setLocationFromOffset(parentWidth: Int, offset: Int, width: Int, RTL: Boolean) {
            if (RTL) {
                left = parentWidth - offset - width
                right = parentWidth - offset
            } else {
                left = offset
                right = offset + width
            }
        }
    }
}
}
 No newline at end of file