mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 11:18:21 +00:00
Allow LauncherOverlay to access and manage insets
Change-Id: Ib9faf37eb22ad2a0b18c076978ec9f2fd8864c0c
This commit is contained in:
52
src/com/android/launcher3/InsettableFrameLayout.java
Normal file
52
src/com/android/launcher3/InsettableFrameLayout.java
Normal file
@@ -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) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user