summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/InsettableFrameLayout.java
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2014-10-23 17:28:30 -0700
committerDanesh M <daneshm90@gmail.com>2015-09-27 18:55:56 -0700
commitbf18c372cd9abf7c24495fd94c535fd850539060 (patch)
treea1e8fa8ebfb21b62d8a6d451b9326c1f2752bdf1 /src/com/android/launcher3/InsettableFrameLayout.java
parente8e3e71f40ba9154fafafb59e93babaddd0e512b (diff)
downloadandroid_packages_apps_Trebuchet-bf18c372cd9abf7c24495fd94c535fd850539060.tar.gz
android_packages_apps_Trebuchet-bf18c372cd9abf7c24495fd94c535fd850539060.tar.bz2
android_packages_apps_Trebuchet-bf18c372cd9abf7c24495fd94c535fd850539060.zip
Allow LauncherOverlay to access and manage insets
Change-Id: Ib9faf37eb22ad2a0b18c076978ec9f2fd8864c0c
Diffstat (limited to 'src/com/android/launcher3/InsettableFrameLayout.java')
-rw-r--r--src/com/android/launcher3/InsettableFrameLayout.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/com/android/launcher3/InsettableFrameLayout.java b/src/com/android/launcher3/InsettableFrameLayout.java
new file mode 100644
index 000000000..4ba9c88cd
--- /dev/null
+++ b/src/com/android/launcher3/InsettableFrameLayout.java
@@ -0,0 +1,52 @@
+package com.android.launcher3;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+
+public class InsettableFrameLayout extends FrameLayout implements
+ ViewGroup.OnHierarchyChangeListener, Insettable {
+
+ protected Rect mInsets = new Rect();
+
+ public InsettableFrameLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setOnHierarchyChangeListener(this);
+ }
+
+ public void setFrameLayoutChildInsets(View child, Rect newInsets, Rect oldInsets) {
+ final FrameLayout.LayoutParams flp = (FrameLayout.LayoutParams) child.getLayoutParams();
+ if (child instanceof Insettable) {
+ ((Insettable) child).setInsets(newInsets);
+ } else {
+ flp.topMargin += (newInsets.top - oldInsets.top);
+ flp.leftMargin += (newInsets.left - oldInsets.left);
+ flp.rightMargin += (newInsets.right - oldInsets.right);
+ flp.bottomMargin += (newInsets.bottom - oldInsets.bottom);
+ }
+ child.setLayoutParams(flp);
+ }
+
+ @Override
+ public void setInsets(Rect insets) {
+ final int n = getChildCount();
+ for (int i = 0; i < n; i++) {
+ final View child = getChildAt(i);
+ setFrameLayoutChildInsets(child, insets, mInsets);
+ }
+ mInsets.set(insets);
+ }
+
+ @Override
+ public void onChildViewAdded(View parent, View child) {
+ setFrameLayoutChildInsets(child, mInsets, new Rect());
+ }
+
+ @Override
+ public void onChildViewRemoved(View parent, View child) {
+ }
+
+}