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

Commit 255568ed authored by Matías Hernández's avatar Matías Hernández
Browse files

Simplify enable DND / choose DND QS duration dialogs to use proper RadioButtons

Instead of a complex layout (one RadioButton plus two TextViews per option) so that the options could have two lines of text. The same can be achieved with a Spanned text in the RadioButton, which removes the unnecessary double a11y focus targets (and simplifies the code significantly).

It also looks nicer (better aligned and and no longer truncates the text) at very high font sizes.

Fixes: 422065897
Fixes: 380493533
Test: atest DndDurationDialogFactoryTest EnableDndDialogFactoryTest + manual with Talkback + manual with max and min font size
Flag: EXEMPT Simple bugfix
Change-Id: Id691921484544ae28a97004f1434793bb2745be3
parent 8d0e4de2
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
@@ -14,50 +14,16 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:clipChildren="false"
    android:layout_marginStart="1dp"
    android:layout_marginEnd="0dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:gravity="center_vertical" >

    <LinearLayout
        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"
        android:layout_toStartOf="@android:id/button1">

        <TextView
            android:id="@android:id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:textAlignment="viewStart"
            android:maxLines="1"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="16sp"/>

        <TextView
            android:id="@android:id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/zen_mode_condition_detail_item_interline_spacing"
            android:ellipsize="end"
            android:textAlignment="viewStart"
            android:maxLines="1"
            android:scrollbars="none"
            android:textColor="?android:attr/textColorSecondary"
            android:textSize="14sp"/>

    </LinearLayout>

    <ImageView
        android:id="@android:id/button1"
        style="@style/BorderlessButton"
@@ -65,7 +31,6 @@
        android:layout_height="48dp"
        android:layout_centerVertical="true"
        android:scaleType="center"
        android:layout_toStartOf="@android:id/button2"
        android:contentDescription="@string/accessibility_manual_zen_less_time"
        android:tint="?android:attr/colorAccent"
        android:src="@*android:drawable/ic_minus" />
@@ -75,11 +40,10 @@
        style="@style/BorderlessButton"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:scaleType="center"
        android:layout_centerVertical="true"
        android:scaleType="center"
        android:contentDescription="@string/accessibility_manual_zen_more_time"
        android:tint="?android:attr/colorAccent"
        android:src="@*android:drawable/ic_plus" />

</RelativeLayout>
</LinearLayout>
+5 −3
Original line number Diff line number Diff line
@@ -39,12 +39,14 @@
            android:orientation="horizontal">
            <RadioGroup
                android:id="@+id/zen_radio_buttons"
                android:layout_width="wrap_content"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content" />
            <LinearLayout
                android:id="@+id/zen_radio_buttons_content"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="end"
                android:orientation="vertical"/>
        </com.android.settingslib.notification.modes.ZenRadioLayout>
    </LinearLayout>
+8 −7
Original line number Diff line number Diff line
@@ -17,13 +17,14 @@
<RadioButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/checkbox"
    android:layout_height="48dp"
    android:layout_width="48dp"
    android:minHeight="48dp"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginStart="7dp"
    android:layout_marginEnd="4dp"
    android:layout_alignParentStart="true"
    android:gravity="center"
    android:paddingTop="10dp"
    android:paddingBottom="10dp">

</RadioButton>
 No newline at end of file
    android:paddingStart="16dp"
    android:textColor="?android:attr/textColorPrimary"
    android:textSize="16sp"
    android:lineSpacingExtra="@dimen/zen_mode_condition_detail_item_interline_spacing"
    android:gravity="center_vertical" />
+5 −3
Original line number Diff line number Diff line
@@ -39,12 +39,14 @@
            android:orientation="horizontal">
            <RadioGroup
                android:id="@+id/zen_radio_buttons"
                android:layout_width="wrap_content"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content" />
            <LinearLayout
                android:id="@+id/zen_radio_buttons_content"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="end"
                android:orientation="vertical"/>
        </com.android.settingslib.notification.modes.ZenRadioLayout>

