From d43e77867c3a58e434307b4eb9469b1766ddc6c8 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 17 Jul 2018 20:31:41 +0530 Subject: [PATCH] fab: slide fab up when a snackbar shows Signed-off-by: Harsh Shandilya --- .../fab/FloatingActionButtonBehavior.java | 32 +++++++++++++++++++ .../main/res/layout/tunnel_list_fragment.xml | 3 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java diff --git a/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java new file mode 100644 index 00000000..84868a4c --- /dev/null +++ b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2018 Harsh Shandilya + * Copyright © 2018 Jason A. Donenfeld . All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.wireguard.android.widget.fab; + +import android.content.Context; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.Snackbar; +import android.util.AttributeSet; +import android.view.View; + +public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior { + + public FloatingActionButtonBehavior(final Context context, final AttributeSet attrs) { } + + @Override + public boolean layoutDependsOn(final CoordinatorLayout parent, final FloatingActionsMenu child, + final View dependency) { + return dependency instanceof Snackbar.SnackbarLayout; + } + + @Override + public boolean onDependentViewChanged(final CoordinatorLayout parent, final FloatingActionsMenu child, + final View dependency) { + final float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); + child.setTranslationY(translationY); + return true; + } +} diff --git a/app/src/main/res/layout/tunnel_list_fragment.xml b/app/src/main/res/layout/tunnel_list_fragment.xml index 5aff4739..a8a33dcc 100644 --- a/app/src/main/res/layout/tunnel_list_fragment.xml +++ b/app/src/main/res/layout/tunnel_list_fragment.xml @@ -43,7 +43,8 @@ android:layout_margin="16dp" app:fab_labelStyle="@style/fab_label" android:clipChildren="false" - app:fab_labelsPosition="left" > + app:fab_labelsPosition="left" + app:layout_behavior="com.wireguard.android.widget.fab.FloatingActionButtonBehavior" >