Merge "Convert more pages to use ActionButtonPreference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c7e7f28e88
@@ -67,7 +67,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.webkit.IWebViewUpdateService;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.os.BatterySipper;
|
||||
@@ -93,6 +92,7 @@ import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.notification.AppNotificationSettings;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.notification.NotificationBackend.AppRow;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.AppItem;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
@@ -123,8 +123,7 @@ import java.util.Set;
|
||||
* uninstall the application.
|
||||
*/
|
||||
public class InstalledAppDetails extends AppInfoBase
|
||||
implements View.OnClickListener, OnPreferenceClickListener,
|
||||
LoaderManager.LoaderCallbacks<AppStorageStats> {
|
||||
implements OnPreferenceClickListener, LoaderManager.LoaderCallbacks<AppStorageStats> {
|
||||
|
||||
private static final String LOG_TAG = "InstalledAppDetails";
|
||||
|
||||
@@ -166,10 +165,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
private boolean mInitialized;
|
||||
private boolean mShowUninstalled;
|
||||
private LayoutPreference mHeader;
|
||||
private LayoutPreference mActionButtons;
|
||||
private Button mUninstallButton;
|
||||
private boolean mUpdatedSysApp = false;
|
||||
private Button mForceStopButton;
|
||||
private Preference mNotificationPreference;
|
||||
private Preference mStoragePreference;
|
||||
private Preference mPermissionsPreference;
|
||||
@@ -186,6 +182,8 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
private ChartData mChartData;
|
||||
private INetworkStatsSession mStatsSession;
|
||||
|
||||
@VisibleForTesting
|
||||
ActionButtonPreference mActionButtons;
|
||||
@VisibleForTesting
|
||||
Preference mBatteryPreference;
|
||||
@VisibleForTesting
|
||||
@@ -230,7 +228,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
boolean handleDisableable(Button button) {
|
||||
boolean handleDisableable() {
|
||||
boolean disableable = false;
|
||||
// Try to prevent the user from bricking their phone
|
||||
// by not allowing disabling of apps signed with the
|
||||
@@ -238,13 +236,19 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
if (mHomePackages.contains(mAppEntry.info.packageName)
|
||||
|| Utils.isSystemPackage(getContext().getResources(), mPm, mPackageInfo)) {
|
||||
// Disable button for core system applications.
|
||||
button.setText(R.string.disable_text);
|
||||
mActionButtons
|
||||
.setButton1Text(R.string.disable_text)
|
||||
.setButton1Positive(false);
|
||||
} else if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
||||
button.setText(R.string.disable_text);
|
||||
mActionButtons
|
||||
.setButton1Text(R.string.disable_text)
|
||||
.setButton1Positive(false);
|
||||
disableable = !mApplicationFeatureProvider.getKeepEnabledPackages()
|
||||
.contains(mAppEntry.info.packageName);
|
||||
} else {
|
||||
button.setText(R.string.enable_text);
|
||||
mActionButtons
|
||||
.setButton1Text(R.string.enable_text)
|
||||
.setButton1Positive(true);
|
||||
disableable = true;
|
||||
}
|
||||
|
||||
@@ -258,11 +262,11 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
|
||||
private void initUninstallButtons() {
|
||||
final boolean isBundled = (mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
boolean enabled = true;
|
||||
boolean enabled;
|
||||
if (isBundled) {
|
||||
enabled = handleDisableable(mUninstallButton);
|
||||
enabled = handleDisableable();
|
||||
} else {
|
||||
enabled = initUnintsallButtonForUserApp();
|
||||
enabled = initUninstallButtonForUserApp();
|
||||
}
|
||||
// If this is a device admin, it can't be uninstalled or disabled.
|
||||
// We do this here so the text of the button is still set correctly.
|
||||
@@ -325,15 +329,15 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
mUninstallButton.setEnabled(enabled);
|
||||
mActionButtons.setButton1Enabled(enabled);
|
||||
if (enabled) {
|
||||
// Register listener
|
||||
mUninstallButton.setOnClickListener(this);
|
||||
mActionButtons.setButton1OnClickListener(v -> handleUninstallButtonClick());
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean initUnintsallButtonForUserApp() {
|
||||
boolean initUninstallButtonForUserApp() {
|
||||
boolean enabled = true;
|
||||
if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0
|
||||
&& mUserManager.getUsers().size() >= 2) {
|
||||
@@ -342,9 +346,9 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
enabled = false;
|
||||
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
||||
enabled = false;
|
||||
mUninstallButton.setVisibility(View.GONE);
|
||||
mActionButtons.setButton1Visible(false);
|
||||
}
|
||||
mUninstallButton.setText(R.string.uninstall_text);
|
||||
mActionButtons.setButton1Text(R.string.uninstall_text);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@@ -444,7 +448,10 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
}
|
||||
final Activity activity = getActivity();
|
||||
mHeader = (LayoutPreference) findPreference(KEY_HEADER);
|
||||
mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
|
||||
mActionButtons = ((ActionButtonPreference) findPreference(KEY_ACTION_BUTTONS))
|
||||
.setButton2Text(R.string.force_stop)
|
||||
.setButton2Positive(false)
|
||||
.setButton2Enabled(false);
|
||||
EntityHeaderController.newInstance(activity, this, mHeader.findViewById(R.id.entity_header))
|
||||
.setRecyclerView(getListView(), getLifecycle())
|
||||
.setPackageName(mPackageName)
|
||||
@@ -453,7 +460,6 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
EntityHeaderController.ActionType.ACTION_NONE)
|
||||
.styleActionBar(activity)
|
||||
.bindHeaderButtons();
|
||||
prepareUninstallAndStop();
|
||||
|
||||
mNotificationPreference = findPreference(KEY_NOTIFICATION);
|
||||
mNotificationPreference.setOnPreferenceClickListener(this);
|
||||
@@ -514,13 +520,6 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
return true;
|
||||
}
|
||||
|
||||
private void prepareUninstallAndStop() {
|
||||
mForceStopButton = (Button) mActionButtons.findViewById(R.id.right_button);
|
||||
mForceStopButton.setText(R.string.force_stop);
|
||||
mUninstallButton = (Button) mActionButtons.findViewById(R.id.left_button);
|
||||
mForceStopButton.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset)
|
||||
@@ -903,12 +902,10 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
}
|
||||
|
||||
private void updateForceStopButton(boolean enabled) {
|
||||
if (mAppsControlDisallowedBySystem) {
|
||||
mForceStopButton.setEnabled(false);
|
||||
} else {
|
||||
mForceStopButton.setEnabled(enabled);
|
||||
mForceStopButton.setOnClickListener(this);
|
||||
}
|
||||
mActionButtons
|
||||
.setButton2Enabled(mAppsControlDisallowedBySystem ? false : enabled)
|
||||
.setButton2OnClickListener(mAppsControlDisallowedBySystem
|
||||
? null : v -> handleForceStopButtonClick());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -919,7 +916,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
updateForceStopButton(false);
|
||||
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
||||
updateForceStopButton(false);
|
||||
mForceStopButton.setVisibility(View.GONE);
|
||||
mActionButtons.setButton2Visible(false);
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
|
||||
// If the app isn't explicitly stopped, then always show the
|
||||
// force stop button.
|
||||
@@ -966,67 +963,67 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
SUB_INFO_FRAGMENT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Method implementing functionality of buttons clicked
|
||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||
*/
|
||||
public void onClick(View v) {
|
||||
private void handleUninstallButtonClick() {
|
||||
if (mAppEntry == null) {
|
||||
setIntentAndFinish(true, true);
|
||||
return;
|
||||
}
|
||||
String packageName = mAppEntry.info.packageName;
|
||||
if (v == mUninstallButton) {
|
||||
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
||||
stopListeningToPackageRemove();
|
||||
Activity activity = getActivity();
|
||||
Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
|
||||
uninstallDAIntent.putExtra(DeviceAdminAdd.EXTRA_DEVICE_ADMIN_PACKAGE_NAME,
|
||||
mPackageName);
|
||||
mMetricsFeatureProvider.action(
|
||||
activity, MetricsEvent.ACTION_SETTINGS_UNINSTALL_DEVICE_ADMIN);
|
||||
activity.startActivityForResult(uninstallDAIntent, REQUEST_REMOVE_DEVICE_ADMIN);
|
||||
return;
|
||||
}
|
||||
EnforcedAdmin admin = RestrictedLockUtils.checkIfUninstallBlocked(getActivity(),
|
||||
packageName, mUserId);
|
||||
boolean uninstallBlockedBySystem = mAppsControlDisallowedBySystem ||
|
||||
RestrictedLockUtils.hasBaseUserRestriction(getActivity(), packageName, mUserId);
|
||||
if (admin != null && !uninstallBlockedBySystem) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), admin);
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
||||
// If the system app has an update and this is the only user on the device,
|
||||
// then offer to downgrade the app, otherwise only offer to disable the
|
||||
// app for this user.
|
||||
if (mUpdatedSysApp && isSingleUser()) {
|
||||
showDialogInner(DLG_SPECIAL_DISABLE, 0);
|
||||
} else {
|
||||
showDialogInner(DLG_DISABLE, 0);
|
||||
}
|
||||
final String packageName = mAppEntry.info.packageName;
|
||||
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
||||
stopListeningToPackageRemove();
|
||||
Activity activity = getActivity();
|
||||
Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
|
||||
uninstallDAIntent.putExtra(DeviceAdminAdd.EXTRA_DEVICE_ADMIN_PACKAGE_NAME,
|
||||
mPackageName);
|
||||
mMetricsFeatureProvider.action(
|
||||
activity, MetricsEvent.ACTION_SETTINGS_UNINSTALL_DEVICE_ADMIN);
|
||||
activity.startActivityForResult(uninstallDAIntent, REQUEST_REMOVE_DEVICE_ADMIN);
|
||||
return;
|
||||
}
|
||||
EnforcedAdmin admin = RestrictedLockUtils.checkIfUninstallBlocked(getActivity(),
|
||||
packageName, mUserId);
|
||||
boolean uninstallBlockedBySystem = mAppsControlDisallowedBySystem ||
|
||||
RestrictedLockUtils.hasBaseUserRestriction(getActivity(), packageName, mUserId);
|
||||
if (admin != null && !uninstallBlockedBySystem) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), admin);
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
||||
// If the system app has an update and this is the only user on the device,
|
||||
// then offer to downgrade the app, otherwise only offer to disable the
|
||||
// app for this user.
|
||||
if (mUpdatedSysApp && isSingleUser()) {
|
||||
showDialogInner(DLG_SPECIAL_DISABLE, 0);
|
||||
} else {
|
||||
mMetricsFeatureProvider.action(
|
||||
getActivity(),
|
||||
mAppEntry.info.enabled
|
||||
? MetricsEvent.ACTION_SETTINGS_DISABLE_APP
|
||||
: MetricsEvent.ACTION_SETTINGS_ENABLE_APP);
|
||||
new DisableChanger(this, mAppEntry.info,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
|
||||
.execute((Object) null);
|
||||
showDialogInner(DLG_DISABLE, 0);
|
||||
}
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
||||
uninstallPkg(packageName, true, false);
|
||||
} else {
|
||||
uninstallPkg(packageName, false, false);
|
||||
}
|
||||
} else if (v == mForceStopButton) {
|
||||
if (mAppsControlDisallowedAdmin != null && !mAppsControlDisallowedBySystem) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
||||
getActivity(), mAppsControlDisallowedAdmin);
|
||||
} else {
|
||||
showDialogInner(DLG_FORCE_STOP, 0);
|
||||
//forceStopPackage(mAppInfo.packageName);
|
||||
mMetricsFeatureProvider.action(
|
||||
getActivity(),
|
||||
mAppEntry.info.enabled
|
||||
? MetricsEvent.ACTION_SETTINGS_DISABLE_APP
|
||||
: MetricsEvent.ACTION_SETTINGS_ENABLE_APP);
|
||||
new DisableChanger(this, mAppEntry.info,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
|
||||
.execute((Object) null);
|
||||
}
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
||||
uninstallPkg(packageName, true, false);
|
||||
} else {
|
||||
uninstallPkg(packageName, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleForceStopButtonClick() {
|
||||
if (mAppEntry == null) {
|
||||
setIntentAndFinish(true, true);
|
||||
return;
|
||||
}
|
||||
if (mAppsControlDisallowedAdmin != null && !mAppsControlDisallowedBySystem) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
||||
getActivity(), mAppsControlDisallowedAdmin);
|
||||
} else {
|
||||
showDialogInner(DLG_FORCE_STOP, 0);
|
||||
//forceStopPackage(mAppInfo.packageName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,11 +19,9 @@ package com.android.settings.bluetooth;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
@@ -35,7 +33,8 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
|
||||
private static final String KEY_ACTION_BUTTONS = "action_buttons";
|
||||
private boolean mIsConnected;
|
||||
|
||||
private LayoutPreference mActionButtons;
|
||||
private boolean mButton1Initialized;
|
||||
private ActionButtonPreference mActionButtons;
|
||||
|
||||
public BluetoothDetailsButtonsController(Context context, PreferenceFragment fragment,
|
||||
CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||
@@ -51,35 +50,35 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
mActionButtons = (LayoutPreference) screen.findPreference(getPreferenceKey());
|
||||
Button rightButton = (Button) mActionButtons.findViewById(R.id.right_button);
|
||||
rightButton.setText(R.string.forget);
|
||||
rightButton.setOnClickListener((view) -> {
|
||||
onForgetButtonPressed();
|
||||
});
|
||||
mActionButtons = ((ActionButtonPreference) screen.findPreference(getPreferenceKey()))
|
||||
.setButton2Text(R.string.forget)
|
||||
.setButton2OnClickListener((view) -> onForgetButtonPressed())
|
||||
.setButton2Positive(false)
|
||||
.setButton2Enabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
Button leftButton = (Button) mActionButtons.findViewById(R.id.left_button);
|
||||
leftButton.setEnabled(!mCachedDevice.isBusy());
|
||||
boolean notInitialized = TextUtils.isEmpty(leftButton.getText());
|
||||
mActionButtons.setButton1Enabled(!mCachedDevice.isBusy());
|
||||
|
||||
boolean previouslyConnected = mIsConnected;
|
||||
mIsConnected = mCachedDevice.isConnected();
|
||||
if (mIsConnected) {
|
||||
if (notInitialized || !previouslyConnected) {
|
||||
leftButton.setText(R.string.bluetooth_device_context_disconnect);
|
||||
leftButton.setOnClickListener((view) -> {
|
||||
mCachedDevice.disconnect();
|
||||
});
|
||||
if (!mButton1Initialized || !previouslyConnected) {
|
||||
mActionButtons
|
||||
.setButton1Text(R.string.bluetooth_device_context_disconnect)
|
||||
.setButton1OnClickListener(view -> mCachedDevice.disconnect())
|
||||
.setButton1Positive(false);
|
||||
mButton1Initialized = true;
|
||||
}
|
||||
} else {
|
||||
if (notInitialized || previouslyConnected) {
|
||||
leftButton.setText(R.string.bluetooth_device_context_connect);
|
||||
leftButton.setOnClickListener((view) -> {
|
||||
mCachedDevice.connect(true);
|
||||
});
|
||||
if (!mButton1Initialized || previouslyConnected) {
|
||||
mActionButtons
|
||||
.setButton1Text(R.string.bluetooth_device_context_connect)
|
||||
.setButton1OnClickListener(
|
||||
view -> mCachedDevice.connect(true /* connectAllProfiles */))
|
||||
.setButton1Positive(true);
|
||||
mButton1Initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,4 +87,5 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
|
||||
public String getPreferenceKey() {
|
||||
return KEY_ACTION_BUTTONS;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,7 +16,10 @@
|
||||
|
||||
package com.android.settings.tts;
|
||||
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import static android.provider.Settings.Secure.TTS_DEFAULT_PITCH;
|
||||
import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
|
||||
import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ContentResolver;
|
||||
@@ -26,24 +29,23 @@ import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.TextToSpeech.EngineInfo;
|
||||
import android.speech.tts.TtsEngines;
|
||||
import android.speech.tts.UtteranceProgressListener;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import java.util.Comparator;
|
||||
import java.util.Collections;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
import android.widget.Button;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -51,13 +53,8 @@ import java.util.MissingResourceException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static android.provider.Settings.Secure.TTS_DEFAULT_PITCH;
|
||||
import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
|
||||
import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
|
||||
|
||||
public class TextToSpeechSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener,
|
||||
View.OnClickListener,
|
||||
GearPreference.OnGearClickListener {
|
||||
|
||||
private static final String STATE_KEY_LOCALE_ENTRIES = "locale_entries";
|
||||
@@ -108,9 +105,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
||||
|
||||
private SeekBarPreference mDefaultPitchPref;
|
||||
private SeekBarPreference mDefaultRatePref;
|
||||
private Button mResetButton;
|
||||
private Button mPlayButton;
|
||||
private LayoutPreference mActionButtons;
|
||||
private ActionButtonPreference mActionButtons;
|
||||
|
||||
private int mDefaultPitch = TextToSpeech.Engine.DEFAULT_PITCH;
|
||||
private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
|
||||
@@ -126,7 +121,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
||||
private String mSampleText = null;
|
||||
|
||||
private ListPreference mLocalePreference;
|
||||
private Preference mInstallVoicesPreference;
|
||||
|
||||
/**
|
||||
* Default locale used by selected TTS engine, null if not connected to any engine.
|
||||
@@ -172,12 +166,15 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
||||
mDefaultPitchPref = (SeekBarPreference) findPreference(KEY_DEFAULT_PITCH);
|
||||
mDefaultRatePref = (SeekBarPreference) findPreference(KEY_DEFAULT_RATE);
|
||||
|
||||
mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
|
||||
mPlayButton = (Button) mActionButtons.findViewById(R.id.tts_play_button);
|
||||
mPlayButton.setOnClickListener(this);
|
||||
mPlayButton.setEnabled(false);
|
||||
mResetButton = (Button) mActionButtons.findViewById(R.id.tts_reset_button);
|
||||
mResetButton.setOnClickListener(this);
|
||||
mActionButtons = ((ActionButtonPreference) findPreference(KEY_ACTION_BUTTONS))
|
||||
.setButton1Text(R.string.tts_play)
|
||||
.setButton1Positive(true)
|
||||
.setButton1OnClickListener(v -> speakSampleText())
|
||||
.setButton1Enabled(false)
|
||||
.setButton2Text(R.string.tts_reset)
|
||||
.setButton2Positive(false)
|
||||
.setButton2OnClickListener(v -> resetTts())
|
||||
.setButton1Enabled(true);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
mLocalePreference.setEnabled(false);
|
||||
@@ -656,32 +653,18 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
||||
mTts.setLanguage((locale != null) ? locale : Locale.getDefault());
|
||||
}
|
||||
|
||||
/** Called when mPlayButton, mResetButton is clicked. */
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.tts_play_button:
|
||||
// Play button.
|
||||
// Get the sample text from the TTS engine; onActivityResult will do
|
||||
// the actual speaking
|
||||
speakSampleText();
|
||||
break;
|
||||
case R.id.tts_reset_button:
|
||||
// Reset button.
|
||||
int speechRateSeekbarProgress =
|
||||
getSeekBarProgressFromValue(
|
||||
KEY_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
|
||||
mDefaultRatePref.setProgress(speechRateSeekbarProgress);
|
||||
updateSpeechRate(speechRateSeekbarProgress);
|
||||
int pitchSeekbarProgress =
|
||||
getSeekBarProgressFromValue(
|
||||
KEY_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
|
||||
mDefaultPitchPref.setProgress(pitchSeekbarProgress);
|
||||
updateSpeechPitchValue(pitchSeekbarProgress);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
private void resetTts() {
|
||||
// Reset button.
|
||||
int speechRateSeekbarProgress =
|
||||
getSeekBarProgressFromValue(
|
||||
KEY_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
|
||||
mDefaultRatePref.setProgress(speechRateSeekbarProgress);
|
||||
updateSpeechRate(speechRateSeekbarProgress);
|
||||
int pitchSeekbarProgress =
|
||||
getSeekBarProgressFromValue(
|
||||
KEY_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
|
||||
mDefaultPitchPref.setProgress(pitchSeekbarProgress);
|
||||
updateSpeechPitchValue(pitchSeekbarProgress);
|
||||
}
|
||||
|
||||
private void updateSpeechRate(int speechRateSeekBarProgress) {
|
||||
@@ -715,7 +698,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private void updateWidgetState(boolean enable) {
|
||||
mPlayButton.setEnabled(enable);
|
||||
mActionButtons.setButton1Enabled(enable);
|
||||
mDefaultRatePref.setEnabled(enable);
|
||||
mDefaultPitchPref.setEnabled(enable);
|
||||
}
|
||||
|
Reference in New Issue
Block a user