Merge "Clean up tts preference layout." into qt-dev

This commit is contained in:
TreeHugger Robot
2019-04-05 23:36:07 +00:00
committed by Android (Google) Code Review
3 changed files with 17 additions and 61 deletions

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 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="?android:attr/listPreferredItemHeight"
android:paddingStart="@dimen/preference_no_icon_padding_start"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:layout_gravity="center_vertical">
<RadioButton
android:id="@+id/tts_engine_radiobutton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:layout_weight="1"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee"/>
</LinearLayout>

View File

@@ -18,7 +18,6 @@ package com.android.settings.tts;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.speech.tts.TextToSpeech.EngineInfo;
import android.util.Log;
import android.widget.Checkable;
@@ -30,7 +29,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
public class TtsEnginePreference extends Preference {
@@ -54,9 +52,6 @@ public class TtsEnginePreference extends Preference {
*/
private volatile boolean mPreventRadioButtonCallbacks;
private RadioButton mRadioButton;
private Intent mVoiceCheckData;
private final CompoundButton.OnCheckedChangeListener mRadioChangeListener =
new CompoundButton.OnCheckedChangeListener() {
@Override
@@ -65,10 +60,12 @@ public class TtsEnginePreference extends Preference {
}
};
public TtsEnginePreference(Context context, EngineInfo info, RadioButtonGroupState state,
SettingsActivity prefActivity) {
public TtsEnginePreference(Context context, EngineInfo info, RadioButtonGroupState state) {
super(context);
setLayoutResource(R.layout.preference_tts_engine);
setWidgetLayoutResource(R.layout.preference_widget_radiobutton);
setLayoutResource(R.layout.preference_radio);
setIconSpaceReserved(false);
mSharedState = state;
mEngineInfo = info;
@@ -87,9 +84,8 @@ public class TtsEnginePreference extends Preference {
"setSharedState()");
}
final RadioButton rb = (RadioButton) view.findViewById(R.id.tts_engine_radiobutton);
final RadioButton rb = view.itemView.findViewById(android.R.id.checkbox);
rb.setOnCheckedChangeListener(mRadioChangeListener);
rb.setText(mEngineInfo.label);
boolean isChecked = getKey().equals(mSharedState.getCurrentKey());
if (isChecked) {
@@ -99,12 +95,6 @@ public class TtsEnginePreference extends Preference {
mPreventRadioButtonCallbacks = true;
rb.setChecked(isChecked);
mPreventRadioButtonCallbacks = false;
mRadioButton = rb;
}
public void setVoiceDataDetails(Intent data) {
mVoiceCheckData = data;
}
private boolean shouldDisplayDataAlert() {
@@ -145,7 +135,7 @@ public class TtsEnginePreference extends Preference {
public void onClick(DialogInterface dialog, int which) {
makeCurrentEngine(buttonView);
}
},new DialogInterface.OnClickListener() {
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Undo the click.
@@ -176,9 +166,11 @@ public class TtsEnginePreference extends Preference {
*/
public interface RadioButtonGroupState {
String getCurrentKey();
Checkable getCurrentChecked();
void setCurrentKey(String key);
void setCurrentChecked(Checkable current);
}

View File

@@ -15,7 +15,6 @@ import android.widget.Checkable;
import androidx.preference.PreferenceCategory;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -87,12 +86,10 @@ public class TtsEnginePreferenceFragment extends SettingsPreferenceFragment
mEnginePreferenceCategory.removeAll();
SettingsActivity activity = (SettingsActivity) getActivity();
List<EngineInfo> engines = mEnginesHelper.getEngines();
for (EngineInfo engine : engines) {
TtsEnginePreference enginePref =
new TtsEnginePreference(getPrefContext(), engine, this, activity);
new TtsEnginePreference(getPrefContext(), engine, this);
mEnginePreferenceCategory.addPreference(enginePref);
}
}
@@ -161,6 +158,7 @@ public class TtsEnginePreferenceFragment extends SettingsPreferenceFragment
public void onUpdateEngine(int status) {
if (status == TextToSpeech.SUCCESS) {
Log.d(
TAG,
"Updating engine: Successfully bound to the engine: "
+ mTts.getCurrentEngine());