Removing dependency on LauncherCallbacks for getting the search bounds
> Instead of handling insets in BaseContainerView, directly applying them to margins, as that scpace can't be used for scroll handling > Appliying the top and bottom padding in xml > The left & right padding is defied in xml which is reused for scroll handling Bug: 27108154 Change-Id: Ia32e6d5e8fd1bfafb1d77d1244ce2268e4da9df9
This commit is contained in:
parent
1bc8fc3de2
commit
05c8c57fa7
|
@ -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">
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
<!-- QSB -->
|
||||
<dimen name="toolbar_button_vertical_padding">8dip</dimen>
|
||||
<dimen name="toolbar_button_horizontal_padding">0dip</dimen>
|
||||
|
||||
<!-- Container -->
|
||||
<item name="container_margin" format="fraction" type="fraction">12%</item>
|
||||
</resources>
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
-->
|
||||
|
||||
<resources>
|
||||
<!-- Container -->
|
||||
<dimen name="container_min_margin">16dp</dimen>
|
||||
|
||||
<!-- All Apps -->
|
||||
<dimen name="all_apps_grid_view_start_margin">0dp</dimen>
|
||||
<dimen name="all_apps_grid_section_text_size">26sp</dimen>
|
||||
|
|
|
@ -67,6 +67,9 @@
|
|||
<dimen name="container_fastscroll_popup_size">72dp</dimen>
|
||||
<dimen name="container_fastscroll_popup_text_size">48dp</dimen>
|
||||
|
||||
<item name="container_margin" format="fraction" type="fraction">0%</item>
|
||||
<dimen name="container_min_margin">8dp</dimen>
|
||||
|
||||
<!-- All Apps -->
|
||||
<dimen name="all_apps_button_scale_down">0dp</dimen>
|
||||
<dimen name="all_apps_grid_view_start_margin">0dp</dimen>
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,7 @@ public abstract class AllAppsSearchBarController
|
|||
/**
|
||||
* Called when the bounds of the search bar has changed.
|
||||
*/
|
||||
@Deprecated
|
||||
void onBoundsChanged(Rect newBounds);
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue