Move floating action button constants and helpers to ContactsCommon.
- Move constants from Dialer to ContactsCommon.
- Move configure method from DialtactsActivity to Viewutil.
Bug: 13956531
Change-Id: I7013315a8bff25eb8137cd777fa9748b49ad8d4e
diff --git a/src/com/android/contacts/common/util/ViewUtil.java b/src/com/android/contacts/common/util/ViewUtil.java
index fadb3de..e18c45c 100644
--- a/src/com/android/contacts/common/util/ViewUtil.java
+++ b/src/com/android/contacts/common/util/ViewUtil.java
@@ -16,9 +16,13 @@
package com.android.contacts.common.util;
+import android.content.res.Resources;
+import android.graphics.Outline;
import android.view.View;
import android.view.ViewGroup;
+import com.android.contacts.common.R;
+
/**
* Provides static functions to work with views
*/
@@ -49,4 +53,30 @@
public static boolean isViewLayoutRtl(View view) {
return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}
+
+ /**
+ * Configures the floating action button, clipping it to a circle and setting its translation z.
+ * @param view The float action button's view.
+ * @param res The resources file.
+ */
+ public static void setupFloatingActionButton(View view, Resources res) {
+ // Once layout is complete and the floating action button has been assigned a width and
+ // height, assign the outline.
+ view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
+ int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ final Outline outline = new Outline();
+ final int minDimension = Math.min(right - left, bottom - top);
+ if (minDimension <= 0) {
+ return;
+ }
+ outline.setRoundRect(0, 0, right - left, bottom - top, minDimension / 2);
+ v.setOutline(outline);
+ v.setClipToOutline(true);
+ }
+ });
+ view.setTranslationZ(
+ res.getDimensionPixelSize(R.dimen.floating_action_button_translation_z));
+ }
}