Fix radio buttons when user cancel TTS engine change
When user decides to change tts engine, and if it's not system one, then he sees dialog warning about possibility of sending all kinds of data to the engine. If user chooses to not changes engine, radio button still sticks to the new position. This change delays all operations regarding changing current engine after user closes dialog. It also unsets the radio button if user chooses to cancel it. Bug: 7628362 Change-Id: I977abe71b3547f2545a971fc0d69179be6fafb44
This commit is contained in:
committed by
Android (Google) Code Review
parent
4745ccf1ae
commit
820dc4c910
@@ -26,7 +26,6 @@ import com.android.settings.tts.TtsEnginePreference.RadioButtonGroupState;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
@@ -358,27 +357,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
mDefaultRatePref.setEnabled(enable);
|
mDefaultRatePref.setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayDataAlert(final String key) {
|
|
||||||
Log.i(TAG, "Displaying data alert for :" + key);
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
||||||
builder.setTitle(android.R.string.dialog_alert_title);
|
|
||||||
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
|
||||||
builder.setMessage(getActivity().getString(
|
|
||||||
R.string.tts_engine_security_warning, mEnginesHelper.getEngineInfo(key).label));
|
|
||||||
builder.setCancelable(true);
|
|
||||||
builder.setPositiveButton(android.R.string.ok,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
updateDefaultEngine(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(android.R.string.cancel, null);
|
|
||||||
|
|
||||||
AlertDialog dialog = builder.create();
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayNetworkAlert() {
|
private void displayNetworkAlert() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
builder.setTitle(android.R.string.dialog_alert_title);
|
builder.setTitle(android.R.string.dialog_alert_title);
|
||||||
@@ -496,11 +474,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
updateWidgetState(true);
|
updateWidgetState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldDisplayDataAlert(String engine) {
|
|
||||||
final EngineInfo info = mEnginesHelper.getEngineInfo(engine);
|
|
||||||
return !info.system;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Checkable getCurrentChecked() {
|
public Checkable getCurrentChecked() {
|
||||||
return mCurrentChecked;
|
return mCurrentChecked;
|
||||||
@@ -519,11 +492,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void setCurrentKey(String key) {
|
public void setCurrentKey(String key) {
|
||||||
mCurrentEngine = key;
|
mCurrentEngine = key;
|
||||||
if (shouldDisplayDataAlert(mCurrentEngine)) {
|
|
||||||
displayDataAlert(mCurrentEngine);
|
|
||||||
} else {
|
|
||||||
updateDefaultEngine(mCurrentEngine);
|
updateDefaultEngine(mCurrentEngine);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -16,12 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.tts;
|
package com.android.settings.tts;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.speech.tts.TextToSpeech.EngineInfo;
|
import android.speech.tts.TextToSpeech.EngineInfo;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Checkable;
|
import android.widget.Checkable;
|
||||||
@@ -34,6 +37,8 @@ import com.android.settings.R;
|
|||||||
|
|
||||||
public class TtsEnginePreference extends Preference {
|
public class TtsEnginePreference extends Preference {
|
||||||
|
|
||||||
|
private static final String TAG = "TtsEnginePreference";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key for the name of the TTS engine passed in to the engine
|
* Key for the name of the TTS engine passed in to the engine
|
||||||
* settings fragment {@link TtsEngineSettingsFragment}.
|
* settings fragment {@link TtsEngineSettingsFragment}.
|
||||||
@@ -173,22 +178,69 @@ public class TtsEnginePreference extends Preference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onRadioButtonClicked(CompoundButton buttonView, boolean isChecked) {
|
private boolean shouldDisplayDataAlert() {
|
||||||
|
return !mEngineInfo.system;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void displayDataAlert(
|
||||||
|
DialogInterface.OnClickListener positiveOnClickListener,
|
||||||
|
DialogInterface.OnClickListener negativeOnClickListener) {
|
||||||
|
Log.i(TAG, "Displaying data alert for :" + mEngineInfo.name);
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
|
builder.setTitle(android.R.string.dialog_alert_title);
|
||||||
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
||||||
|
builder.setMessage(getContext().getString(
|
||||||
|
R.string.tts_engine_security_warning, mEngineInfo.label));
|
||||||
|
builder.setCancelable(true);
|
||||||
|
builder.setPositiveButton(android.R.string.ok, positiveOnClickListener);
|
||||||
|
builder.setNegativeButton(android.R.string.cancel, negativeOnClickListener);
|
||||||
|
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void onRadioButtonClicked(final CompoundButton buttonView,
|
||||||
|
boolean isChecked) {
|
||||||
if (mPreventRadioButtonCallbacks ||
|
if (mPreventRadioButtonCallbacks ||
|
||||||
(mSharedState.getCurrentChecked() == buttonView)) {
|
(mSharedState.getCurrentChecked() == buttonView)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
// Should we alert user? if that's true, delay making engine current one.
|
||||||
|
if (shouldDisplayDataAlert()) {
|
||||||
|
displayDataAlert(new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
makeCurrentEngine(buttonView);
|
||||||
|
}
|
||||||
|
},new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
// Undo the click.
|
||||||
|
buttonView.setChecked(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Privileged engine, set it current
|
||||||
|
makeCurrentEngine(buttonView);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mSettingsIcon.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeCurrentEngine(Checkable current) {
|
||||||
if (mSharedState.getCurrentChecked() != null) {
|
if (mSharedState.getCurrentChecked() != null) {
|
||||||
mSharedState.getCurrentChecked().setChecked(false);
|
mSharedState.getCurrentChecked().setChecked(false);
|
||||||
}
|
}
|
||||||
mSharedState.setCurrentChecked(buttonView);
|
mSharedState.setCurrentChecked(current);
|
||||||
mSharedState.setCurrentKey(getKey());
|
mSharedState.setCurrentKey(getKey());
|
||||||
callChangeListener(mSharedState.getCurrentKey());
|
callChangeListener(mSharedState.getCurrentKey());
|
||||||
}
|
mSettingsIcon.setEnabled(true);
|
||||||
|
|
||||||
mSettingsIcon.setEnabled(isChecked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user