+8 −49
Original line number Diff line number Diff line
@@ -26,13 +26,11 @@ import android.service.notification.ZenModeConfig;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
@@ -150,7 +148,7 @@ public class DndDurationDialogFactory {
        }
        View contentView = mLayoutInflater.inflate(R.layout.zen_mode_duration_dialog,
                null);
        ScrollView container = (ScrollView) contentView.findViewById(R.id.zen_duration_container);
        ScrollView container = contentView.findViewById(R.id.zen_duration_container);

        mZenRadioGroup = container.findViewById(R.id.zen_radio_buttons);
        mZenRadioGroupContent = container.findViewById(R.id.zen_radio_buttons_content);
@@ -161,10 +159,10 @@ public class DndDurationDialogFactory {
            mZenRadioGroup.addView(radioButton);
            radioButton.setId(i);

            final View radioButtonContent = mLayoutInflater.inflate(R.layout.zen_mode_condition,
                    mZenRadioGroupContent, false);
            radioButtonContent.setId(i + MAX_MANUAL_DND_OPTIONS);
            mZenRadioGroupContent.addView(radioButtonContent);
            final View radioButtonExtraContent = mLayoutInflater.inflate(
                    R.layout.zen_mode_condition_plusminus, mZenRadioGroupContent, false);
            radioButtonExtraContent.setId(i + MAX_MANUAL_DND_OPTIONS);
            mZenRadioGroupContent.addView(radioButtonExtraContent);
        }

        return contentView;
@@ -204,18 +202,6 @@ public class DndDurationDialogFactory {
            tag.countdownZenDuration = currZenDuration;
        }

        tag.rb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    tag.rb.setChecked(true);
                }
                tag.line1.setStateDescription(
                        isChecked ? buttonView.getContext().getString(
                                com.android.internal.R.string.selected) : null);
            }
        });

        updateUi(tag, row, rowIndex);
    }

@@ -224,27 +210,6 @@ public class DndDurationDialogFactory {
        return (ConditionTag) mZenRadioGroupContent.getChildAt(index).getTag();
    }


    private void setupUi(ConditionTag tag, View row) {
        if (tag.lines == null) {
            tag.lines = row.findViewById(android.R.id.content);
        }

        if (tag.line1 == null) {
            tag.line1 = (TextView) row.findViewById(android.R.id.text1);
        }

        // text2 is not used in zen duration dialog
        row.findViewById(android.R.id.text2).setVisibility(View.GONE);

        tag.lines.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tag.rb.setChecked(true);
            }
        });
    }

    private void updateButtons(ConditionTag tag, View row, int rowIndex) {
        final ImageView minusButton = (ImageView) row.findViewById(android.R.id.button1);
        final ImageView plusButton = (ImageView) row.findViewById(android.R.id.button2);
@@ -254,7 +219,7 @@ public class DndDurationDialogFactory {
                @Override
                public void onClick(View v) {
                    onClickTimeButton(row, tag, false /*down*/, rowIndex);
                    tag.lines.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
                    tag.rb.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
                }
            });

@@ -262,7 +227,7 @@ public class DndDurationDialogFactory {
                @Override
                public void onClick(View v) {
                    onClickTimeButton(row, tag, true /*up*/, rowIndex);
                    tag.lines.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
                    tag.rb.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
                }
            });
            minusButton.setVisibility(View.VISIBLE);
@@ -285,10 +250,6 @@ public class DndDurationDialogFactory {

    @VisibleForTesting
    protected void updateUi(ConditionTag tag, View row, int rowIndex) {
        if (tag.lines == null) {
            setupUi(tag, row);
        }

        updateButtons(tag, row, rowIndex);

        String radioContentText = "";
@@ -307,7 +268,7 @@ public class DndDurationDialogFactory {
                break;
        }

        tag.line1.setText(radioContentText);
        tag.rb.setText(radioContentText);
    }

    @VisibleForTesting
@@ -344,8 +305,6 @@ public class DndDurationDialogFactory {
    @VisibleForTesting
    protected static class ConditionTag {
        public RadioButton rb;
        public View lines;
        public TextView line1;
        public int countdownZenDuration; // only important for countdown radio button
    }
}
Loading