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 17package com.android.deskclock.widget.toast; 18 19import android.content.Context; 20import android.support.design.widget.CoordinatorLayout; 21import android.support.design.widget.Snackbar; 22import android.util.AttributeSet; 23import android.view.View; 24import android.widget.LinearLayout; 25 26/** 27 * LinearLayout Behavior that slides up and down when snackbar appears/disappears. 28 */ 29public final class LinearLayoutWithSnackbarBehavior 30 extends CoordinatorLayout.Behavior<LinearLayout> { 31 32 public LinearLayoutWithSnackbarBehavior(Context context, AttributeSet attrs) {} 33 34 @Override 35 public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) { 36 return dependency instanceof Snackbar.SnackbarLayout; 37 } 38 39 @Override 40 public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, 41 View dependency) { 42 final float translationY = Math.min(0, 43 dependency.getTranslationY() - dependency.getHeight()); 44 child.setTranslationY(translationY); 45 return true; 46 } 47} 48