1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.dialer; 17 18 import android.content.Context; 19 import android.support.design.widget.CoordinatorLayout; 20 import android.support.design.widget.Snackbar.SnackbarLayout; 21 import android.util.AttributeSet; 22 import android.view.View; 23 import android.widget.FrameLayout; 24 25 /** 26 * Implements custom behavior for the movement of the FAB in response to the Snackbar. 27 * Because we are not using the design framework FloatingActionButton widget, we need to manually 28 * implement the Material Design behavior of having the FAB translate upward and downward with 29 * the appearance and disappearance of a Snackbar. 30 */ 31 public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior<FrameLayout> { 32 public FloatingActionButtonBehavior(Context context, AttributeSet attrs) { 33 } 34 35 @Override 36 public boolean layoutDependsOn(CoordinatorLayout parent, FrameLayout child, View dependency) { 37 return dependency instanceof SnackbarLayout; 38 } 39 40 @Override 41 public boolean onDependentViewChanged(CoordinatorLayout parent, FrameLayout child, 42 View dependency) { 43 float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); 44 child.setTranslationY(translationY); 45 return true; 46 } 47 } 48