/** * 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); }
@Override public void onSearchViewClicked() { // Hide FAB, as the keyboard is shown. mFloatingActionButtonController.scaleOut(); } });
public ProportionalLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initFromAttributes(context, attrs); }
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 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 */); } });
/** * Create new fragment instance with default title and no option to set as default. * * @param accountHandles The {@code PhoneAccountHandle}s available to select from. * @param listener The listener for the results of the account selection. */ public static SelectPhoneAccountDialogFragment newInstance( List<PhoneAccountHandle> accountHandles, SelectPhoneAccountListener listener) { return newInstance(R.string.select_account_dialog_title, false, accountHandles, listener); }
@Override protected void onReceiveResult(int resultCode, Bundle resultData) { if (resultCode == RESULT_SELECTED) { onPhoneAccountSelected( (PhoneAccountHandle) resultData.getParcelable( EXTRA_SELECTED_ACCOUNT_HANDLE), resultData.getBoolean(EXTRA_SET_DEFAULT)); } else if (resultCode == RESULT_DISMISSED) { onDialogDismissed(); } }
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { if (getChildCount() != 1) { throw new IllegalStateException("ProportionalLayout requires exactly one child"); } final View child = getChildAt(0); child.layout(0, 0, right-left, bottom-top); }
/** * 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 onStop() { if (!mIsSelected && mListener != null) { mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, null); } super.onStop(); } }
@Override public void requestLayout() { forceLayout(); } }
@Override public void requestLayout() { forceLayout(); } }
/** * 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; }
/** * 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))); }
private void initFromAttributes(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProportionalLayout); mDirection = Direction.parse(a.getString(R.styleable.ProportionalLayout_direction)); mRatio = a.getFloat(R.styleable.ProportionalLayout_ratio, 1.0f); a.recycle(); }
@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)); } }
public ProportionalLayout(Context context, AttributeSet attrs) { super(context, attrs); initFromAttributes(context, attrs); }
@Override public void onClick(DialogInterface dialog, int which) { mIsSelected = true; PhoneAccountHandle selectedAccountHandle = mAccountHandles.get(which); final Bundle result = new Bundle(); result.putParcelable(SelectPhoneAccountListener.EXTRA_SELECTED_ACCOUNT_HANDLE, selectedAccountHandle); result.putBoolean(SelectPhoneAccountListener.EXTRA_SET_DEFAULT, mIsDefaultChecked); if (mListener != null) { mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_SELECTED, result); } } };