Tweaked the input dialogs for the group name and the type

 - Tweaked padding in type editor
 - Made it so that OK is disabled in group editor
 - Automatically show the keyboard
 - Made the implementations a little more similar to each other

Change-Id: I2c1a131a7eb7ea3e306fdaa430be8945accf915b
diff --git a/res/layout/contact_editor_label_name_dialog.xml b/res/layout/contact_editor_label_name_dialog.xml
new file mode 100644
index 0000000..8960869
--- /dev/null
+++ b/res/layout/contact_editor_label_name_dialog.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:paddingTop="25dip"
+    android:paddingRight="25dip"
+    android:paddingBottom="25dip"
+    android:paddingLeft="25dip">
+    <EditText
+        android:id="@+id/custom_dialog_content"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" />
+</FrameLayout>
diff --git a/src/com/android/contacts/editor/LabeledEditorView.java b/src/com/android/contacts/editor/LabeledEditorView.java
index 1d12978..6f10fa2 100644
--- a/src/com/android/contacts/editor/LabeledEditorView.java
+++ b/src/com/android/contacts/editor/LabeledEditorView.java
@@ -31,19 +31,24 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Entity;
+import android.content.DialogInterface.OnShowListener;
 import android.os.Bundle;
 import android.os.Handler;
+import android.text.Editable;
 import android.text.TextUtils;
+import android.text.TextWatcher;
 import android.text.TextUtils.TruncateAt;
 import android.util.AttributeSet;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.WindowManager;
 import android.view.inputmethod.EditorInfo;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.ArrayAdapter;
+import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -376,20 +381,21 @@
      */
     private Dialog createCustomDialog() {
         final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
+        final LayoutInflater layoutInflater = LayoutInflater.from(builder.getContext());
         builder.setTitle(R.string.customLabelPickerTitle);
 
-        final EditText customType = new EditText(builder.getContext());
-        customType.setId(R.id.custom_dialog_content);
-        customType.setInputType(INPUT_TYPE_CUSTOM);
-        customType.setSaveEnabled(true);
-        customType.requestFocus();
+        final View view = layoutInflater.inflate(R.layout.contact_editor_label_name_dialog, null);
+        final EditText editText = (EditText) view.findViewById(R.id.custom_dialog_content);
+        editText.setInputType(INPUT_TYPE_CUSTOM);
+        editText.setSaveEnabled(true);
 
-        builder.setView(customType);
+        builder.setView(view);
+        editText.requestFocus();
 
         builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
-                final String customText = customType.getText().toString().trim();
+                final String customText = editText.getText().toString().trim();
                 if (ContactsUtils.isGraphic(customText)) {
                     final List<EditType> allTypes =
                             EntityModifier.getValidTypes(mState, mKind, null);
@@ -413,7 +419,36 @@
 
         builder.setNegativeButton(android.R.string.cancel, null);
 
-        return builder.create();
+        final AlertDialog dialog = builder.create();
+        dialog.setOnShowListener(new OnShowListener() {
+            @Override
+            public void onShow(DialogInterface dialogInterface) {
+                updateCustomDialogOkButtonState(dialog, editText);
+            }
+        });
+        editText.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+            }
+
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {
+                updateCustomDialogOkButtonState(dialog, editText);
+            }
+        });
+        dialog.getWindow().setSoftInputMode(
+                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+
+        return dialog;
+    }
+
+    /* package */ void updateCustomDialogOkButtonState(AlertDialog dialog, EditText editText) {
+        final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
+        okButton.setEnabled(!TextUtils.isEmpty(editText.getText().toString().trim()));
     }
 
     /**
diff --git a/src/com/android/contacts/interactions/GroupNameDialogFragment.java b/src/com/android/contacts/interactions/GroupNameDialogFragment.java
index 0be236e..8798c59 100644
--- a/src/com/android/contacts/interactions/GroupNameDialogFragment.java
+++ b/src/com/android/contacts/interactions/GroupNameDialogFragment.java
@@ -28,16 +28,14 @@
 import android.text.TextWatcher;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.WindowManager;
 import android.widget.Button;
 import android.widget.EditText;
 
 /**
  * A common superclass for creating and renaming groups.
  */
-public abstract class GroupNameDialogFragment extends DialogFragment
-        implements TextWatcher, OnShowListener {
-    private EditText mEdit;
-
+public abstract class GroupNameDialogFragment extends DialogFragment {
     protected abstract int getTitleResourceId();
     protected abstract void initializeGroupLabelEditText(EditText editText);
     protected abstract void onCompleted(String groupLabel);
@@ -47,52 +45,51 @@
         final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
         final LayoutInflater layoutInflater = LayoutInflater.from(builder.getContext());
         final View view = layoutInflater.inflate(R.layout.group_name_dialog, null);
-        mEdit = (EditText) view.findViewById(R.id.group_label);
-        initializeGroupLabelEditText(mEdit);
-
-        mEdit.addTextChangedListener(this);
+        final EditText editText = (EditText) view.findViewById(R.id.group_label);
+        initializeGroupLabelEditText(editText);
 
         builder.setTitle(getTitleResourceId());
         builder.setView(view);
+        editText.requestFocus();
         builder.setPositiveButton(android.R.string.ok,
                 new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialogInterface, int whichButton) {
-                        onCompleted(mEdit.getText().toString().trim());
+                        onCompleted(editText.getText().toString().trim());
                     }
                 }
             );
+
         builder.setNegativeButton(android.R.string.cancel, null);
         final AlertDialog dialog = builder.create();
 
-        dialog.setOnShowListener(this);
+        dialog.setOnShowListener(new OnShowListener() {
+            @Override
+            public void onShow(DialogInterface dialogInterface) {
+                updateOkButtonState(dialog, editText);
+            }
+        });
+        editText.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+            }
+
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {
+                updateOkButtonState(dialog, editText);
+            }
+        });
+        dialog.getWindow().setSoftInputMode(
+                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
         return dialog;
     }
 
-    @Override
-    public void onShow(DialogInterface dialog) {
-        updateOkButtonState((AlertDialog) dialog);
-    }
-
-    @Override
-    public void afterTextChanged(Editable s) {
-        AlertDialog dialog = (AlertDialog) getDialog();
-        // Make sure the dialog has not already been dismissed or destroyed.
-        if (dialog != null) {
-            updateOkButtonState(dialog);
-        }
-    }
-
-    private void updateOkButtonState(AlertDialog dialog) {
-        Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
-        okButton.setEnabled(!TextUtils.isEmpty(mEdit.getText().toString().trim()));
-    }
-
-    @Override
-    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-    }
-
-    @Override
-    public void onTextChanged(CharSequence s, int start, int before, int count) {
+    /* package */ void updateOkButtonState(AlertDialog dialog, EditText editText) {
+        final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
+        okButton.setEnabled(!TextUtils.isEmpty(editText.getText().toString().trim()));
     }
 }