From ed4e11ddafece1d308b87955880f4f153dbfc8e2 Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Tue, 5 Sep 2017 18:24:47 -0700 Subject: Automated g4 rollback of changelist 167332236. *** Reason for rollback *** Based off a CL that needs to be rolled back. *** Original change description *** Improved behavior of back button in search ui. Pressing the back button in the search UI now functions as follows: - If the keyboard is opened, the keyboard is minimized - If the dialpad is opened, the dialpad is closed - If the keyboard and dialpad is closed, the search ui is closed Our existing behavior was dependent on whether a query had been built yet. basically, if the user pressed back with no query selected, the search ui was closed. From the bugbash: 7. No scroll bar in the search... *** Bug: 64902476,64137632,62685859,63691995,63939331 Test: n/a PiperOrigin-RevId: 167661409 Change-Id: I0627d54af33fb55c64b5edcd459dde6a73d93266 --- java/com/android/dialer/app/DialtactsActivity.java | 113 +++++++++++++-------- .../dialer/app/widget/ActionBarController.java | 28 +++-- .../dialer/app/widget/SearchEditTextLayout.java | 67 +++++++++++- .../dialer/dialpadview/DialpadFragment.java | 12 +-- 4 files changed, 165 insertions(+), 55 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java index 7f5a9b94a..13b6eb92c 100644 --- a/java/com/android/dialer/app/DialtactsActivity.java +++ b/java/com/android/dialer/app/DialtactsActivity.java @@ -49,6 +49,7 @@ import android.text.TextUtils; import android.text.TextWatcher; import android.view.DragEvent; import android.view.Gravity; +import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; @@ -168,7 +169,6 @@ public class DialtactsActivity extends TransactionSafeActivity private static final String TAG = "DialtactsActivity"; private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui"; private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui"; - private static final String KEY_IN_NEW_SEARCH_UI = "in_new_search_ui"; private static final String KEY_SEARCH_QUERY = "search_query"; private static final String KEY_FIRST_LAUNCH = "first_launch"; private static final String KEY_WAS_CONFIGURATION_CHANGE = "was_configuration_change"; @@ -213,8 +213,6 @@ public class DialtactsActivity extends TransactionSafeActivity */ private boolean mStateSaved; - private boolean mIsKeyboardOpen; - private boolean mInNewSearch; private boolean mIsRestarting; private boolean mInDialpadSearch; private boolean mInRegularSearch; @@ -332,6 +330,27 @@ public class DialtactsActivity extends TransactionSafeActivity private int mActionBarHeight; private int mPreviouslySelectedTabIndex; + /** Handles the user closing the soft keyboard. */ + private final View.OnKeyListener mSearchEditTextLayoutListener = + new View.OnKeyListener() { + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { + if (TextUtils.isEmpty(mSearchView.getText().toString())) { + // If the search term is empty, close the search UI. + PerformanceReport.recordClick(UiAction.Type.CLOSE_SEARCH_WITH_HIDE_BUTTON); + maybeExitSearchUi(); + } else { + // If the search term is not empty, show the dialpad fab. + if (!mFloatingActionButtonController.isVisible()) { + PerformanceReport.recordClick(UiAction.Type.HIDE_KEYBOARD_IN_SEARCH); + } + showFabInSearchUi(); + } + } + return false; + } + }; /** * The text returned from a voice search query. Set in {@link #onActivityResult} and used in @@ -391,20 +410,30 @@ public class DialtactsActivity extends TransactionSafeActivity SearchEditTextLayout searchEditTextLayout = actionBar.getCustomView().findViewById(R.id.search_view_container); + searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener); mActionBarController = new ActionBarController(this, searchEditTextLayout); mSearchView = searchEditTextLayout.findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); mSearchView.setHint(getSearchBoxHint()); - mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button); searchEditTextLayout .findViewById(R.id.search_box_collapsed) .setOnClickListener(mSearchViewOnClickListener); - searchEditTextLayout - .findViewById(R.id.search_back_button) - .setOnClickListener(v -> exitSearchUi()); + searchEditTextLayout.setCallback( + new SearchEditTextLayout.Callback() { + @Override + public void onBackButtonClicked() { + onBackPressed(); + } + + @Override + public void onSearchViewClicked() { + // Hide FAB, as the keyboard is shown. + mFloatingActionButtonController.scaleOut(); + } + }); mIsLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; @@ -431,7 +460,6 @@ public class DialtactsActivity extends TransactionSafeActivity mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); - mInNewSearch = savedInstanceState.getBoolean(KEY_IN_NEW_SEARCH_UI); mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); mWasConfigurationChange = savedInstanceState.getBoolean(KEY_WAS_CONFIGURATION_CHANGE); mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN); @@ -626,7 +654,6 @@ public class DialtactsActivity extends TransactionSafeActivity outState.putString(KEY_SEARCH_QUERY, mSearchQuery); outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch); outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch); - outState.putBoolean(KEY_IN_NEW_SEARCH_UI, mInNewSearch); outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown); outState.putBoolean(KEY_WAS_CONFIGURATION_CHANGE, isChangingConfigurations()); @@ -866,19 +893,14 @@ public class DialtactsActivity extends TransactionSafeActivity updateSearchFragmentPosition(); } - @Override - public void onCallPlacedFromDialpad() { - hideDialpadFragment(false /* animate */, true /*clearDialpad */); - exitSearchUi(); - } - /** * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in a * callback after the hide animation ends. * * @see #commitDialpadFragmentHide */ - private void hideDialpadFragment(boolean animate, boolean clearDialpad) { + @Override + public void hideDialpadFragment(boolean animate, boolean clearDialpad) { LogUtil.enterBlock("DialtactsActivity.hideDialpadFragment"); if (mDialpadFragment == null || mDialpadFragment.getView() == null) { return; @@ -913,6 +935,11 @@ public class DialtactsActivity extends TransactionSafeActivity mActionBarController.onDialpadDown(); + if (isInSearchUi()) { + if (TextUtils.isEmpty(mSearchQuery)) { + exitSearchUi(); + } + } // reset the title to normal. setTitle(R.string.launcherActivityLabel); } @@ -960,7 +987,7 @@ public class DialtactsActivity extends TransactionSafeActivity @Override public boolean isInSearchUi() { - return mInDialpadSearch || mInRegularSearch || mInNewSearch; + return mInDialpadSearch || mInRegularSearch; } @Override @@ -971,7 +998,6 @@ public class DialtactsActivity extends TransactionSafeActivity private void setNotInSearchUi() { mInDialpadSearch = false; mInRegularSearch = false; - mInNewSearch = false; } private void hideDialpadAndSearchUi() { @@ -1145,21 +1171,17 @@ public class DialtactsActivity extends TransactionSafeActivity } final String tag; - mInDialpadSearch = false; - mInRegularSearch = false; - mInNewSearch = false; boolean useNewSearch = ConfigProviderBindings.get(this).getBoolean("enable_new_search_fragment", false); if (useNewSearch) { tag = TAG_NEW_SEARCH_FRAGMENT; - mInNewSearch = true; } else if (smartDialSearch) { tag = TAG_SMARTDIAL_SEARCH_FRAGMENT; - mInDialpadSearch = true; } else { tag = TAG_REGULAR_SEARCH_FRAGMENT; - mInRegularSearch = true; } + mInDialpadSearch = smartDialSearch; + mInRegularSearch = !smartDialSearch; mFloatingActionButtonController.scaleOut(); @@ -1282,36 +1304,45 @@ public class DialtactsActivity extends TransactionSafeActivity return; } if (mIsDialpadShown) { - hideDialpadFragment(true, false); - } else if (isInSearchUi()) { - if (mIsKeyboardOpen) { - DialerUtils.hideInputMethod(mParentLayout); - PerformanceReport.recordClick(UiAction.Type.HIDE_KEYBOARD_IN_SEARCH); - } else { + if (TextUtils.isEmpty(mSearchQuery) + || (mSmartDialSearchFragment != null + && mSmartDialSearchFragment.isVisible() + && mSmartDialSearchFragment.getAdapter().getCount() == 0)) { exitSearchUi(); } + hideDialpadFragment(true, false); + } else if (isInSearchUi()) { + exitSearchUi(); + DialerUtils.hideInputMethod(mParentLayout); } else { super.onBackPressed(); } } - @Override - public void onConfigurationChanged(Configuration configuration) { - super.onConfigurationChanged(configuration); - // Checks whether a hardware keyboard is available - if (configuration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) { - mIsKeyboardOpen = true; - } else if (configuration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) { - mIsKeyboardOpen = false; - } - } - private void maybeEnterSearchUi() { if (!isInSearchUi()) { enterSearchUi(true /* isSmartDial */, mSearchQuery, false); } } + /** @return True if the search UI was exited, false otherwise */ + private boolean maybeExitSearchUi() { + if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) { + exitSearchUi(); + DialerUtils.hideInputMethod(mParentLayout); + return true; + } + return false; + } + + private void showFabInSearchUi() { + mFloatingActionButtonController.changeIcon( + getResources().getDrawable(R.drawable.quantum_ic_dialpad_white_24, null), + getResources().getString(R.string.action_menu_dialpad_button)); + mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); + mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); + } + @Override public void onDialpadQueryChanged(String query) { mDialpadQuery = query; diff --git a/java/com/android/dialer/app/widget/ActionBarController.java b/java/com/android/dialer/app/widget/ActionBarController.java index 3daa0e2d4..c1b4cc2b4 100644 --- a/java/com/android/dialer/app/widget/ActionBarController.java +++ b/java/com/android/dialer/app/widget/ActionBarController.java @@ -49,6 +49,18 @@ public class ActionBarController { } }; + private final AnimationCallback mFadeInCallback = + new AnimationCallback() { + @Override + public void onAnimationEnd() { + slideActionBar(false /* slideUp */, false /* animate */); + } + + @Override + public void onAnimationCancel() { + slideActionBar(false /* slideUp */, false /* animate */); + } + }; private ValueAnimator mAnimator; public ActionBarController(ActivityUi activityUi, SearchEditTextLayout searchBox) { @@ -100,13 +112,17 @@ public class ActionBarController { mSearchBox.isFadedOut(), mSearchBox.isExpanded()); if (mActivityUi.isInSearchUi()) { - if (mSearchBox.isFadedOut()) { - mSearchBox.setVisible(true); - } - if (!mSearchBox.isExpanded()) { - mSearchBox.expand(false /* animate */, false /* requestFocus */); + if (mActivityUi.hasSearchQuery()) { + if (mSearchBox.isFadedOut()) { + mSearchBox.setVisible(true); + } + if (!mSearchBox.isExpanded()) { + mSearchBox.expand(false /* animate */, false /* requestFocus */); + } + slideActionBar(false /* slideUp */, true /* animate */); + } else { + mSearchBox.fadeIn(mFadeInCallback); } - slideActionBar(false /* slideUp */, true /* animate */); } } diff --git a/java/com/android/dialer/app/widget/SearchEditTextLayout.java b/java/com/android/dialer/app/widget/SearchEditTextLayout.java index 2051b65f2..95bd12aa1 100644 --- a/java/com/android/dialer/app/widget/SearchEditTextLayout.java +++ b/java/com/android/dialer/app/widget/SearchEditTextLayout.java @@ -23,6 +23,7 @@ import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.util.AttributeSet; +import android.view.KeyEvent; import android.view.View; import android.widget.EditText; import android.widget.FrameLayout; @@ -37,6 +38,7 @@ public class SearchEditTextLayout extends FrameLayout { /* Subclass-visible for testing */ protected boolean mIsExpanded = false; protected boolean mIsFadedOut = false; + private OnKeyListener mPreImeKeyListener; private int mTopMargin; private int mBottomMargin; private int mLeftMargin; @@ -54,10 +56,20 @@ public class SearchEditTextLayout extends FrameLayout { private ValueAnimator mAnimator; + private Callback mCallback; + public SearchEditTextLayout(Context context, AttributeSet attrs) { super(context, attrs); } + public void setPreImeKeyListener(OnKeyListener listener) { + mPreImeKeyListener = listener; + } + + public void setCallback(Callback listener) { + mCallback = listener; + } + @Override protected void onFinishInflate() { MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); @@ -70,7 +82,7 @@ public class SearchEditTextLayout extends FrameLayout { mCollapsed = findViewById(R.id.search_box_collapsed); mExpanded = findViewById(R.id.search_box_expanded); - mSearchView = mExpanded.findViewById(R.id.search_view); + mSearchView = (EditText) mExpanded.findViewById(R.id.search_view); mSearchIcon = findViewById(R.id.search_magnifying_glass); mCollapsedSearchBox = findViewById(R.id.search_box_start_search); @@ -111,6 +123,16 @@ public class SearchEditTextLayout extends FrameLayout { } }); + mSearchView.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mCallback != null) { + mCallback.onSearchViewClicked(); + } + } + }); + mSearchView.addTextChangedListener( new TextWatcher() { @Override @@ -125,10 +147,43 @@ public class SearchEditTextLayout extends FrameLayout { public void afterTextChanged(Editable s) {} }); - mClearButtonView.setOnClickListener(v -> mSearchView.setText(null)); + 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 (mCallback != null) { + mCallback.onBackButtonClicked(); + } + } + }); + super.onFinishInflate(); } + @Override + public boolean dispatchKeyEventPreIme(KeyEvent event) { + if (mPreImeKeyListener != null) { + if (mPreImeKeyListener.onKey(this, event.getKeyCode(), event)) { + return true; + } + } + return super.dispatchKeyEventPreIme(event); + } + + public void fadeOut() { + fadeOut(null); + } + public void fadeOut(AnimUtils.AnimationCallback callback) { AnimUtils.fadeOut(this, ANIMATION_DURATION, callback); mIsFadedOut = true; @@ -269,4 +324,12 @@ public class SearchEditTextLayout extends FrameLayout { params.rightMargin = (int) (mRightMargin * fraction); requestLayout(); } + + /** Listener for the back button next to the search view being pressed */ + public interface Callback { + + void onBackButtonClicked(); + + void onSearchViewClicked(); + } } diff --git a/java/com/android/dialer/dialpadview/DialpadFragment.java b/java/com/android/dialer/dialpadview/DialpadFragment.java index 837c3af90..86a83796e 100644 --- a/java/com/android/dialer/dialpadview/DialpadFragment.java +++ b/java/com/android/dialer/dialpadview/DialpadFragment.java @@ -1001,12 +1001,12 @@ public class DialpadFragment extends Fragment DialerUtils.startActivityWithErrorToast( getActivity(), new CallIntentBuilder(CallUtil.getVoicemailUri(), CallInitiationType.Type.DIALPAD).build()); - hideAndClearDialpad(); + hideAndClearDialpad(false); } - private void hideAndClearDialpad() { + private void hideAndClearDialpad(boolean animate) { LogUtil.enterBlock("DialpadFragment.hideAndClearDialpad"); - FragmentUtils.getParentUnsafe(this, DialpadListener.class).onCallPlacedFromDialpad(); + FragmentUtils.getParentUnsafe(this, DialpadListener.class).hideDialpadFragment(animate, true); } /** @@ -1053,7 +1053,7 @@ public class DialpadFragment extends Fragment final Intent intent = new CallIntentBuilder(number, CallInitiationType.Type.DIALPAD).build(); DialerUtils.startActivityWithErrorToast(getActivity(), intent); - hideAndClearDialpad(); + hideAndClearDialpad(false); } } } @@ -1297,7 +1297,7 @@ public class DialpadFragment extends Fragment return true; } else if (resId == R.id.menu_call_with_note) { CallSubjectDialog.start(getActivity(), mDigits.getText().toString()); - hideAndClearDialpad(); + hideAndClearDialpad(false); return true; } else { return false; @@ -1710,7 +1710,7 @@ public class DialpadFragment extends Fragment void onDialpadShown(); - void onCallPlacedFromDialpad(); + void hideDialpadFragment(boolean animate, boolean value); } /** Callback for async lookup of the last number dialed. */ -- cgit v1.2.3