Merge "Removing dependency on LauncherCallbacks for getting the search bounds" into ub-launcher3-calgary
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
android:id="@+id/apps_view"
|
android:id="@+id/apps_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:paddingTop="@dimen/container_bounds_inset"
|
||||||
|
android:paddingBottom="@dimen/container_bounds_inset"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
launcher:revealBackground="@drawable/quantum_panel_shape">
|
launcher:revealBackground="@drawable/quantum_panel_shape">
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
android:id="@+id/widgets_view"
|
android:id="@+id/widgets_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:paddingTop="@dimen/container_bounds_inset"
|
||||||
|
android:paddingBottom="@dimen/container_bounds_inset"
|
||||||
android:descendantFocusability="afterDescendants"
|
android:descendantFocusability="afterDescendants"
|
||||||
launcher:revealBackground="@drawable/quantum_panel_shape_dark">
|
launcher:revealBackground="@drawable/quantum_panel_shape_dark">
|
||||||
|
|
||||||
|
|||||||
@@ -18,4 +18,7 @@
|
|||||||
<!-- QSB -->
|
<!-- QSB -->
|
||||||
<dimen name="toolbar_button_vertical_padding">8dip</dimen>
|
<dimen name="toolbar_button_vertical_padding">8dip</dimen>
|
||||||
<dimen name="toolbar_button_horizontal_padding">0dip</dimen>
|
<dimen name="toolbar_button_horizontal_padding">0dip</dimen>
|
||||||
|
|
||||||
|
<!-- Container -->
|
||||||
|
<item name="container_margin" format="fraction" type="fraction">12%</item>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
<!-- Container -->
|
||||||
|
<dimen name="container_min_margin">16dp</dimen>
|
||||||
|
|
||||||
<!-- All Apps -->
|
<!-- All Apps -->
|
||||||
<dimen name="all_apps_grid_view_start_margin">0dp</dimen>
|
<dimen name="all_apps_grid_view_start_margin">0dp</dimen>
|
||||||
<dimen name="all_apps_grid_section_text_size">26sp</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_size">72dp</dimen>
|
||||||
<dimen name="container_fastscroll_popup_text_size">48dp</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 -->
|
<!-- All Apps -->
|
||||||
<dimen name="all_apps_button_scale_down">0dp</dimen>
|
<dimen name="all_apps_button_scale_down">0dp</dimen>
|
||||||
<dimen name="all_apps_grid_view_start_margin">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.
|
* 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";
|
protected final int mHorizontalPadding;
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
private final Drawable mRevealDrawable;
|
private final Drawable mRevealDrawable;
|
||||||
|
|
||||||
@@ -60,11 +50,17 @@ public abstract class BaseContainerView extends FrameLayout implements Insettabl
|
|||||||
|
|
||||||
public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, 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,
|
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||||
R.styleable.BaseContainerView, defStyleAttr, 0);
|
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();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,90 +70,13 @@ public abstract class BaseContainerView extends FrameLayout implements Insettabl
|
|||||||
|
|
||||||
mContent = findViewById(R.id.main_content);
|
mContent = findViewById(R.id.main_content);
|
||||||
mRevealView = findViewById(R.id.reveal_view);
|
mRevealView = findViewById(R.id.reveal_view);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
|
||||||
final public void setInsets(Rect insets) {
|
mContent.setBackground(mRevealDrawable);
|
||||||
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);
|
|
||||||
|
|
||||||
// We let the content have a intent background, but still have full width.
|
// 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.
|
// This allows the scroll bar to be used responsive outside the background bounds as well.
|
||||||
mContent.setPadding(0, 0, 0, 0);
|
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() {
|
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 */
|
/** To be overridden by subclasses to hint to Launcher that we have custom content */
|
||||||
protected boolean hasCustomContentToLeft() {
|
protected boolean hasCustomContentToLeft() {
|
||||||
if (mLauncherCallbacks != null) {
|
if (mLauncherCallbacks != null) {
|
||||||
|
|||||||
@@ -230,8 +230,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
|||||||
mSearchBarController = searchController;
|
mSearchBarController = searchController;
|
||||||
mSearchBarController.initialize(mApps, mSearchInput, mLauncher, this);
|
mSearchBarController.initialize(mApps, mSearchInput, mLauncher, this);
|
||||||
mAdapter.setSearchController(mSearchBarController);
|
mAdapter.setSearchController(mSearchBarController);
|
||||||
|
|
||||||
updateBackgroundAndPaddings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -311,19 +309,17 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
|||||||
mAppsRecyclerView.setPremeasuredIconHeights(predIcon.getMeasuredHeight(),
|
mAppsRecyclerView.setPremeasuredIconHeights(predIcon.getMeasuredHeight(),
|
||||||
icon.getMeasuredHeight());
|
icon.getMeasuredHeight());
|
||||||
|
|
||||||
updateBackgroundAndPaddings();
|
updatePaddingsAndMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBoundsChanged(Rect newBounds) {
|
public void onBoundsChanged(Rect newBounds) { }
|
||||||
mLauncher.updateOverlayBounds(newBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
mContentBounds.set(mContentPadding.left, mContentPadding.top,
|
mContentBounds.set(mHorizontalPadding, 0,
|
||||||
MeasureSpec.getSize(widthMeasureSpec) - mContentPadding.right,
|
MeasureSpec.getSize(widthMeasureSpec) - mHorizontalPadding,
|
||||||
MeasureSpec.getSize(heightMeasureSpec) - mContentPadding.bottom);
|
MeasureSpec.getSize(heightMeasureSpec));
|
||||||
|
|
||||||
// Update the number of items in the grid before we measure the view
|
// Update the number of items in the grid before we measure the view
|
||||||
// TODO: mSectionNamesMargin is currently 0, but also account for it,
|
// 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
|
* 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.
|
* recycler view to handle touch events (for fast scrolling) all the way to the edge.
|
||||||
*/
|
*/
|
||||||
@Override
|
private void updatePaddingsAndMargins() {
|
||||||
protected void onUpdateBgPadding(Rect padding, Rect bgPadding) {
|
Rect bgPadding = new Rect();
|
||||||
|
getRevealView().getBackground().getPadding(bgPadding);
|
||||||
|
|
||||||
mAppsRecyclerView.updateBackgroundPadding(bgPadding);
|
mAppsRecyclerView.updateBackgroundPadding(bgPadding);
|
||||||
mAdapter.updateBackgroundPadding(bgPadding);
|
mAdapter.updateBackgroundPadding(bgPadding);
|
||||||
mElevationController.updateBackgroundPadding(bgPadding);
|
mElevationController.updateBackgroundPadding(bgPadding);
|
||||||
@@ -377,16 +375,16 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
|||||||
int startInset = Math.max(mSectionNamesMargin, maxScrollBarWidth);
|
int startInset = Math.max(mSectionNamesMargin, maxScrollBarWidth);
|
||||||
int topBottomPadding = mRecyclerViewTopBottomPadding;
|
int topBottomPadding = mRecyclerViewTopBottomPadding;
|
||||||
if (Utilities.isRtl(getResources())) {
|
if (Utilities.isRtl(getResources())) {
|
||||||
mAppsRecyclerView.setPadding(padding.left + maxScrollBarWidth,
|
mAppsRecyclerView.setPadding(bgPadding.left + maxScrollBarWidth,
|
||||||
topBottomPadding, padding.right + startInset, topBottomPadding);
|
topBottomPadding, bgPadding.right + startInset, topBottomPadding);
|
||||||
} else {
|
} else {
|
||||||
mAppsRecyclerView.setPadding(padding.left + startInset, topBottomPadding,
|
mAppsRecyclerView.setPadding(bgPadding.left + startInset, topBottomPadding,
|
||||||
padding.right + maxScrollBarWidth, topBottomPadding);
|
bgPadding.right + maxScrollBarWidth, topBottomPadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
MarginLayoutParams lp = (MarginLayoutParams) mSearchContainer.getLayoutParams();
|
MarginLayoutParams lp = (MarginLayoutParams) mSearchContainer.getLayoutParams();
|
||||||
lp.leftMargin = padding.left;
|
lp.leftMargin = bgPadding.left;
|
||||||
lp.rightMargin = padding.right;
|
lp.rightMargin = bgPadding.right;
|
||||||
mSearchContainer.setLayoutParams(lp);
|
mSearchContainer.setLayoutParams(lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ public abstract class AllAppsSearchBarController
|
|||||||
/**
|
/**
|
||||||
* Called when the bounds of the search bar has changed.
|
* Called when the bounds of the search bar has changed.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void onBoundsChanged(Rect newBounds);
|
void onBoundsChanged(Rect newBounds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -96,6 +96,18 @@ public class WidgetsContainerView extends BaseContainerView
|
|||||||
mRecyclerView = (WidgetsRecyclerView) getContentView().findViewById(R.id.widgets_list_view);
|
mRecyclerView = (WidgetsRecyclerView) getContentView().findViewById(R.id.widgets_list_view);
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
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.
|
* Initialize the widget data model.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user