Merge "Radio buttons belong in a radio group." into nyc-dev am: d05a7b5972
am: 88470b5ba2
* commit '88470b5ba2aeb38ff5d8d25b17b9897ed1efa5cd':
Radio buttons belong in a radio group.
Change-Id: I17cbb329efa9cb1fc7a3a229cd523ce0abab852f
This commit is contained in:
29
packages/SystemUI/res/layout/zen_mode_button.xml
Normal file
29
packages/SystemUI/res/layout/zen_mode_button.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2016 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.
|
||||||
|
-->
|
||||||
|
<RadioButton
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@android:id/checkbox"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_marginStart="7dp"
|
||||||
|
android:layout_marginEnd="4dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingTop="10dp"
|
||||||
|
android:paddingBottom="10dp">
|
||||||
|
|
||||||
|
</RadioButton>
|
||||||
@@ -18,18 +18,10 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clipChildren="false"
|
android:clipChildren="false"
|
||||||
android:layout_marginBottom="@dimen/zen_mode_condition_detail_item_spacing"
|
|
||||||
android:layout_marginStart="1dp"
|
android:layout_marginStart="1dp"
|
||||||
android:layout_marginEnd="0dp" >
|
android:layout_marginEnd="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
<RadioButton
|
android:gravity="center_vertical" >
|
||||||
android:id="@android:id/checkbox"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_marginStart="7dp"
|
|
||||||
android:layout_marginEnd="4dp"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:gravity="center" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@android:id/content"
|
android:id="@android:id/content"
|
||||||
|
|||||||
@@ -94,9 +94,18 @@
|
|||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="4dp"
|
android:layout_marginEnd="4dp"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:orientation="vertical"
|
android:paddingBottom="@dimen/zen_mode_condition_detail_bottom_padding"
|
||||||
android:paddingBottom="@dimen/zen_mode_condition_detail_bottom_padding" />
|
android:orientation="horizontal" >
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/zen_radio_buttons"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/zen_radio_buttons_content"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/zen_alarm_warning"
|
android:id="@+id/zen_alarm_warning"
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
@@ -102,6 +103,8 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
private TextView mZenIntroductionCustomize;
|
private TextView mZenIntroductionCustomize;
|
||||||
protected LinearLayout mZenConditions;
|
protected LinearLayout mZenConditions;
|
||||||
private TextView mZenAlarmWarning;
|
private TextView mZenAlarmWarning;
|
||||||
|
private RadioGroup mZenRadioGroup;
|
||||||
|
private LinearLayout mZenRadioGroupContent;
|
||||||
|
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private ZenModeController mController;
|
private ZenModeController mController;
|
||||||
@@ -117,7 +120,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
private Condition mSessionExitCondition;
|
private Condition mSessionExitCondition;
|
||||||
private Condition[] mConditions;
|
private Condition[] mConditions;
|
||||||
private Condition mTimeCondition;
|
private Condition mTimeCondition;
|
||||||
private Condition mTimeUntilAlarmCondition;
|
|
||||||
private boolean mVoiceCapable;
|
private boolean mVoiceCapable;
|
||||||
|
|
||||||
public ZenModePanel(Context context, AttributeSet attrs) {
|
public ZenModePanel(Context context, AttributeSet attrs) {
|
||||||
@@ -190,6 +192,8 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
|
|
||||||
mZenConditions = (LinearLayout) findViewById(R.id.zen_conditions);
|
mZenConditions = (LinearLayout) findViewById(R.id.zen_conditions);
|
||||||
mZenAlarmWarning = (TextView) findViewById(R.id.zen_alarm_warning);
|
mZenAlarmWarning = (TextView) findViewById(R.id.zen_alarm_warning);
|
||||||
|
mZenRadioGroup = (RadioGroup) findViewById(R.id.zen_radio_buttons);
|
||||||
|
mZenRadioGroupContent = (LinearLayout) findViewById(R.id.zen_radio_buttons_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -309,7 +313,12 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
|
|
||||||
protected void addZenConditions(int count) {
|
protected void addZenConditions(int count) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false));
|
final View rb = mInflater.inflate(R.layout.zen_mode_button, this, false);
|
||||||
|
rb.setId(i);
|
||||||
|
mZenRadioGroup.addView(rb);
|
||||||
|
final View rbc = mInflater.inflate(R.layout.zen_mode_condition, this, false);
|
||||||
|
rbc.setId(i + count);
|
||||||
|
mZenRadioGroupContent.addView(rbc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,7 +397,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
final ConditionTag tag = getConditionTagAt(i);
|
final ConditionTag tag = getConditionTagAt(i);
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
if (sameConditionId(tag.condition, mExitCondition)) {
|
if (sameConditionId(tag.condition, mExitCondition)) {
|
||||||
bind(exitCondition, mZenConditions.getChildAt(i), i);
|
bind(exitCondition, mZenRadioGroupContent.getChildAt(i), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -484,11 +493,11 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
final int conditionCount = mConditions == null ? 0 : mConditions.length;
|
final int conditionCount = mConditions == null ? 0 : mConditions.length;
|
||||||
if (DEBUG) Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount);
|
if (DEBUG) Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount);
|
||||||
// forever
|
// forever
|
||||||
bind(forever(), mZenConditions.getChildAt(FOREVER_CONDITION_INDEX),
|
bind(forever(), mZenRadioGroupContent.getChildAt(FOREVER_CONDITION_INDEX),
|
||||||
FOREVER_CONDITION_INDEX);
|
FOREVER_CONDITION_INDEX);
|
||||||
// countdown
|
// countdown
|
||||||
if (mCountdownConditionSupported && mTimeCondition != null) {
|
if (mCountdownConditionSupported && mTimeCondition != null) {
|
||||||
bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX),
|
bind(mTimeCondition, mZenRadioGroupContent.getChildAt(COUNTDOWN_CONDITION_INDEX),
|
||||||
COUNTDOWN_CONDITION_INDEX);
|
COUNTDOWN_CONDITION_INDEX);
|
||||||
}
|
}
|
||||||
// countdown until alarm
|
// countdown until alarm
|
||||||
@@ -496,7 +505,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
Condition nextAlarmCondition = getTimeUntilNextAlarmCondition();
|
Condition nextAlarmCondition = getTimeUntilNextAlarmCondition();
|
||||||
if (nextAlarmCondition != null) {
|
if (nextAlarmCondition != null) {
|
||||||
bind(nextAlarmCondition,
|
bind(nextAlarmCondition,
|
||||||
mZenConditions.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX),
|
mZenRadioGroupContent.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX),
|
||||||
COUNTDOWN_ALARM_CONDITION_INDEX);
|
COUNTDOWN_ALARM_CONDITION_INDEX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,22 +553,22 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ConditionTag getConditionTagAt(int index) {
|
private ConditionTag getConditionTagAt(int index) {
|
||||||
return (ConditionTag) mZenConditions.getChildAt(index).getTag();
|
return (ConditionTag) mZenRadioGroupContent.getChildAt(index).getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getVisibleConditions() {
|
private int getVisibleConditions() {
|
||||||
int rt = 0;
|
int rt = 0;
|
||||||
final int N = mZenConditions.getChildCount();
|
final int N = mZenRadioGroupContent.getChildCount();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
rt += mZenConditions.getChildAt(i).getVisibility() == VISIBLE ? 1 : 0;
|
rt += mZenRadioGroupContent.getChildAt(i).getVisibility() == VISIBLE ? 1 : 0;
|
||||||
}
|
}
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideAllConditions() {
|
private void hideAllConditions() {
|
||||||
final int N = mZenConditions.getChildCount();
|
final int N = mZenRadioGroupContent.getChildCount();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
mZenConditions.getChildAt(i).setVisibility(GONE);
|
mZenRadioGroupContent.getChildAt(i).setVisibility(GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,27 +588,14 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
if (DEBUG) Log.d(mTag, "Selecting a default");
|
if (DEBUG) Log.d(mTag, "Selecting a default");
|
||||||
final int favoriteIndex = mPrefs.getMinuteIndex();
|
final int favoriteIndex = mPrefs.getMinuteIndex();
|
||||||
if (favoriteIndex == -1 || !mCountdownConditionSupported) {
|
if (favoriteIndex == -1 || !mCountdownConditionSupported) {
|
||||||
setChecked(foreverTag.rb, true);
|
foreverTag.rb.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
mTimeCondition = ZenModeConfig.toTimeCondition(mContext,
|
mTimeCondition = ZenModeConfig.toTimeCondition(mContext,
|
||||||
MINUTE_BUCKETS[favoriteIndex], ActivityManager.getCurrentUser());
|
MINUTE_BUCKETS[favoriteIndex], ActivityManager.getCurrentUser());
|
||||||
mBucketIndex = favoriteIndex;
|
mBucketIndex = favoriteIndex;
|
||||||
bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX),
|
bind(mTimeCondition, mZenRadioGroupContent.getChildAt(COUNTDOWN_CONDITION_INDEX),
|
||||||
COUNTDOWN_CONDITION_INDEX);
|
COUNTDOWN_CONDITION_INDEX);
|
||||||
setChecked(getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb, true);
|
getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.setChecked(true);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setChecked(RadioButton rb, boolean checked) {
|
|
||||||
final int N = getVisibleConditions();
|
|
||||||
for (int i = 0; i < N; i++) {
|
|
||||||
final ConditionTag tag = getConditionTagAt(i);
|
|
||||||
if (tag != null && tag.rb.isChecked() && !Objects.equals(tag.rb, rb)) {
|
|
||||||
tag.rb.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rb.isChecked() != checked) {
|
|
||||||
rb.setChecked(checked);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,18 +615,18 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
row.setTag(tag);
|
row.setTag(tag);
|
||||||
final boolean first = tag.rb == null;
|
final boolean first = tag.rb == null;
|
||||||
if (tag.rb == null) {
|
if (tag.rb == null) {
|
||||||
tag.rb = (RadioButton) row.findViewById(android.R.id.checkbox);
|
tag.rb = (RadioButton) mZenRadioGroup.getChildAt(rowId);
|
||||||
}
|
}
|
||||||
tag.condition = condition;
|
tag.condition = condition;
|
||||||
final Uri conditionId = getConditionId(tag.condition);
|
final Uri conditionId = getConditionId(tag.condition);
|
||||||
if (DEBUG) Log.d(mTag, "bind i=" + mZenConditions.indexOfChild(row) + " first=" + first
|
if (DEBUG) Log.d(mTag, "bind i=" + mZenRadioGroupContent.indexOfChild(row) + " first="
|
||||||
+ " condition=" + conditionId);
|
+ first + " condition=" + conditionId);
|
||||||
tag.rb.setEnabled(enabled);
|
tag.rb.setEnabled(enabled);
|
||||||
tag.rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
tag.rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (mExpanded && isChecked) {
|
if (mExpanded && isChecked) {
|
||||||
setChecked(tag.rb, isChecked);
|
tag.rb.setChecked(true);
|
||||||
if (DEBUG) Log.d(mTag, "onCheckedChanged " + conditionId);
|
if (DEBUG) Log.d(mTag, "onCheckedChanged " + conditionId);
|
||||||
MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT);
|
MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT);
|
||||||
select(tag.condition);
|
select(tag.condition);
|
||||||
@@ -681,7 +677,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
tag.lines.setOnClickListener(new OnClickListener() {
|
tag.lines.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
setChecked(tag.rb, true);
|
tag.rb.setChecked(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -770,7 +766,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
}
|
}
|
||||||
mTimeCondition = newCondition;
|
mTimeCondition = newCondition;
|
||||||
bind(mTimeCondition, row, rowId);
|
bind(mTimeCondition, row, rowId);
|
||||||
setChecked(tag.rb, true);
|
tag.rb.setChecked(true);
|
||||||
select(mTimeCondition);
|
select(mTimeCondition);
|
||||||
announceConditionSelection(tag);
|
announceConditionSelection(tag);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user