aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/settings
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/settings')
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java49
1 files changed, 36 insertions, 13 deletions
diff --git a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
index c7c29772b..9a8a7b9e0 100644
--- a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
@@ -22,6 +22,7 @@ import static com.android.inputmethod.latin.settings.LocalSettingsConstants.PREF
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.DialogInterface.OnShowListener;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.AsyncTask;
@@ -32,7 +33,9 @@ import android.preference.Preference.OnPreferenceClickListener;
import android.preference.SwitchPreference;
import android.preference.TwoStatePreference;
import android.text.TextUtils;
+import android.text.method.LinkMovementMethod;
import android.widget.ListView;
+import android.widget.TextView;
import android.widget.Toast;
import com.android.inputmethod.annotations.UsedForTesting;
@@ -201,24 +204,19 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
* is currently selected.
*/
private void refreshAccountAndDependentPreferences(@Nullable final String currentAccount) {
+ // TODO(cvnguyen): Write tests.
if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
return;
}
- if (currentAccount == null) {
- // No account is currently selected; switch enable sync preference off.
- mAccountSwitcher.setSummary(getString(R.string.no_accounts_selected));
- mEnableSyncPreference.setChecked(false);
- } else {
- // Set the currently selected account as the summary text.
- mAccountSwitcher.setSummary(getString(R.string.account_selected, currentAccount));
- }
+ final String[] accountsForLogin =
+ LoginAccountUtils.getAccountsForLogin(getActivity());
- mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ if (accountsForLogin.length > 0) {
+ enableSyncPreferences();
+ mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
- final String[] accountsForLogin =
- LoginAccountUtils.getAccountsForLogin(getActivity());
if (accountsForLogin.length > 0) {
// TODO: Add addition of account.
createAccountPicker(accountsForLogin, currentAccount,
@@ -226,7 +224,21 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
}
return true;
}
- });
+ });
+ } else {
+ mAccountSwitcher.setEnabled(false);
+ disableSyncPreferences();
+ mEnableSyncPreference.setSummary(getString(R.string.add_account_to_enable_sync));
+ }
+
+ if (currentAccount == null) {
+ // No account is currently selected; switch enable sync preference off.
+ mAccountSwitcher.setSummary(getString(R.string.no_accounts_selected));
+ mEnableSyncPreference.setChecked(false);
+ } else {
+ // Set the currently selected account as the summary text.
+ mAccountSwitcher.setSummary(getString(R.string.account_selected, currentAccount));
+ }
}
@Nullable
@@ -363,7 +375,8 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
/**
* Listens to events when user clicks on "Enable sync" feature.
*/
- class EnableSyncClickListener implements Preference.OnPreferenceClickListener {
+ class EnableSyncClickListener implements OnShowListener, Preference.OnPreferenceClickListener {
+ // TODO(cvnguyen): Write tests.
@Override
public boolean onPreferenceClick(final Preference preference) {
final TwoStatePreference syncPreference = (TwoStatePreference) preference;
@@ -393,9 +406,19 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
})
.setNegativeButton(R.string.cloud_sync_cancel, null)
.create();
+ optInDialog.setOnShowListener(this);
optInDialog.show();
}
return true;
}
+
+ @Override
+ public void onShow(DialogInterface dialog) {
+ TextView messageView = (TextView) ((AlertDialog) dialog).findViewById(
+ android.R.id.message);
+ if (messageView != null) {
+ messageView.setMovementMethod(LinkMovementMethod.getInstance());
+ }
+ }
}
}