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); }
/** * Updates the FAB location (middle to right position) as the PageView scrolls. * * @param positionOffset A fraction used to calculate position of the FAB during page scroll. */ public void onPageScrolled(float positionOffset) { // As the page is scrolling, if we're on the first tab, update the FAB position so it // moves along with it. mFloatingActionButtonContainer.setTranslationX( (int) (positionOffset * getTranslationXForAlignment(ALIGN_END))); }
/** * Calculates the X offset of the FAB to the given alignment, adjusted for whether or not the * view is in RTL mode. * * @param align One of ALIGN_MIDDLE, ALIGN_QUARTER_RIGHT, or ALIGN_RIGHT. * @return The translationX for the given alignment. */ public int getTranslationXForAlignment(int align) { int result = 0; switch (align) { case ALIGN_MIDDLE: // Moves the FAB to exactly center screen. return 0; case ALIGN_QUARTER_END: // Moves the FAB a quarter of the screen width. result = mScreenWidth / 4; break; case ALIGN_END: // Moves the FAB half the screen width. Same as aligning right with a marginRight. result = mScreenWidth / 2 - mFloatingActionButtonWidth / 2 - mFloatingActionButtonMarginRight; break; } if (isLayoutRtl()) { result *= -1; } return result; }
@Override public void onGlobalLayout() { final ViewTreeObserver observer = floatingActionButtonContainer.getViewTreeObserver(); if (!observer.isAlive()) { return; } observer.removeOnGlobalLayoutListener(this); int screenWidth = mParentLayout.getWidth(); mFloatingActionButtonController.setScreenWidth(screenWidth); mFloatingActionButtonController.align( getFabAlignment(), false /* animate */); } });
@Override public void onHiddenChanged(boolean hidden) { super.onHiddenChanged(hidden); final DialtactsActivity activity = (DialtactsActivity) getActivity(); final DialpadView dialpadView = (DialpadView) getView().findViewById(R.id.dialpad_view); if (activity == null) return; if (!hidden && !isDialpadChooserVisible()) { if (mAnimate) { dialpadView.animateShow(); } mFloatingActionButtonController.setVisible(false); mFloatingActionButtonController.scaleIn(mAnimate ? mDialpadSlideInDuration : 0); activity.onDialpadShown(); mDigits.requestFocus(); } if (hidden) { if (mAnimate) { mFloatingActionButtonController.scaleOut(); } else { mFloatingActionButtonController.setVisible(false); } } }
/** * Aligns the FAB to the described location * * @param align One of ALIGN_MIDDLE, ALIGN_QUARTER_RIGHT, or ALIGN_RIGHT. * @param animate Whether or not to animate the transition. */ public void align(int align, boolean animate) { align(align, 0 /*offsetX */, 0 /* offsetY */, animate); }
mFloatingActionButtonController.scaleOut(); } else { mFloatingActionButtonController.setVisible(false); maybeEnterSearchUi();
mFloatingActionButtonController.setVisible(false); mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); onPageScrolled(mListsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */); onPageSelected(mListsFragment.getCurrentTabIndex());
/** * Scales the floating action button from no height and width to its actual dimensions. This is * an animation for showing the floating action button. * @param delayMs The delay for the effect, in milliseconds. */ public void scaleIn(int delayMs) { setVisible(true); AnimUtils.scaleIn(mFloatingActionButtonContainer, FAB_SCALE_IN_DURATION, delayMs); AnimUtils.fadeIn(mFloatingActionButton, FAB_SCALE_IN_DURATION, delayMs + FAB_SCALE_IN_FADE_IN_DELAY, null); }
@Override public void onSearchViewClicked() { // Hide FAB, as the keyboard is shown. mFloatingActionButtonController.scaleOut(); } });
(ImageButton) fragmentView.findViewById(R.id.dialpad_floating_action_button); floatingActionButton.setOnClickListener(this); mFloatingActionButtonController = new FloatingActionButtonController(getActivity(), floatingActionButtonContainer, floatingActionButton); Trace.endSection();
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { int tabIndex = mListsFragment.getCurrentTabIndex(); // Scroll the button from center to end when moving from the Speed Dial to Call History tab. // In RTL, scroll when the current tab is Call History instead, since the order of the tabs // is reversed and the ViewPager returns the left tab position during scroll. boolean isRtl = DialerUtils.isRtl(); if (!isRtl && tabIndex == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) { mFloatingActionButtonController.onPageScrolled(positionOffset); } else if (isRtl && tabIndex == ListsFragment.TAB_INDEX_HISTORY && !mIsLandscape) { mFloatingActionButtonController.onPageScrolled(1 - positionOffset); } else if (tabIndex != ListsFragment.TAB_INDEX_SPEED_DIAL) { mFloatingActionButtonController.onPageScrolled(1); } }
/** * Finishes hiding the dialpad fragment after any animations are completed. */ private void commitDialpadFragmentHide() { if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) { final FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.hide(mDialpadFragment); ft.commit(); } mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY); }
@Override public void onPageSelected(int position) { updateMissedCalls(); int tabIndex = mListsFragment.getCurrentTabIndex(); mPreviouslySelectedTabIndex = tabIndex; if (tabIndex == ListsFragment.TAB_INDEX_ALL_CONTACTS) { mFloatingActionButtonController.changeIcon( getResources().getDrawable(R.drawable.ic_person_add_24dp), getResources().getString(R.string.search_shortcut_create_new_contact)); } else { mFloatingActionButtonController.changeIcon( getResources().getDrawable(R.drawable.fab_ic_dial), getResources().getString(R.string.action_menu_dialpad_button)); } }
mFloatingActionButtonController.align(getFabAlignment(), false /* animate */);
mFloatingActionButtonController.setVisible(false); mDialpadChooser.setVisibility(View.VISIBLE); mFloatingActionButtonController.setVisible(true); mDialpadChooser.setVisibility(View.GONE);
mInRegularSearch = !smartDialSearch; mFloatingActionButtonController.scaleOut();
ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button); floatingActionButton.setOnClickListener(this); mFloatingActionButtonController = new FloatingActionButtonController(this, floatingActionButtonContainer, floatingActionButton);
mFloatingActionButtonController.align(getFabAlignment(), animate); if (animate) { mDialpadFragment.getView().startAnimation(mSlideOut);
/** * Aligns the FAB to the described location plus specified additional offsets. * * @param align One of ALIGN_MIDDLE, ALIGN_QUARTER_RIGHT, or ALIGN_RIGHT. * @param offsetX Additional offsetX to translate by. * @param offsetY Additional offsetY to translate by. * @param animate Whether or not to animate the transition. */ public void align(int align, int offsetX, int offsetY, boolean animate) { if (mScreenWidth == 0) { return; } int translationX = getTranslationXForAlignment(align); // Skip animation if container is not shown; animation causes container to show again. if (animate && mFloatingActionButtonContainer.isShown()) { mFloatingActionButtonContainer.animate() .translationX(translationX + offsetX) .translationY(offsetY) .setInterpolator(mFabInterpolator) .setDuration(mAnimationDuration) .start(); } else { mFloatingActionButtonContainer.setTranslationX(translationX + offsetX); mFloatingActionButtonContainer.setTranslationY(offsetY); } }