From a7f6eb1a3752e472c115060cfe01812861d69501 Mon Sep 17 00:00:00 2001 From: linus_lee Date: Tue, 20 Jan 2015 18:19:01 -0800 Subject: Settings: Enforce non-blank profile names Change-Id: I2633c5a29461a098af82a4daf207b0e9a8686de2 --- .../settings/profiles/SetupActionsFragment.java | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/com/android/settings/profiles') diff --git a/src/com/android/settings/profiles/SetupActionsFragment.java b/src/com/android/settings/profiles/SetupActionsFragment.java index 485981a..7203b48 100644 --- a/src/com/android/settings/profiles/SetupActionsFragment.java +++ b/src/com/android/settings/profiles/SetupActionsFragment.java @@ -42,6 +42,9 @@ import android.os.Bundle; import android.provider.Settings; import android.telecom.TelecomManager; import android.telephony.TelephonyManager; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -50,6 +53,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; +import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; @@ -702,7 +706,7 @@ public class SetupActionsFragment extends SettingsPreferenceFragment entry.setText(mProfile.getName()); entry.setSelectAllOnFocus(true); - new AlertDialog.Builder(getActivity()) + final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.rename_dialog_title) .setView(dialogView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -715,7 +719,27 @@ public class SetupActionsFragment extends SettingsPreferenceFragment } }) .setNegativeButton(android.R.string.cancel, null) - .show(); + .create(); + + entry.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + final boolean empty = TextUtils.isEmpty(s.toString()); + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!empty); + } + }); + + alertDialog.show(); } @Override -- cgit v1.1