From 6324f707bc35d9d3336f58f6004d1f3b1e6de1a3 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 16 Jun 2015 14:45:58 -0700 Subject: Fix FAB state and transitions. + Change to dialpad FAB in search (used to stay as add contact FAB, if we were in the Contacts list). + Position dialpad to align end in search (used to stay in the center, if we opened the search from Speed Dial). + Restore correct position/icon when exiting search. + Add correct FAB scale in/out behaviors in for transitions between lists fragment and search UI, search UI and dialpad, in particular for when the FAB changes position from END to MIDDLE when going from search UI back to Speed Dial. + Add FAB scale in/outs for showing/hiding the soft keyboard. Bug: 21161760 Change-Id: Idbddbac161e459e3708d43395850d80927d5e448 --- src/com/android/dialer/DialtactsActivity.java | 77 ++++++++++++++++++++------- 1 file changed, 57 insertions(+), 20 deletions(-) (limited to 'src/com/android/dialer/DialtactsActivity.java') diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 47e52342a..fc0f1fb24 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -84,7 +84,7 @@ import com.android.dialer.util.IntentUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.widget.ActionBarController; import com.android.dialer.widget.SearchEditTextLayout; -import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener; +import com.android.dialer.widget.SearchEditTextLayout.Callback; import com.android.dialerbind.DatabaseHelperManager; import com.android.phone.common.animation.AnimUtils; import com.android.phone.common.animation.AnimationListenerAdapter; @@ -136,6 +136,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; + private static final int FAB_SCALE_IN_DELAY_MS = 300; + private FrameLayout mParentLayout; /** @@ -338,14 +340,19 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O }; /** - * If the search term is empty and the user closes the soft keyboard, close the search UI. + * 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 && - TextUtils.isEmpty(mSearchView.getText().toString())) { - maybeExitSearchUi(); + 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. + maybeExitSearchUi(); + } else { + // If the search term is not empty, show the dialpad fab. + showFabInSearchUi(); + } } return false; } @@ -394,11 +401,17 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O .setOnClickListener(mSearchViewOnClickListener); searchEditTextLayout.findViewById(R.id.search_box_start_search) .setOnClickListener(mSearchViewOnClickListener); - searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() { + 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 @@ -463,7 +476,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O observer.removeOnGlobalLayoutListener(this); int screenWidth = mParentLayout.getWidth(); mFloatingActionButtonController.setScreenWidth(screenWidth); - updateFloatingActionButtonControllerAlignment(false /* animate */); + mFloatingActionButtonController.align( + getFabAlignment(), false /* animate */); } }); @@ -527,7 +541,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } prepareVoiceSearchButton(); mDialerDatabaseHelper.startSmartDialUpdateThread(); - updateFloatingActionButtonControllerAlignment(false /* animate */); + mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); Trace.endSection(); } @@ -744,7 +758,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O updateSearchFragmentPosition(); - updateFloatingActionButtonControllerAlignment(animate); + mFloatingActionButtonController.align(getFabAlignment(), animate); if (animate) { mDialpadFragment.getView().startAnimation(mSlideOut); } else { @@ -948,6 +962,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mInDialpadSearch = smartDialSearch; mInRegularSearch = !smartDialSearch; + mFloatingActionButtonController.scaleOut(); + SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); if (animate) { transaction.setCustomAnimations(android.R.animator.fade_in, 0); @@ -959,6 +975,15 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O fragment = new SmartDialSearchFragment(); } else { fragment = new RegularSearchFragment(); + fragment.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + // Show the FAB when the user touches the lists fragment and the soft + // keyboard is hidden. + showFabInSearchUi(); + return false; + } + }); } transaction.add(R.id.dialtacts_frame, fragment, tag); } else { @@ -995,6 +1020,14 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O setNotInSearchUi(); + // Restore the FAB for the lists fragment. + if (getFabAlignment() != FloatingActionButtonController.ALIGN_END) { + mFloatingActionButtonController.setVisible(false); + } + mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); + onPageScrolled(mListsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */); + onPageSelected(mListsFragment.getCurrentTabIndex()); + final FragmentTransaction transaction = getFragmentManager().beginTransaction(); if (mSmartDialSearchFragment != null) { transaction.remove(mSmartDialSearchFragment); @@ -1055,6 +1088,14 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O return false; } + private void showFabInSearchUi() { + mFloatingActionButtonController.changeIcon( + getResources().getDrawable(R.drawable.fab_ic_dial), + 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) { if (mSmartDialSearchFragment != null) { @@ -1251,16 +1292,12 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O return mActionBarHeight; } - /** - * Updates controller based on currently known information. - * - * @param animate Whether or not to animate the transition. - */ - private void updateFloatingActionButtonControllerAlignment(boolean animate) { - int align = (!mIsLandscape && - mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) ? - FloatingActionButtonController.ALIGN_MIDDLE : - FloatingActionButtonController.ALIGN_END; - mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate); + + private int getFabAlignment() { + if (!mIsLandscape && !isInSearchUi() && + mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) { + return FloatingActionButtonController.ALIGN_MIDDLE; + } + return FloatingActionButtonController.ALIGN_END; } } -- cgit v1.2.3