summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/DialtactsActivity.java44
-rw-r--r--src/com/android/dialer/widget/SearchEditTextLayout.java70
2 files changed, 83 insertions, 31 deletions
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 39f611e9a..d89860008 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -85,6 +85,7 @@ import com.android.dialer.list.RemoveView;
import com.android.dialer.list.SearchFragment;
import com.android.dialer.list.SmartDialSearchFragment;
import com.android.dialer.widget.SearchEditTextLayout;
+import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
import com.android.dialerbind.DatabaseHelperManager;
import com.android.internal.telephony.ITelephony;
@@ -190,8 +191,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
private String mPendingSearchViewQuery;
private EditText mSearchView;
- private View mSearchIcon;
- private View mSearchViewCloseButton;
private View mVoiceSearchButton;
private SearchEditTextLayout mSearchEditTextLayout;
@@ -278,14 +277,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
} else if (mRegularSearchFragment != null) {
mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
}
-
- if (TextUtils.isEmpty(newText)) {
- mSearchViewCloseButton.setVisibility(View.GONE);
- mVoiceSearchButton.setVisibility(View.VISIBLE);
- } else {
- mSearchViewCloseButton.setVisibility(View.VISIBLE);
- mVoiceSearchButton.setVisibility(View.GONE);
- }
}
@Override
@@ -295,15 +286,14 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
/**
- * Open the search UI when the user touches the search text view.
+ * Open the search UI when the user clicks on the search box.
*/
- private final View.OnTouchListener mSearchViewOnTouchListener = new View.OnTouchListener() {
+ private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
@Override
- public boolean onTouch(View v, MotionEvent event) {
+ public void onClick(View v) {
if (!isInSearchUi()) {
enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
}
- return false;
}
};
@@ -336,15 +326,17 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView();
mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
- mSearchIcon = mSearchEditTextLayout.findViewById(R.id.search_magnifying_glass);
- mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button);
-
mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view);
mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
- mSearchView.setOnTouchListener(mSearchViewOnTouchListener);
-
- mSearchViewCloseButton = mSearchEditTextLayout.findViewById(R.id.search_close_button);
- mSearchViewCloseButton.setOnClickListener(this);
+ mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button);
+ mSearchEditTextLayout.findViewById(R.id.search_box_start_search).setOnClickListener(
+ mSearchViewOnClickListener);
+ mSearchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
+ @Override
+ public void onBackButtonClicked() {
+ onBackPressed();
+ }
+ });
ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById(
R.id.dialtacts_options_menu_button);
@@ -609,11 +601,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
}
mListsFragment.maybeShowActionBar();
+
if (isInSearchUi()) {
if (TextUtils.isEmpty(mSearchQuery)) {
exitSearchUi();
- } else {
- mSearchIcon.setVisibility(View.GONE);
}
}
}
@@ -822,10 +813,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
mListsFragment.getView().animate().alpha(0).withLayer();
mSearchEditTextLayout.animateExpandOrCollapse(true);
-
- if (!mIsDialpadShown) {
- mSearchIcon.setVisibility(View.GONE);
- }
}
/**
@@ -843,7 +830,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(0, android.R.animator.fade_out);
-
if (mSmartDialSearchFragment != null) {
transaction.remove(mSmartDialSearchFragment);
}
@@ -854,7 +840,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
mListsFragment.getView().animate().alpha(1).withLayer();
mSearchEditTextLayout.animateExpandOrCollapse(false);
- mSearchIcon.setVisibility(View.VISIBLE);
}
/** Returns an Intent to launch Call Settings screen */
@@ -874,6 +859,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
hideDialpadFragment(true, false);
} else if (isInSearchUi()) {
exitSearchUi();
+ hideInputMethod(parentLayout);
} else {
super.onBackPressed();
}
diff --git a/src/com/android/dialer/widget/SearchEditTextLayout.java b/src/com/android/dialer/widget/SearchEditTextLayout.java
index e2cbcb3ef..33bf09f59 100644
--- a/src/com/android/dialer/widget/SearchEditTextLayout.java
+++ b/src/com/android/dialer/widget/SearchEditTextLayout.java
@@ -20,12 +20,19 @@ import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.KeyEvent;
-import android.widget.LinearLayout;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import com.android.contacts.common.animation.AnimationUtils;
import com.android.dialer.R;
-public class SearchEditTextLayout extends LinearLayout {
+public class SearchEditTextLayout extends FrameLayout {
+ private static final int ANIMATION_DURATION = 200;
+
private OnKeyListener mPreImeKeyListener;
private int mTopMargin;
private int mBottomMargin;
@@ -34,6 +41,19 @@ public class SearchEditTextLayout extends LinearLayout {
private int mBackgroundColor;
+ private View mCollapsed;
+ private View mExpanded;
+ private EditText mSearchView;
+
+ private OnBackButtonClickedListener mOnBackButtonClickedListener;
+
+ /**
+ * Listener for the back button next to the search view being pressed
+ */
+ public interface OnBackButtonClickedListener {
+ public void onBackButtonClicked();
+ }
+
public SearchEditTextLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mBackgroundColor = getResources().getColor(R.color.searchbox_background_color);
@@ -43,6 +63,10 @@ public class SearchEditTextLayout extends LinearLayout {
mPreImeKeyListener = listener;
}
+ public void setOnBackButtonClickedListener(OnBackButtonClickedListener listener) {
+ mOnBackButtonClickedListener = listener;
+ }
+
@Override
protected void onFinishInflate() {
MarginLayoutParams params = (MarginLayoutParams) getLayoutParams();
@@ -50,6 +74,36 @@ public class SearchEditTextLayout extends LinearLayout {
mBottomMargin = params.bottomMargin;
mLeftMargin = params.leftMargin;
mRightMargin = params.rightMargin;
+
+ mCollapsed = findViewById(R.id.search_box_collapsed);
+ mExpanded = findViewById(R.id.search_box_expanded);
+ mSearchView = (EditText) mExpanded.findViewById(R.id.search_view);
+
+ mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus) {
+ showInputMethod(v);
+ }
+ }
+ });
+
+ findViewById(R.id.search_close_button).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mSearchView.setText(null);
+ }
+ });
+
+ findViewById(R.id.search_back_button).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mOnBackButtonClickedListener != null) {
+ mOnBackButtonClickedListener.onBackButtonClicked();
+ }
+ }
+ });
+
super.onFinishInflate();
}
@@ -66,9 +120,12 @@ public class SearchEditTextLayout extends LinearLayout {
public void animateExpandOrCollapse(boolean expand) {
final ValueAnimator animator;
if (expand) {
+ AnimationUtils.crossFadeViews(mExpanded, mCollapsed, ANIMATION_DURATION);
animator = ValueAnimator.ofFloat(1f, 0f);
setBackgroundColor(mBackgroundColor);
+ mSearchView.requestFocus();
} else {
+ AnimationUtils.crossFadeViews(mCollapsed, mExpanded, ANIMATION_DURATION);
animator = ValueAnimator.ofFloat(0f, 1f);
setBackgroundResource(R.drawable.rounded_corner);
}
@@ -84,6 +141,15 @@ public class SearchEditTextLayout extends LinearLayout {
requestLayout();
}
});
+ animator.setDuration(ANIMATION_DURATION);
animator.start();
}
+
+ private void showInputMethod(View view) {
+ final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.showSoftInput(view, 0);
+ }
+ }
} \ No newline at end of file