diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml index faa88f7cff..1b843ed7d6 100644 --- a/res/layout/all_apps.xml +++ b/res/layout/all_apps.xml @@ -22,6 +22,8 @@ android:id="@+id/apps_view" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingTop="@dimen/container_bounds_inset" + android:paddingBottom="@dimen/container_bounds_inset" android:orientation="vertical" launcher:revealBackground="@drawable/quantum_panel_shape"> diff --git a/res/layout/widgets_view.xml b/res/layout/widgets_view.xml index 410d1be3fa..e55f6f0850 100644 --- a/res/layout/widgets_view.xml +++ b/res/layout/widgets_view.xml @@ -22,6 +22,8 @@ android:id="@+id/widgets_view" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingTop="@dimen/container_bounds_inset" + android:paddingBottom="@dimen/container_bounds_inset" android:descendantFocusability="afterDescendants" launcher:revealBackground="@drawable/quantum_panel_shape_dark"> diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml index 06a99842ef..2be9391540 100644 --- a/res/values-land/dimens.xml +++ b/res/values-land/dimens.xml @@ -18,4 +18,7 @@ 8dip 0dip + + + 12% diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml index 8e1e4f1801..e5f2d829bf 100644 --- a/res/values-sw600dp/dimens.xml +++ b/res/values-sw600dp/dimens.xml @@ -15,6 +15,9 @@ --> + + 16dp + 0dp 26sp diff --git a/res/values/dimens.xml b/res/values/dimens.xml index b06afc48c7..a70d3b806d 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -67,6 +67,9 @@ 72dp 48dp + 0% + 8dp + 0dp 0dp diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java index bd41992648..51a97b91b6 100644 --- a/src/com/android/launcher3/BaseContainerView.java +++ b/src/com/android/launcher3/BaseContainerView.java @@ -31,19 +31,9 @@ import com.android.launcher3.config.ProviderConfig; /** * A base container view, which supports resizing. */ -public abstract class BaseContainerView extends FrameLayout implements Insettable { +public abstract class BaseContainerView extends FrameLayout { - private final static String TAG = "BaseContainerView"; - - // The window insets - private final Rect mInsets = new Rect(); - // The bounds of the search bar. Only the left, top, right are used to inset the - // search bar and the height is determined by the measurement of the layout - private final Rect mFixedSearchBarBounds = new Rect(); - // The computed padding to apply to the container to achieve the container bounds - protected final Rect mContentPadding = new Rect(); - // The inset to apply to the edges and between the search bar and the container - private final int mContainerBoundsInset; + protected final int mHorizontalPadding; private final Drawable mRevealDrawable; @@ -60,11 +50,17 @@ public abstract class BaseContainerView extends FrameLayout implements Insettabl public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - mContainerBoundsInset = getResources().getDimensionPixelSize(R.dimen.container_bounds_inset); + + int width = ((Launcher) context).getDeviceProfile().availableWidthPx; + mHorizontalPadding = Math.max( + getResources().getDimensionPixelSize(R.dimen.container_min_margin), + (int) getResources().getFraction(R.fraction.container_margin, width, 1)); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BaseContainerView, defStyleAttr, 0); - mRevealDrawable = a.getDrawable(R.styleable.BaseContainerView_revealBackground); + mRevealDrawable = new InsetDrawable( + a.getDrawable(R.styleable.BaseContainerView_revealBackground), + mHorizontalPadding, 0, mHorizontalPadding, 0); a.recycle(); } @@ -74,90 +70,13 @@ public abstract class BaseContainerView extends FrameLayout implements Insettabl mContent = findViewById(R.id.main_content); mRevealView = findViewById(R.id.reveal_view); - } - @Override - final public void setInsets(Rect insets) { - mInsets.set(insets); - updateBackgroundAndPaddings(); - } - - /** - * Sets the search bar bounds for this container view to match. - */ - final public void setSearchBarBounds(Rect bounds) { - if (ProviderConfig.IS_DOGFOOD_BUILD && !isValidSearchBarBounds(bounds)) { - Log.e(TAG, "Invalid search bar bounds: " + bounds); - } - - mFixedSearchBarBounds.set(bounds); - - // Post the updates since they can trigger a relayout, and this call can be triggered from - // a layout pass itself. - post(new Runnable() { - @Override - public void run() { - updateBackgroundAndPaddings(); - } - }); - } - - /** - * Update the backgrounds and padding in response to a change in the bounds or insets. - */ - protected void updateBackgroundAndPaddings() { - Rect padding; - if (isValidSearchBarBounds(mFixedSearchBarBounds)) { - padding = new Rect( - mFixedSearchBarBounds.left, - mInsets.top + mContainerBoundsInset, - getMeasuredWidth() - mFixedSearchBarBounds.right, - mInsets.bottom + mContainerBoundsInset - ); - } else { - padding = new Rect( - mInsets.left + mContainerBoundsInset, - mInsets.top + mContainerBoundsInset, - mInsets.right + mContainerBoundsInset, - mInsets.bottom + mContainerBoundsInset - ); - } - - // The container padding changed, notify the container. - if (!padding.equals(mContentPadding)) { - mContentPadding.set(padding); - onUpdateBackgroundAndPaddings(padding); - } - } - - private void onUpdateBackgroundAndPaddings(Rect padding) { - // Apply the top-bottom padding to itself so that the launcher transition is - // clipped correctly - setPadding(0, padding.top, 0, padding.bottom); - - InsetDrawable background = new InsetDrawable(mRevealDrawable, - padding.left, 0, padding.right, 0); - mRevealView.setBackground(background.getConstantState().newDrawable()); - mContent.setBackground(background); + mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable()); + mContent.setBackground(mRevealDrawable); // We let the content have a intent background, but still have full width. // This allows the scroll bar to be used responsive outside the background bounds as well. mContent.setPadding(0, 0, 0, 0); - - Rect bgPadding = new Rect(); - background.getPadding(bgPadding); - onUpdateBgPadding(padding, bgPadding); - } - - protected abstract void onUpdateBgPadding(Rect padding, Rect bgPadding); - - /** - * Returns whether the search bar bounds we got are considered valid. - */ - private boolean isValidSearchBarBounds(Rect searchBarBounds) { - return !searchBarBounds.isEmpty() && - searchBarBounds.right <= getMeasuredWidth() && - searchBarBounds.bottom <= getMeasuredHeight(); } public final View getContentView() { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 245b399098..5a1f99a65c 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -583,14 +583,6 @@ public class Launcher extends Activity } } - /** - * Updates the bounds of all the overlays to match the new fixed bounds. - */ - public void updateOverlayBounds(Rect newBounds) { - mAppsView.setSearchBarBounds(newBounds); - mWidgetsView.setSearchBarBounds(newBounds); - } - /** To be overridden by subclasses to hint to Launcher that we have custom content */ protected boolean hasCustomContentToLeft() { if (mLauncherCallbacks != null) { diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 9d5afb4656..fa34d75a65 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -230,8 +230,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc mSearchBarController = searchController; mSearchBarController.initialize(mApps, mSearchInput, mLauncher, this); mAdapter.setSearchController(mSearchBarController); - - updateBackgroundAndPaddings(); } /** @@ -311,19 +309,17 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc mAppsRecyclerView.setPremeasuredIconHeights(predIcon.getMeasuredHeight(), icon.getMeasuredHeight()); - updateBackgroundAndPaddings(); + updatePaddingsAndMargins(); } @Override - public void onBoundsChanged(Rect newBounds) { - mLauncher.updateOverlayBounds(newBounds); - } + public void onBoundsChanged(Rect newBounds) { } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - mContentBounds.set(mContentPadding.left, mContentPadding.top, - MeasureSpec.getSize(widthMeasureSpec) - mContentPadding.right, - MeasureSpec.getSize(heightMeasureSpec) - mContentPadding.bottom); + mContentBounds.set(mHorizontalPadding, 0, + MeasureSpec.getSize(widthMeasureSpec) - mHorizontalPadding, + MeasureSpec.getSize(heightMeasureSpec)); // Update the number of items in the grid before we measure the view // TODO: mSectionNamesMargin is currently 0, but also account for it, @@ -365,8 +361,10 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc * container view, we inset the background and padding of the recycler view to allow for the * recycler view to handle touch events (for fast scrolling) all the way to the edge. */ - @Override - protected void onUpdateBgPadding(Rect padding, Rect bgPadding) { + private void updatePaddingsAndMargins() { + Rect bgPadding = new Rect(); + getRevealView().getBackground().getPadding(bgPadding); + mAppsRecyclerView.updateBackgroundPadding(bgPadding); mAdapter.updateBackgroundPadding(bgPadding); mElevationController.updateBackgroundPadding(bgPadding); @@ -377,16 +375,16 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc int startInset = Math.max(mSectionNamesMargin, maxScrollBarWidth); int topBottomPadding = mRecyclerViewTopBottomPadding; if (Utilities.isRtl(getResources())) { - mAppsRecyclerView.setPadding(padding.left + maxScrollBarWidth, - topBottomPadding, padding.right + startInset, topBottomPadding); + mAppsRecyclerView.setPadding(bgPadding.left + maxScrollBarWidth, + topBottomPadding, bgPadding.right + startInset, topBottomPadding); } else { - mAppsRecyclerView.setPadding(padding.left + startInset, topBottomPadding, - padding.right + maxScrollBarWidth, topBottomPadding); + mAppsRecyclerView.setPadding(bgPadding.left + startInset, topBottomPadding, + bgPadding.right + maxScrollBarWidth, topBottomPadding); } MarginLayoutParams lp = (MarginLayoutParams) mSearchContainer.getLayoutParams(); - lp.leftMargin = padding.left; - lp.rightMargin = padding.right; + lp.leftMargin = bgPadding.left; + lp.rightMargin = bgPadding.right; mSearchContainer.setLayoutParams(lp); } diff --git a/src/com/android/launcher3/allapps/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/AllAppsSearchBarController.java index 39d6dd50cd..a4bea8dbd6 100644 --- a/src/com/android/launcher3/allapps/AllAppsSearchBarController.java +++ b/src/com/android/launcher3/allapps/AllAppsSearchBarController.java @@ -175,6 +175,7 @@ public abstract class AllAppsSearchBarController /** * Called when the bounds of the search bar has changed. */ + @Deprecated void onBoundsChanged(Rect newBounds); /** diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java index 5d6f47510f..23d04331f8 100644 --- a/src/com/android/launcher3/widget/WidgetsContainerView.java +++ b/src/com/android/launcher3/widget/WidgetsContainerView.java @@ -96,6 +96,18 @@ public class WidgetsContainerView extends BaseContainerView mRecyclerView = (WidgetsRecyclerView) getContentView().findViewById(R.id.widgets_list_view); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + + Rect bgPadding = new Rect(); + getRevealView().getBackground().getPadding(bgPadding); + if (Utilities.isRtl(getResources())) { + getContentView().setPadding(0, bgPadding.top, + bgPadding.right, bgPadding.bottom); + mRecyclerView.updateBackgroundPadding(new Rect(bgPadding.left, 0, 0, 0)); + } else { + getContentView().setPadding(bgPadding.left, bgPadding.top, + 0, bgPadding.bottom); + mRecyclerView.updateBackgroundPadding(new Rect(0, 0, bgPadding.right, 0)); + } } // @@ -310,22 +322,6 @@ public class WidgetsContainerView extends BaseContainerView } } - // - // Container rendering related. - // - @Override - protected void onUpdateBgPadding(Rect padding, Rect bgPadding) { - if (Utilities.isRtl(getResources())) { - getContentView().setPadding(0, bgPadding.top, - bgPadding.right, bgPadding.bottom); - mRecyclerView.updateBackgroundPadding(new Rect(bgPadding.left, 0, 0, 0)); - } else { - getContentView().setPadding(bgPadding.left, bgPadding.top, - 0, bgPadding.bottom); - mRecyclerView.updateBackgroundPadding(new Rect(0, 0, bgPadding.right, 0)); - } - } - /** * Initialize the widget data model. */