Moving auto-dismissal of soft keyboard from Activity to Fragment
Change-Id: I40d8ccb0332aa71c8465a2398afd868b9a7920aa
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index a4a40fa..8a2fd94 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -124,7 +124,7 @@
@SuppressWarnings("deprecation")
public class ContactsListActivity extends Activity implements View.OnCreateContextMenuListener,
View.OnClickListener,
- OnFocusChangeListener, OnTouchListener, ContactsApplicationController {
+ ContactsApplicationController {
private static final String TAG = "ContactsListActivity";
@@ -685,9 +685,6 @@
public void setupListView(ListAdapter adapter, ListView list) {
mAdapter = (ContactEntryListAdapter)adapter;
- list.setOnFocusChangeListener(this);
- list.setOnTouchListener(this);
-
// We manually save/restore the listview state
list.setSaveEnabled(false);
}
@@ -1378,25 +1375,6 @@
}
}
- /**
- * Dismisses the soft keyboard when the list takes focus.
- */
- public void onFocusChange(View view, boolean hasFocus) {
- if (view == mListView && hasFocus) {
- hideSoftKeyboard();
- }
- }
-
- /**
- * Dismisses the soft keyboard when the list takes focus.
- */
- public boolean onTouch(View view, MotionEvent event) {
- if (view == mListView) {
- hideSoftKeyboard();
- }
- return false;
- }
-
public void onListItemClick(int position, long id) {
if (mSearchMode &&
((ContactItemListAdapter)(mAdapter)).isSearchAllContactsItemPosition(position)) {
diff --git a/src/com/android/contacts/list/ContactEntryListFragment.java b/src/com/android/contacts/list/ContactEntryListFragment.java
index 0bf7735..6d3b75c 100644
--- a/src/com/android/contacts/list/ContactEntryListFragment.java
+++ b/src/com/android/contacts/list/ContactEntryListFragment.java
@@ -33,8 +33,11 @@
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.view.View.OnFocusChangeListener;
+import android.view.View.OnTouchListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
@@ -42,15 +45,16 @@
import android.widget.Filter;
import android.widget.ListView;
import android.widget.TextView;
+import android.widget.TextView.OnEditorActionListener;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
/**
* Common base class for various contact-related list fragments.
*/
-public abstract class ContactEntryListFragment extends Fragment implements
- OnItemClickListener, OnScrollListener, TextWatcher,
- TextView.OnEditorActionListener, OnCloseListener {
+public abstract class ContactEntryListFragment extends Fragment implements OnItemClickListener,
+ OnScrollListener, TextWatcher, OnEditorActionListener, OnCloseListener,
+ OnFocusChangeListener, OnTouchListener {
private boolean mSectionHeaderDisplayEnabled;
private boolean mPhotoLoaderEnabled;
@@ -181,6 +185,9 @@
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
+ mListView.setOnFocusChangeListener(this);
+ mListView.setOnTouchListener(this);
+
// Tell list view to not show dividers. We'll do it ourself so that we can *not* show
// them when an A-Z headers is visible.
mListView.setDividerHeight(0);
@@ -306,6 +313,25 @@
}
/**
+ * Dismisses the soft keyboard when the list takes focus.
+ */
+ public void onFocusChange(View view, boolean hasFocus) {
+ if (view == mListView && hasFocus) {
+ hideSoftKeyboard();
+ }
+ }
+
+ /**
+ * Dismisses the soft keyboard when the list is touched.
+ */
+ public boolean onTouch(View view, MotionEvent event) {
+ if (view == mListView) {
+ hideSoftKeyboard();
+ }
+ return false;
+ }
+
+ /**
* Dismisses the search UI along with the keyboard if the filter text is empty.
*/
public void onClose() {