Make search button focus the search field while in search mode
- Also removed a totally unused class
- Also turned an enum into an abstract class
Bug:5188996
Change-Id: I0dde1e49b360459f71196b151160a25d24d21343
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index 8bd9bf9..b9401e1 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -42,11 +42,13 @@
public class ActionBarAdapter implements OnQueryTextListener, OnCloseListener {
public interface Listener {
- public enum Action {
- CHANGE_SEARCH_QUERY, START_SEARCH_MODE, STOP_SEARCH_MODE
+ public abstract class Action {
+ public static final int CHANGE_SEARCH_QUERY = 0;
+ public static final int START_SEARCH_MODE = 1;
+ public static final int STOP_SEARCH_MODE = 2;
}
- void onAction(Action action);
+ void onAction(int action);
/**
* Called when the user selects a tab. The new tab can be obtained using
@@ -238,6 +240,9 @@
} else {
mSearchView.setQuery(null, false);
}
+ } else if (flag) {
+ // Everything is already set up. Still make sure the keyboard is up
+ if (mSearchView != null) setFocusOnSearchView();
}
}
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index eff3294..2d6e4c8 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -615,20 +615,20 @@
* Handler for action bar actions.
*/
@Override
- public void onAction(Action action) {
+ public void onAction(int action) {
switch (action) {
- case START_SEARCH_MODE:
+ case ActionBarAdapter.Listener.Action.START_SEARCH_MODE:
// Tell the fragments that we're in the search mode
configureFragments(false /* from request */);
updateFragmentsVisibility();
invalidateOptionsMenu();
break;
- case STOP_SEARCH_MODE:
+ case ActionBarAdapter.Listener.Action.STOP_SEARCH_MODE:
setQueryTextToFragment("");
updateFragmentsVisibility();
invalidateOptionsMenu();
break;
- case CHANGE_SEARCH_QUERY:
+ case ActionBarAdapter.Listener.Action.CHANGE_SEARCH_QUERY:
setQueryTextToFragment(mActionBarAdapter.getQueryString());
break;
default:
diff --git a/src/com/android/contacts/widget/SearchEditText.java b/src/com/android/contacts/widget/SearchEditText.java
deleted file mode 100644
index d8ea2be..0000000
--- a/src/com/android/contacts/widget/SearchEditText.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-package com.android.contacts.widget;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.text.Editable;
-import android.text.TextUtils;
-import android.text.TextWatcher;
-import android.util.AttributeSet;
-import android.view.KeyEvent;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.EditText;
-import android.widget.TextView;
-import android.widget.TextView.OnEditorActionListener;
-
-/**
- * A custom text editor that helps automatically dismiss the activity along with the soft
- * keyboard.
- */
-public class SearchEditText extends EditText implements OnEditorActionListener, TextWatcher {
-
- private boolean mMaginfyingGlassEnabled = true;
- private Drawable mMagnifyingGlass;
- private OnFilterTextListener mListener;
-
- private boolean mMagnifyingGlassShown;
-
- public interface OnFilterTextListener {
- void onFilterChange(String queryString);
- void onCancelSearch();
- }
-
- public SearchEditText(Context context, AttributeSet attrs) {
- super(context, attrs);
- addTextChangedListener(this);
- setOnEditorActionListener(this);
- mMagnifyingGlass = getCompoundDrawables()[2];
- setCompoundDrawables(null, null, null, null);
- }
-
- public boolean isMaginfyingGlassEnabled() {
- return mMaginfyingGlassEnabled;
- }
-
- public void setMaginfyingGlassEnabled(boolean flag) {
- this.mMaginfyingGlassEnabled = flag;
- }
-
- public void setOnFilterTextListener(OnFilterTextListener listener) {
- this.mListener = listener;
- }
-
- /**
- * Conditionally shows a magnifying glass icon on the right side of the text field
- * when the text it empty.
- */
- @Override
- public boolean onPreDraw() {
- boolean emptyText = TextUtils.isEmpty(getText());
- if (mMagnifyingGlassShown != emptyText) {
- mMagnifyingGlassShown = emptyText;
- if (mMagnifyingGlassShown && mMaginfyingGlassEnabled) {
- setCompoundDrawables(null, null, mMagnifyingGlass, null);
- } else {
- setCompoundDrawables(null, null, null, null);
- }
- return false;
- }
- return super.onPreDraw();
- }
-
- /**
- * Dismisses the search UI along with the keyboard if the filter text is empty.
- */
- @Override
- public boolean onKeyPreIme(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK && TextUtils.isEmpty(getText()) && mListener != null) {
- mListener.onCancelSearch();
- return true;
- }
- return false;
- }
-
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- /**
- * Event handler for search UI.
- */
- public void afterTextChanged(Editable s) {
- if (mListener != null) {
- mListener.onFilterChange(trim(s));
- }
- }
-
- private String trim(Editable s) {
- return s.toString().trim();
- }
-
- /**
- * Event handler for search UI.
- */
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_DONE) {
- hideSoftKeyboard();
- if (TextUtils.isEmpty(trim(getText())) && mListener != null) {
- mListener.onCancelSearch();
- }
- return true;
- }
- return false;
- }
-
- private void hideSoftKeyboard() {
- // Hide soft keyboard, if visible
- InputMethodManager inputMethodManager = (InputMethodManager)
- getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
- }
-
-}