Allow LauncherOverlay to access and manage insets
Change-Id: Ib9faf37eb22ad2a0b18c076978ec9f2fd8864c0c
This commit is contained in:
parent
4a080dcadd
commit
a6d0492e5f
|
@ -15,20 +15,20 @@
|
|||
-->
|
||||
|
||||
<!-- Full screen view projects under the status bar and contains the background -->
|
||||
<FrameLayout
|
||||
<com.android.launcher3.LauncherRootView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3"
|
||||
|
||||
android:id="@+id/launcher"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/workspace_bg">
|
||||
android:background="@drawable/workspace_bg"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.android.launcher3.DragLayer
|
||||
android:id="@+id/drag_layer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.android.launcher3.FocusIndicatorView
|
||||
android:id="@+id/focus_indicator"
|
||||
|
@ -70,4 +70,4 @@
|
|||
android:layout_height="match_parent"
|
||||
android:inflatedId="@+id/launcher_overlay"
|
||||
android:layout="@layout/launcher_overlay" />
|
||||
</FrameLayout>
|
||||
</com.android.launcher3.LauncherRootView>
|
||||
|
|
|
@ -15,14 +15,15 @@
|
|||
-->
|
||||
|
||||
<!-- Full screen view projects under the status bar and contains the background -->
|
||||
<FrameLayout
|
||||
<com.android.launcher3.LauncherRootView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3"
|
||||
|
||||
android:id="@+id/launcher"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/workspace_bg">
|
||||
android:background="@drawable/workspace_bg"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.android.launcher3.DragLayer
|
||||
android:id="@+id/drag_layer"
|
||||
|
@ -90,4 +91,4 @@
|
|||
android:layout_height="match_parent"
|
||||
android:inflatedId="@+id/launcher_overlay"
|
||||
android:layout="@layout/launcher_overlay" />
|
||||
</FrameLayout>
|
||||
</com.android.launcher3.LauncherRootView>
|
||||
|
|
|
@ -15,20 +15,20 @@
|
|||
-->
|
||||
|
||||
<!-- Full screen view projects under the status bar and contains the background -->
|
||||
<FrameLayout
|
||||
<com.android.launcher3.LauncherRootView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3"
|
||||
|
||||
android:id="@+id/launcher"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/workspace_bg">
|
||||
android:background="@drawable/workspace_bg"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.android.launcher3.DragLayer
|
||||
android:id="@+id/drag_layer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.android.launcher3.FocusIndicatorView
|
||||
android:id="@+id/focus_indicator"
|
||||
|
@ -90,4 +90,4 @@
|
|||
android:inflatedId="@+id/launcher_overlay"
|
||||
android:layout="@layout/launcher_overlay" />
|
||||
|
||||
</FrameLayout>
|
||||
</com.android.launcher3.LauncherRootView>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
<com.android.launcher3.InsettableFrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent" />
|
||||
|
|
|
@ -14,19 +14,19 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
<com.android.launcher3.InsettableFrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
<com.android.launcher3.InsettableFrameLayout
|
||||
android:id="@+id/search_overlay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#ff00ff00"
|
||||
android:visibility="invisible" />
|
||||
|
||||
<FrameLayout
|
||||
<com.android.launcher3.InsettableFrameLayout
|
||||
android:id="@+id/search_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
|
@ -34,4 +34,4 @@
|
|||
android:layout_marginRight="8dp"
|
||||
android:layout_marginTop="36dp"
|
||||
android:background="#ffff0000" />
|
||||
</FrameLayout>
|
||||
</com.android.launcher3.InsettableFrameLayout>
|
||||
|
|
|
@ -43,7 +43,7 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* A ViewGroup that coordinates dragging across its descendants
|
||||
*/
|
||||
public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChangeListener {
|
||||
public class DragLayer extends InsettableFrameLayout {
|
||||
private DragController mDragController;
|
||||
private int[] mTmpXY = new int[2];
|
||||
|
||||
|
@ -71,8 +71,6 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
|
|||
|
||||
private TouchCompleteListener mTouchCompleteListener;
|
||||
|
||||
private final Rect mInsets = new Rect();
|
||||
|
||||
private View mOverlayView;
|
||||
private int mTopViewIndex;
|
||||
private int mChildCountOnLastUpdate = -1;
|
||||
|
@ -103,7 +101,6 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
|
|||
// Disable multitouch across the workspace/all apps/customize tray
|
||||
setMotionEventSplittingEnabled(false);
|
||||
setChildrenDrawingOrderEnabled(true);
|
||||
setOnHierarchyChangeListener(this);
|
||||
|
||||
final Resources res = getResources();
|
||||
mLeftHoverDrawable = res.getDrawable(R.drawable.page_hover_left);
|
||||
|
@ -123,27 +120,6 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
|
|||
return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fitSystemWindows(Rect insets) {
|
||||
final int n = getChildCount();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final View child = getChildAt(i);
|
||||
setInsets(child, insets, mInsets);
|
||||
}
|
||||
mInsets.set(insets);
|
||||
return true; // I'll take it from here
|
||||
}
|
||||
|
||||
Rect getInsets() {
|
||||
return mInsets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
|
||||
super.addView(child, index, params);
|
||||
setInsets(child, mInsets, new Rect());
|
||||
}
|
||||
|
||||
public void showOverlayView(View overlayView) {
|
||||
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
mOverlayView = overlayView;
|
||||
|
@ -158,19 +134,6 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
|
|||
removeView(mOverlayView);
|
||||
}
|
||||
|
||||
private void setInsets(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);
|
||||
}
|
||||
|
||||
private boolean isEventOverFolderTextRegion(Folder folder, MotionEvent ev) {
|
||||
getDescendantRectRelativeToSelf(folder.getEditTextRegion(), mHitRect);
|
||||
if (mHitRect.contains((int) ev.getX(), (int) ev.getY())) {
|
||||
|
@ -815,6 +778,7 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
|
|||
|
||||
@Override
|
||||
public void onChildViewAdded(View parent, View child) {
|
||||
super.onChildViewAdded(parent, child);
|
||||
if (mOverlayView != null) {
|
||||
// ensure that the overlay view stays on top. we can't use drawing order for this
|
||||
// because in API level 16 touch dispatch doesn't respect drawing order.
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
||||
}
|
|
@ -231,7 +231,7 @@ public class Launcher extends Activity
|
|||
|
||||
LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
|
||||
LauncherOverlay mLauncherOverlay;
|
||||
ViewGroup mLauncherOverlayView;
|
||||
InsettableFrameLayout mLauncherOverlayContainer;
|
||||
|
||||
static final int APPWIDGET_HOST_ID = 1024;
|
||||
public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
|
||||
|
@ -514,9 +514,9 @@ public class Launcher extends Activity
|
|||
mLauncherCallbacks.onCreate(savedInstanceState);
|
||||
if (mLauncherCallbacks.hasLauncherOverlay()) {
|
||||
ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
|
||||
mLauncherOverlayView = (ViewGroup) stub.inflate();
|
||||
mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(mLauncherOverlayView,
|
||||
mLauncherOverlayCallbacks);
|
||||
mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
|
||||
mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
|
||||
mLauncherOverlayContainer, mLauncherOverlayCallbacks);
|
||||
mWorkspace.setLauncherOverlay(mLauncherOverlay);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,11 +98,11 @@ public interface LauncherCallbacks {
|
|||
/**
|
||||
* Handshake to establish an overlay relationship
|
||||
*
|
||||
* @param overlayView Full screen overlay ViewGroup into which custom views can be placed.
|
||||
* @param container Full screen overlay ViewGroup into which custom views can be placed.
|
||||
* @param callbacks A set of callbacks provided by Launcher in relation to the overlay
|
||||
* @return an interface used to make requests and notify the Launcher in relation to the overlay
|
||||
*/
|
||||
public Launcher.LauncherOverlay setLauncherOverlayView(ViewGroup overlayView,
|
||||
public Launcher.LauncherOverlay setLauncherOverlayView(InsettableFrameLayout container,
|
||||
Launcher.LauncherOverlayCallbacks callbacks);
|
||||
|
||||
}
|
||||
|
|
|
@ -252,11 +252,11 @@ public class LauncherExtension extends Launcher {
|
|||
}
|
||||
|
||||
@Override
|
||||
public LauncherOverlay setLauncherOverlayView(ViewGroup overlayView,
|
||||
public LauncherOverlay setLauncherOverlayView(InsettableFrameLayout container,
|
||||
LauncherOverlayCallbacks callbacks) {
|
||||
|
||||
mLauncherOverlay.setOverlayCallbacks(callbacks);
|
||||
mLauncherOverlay.setOverlayView(overlayView);
|
||||
mLauncherOverlay.setOverlayContainer(container);
|
||||
|
||||
return mLauncherOverlay;
|
||||
}
|
||||
|
@ -335,9 +335,9 @@ public class LauncherExtension extends Launcher {
|
|||
hideOverlayPanel();
|
||||
}
|
||||
|
||||
public void setOverlayView(ViewGroup overlayView) {
|
||||
public void setOverlayContainer(InsettableFrameLayout container) {
|
||||
mOverlayView = (ViewGroup) getLayoutInflater().inflate(
|
||||
R.layout.launcher_overlay_example, overlayView);
|
||||
R.layout.launcher_overlay_example, container);
|
||||
mSearchOverlay = mOverlayView.findViewById(R.id.search_overlay);
|
||||
mSearchBox = mOverlayView.findViewById(R.id.search_box);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.android.launcher3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class LauncherRootView extends InsettableFrameLayout {
|
||||
public LauncherRootView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fitSystemWindows(Rect insets) {
|
||||
setInsets(insets);
|
||||
return true; // I'll take it from here
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue