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