1/*
2 * Copyright (C) 2016 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 */
16package android.support.design.custom;
17
18import android.content.Context;
19import android.support.design.widget.CoordinatorLayout;
20import android.support.design.widget.Snackbar;
21import android.util.AttributeSet;
22import android.view.View;
23import android.widget.TextView;
24
25public class TestFloatingBehavior extends CoordinatorLayout.Behavior<TextView> {
26    // Default constructor is needed to instantiate a Behavior object when it is attached
27    // to custom view class as class-level annotation
28    public TestFloatingBehavior() {
29    }
30
31    // This constructor is needed to instantiate a Behavior object when it is attached to a
32    // view via layout_behavior XML attribute
33    public TestFloatingBehavior(Context context, AttributeSet attrs) {
34    }
35
36    @Override
37    public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {
38        return dependency instanceof Snackbar.SnackbarLayout;
39    }
40
41    @Override
42    public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child,
43            View dependency) {
44        child.setTranslationY(Math.min(0,
45                dependency.getTranslationY() - dependency.getHeight()));
46        return true;
47    }
48}
49