FloatingActionButtonController.java revision 6aa50bc71fd11826ca85b0d3541d08c7f567d2b9
16cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati/* 26cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Copyright (C) 2014 The Android Open Source Project 36cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 46cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Licensed under the Apache License, Version 2.0 (the "License"); 56cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * you may not use this file except in compliance with the License. 66cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * You may obtain a copy of the License at 76cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 86cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * http://www.apache.org/licenses/LICENSE-2.0 96cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 106cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Unless required by applicable law or agreed to in writing, software 116cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * distributed under the License is distributed on an "AS IS" BASIS, 126cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * See the License for the specific language governing permissions and 146cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * limitations under the License. 156cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati */ 166cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 176cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatipackage com.android.contacts.common.widget; 186cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 196cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatiimport android.app.Activity; 206cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatiimport android.content.res.Resources; 21bf6731b85f825f153d839183ea767435617f662fAndrew Leeimport android.graphics.drawable.Drawable; 226cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatiimport android.view.animation.AnimationUtils; 236cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatiimport android.view.animation.Interpolator; 246cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatiimport android.view.View; 25bf6731b85f825f153d839183ea767435617f662fAndrew Leeimport android.widget.ImageButton; 266cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 276cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatiimport com.android.contacts.common.util.ViewUtil; 286cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatiimport com.android.contacts.common.R; 297c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Leeimport com.android.phone.common.animation.AnimUtils; 306cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 316cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati/** 326cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Controls the movement and appearance of the FAB (Floating Action Button). 336cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati */ 346cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapatipublic class FloatingActionButtonController { 356cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati public static final int ALIGN_MIDDLE = 0; 36a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee public static final int ALIGN_QUARTER_END = 1; 37a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee public static final int ALIGN_END = 2; 386cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 39d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee private static final int FAB_SCALE_IN_DURATION = 266; 40d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee private static final int FAB_SCALE_IN_FADE_IN_DELAY = 100; 41d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee private static final int FAB_ICON_FADE_OUT_DURATION = 66; 42435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee 436cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati private final int mAnimationDuration; 446cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati private final int mFloatingActionButtonWidth; 456cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati private final int mFloatingActionButtonMarginRight; 466cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati private final View mFloatingActionButtonContainer; 47bf6731b85f825f153d839183ea767435617f662fAndrew Lee private final ImageButton mFloatingActionButton; 486cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati private final Interpolator mFabInterpolator; 496cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati private int mScreenWidth; 506cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 51bf6731b85f825f153d839183ea767435617f662fAndrew Lee public FloatingActionButtonController(Activity activity, View container, ImageButton button) { 526cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati Resources resources = activity.getResources(); 536cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFabInterpolator = AnimationUtils.loadInterpolator(activity, 546cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati android.R.interpolator.fast_out_slow_in); 556cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonWidth = resources.getDimensionPixelSize( 566cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati R.dimen.floating_action_button_width); 576cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonMarginRight = resources.getDimensionPixelOffset( 586cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati R.dimen.floating_action_button_margin_right); 596cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mAnimationDuration = resources.getInteger( 606cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati R.integer.floating_action_button_animation_duration); 616cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonContainer = container; 62435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee mFloatingActionButton = button; 636cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati ViewUtil.setupFloatingActionButton(mFloatingActionButtonContainer, resources); 646cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 656cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 666cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati /** 676cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Passes the screen width into the class. Necessary for translation calculations. 686cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Should be called as soon as parent View width is available. 696cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 706cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @param screenWidth The width of the screen in pixels. 716cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati */ 726cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati public void setScreenWidth(int screenWidth) { 736cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mScreenWidth = screenWidth; 746cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 756cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 766cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati /** 776cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Sets FAB as View.VISIBLE or View.GONE. 786cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 796cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @param visible Whether or not to make the container visible. 806cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati */ 816cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati public void setVisible(boolean visible) { 826cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonContainer.setVisibility(visible ? View.VISIBLE : View.GONE); 836cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 846cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 85bf6731b85f825f153d839183ea767435617f662fAndrew Lee public void changeIcon(Drawable icon, String description) { 86bf6731b85f825f153d839183ea767435617f662fAndrew Lee if (mFloatingActionButton.getDrawable() != icon 87bf6731b85f825f153d839183ea767435617f662fAndrew Lee || !mFloatingActionButton.getContentDescription().equals(description)) { 88bf6731b85f825f153d839183ea767435617f662fAndrew Lee mFloatingActionButton.setImageDrawable(icon); 89bf6731b85f825f153d839183ea767435617f662fAndrew Lee mFloatingActionButton.setContentDescription(description); 90bf6731b85f825f153d839183ea767435617f662fAndrew Lee } 91bf6731b85f825f153d839183ea767435617f662fAndrew Lee } 92bf6731b85f825f153d839183ea767435617f662fAndrew Lee 936cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati /** 946cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Updates the FAB location (middle to right position) as the PageView scrolls. 956cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 966cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @param positionOffset A fraction used to calculate position of the FAB during page scroll. 976cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati */ 986cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati public void onPageScrolled(float positionOffset) { 996cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati // As the page is scrolling, if we're on the first tab, update the FAB position so it 1006cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati // moves along with it. 1016cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonContainer.setTranslationX( 102a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee (int) (positionOffset * getTranslationXForAlignment(ALIGN_END))); 1036cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonContainer.setTranslationY(0); 1046cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 1056cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 1066cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati /** 1076cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * Aligns the FAB to the described location plus specified additional offsets. 1086cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 1096cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @param align One of ALIGN_MIDDLE, ALIGN_QUARTER_RIGHT, or ALIGN_RIGHT. 1106cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @param offsetX Additional offsetX to translate by. 1116cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @param animate Whether or not to animate the transition. 1126cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati */ 1136cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati public void align(int align, int offsetX, int offsetY, boolean animate) { 1147c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee if (mScreenWidth == 0) { 1157c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee return; 1167c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee } 1177c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee 1186cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati int translationX = getTranslationXForAlignment(align); 119955e10d3b07db60791c88f156bb05e568b28f7a2Andrew Lee 120955e10d3b07db60791c88f156bb05e568b28f7a2Andrew Lee // Skip animation if container is not shown; animation causes container to show again. 121955e10d3b07db60791c88f156bb05e568b28f7a2Andrew Lee if (animate && mFloatingActionButtonContainer.isShown()) { 1226cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonContainer.animate() 1236cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati .translationX(translationX + offsetX) 1246cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati .translationY(offsetY) 1256cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati .setInterpolator(mFabInterpolator) 1267c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee .setDuration(mAnimationDuration) 1277c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee .start(); 1286cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } else { 1296cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonContainer.setTranslationX(translationX + offsetX); 1306cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati mFloatingActionButtonContainer.setTranslationY(offsetY); 1316cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 1326cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 1336cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 1346cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati /** 1357c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee * Resizes width and height of the floating action bar container. 1367c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee * @param dimension The new dimensions for the width and height. 1377c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee * @param animate Whether to animate this change. 1387c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee */ 1397c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee public void resize(int dimension, boolean animate) { 1407c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee if (animate) { 1417c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee AnimUtils.changeDimensions(mFloatingActionButtonContainer, dimension, dimension); 1427c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee } else { 1437c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee mFloatingActionButtonContainer.getLayoutParams().width = dimension; 1447c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee mFloatingActionButtonContainer.getLayoutParams().height = dimension; 1457c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee mFloatingActionButtonContainer.requestLayout(); 1467c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee } 1477c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee } 1487c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee 1497c7eaa7651588ae6e278446d5ebea56fe6dcc84dAndrew Lee /** 150435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee * Scales the floating action button from no height and width to its actual dimensions. This is 151435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee * an animation for showing the floating action button. 152d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee * @param delayMs The delay for the effect, in milliseconds. 153435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee */ 154d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee public void scaleIn(int delayMs) { 155d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee setVisible(true); 156d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee AnimUtils.scaleIn(mFloatingActionButtonContainer, FAB_SCALE_IN_DURATION, delayMs); 157d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee AnimUtils.fadeIn(mFloatingActionButton, FAB_SCALE_IN_DURATION, 158d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee delayMs + FAB_SCALE_IN_FADE_IN_DELAY, null); 159435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee } 160435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee 161435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee /** 162143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell * Immediately remove the affects of the last call to {@link #scaleOut}. 163143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell */ 164143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell public void resetIn() { 1656aa50bc71fd11826ca85b0d3541d08c7f567d2b9Brian Attwell mFloatingActionButton.setAlpha(1f); 166143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell mFloatingActionButton.setVisibility(View.VISIBLE); 167143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell mFloatingActionButtonContainer.setScaleX(1); 168143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell mFloatingActionButtonContainer.setScaleY(1); 169143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell } 170143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell 171143c1893ce5dd80038a730e48c6d80b5ee1b298dBrian Attwell /** 172435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee * Scales the floating action button from its actual dimensions to no height and width. This is 173435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee * an animation for hiding the floating action button. 174435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee */ 175435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee public void scaleOut() { 176435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee AnimUtils.scaleOut(mFloatingActionButtonContainer, mAnimationDuration); 177d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee // Fade out the icon faster than the scale out animation, so that the icon scaling is less 178d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee // obvious. We don't want it to scale, but the resizing the container is not as performant. 179d2bbc2c5dbb7c0e81721e32031e35703761660daAndrew Lee AnimUtils.fadeOut(mFloatingActionButton, FAB_ICON_FADE_OUT_DURATION, null); 180435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee } 181435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee 182435dbb93a393399972acf2b9ecad5f7c89ac4e6aAndrew Lee /** 183a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee * Calculates the X offset of the FAB to the given alignment, adjusted for whether or not the 184a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee * view is in RTL mode. 1856cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * 1866cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @param align One of ALIGN_MIDDLE, ALIGN_QUARTER_RIGHT, or ALIGN_RIGHT. 1876cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati * @return The translationX for the given alignment. 1886cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati */ 1896cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati public int getTranslationXForAlignment(int align) { 190a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee int result = 0; 1916cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati switch (align) { 1926cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati case ALIGN_MIDDLE: 1936cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati // Moves the FAB to exactly center screen. 1946cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati return 0; 195a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee case ALIGN_QUARTER_END: 1966cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati // Moves the FAB a quarter of the screen width. 197a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee result = mScreenWidth / 4; 198a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee break; 199a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee case ALIGN_END: 2006cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati // Moves the FAB half the screen width. Same as aligning right with a marginRight. 201a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee result = mScreenWidth / 2 2026cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati - mFloatingActionButtonWidth / 2 2036cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati - mFloatingActionButtonMarginRight; 204a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee break; 205a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee } 206a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee if (isLayoutRtl()) { 207a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee result *= -1; 2086cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 209a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee return result; 2106cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati } 2116cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati 212a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee private boolean isLayoutRtl() { 213923859f758f551ce8e32e4690d120e912bfd1777Yorke Lee return mFloatingActionButtonContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; 214a2fa4ba1d5032620be04691f8fda6d31b92bc50fYorke Lee } 2156cff9cf3437ffb6214f9e95023c52fa2253e887dSai Cheemalapati} 216