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

Commit ac58e858 authored by Jason Monk's avatar Jason Monk Committed by android-build-merger
Browse files

Merge "Fix QS DND Radio alignment ONCE AND FOR ALL" into oc-dr1-dev

am: a5e3249b

Change-Id: Id4a3373bbb6006a0f31e99e74de4c810b84b3afa
parents df33967d a5e3249b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@
        android:id="@android:id/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="48dp"
        android:gravity="center_vertical"
        android:layout_centerVertical="true"
        android:orientation="vertical"
        android:layout_toEndOf="@android:id/checkbox"
+2 −2
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@

        </RelativeLayout>

        <LinearLayout
        <com.android.systemui.volume.ZenRadioLayout
            android:id="@+id/zen_conditions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
@@ -111,7 +111,7 @@
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"/>
        </LinearLayout>
        </com.android.systemui.volume.ZenRadioLayout>

        <TextView
            android:id="@+id/zen_alarm_warning"
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package com.android.systemui.volume;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

/**
 * Specialized layout for zen mode that allows the radio buttons to reside within
 * a RadioGroup, but also makes sure that all the heights off the radio buttons align
 * with the corresponding content in the second child of this view.
 */
public class ZenRadioLayout extends LinearLayout {

    public ZenRadioLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * Run 2 measurement passes, 1 that figures out the size of the content, and another
     * that sets the size of the radio buttons to the heights of the corresponding content.
     */
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        ViewGroup radioGroup = (ViewGroup) getChildAt(0);
        ViewGroup radioContent = (ViewGroup) getChildAt(1);
        int size = radioGroup.getChildCount();
        if (size != radioContent.getChildCount()) {
            throw new IllegalStateException("Expected matching children");
        }
        boolean hasChanges = false;
        for (int i = 0; i < size; i++) {
            View radio = radioGroup.getChildAt(i);
            View content = radioContent.getChildAt(i);
            if (radio.getLayoutParams().height != content.getMeasuredHeight()) {
                hasChanges = true;
                radio.getLayoutParams().height = content.getMeasuredHeight();
            }
        }
        // Measure again if any heights changed.
        if (hasChanges) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
}