Adding "Cancel" button to contact picker

Bug: 3254117
Change-Id: Id0a40fc63f2ca094c7a1a77205ada84a58c2c457
diff --git a/res/layout/contact_picker.xml b/res/layout/contact_picker.xml
index db0ba19..3724f8f 100644
--- a/res/layout/contact_picker.xml
+++ b/res/layout/contact_picker.xml
@@ -26,14 +26,26 @@
         android:id="@+id/search_view"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_alignParentTop="true"
         android:layout_marginLeft="40dip"
         android:layout_marginBottom="10dip"
         android:layout_marginRight="5dip"
         android:iconifiedByDefault="false" />
     <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="0dip"
+        android:layout_weight="1"
         android:id="@+id/list_container">
     </FrameLayout>
+    <LinearLayout
+        style="?android:attr/buttonBarStyle"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="10dip">
+        <Button
+            style="?android:attr/buttonBarButtonStyle"
+            android:id="@+id/cancel"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@android:string/cancel"/>
+    </LinearLayout>
 </view>
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index 545e6ef..493514d 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -38,6 +38,8 @@
 import android.text.TextUtils;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 import android.widget.SearchView;
 import android.widget.SearchView.OnQueryChangeListener;
 
@@ -46,7 +48,7 @@
  * purposes of selecting one.
  */
 public class ContactSelectionActivity extends Activity
-        implements View.OnCreateContextMenuListener, OnQueryChangeListener {
+        implements View.OnCreateContextMenuListener, OnQueryChangeListener, OnClickListener {
     private static final String TAG = "ContactSelectionActivity";
 
     private static final String KEY_ACTION_CODE = "actionCode";
@@ -105,6 +107,21 @@
         mSearchView = (SearchView)findViewById(R.id.search_view);
         mSearchView.setQueryHint(getString(R.string.hint_findContacts));
         mSearchView.setOnQueryChangeListener(this);
+
+        // This is a hack to prevent the search view from grabbing focus
+        // at this point.  If search view were visible, it would always grabs focus
+        // because it is the first focusable widget in the window.
+        mSearchView.setVisibility(View.INVISIBLE);
+        mSearchView.post(new Runnable() {
+
+            @Override
+            public void run() {
+                mSearchView.setVisibility(View.VISIBLE);
+            }
+        });
+
+        Button cancel = (Button) findViewById(R.id.cancel);
+        cancel.setOnClickListener(this);
     }
 
     @Override
@@ -350,4 +367,12 @@
     public boolean onSubmitQuery(String query) {
         return false;
     }
+
+    @Override
+    public void onClick(View v) {
+        if (v.getId() == R.id.cancel) {
+            setResult(RESULT_CANCELED);
+            finish();
+        }
+    }
 }
diff --git a/src/com/android/contacts/editor/LabeledEditorView.java b/src/com/android/contacts/editor/LabeledEditorView.java
index 9331acb..f06191a 100644
--- a/src/com/android/contacts/editor/LabeledEditorView.java
+++ b/src/com/android/contacts/editor/LabeledEditorView.java
@@ -35,7 +35,6 @@
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.Handler;
-import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;