Translate FAB up and down when Snackbar appears and disappears.
This is implements custom behavior according the Material Design spec
that the Snackbar cannot obscure the FAB. Converts the dialtacts
activity layout to a CoordinatorLayout and attaches the
FloatingActionButtonBehavior to the FAB.
Bug: 23687913
Change-Id: Ic4d0493db415bb97cf7e21de4f23a02df9f753b1
diff --git a/proguard.flags b/proguard.flags
index 38d4050..185d5eb 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -12,4 +12,9 @@
@com.android.dialer.NeededForReflection *;
}
+# For design libraries
+-keep public class * extends android.support.design.widget.CoordinatorLayout$Behavior {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
-verbose
diff --git a/res/layout/dialtacts_activity.xml b/res/layout/dialtacts_activity.xml
index 0f1f2bb..782d4f3 100644
--- a/res/layout/dialtacts_activity.xml
+++ b/res/layout/dialtacts_activity.xml
@@ -13,8 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<FrameLayout
+<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dialtacts_mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -43,7 +44,8 @@
android:layout_width="@dimen/floating_action_button_width"
android:layout_height="@dimen/floating_action_button_height"
android:layout_marginBottom="@dimen/floating_action_button_margin_bottom"
- android:layout_gravity="center_horizontal|bottom">
+ android:layout_gravity="center_horizontal|bottom"
+ app:layout_behavior="com.android.dialer.FloatingActionButtonBehavior">
<ImageButton
android:id="@+id/floating_action_button"
@@ -68,4 +70,4 @@
android:importantForAccessibility="no" />
</FrameLayout>
-</FrameLayout>
+</android.support.design.widget.CoordinatorLayout>
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 4ade04a..6d8ed61 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -30,6 +30,7 @@
import android.os.Trace;
import android.provider.CallLog.Calls;
import android.speech.RecognizerIntent;
+import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.telecom.PhoneAccount;
@@ -52,7 +53,6 @@
import android.view.animation.AnimationUtils;
import android.widget.AbsListView.OnScrollListener;
import android.widget.EditText;
-import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.PopupMenu;
import android.widget.TextView;
@@ -143,7 +143,7 @@
private static final int FAB_SCALE_IN_DELAY_MS = 300;
- private FrameLayout mParentLayout;
+ private CoordinatorLayout mParentLayout;
/**
* Fragment containing the dialpad that slides into view
@@ -468,7 +468,7 @@
mSlideIn.setAnimationListener(mSlideInListener);
mSlideOut.setAnimationListener(mSlideOutListener);
- mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
+ mParentLayout = (CoordinatorLayout) findViewById(R.id.dialtacts_mainlayout);
mParentLayout.setOnDragListener(new LayoutOnDragListener());
floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
diff --git a/src/com/android/dialer/FloatingActionButtonBehavior.java b/src/com/android/dialer/FloatingActionButtonBehavior.java
new file mode 100644
index 0000000..8a407bd
--- /dev/null
+++ b/src/com/android/dialer/FloatingActionButtonBehavior.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer;
+
+import android.content.Context;
+import android.support.design.widget.CoordinatorLayout;
+import android.support.design.widget.Snackbar.SnackbarLayout;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.FrameLayout;
+
+/**
+ * Implements custom behavior for the movement of the FAB in response to the Snackbar.
+ * Because we are not using the design framework FloatingActionButton widget, we need to manually
+ * implement the Material Design behavior of having the FAB translate upward and downward with
+ * the appearance and disappearance of a Snackbar.
+ */
+public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior<FrameLayout> {
+ public FloatingActionButtonBehavior(Context context, AttributeSet attrs) {
+ }
+
+ @Override
+ public boolean layoutDependsOn(CoordinatorLayout parent, FrameLayout child, View dependency) {
+ // This needs to return true to trigger the callback correctly.
+ return true;
+ }
+
+ @Override
+ public boolean onDependentViewChanged(CoordinatorLayout parent, FrameLayout child,
+ View dependency) {
+ if (dependency instanceof SnackbarLayout) {
+ float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
+ child.setTranslationY(translationY);
+ }
+ return true;
+ }
+}