Merge "[Settings] Allow talkback to focus and select APN"

This commit is contained in:
Bonian Chen
2020-08-03 05:25:43 +00:00
committed by Gerrit Code Review
2 changed files with 41 additions and 17 deletions

View File

@@ -4,9 +4,9 @@
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,6 +21,7 @@
android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:minHeight="?android:attr/listPreferredItemHeight" android:minHeight="?android:attr/listPreferredItemHeight"
android:focusable="false"
android:gravity="center_vertical"> android:gravity="center_vertical">
<RelativeLayout <RelativeLayout
@@ -30,13 +31,14 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_weight="1" android:layout_weight="1"
android:focusable="true" android:focusable="true"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"> android:background="?android:attr/selectableItemBackground">
<TextView <TextView
android:id="@android:id/title" android:id="@android:id/title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="true" android:focusable="false"
android:singleLine="true" android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem" /> android:textAppearance="?android:attr/textAppearanceListItem" />
@@ -48,6 +50,7 @@
android:layout_alignStart="@android:id/title" android:layout_alignStart="@android:id/title"
android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:focusable="false"
android:maxLines="2" /> android:maxLines="2" />
</RelativeLayout> </RelativeLayout>
@@ -59,6 +62,7 @@
android:layout_marginStart="8dip" android:layout_marginStart="8dip"
android:layout_marginEnd="8dip" android:layout_marginEnd="8dip"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:focusable="true"
android:clickable="true" /> android:clickable="true" />
</LinearLayout> </LinearLayout>

View File

@@ -27,6 +27,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Toast; import android.widget.Toast;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -34,19 +35,32 @@ import androidx.preference.PreferenceViewHolder;
import com.android.settings.R; import com.android.settings.R;
public class ApnPreference extends Preference implements CompoundButton.OnCheckedChangeListener { /**
* Preference of APN UI entry
*/
public class ApnPreference extends Preference implements CompoundButton.OnCheckedChangeListener,
View.OnClickListener {
final static String TAG = "ApnPreference"; final static String TAG = "ApnPreference";
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
/**
* Constructor of Preference
*/
public ApnPreference(Context context, AttributeSet attrs, int defStyle) { public ApnPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
} }
/**
* Constructor of Preference
*/
public ApnPreference(Context context, AttributeSet attrs) { public ApnPreference(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.apnPreferenceStyle); this(context, attrs, R.attr.apnPreferenceStyle);
} }
/**
* Constructor of Preference
*/
public ApnPreference(Context context) { public ApnPreference(Context context) {
this(context, null); this(context, null);
} }
@@ -61,6 +75,9 @@ public class ApnPreference extends Preference implements CompoundButton.OnChecke
public void onBindViewHolder(PreferenceViewHolder view) { public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view); super.onBindViewHolder(view);
final RelativeLayout textArea = (RelativeLayout) view.findViewById(R.id.text_layout);
textArea.setOnClickListener(this);
final View widget = view.findViewById(R.id.apn_radiobutton); final View widget = view.findViewById(R.id.apn_radiobutton);
if ((widget != null) && widget instanceof RadioButton) { if ((widget != null) && widget instanceof RadioButton) {
final RadioButton rb = (RadioButton) widget; final RadioButton rb = (RadioButton) widget;
@@ -111,22 +128,25 @@ public class ApnPreference extends Preference implements CompoundButton.OnChecke
} }
@Override @Override
protected void onClick() { public void onClick(View layoutView) {
super.onClick(); super.onClick();
final Context context = getContext(); final Context context = getContext();
if (context != null) { final int pos = Integer.parseInt(getKey());
if (mHideDetails) { if (context == null) {
Toast.makeText(context, context.getString( Log.w(TAG, "No context available for pos=" + pos);
R.string.cannot_change_apn_toast), Toast.LENGTH_LONG).show(); return;
return;
}
final int pos = Integer.parseInt(getKey());
final Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
final Intent editIntent = new Intent(Intent.ACTION_EDIT, url);
editIntent.putExtra(ApnSettings.SUB_ID, mSubId);
editIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(editIntent);
} }
if (mHideDetails) {
Toast.makeText(context, context.getString(
R.string.cannot_change_apn_toast), Toast.LENGTH_LONG).show();
return;
}
final Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
final Intent editIntent = new Intent(Intent.ACTION_EDIT, url);
editIntent.putExtra(ApnSettings.SUB_ID, mSubId);
editIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(editIntent);
} }
public void setSelectable(boolean selectable) { public void setSelectable(boolean selectable) {