diff options
author | Adam Cohen <adamcohen@google.com> | 2014-10-23 17:28:30 -0700 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2015-09-27 18:55:56 -0700 |
commit | bf18c372cd9abf7c24495fd94c535fd850539060 (patch) | |
tree | a1e8fa8ebfb21b62d8a6d451b9326c1f2752bdf1 /src | |
parent | e8e3e71f40ba9154fafafb59e93babaddd0e512b (diff) | |
download | android_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')
-rw-r--r-- | src/com/android/launcher3/AppDrawerContainer.java | 32 | ||||
-rw-r--r-- | src/com/android/launcher3/DragLayer.java | 68 | ||||
-rw-r--r-- | src/com/android/launcher3/InsettableFrameLayout.java | 52 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 8 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherCallbacks.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherExtension.java | 8 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherRootView.java | 17 | ||||
-rw-r--r-- | src/com/android/launcher3/OverviewPanel.java | 33 |
8 files changed, 147 insertions, 75 deletions
diff --git a/src/com/android/launcher3/AppDrawerContainer.java b/src/com/android/launcher3/AppDrawerContainer.java new file mode 100644 index 000000000..ed001fefa --- /dev/null +++ b/src/com/android/launcher3/AppDrawerContainer.java @@ -0,0 +1,32 @@ +package com.android.launcher3; + +import android.content.Context; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.LinearLayout; + +public class AppDrawerContainer extends InsettableFrameLayout { + public AppDrawerContainer(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public void setInsets(Rect insets) { + // List view + View view = findViewById(R.id.app_drawer_recyclerview); + FrameLayout.LayoutParams lp = + (FrameLayout.LayoutParams) view.getLayoutParams(); + int paddingBottom = view.getPaddingBottom() + insets.bottom - mInsets.bottom; + int paddingTop = view.getPaddingTop() + insets.top - mInsets.top; + view.setLayoutParams(lp); + view.setPadding(view.getPaddingLeft(), paddingTop, view.getPaddingRight(), paddingBottom); + + // Scrubber + view = findViewById(R.id.app_drawer_scrubber_container); + LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) view.getLayoutParams(); + llp.bottomMargin += insets.bottom - mInsets.bottom; + view.setLayoutParams(llp); + } +} diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java index 1ded03038..156df7d21 100644 --- a/src/com/android/launcher3/DragLayer.java +++ b/src/com/android/launcher3/DragLayer.java @@ -44,7 +44,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]; @@ -72,8 +72,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; @@ -104,7 +102,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); @@ -126,56 +123,9 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang @Override protected boolean fitSystemWindows(Rect insets) { - final int n = getChildCount(); - for (int i = 0; i < n; i++) { - final View child = getChildAt(i); - if (child.getId() == R.id.overview_panel) { - LinearLayout layout = (LinearLayout) - child.findViewById(R.id.settings_container); - FrameLayout.LayoutParams lp = - (FrameLayout.LayoutParams) layout.getLayoutParams(); - lp.bottomMargin += insets.bottom - mInsets.bottom; - layout.setLayoutParams(lp); - continue; - } else if (child.getId() == R.id.app_drawer_container) { - setAppDrawerInsets(child, insets); - - continue; - } - setInsets(child, insets, mInsets); - if (child.getId() == R.id.search_drop_target_bar) { - continue; - } - } - mInsets.set(insets); - return true; // I'll take it from here - } - - private void setAppDrawerInsets(View child, Rect insets) { - // List view - View view = child.findViewById(R.id.app_drawer_recyclerview); - FrameLayout.LayoutParams lp = - (FrameLayout.LayoutParams) view.getLayoutParams(); - int paddingBottom = view.getPaddingBottom() + insets.bottom - mInsets.bottom; - int paddingTop = view.getPaddingTop() + insets.top - mInsets.top; - view.setLayoutParams(lp); - view.setPadding(view.getPaddingLeft(), paddingTop, view.getPaddingRight(), paddingBottom); - - // Scrubber - view = child.findViewById(R.id.app_drawer_scrubber_container); - LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) view.getLayoutParams(); - llp.bottomMargin += insets.bottom - mInsets.bottom; - view.setLayoutParams(llp); - } - 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()); + return super.fitSystemWindows(insets); } public void showOverlayView(View overlayView) { @@ -192,19 +142,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())) { @@ -849,6 +786,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. 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) { + } + +} diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 58a09a435..f8891a091 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -266,7 +266,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; @@ -589,9 +589,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); } } diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java index e0cfa27ba..a1f4e0b90 100644 --- a/src/com/android/launcher3/LauncherCallbacks.java +++ b/src/com/android/launcher3/LauncherCallbacks.java @@ -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); } diff --git a/src/com/android/launcher3/LauncherExtension.java b/src/com/android/launcher3/LauncherExtension.java index 10bbd357d..b264042cf 100644 --- a/src/com/android/launcher3/LauncherExtension.java +++ b/src/com/android/launcher3/LauncherExtension.java @@ -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); } diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java new file mode 100644 index 000000000..e8c11c48b --- /dev/null +++ b/src/com/android/launcher3/LauncherRootView.java @@ -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 + } +}
\ No newline at end of file diff --git a/src/com/android/launcher3/OverviewPanel.java b/src/com/android/launcher3/OverviewPanel.java new file mode 100644 index 000000000..83603d814 --- /dev/null +++ b/src/com/android/launcher3/OverviewPanel.java @@ -0,0 +1,33 @@ +package com.android.launcher3; + +import android.content.Context; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.LinearLayout; + +public class OverviewPanel extends SlidingUpPanelLayout implements Insettable { + public OverviewPanel(Context context) { + super(context); + } + + public OverviewPanel(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public OverviewPanel(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + + @Override + public void setInsets(Rect insets) { + LinearLayout layout = (LinearLayout) + findViewById(R.id.settings_container); + FrameLayout.LayoutParams lp = + (FrameLayout.LayoutParams) layout.getLayoutParams(); + lp.bottomMargin += insets.bottom - insets.bottom; + layout.setLayoutParams(lp); + } +} |