Group name edit input fixes
* Make the input open more consistently when
editing group names
* Close the keyboard when group name edit dialog
is dismissed via cancel button
* Allow spell check when editing the group name.
Also, set the same input type on the editor
group name dialog.
Bug 29536575
Bug 29537527
Change-Id: Icc12a5168dc7429274edd42c3f7da20e1c1a723a
diff --git a/res/layout/group_name_edit_dialog.xml b/res/layout/group_name_edit_dialog.xml
index 8e8ddd2..381d1d8 100644
--- a/res/layout/group_name_edit_dialog.xml
+++ b/res/layout/group_name_edit_dialog.xml
@@ -31,7 +31,7 @@
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:hint="@string/group_name_dialog_hint"
- android:inputType="textCapWords|textNoSuggestions"
+ android:inputType="text"
android:singleLine="true"
android:maxLength="@integer/group_name_max_length"/>
</LinearLayout>
\ No newline at end of file
diff --git a/src/com/android/contacts/group/GroupNameEditDialogFragment.java b/src/com/android/contacts/group/GroupNameEditDialogFragment.java
index d3c518e..5d7bcb8 100644
--- a/src/com/android/contacts/group/GroupNameEditDialogFragment.java
+++ b/src/com/android/contacts/group/GroupNameEditDialogFragment.java
@@ -27,6 +27,7 @@
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
+import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
@@ -98,6 +99,7 @@
.setNegativeButton(android.R.string.cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
+ hideInputMethod();
getListener().onGroupNameEditCancelled();
dismiss();
}
@@ -111,6 +113,8 @@
// Disable the create button when the name is empty
final AlertDialog alertDialog = builder.create();
+ alertDialog.getWindow().setSoftInputMode(
+ WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
@@ -123,6 +127,7 @@
mGroupNameEditText.setSelection(
mGroupName.length() > maxLength ? maxLength : mGroupName.length());
}
+ showInputMethod(mGroupNameEditText);
final Button createButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
createButton.setEnabled(!TextUtils.isEmpty(getGroupName()));
@@ -140,10 +145,9 @@
createButton.setEnabled(!TextUtils.isEmpty(s));
}
});
-
- showInputMethod(mGroupNameEditText);
}
});
+
return alertDialog;
}
@@ -168,6 +172,14 @@
}
}
+ private void hideInputMethod() {
+ final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ if (imm != null && mGroupNameEditText != null) {
+ imm.hideSoftInputFromWindow(mGroupNameEditText.getWindowToken(), /* flags */ 0);
+ }
+ }
+
private Listener getListener() {
if (!(getActivity() instanceof Listener)) {
throw new ClassCastException(getActivity() + " must implement " +
diff --git a/src/com/android/contacts/interactions/GroupNameDialogFragment.java b/src/com/android/contacts/interactions/GroupNameDialogFragment.java
index 7875ee5..5efccfc 100644
--- a/src/com/android/contacts/interactions/GroupNameDialogFragment.java
+++ b/src/com/android/contacts/interactions/GroupNameDialogFragment.java
@@ -23,6 +23,7 @@
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
+import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
@@ -36,6 +37,7 @@
/**
* A common superclass for creating and renaming groups.
*/
+// TODO: consolidate it with GroupNameEditDialogFragment
public abstract class GroupNameDialogFragment extends DialogFragment {
protected abstract int getTitleResourceId();
protected abstract void initializeGroupLabelEditText(EditText editText);
@@ -49,6 +51,7 @@
final EditText editText = (EditText) view.findViewById(R.id.group_label);
final int maxLength = getResources().getInteger(R.integer.group_name_max_length);
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });
+ editText.setInputType(InputType.TYPE_CLASS_TEXT);
initializeGroupLabelEditText(editText);
builder.setTitle(getTitleResourceId());