summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-03-18 20:19:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-03-18 20:19:34 +0000
commitb8f00da8deec7f65002830261042da0140cbead0 (patch)
treed96f4031c1f8de49d7d069daa749fcbf5ce4ce4e /src/com/android
parent4ddc40130aa0460924364eab3557088421eebe0c (diff)
parent05c8c57fa72a81f34058036f6dc30c084ca6742b (diff)
downloadandroid_packages_apps_Trebuchet-b8f00da8deec7f65002830261042da0140cbead0.tar.gz
android_packages_apps_Trebuchet-b8f00da8deec7f65002830261042da0140cbead0.tar.bz2
android_packages_apps_Trebuchet-b8f00da8deec7f65002830261042da0140cbead0.zip
Merge "Removing dependency on LauncherCallbacks for getting the search bounds" into ub-launcher3-calgary
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/launcher3/BaseContainerView.java105
-rw-r--r--src/com/android/launcher3/Launcher.java8
-rw-r--r--src/com/android/launcher3/allapps/AllAppsContainerView.java32
-rw-r--r--src/com/android/launcher3/allapps/AllAppsSearchBarController.java1
-rw-r--r--src/com/android/launcher3/widget/WidgetsContainerView.java28
5 files changed, 40 insertions, 134 deletions
diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java
index bd4199264..51a97b91b 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 245b39909..5a1f99a65 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 9d5afb465..fa34d75a6 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 39d6dd50c..a4bea8dbd 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 5d6f47510..23d04331f 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.
*/