Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76931b46 authored by Walter Jang's avatar Walter Jang
Browse files

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
parent 13710d5d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+14 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.text.Editable;
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 @@ public final class GroupNameEditDialogFragment extends DialogFragment {
                .setNegativeButton(android.R.string.cancel, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        hideInputMethod();
                        getListener().onGroupNameEditCancelled();
                        dismiss();
                    }
@@ -111,6 +113,8 @@ public final class GroupNameEditDialogFragment extends DialogFragment {

        // 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 @@ public final class GroupNameEditDialogFragment extends DialogFragment {
                    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 @@ public final class GroupNameEditDialogFragment extends DialogFragment {
                        createButton.setEnabled(!TextUtils.isEmpty(s));
                    }
                });

                showInputMethod(mGroupNameEditText);
            }
        });

        return alertDialog;
    }

@@ -168,6 +172,14 @@ public final class GroupNameEditDialogFragment extends DialogFragment {
        }
    }

    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 " +
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.DialogInterface.OnShowListener;
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 @@ import com.android.contacts.R;
/**
 * 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 @@ public abstract class GroupNameDialogFragment extends DialogFragment {
        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());