Merge "Support accessibility shorcut secondary action (1/n)"

This commit is contained in:
Kevin Chang
2019-12-06 01:52:28 +00:00
committed by Android (Google) Code Review
5 changed files with 315 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2019 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp" >
<path
android:fillColor="#757575"
android:pathData="M20.41,4.94l-1.35,-1.35c-0.78,-0.78 -2.05,-0.78 -2.83,0L13.4,6.41 3,16.82L3,21h4.18l10.46,-10.46 2.77,-2.77c0.79,-0.78 0.79,-2.05 0,-2.83zM6.41,19.06L5,19v-1.36l9.82,-9.82 1.41,1.41 -9.82,9.83z"/>
</vector>

View File

@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 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
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:clipToPadding="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:gravity="start|center_vertical"
android:clipToPadding="false"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start|center_vertical"
android:minWidth="56dp"
android:orientation="horizontal"
android:clipToPadding="false"
android:paddingRight="16dp"
android:paddingTop="4dp"
android:paddingBottom="4dp">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee" />
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+android:id/title"
android:layout_alignStart="@+android:id/title"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="10" />
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="start|center_vertical"
android:orientation="horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="?android:attr/listDivider" />
</FrameLayout>
<!-- Preference should place its actual preference widget here. -->
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="64dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/settings_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingStart="?android:attr/listPreferredItemPaddingEnd"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/selectableItemBackground"
android:scaleType="center"
android:src="@drawable/ic_mode_edit"
android:contentDescription="@string/settings_button" />
</FrameLayout>
</LinearLayout>

View File

@@ -4856,6 +4856,14 @@
<string name="accessibility_caption_master_switch_title">Use captions</string>
<!-- Used in the Captions preference to tell users that the setting doesn't support all apps. [CHAR LIMIT=NONE] -->
<string name="accessibility_caption_preference_summary">Not all apps support this setting.</string>
<!-- Summary for accessibility shortcut preference for software shortcut type. [CHAR LIMIT=NONE] -->
<string name="accessibility_shortcut_type_software">Accessibility button</string>
<!-- Summary for accessibility shortcut preference for software shortcut type when gesture mode is on. [CHAR LIMIT=NONE] -->
<string name="accessibility_shortcut_type_software_gesture">2-finger swipe up from bottom</string>
<!-- Summary for accessibility shortcut preference for hardware shortcut type. [CHAR LIMIT=NONE] -->
<string name="accessibility_shortcut_type_hardware">Hold volume keys</string>
<!-- Summary for accessibility shortcut preference for magnification triple tap shortcut type. [CHAR LIMIT=NONE] -->
<string name="accessibility_shortcut_type_triple_tap">Triple tap screen</string>
<!-- Button text for the accessibility dialog continue to the next screen for hearing aid. [CHAR LIMIT=32] -->
<string name="accessibility_hearingaid_instruction_continue_button">Continue</string>

View File

@@ -0,0 +1,108 @@
/*
* Copyright (C) 2019 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.settings.accessibility;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
/**
* Preference that can enable accessibility shortcut and let users choose which shortcut type they
* prefer to use.
*/
public class ShortcutPreference extends Preference {
private View.OnClickListener mCheckBoxListener;
private View.OnClickListener mSettingButtonListener;
private boolean mChecked = false;
ShortcutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.accessibility_shortcut_secondary_action);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.itemView.setClickable(false);
final CheckBox checkBox = holder.itemView.findViewById(R.id.checkbox);
checkBox.setOnClickListener(mCheckBoxListener);
checkBox.setChecked(mChecked);
final View settingButton = holder.itemView.findViewById(R.id.settings_button);
settingButton.setOnClickListener(mSettingButtonListener);
}
/**
* Set the shortcut checkbox according to checked value.
*
* @param checked the state value of shortcut checkbox.
*/
public void setChecked(boolean checked) {
if (checked != mChecked) {
mChecked = checked;
notifyChanged();
}
}
/**
* Set the given onClickListener to the SettingButtonListener.
*
* @param listener the given onClickListener.
*/
public void setSettingButtonListener(@Nullable View.OnClickListener listener) {
mSettingButtonListener = listener;
notifyChanged();
}
/**
* Returns the callback to be invoked when the setting button is clicked.
*
* @return The callback to be invoked
*/
public View.OnClickListener getSettingButtonListener() {
return mSettingButtonListener;
}
/**
* Set the given onClickListener to the CheckBoxListener.
*
* @param listener the given onClickListener.
*/
public void setCheckBoxListener(@Nullable View.OnClickListener listener) {
mCheckBoxListener = listener;
notifyChanged();
}
/**
* Returns the callback to be invoked when the checkbox is clicked.
*
* @return The callback to be invoked
*/
public View.OnClickListener getCheckBoxListener() {
return mCheckBoxListener;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2019 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.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.view.View;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
/** Tests for {@link ShortcutPreference} */
@RunWith(RobolectricTestRunner.class)
public class ShortcutPreferenceTest {
private ShortcutPreference mShortcutPreference;
private View.OnClickListener mSettingButtonListener;
private View.OnClickListener mCheckBoxListener;
@Before
public void setUp() {
final Context mContext = RuntimeEnvironment.application;
mShortcutPreference = new ShortcutPreference(mContext, null);
}
@Test
public void setOnClickListeners_shouldSetListeners() {
mShortcutPreference.setSettingButtonListener(mSettingButtonListener);
mShortcutPreference.setCheckBoxListener(mCheckBoxListener);
assertThat(mShortcutPreference.getCheckBoxListener()).isEqualTo(mCheckBoxListener);
assertThat(mShortcutPreference.getSettingButtonListener()).isEqualTo(
mSettingButtonListener);
}
}