summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/BaseContainerView.java
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2015-06-04 17:18:17 -0700
committerWinson Chung <winsonc@google.com>2015-06-15 14:22:47 -0700
commitef7f874a889b609bd34e692b9c9a1f8cefd1ea95 (patch)
tree23d364f99ae51ea31a9d4e9e9c5bcf7048db7184 /src/com/android/launcher3/BaseContainerView.java
parente89cf793ab22fcb8cea3ff94ca981659208446db (diff)
downloadandroid_packages_apps_Trebuchet-ef7f874a889b609bd34e692b9c9a1f8cefd1ea95.tar.gz
android_packages_apps_Trebuchet-ef7f874a889b609bd34e692b9c9a1f8cefd1ea95.tar.bz2
android_packages_apps_Trebuchet-ef7f874a889b609bd34e692b9c9a1f8cefd1ea95.zip
Refactoring all apps search to support external search bar.
- Adding support for an external search bar that can be used to search a container view. This adds a new interface AllAppsSearchController which manages the external search bar. Each controller will have its own search implementation which means that we no longer need a common AppSearchManager interface. - Removing elevation controller as we no longer have a builtin search bar in all apps - Refactoring container view insets so that they behave the same in all containers. - Refactoring apps view to ensure that we only update the number of columns with the available width - Cleaning up LauncherCallbacks interface Bug: 20127840 Bug: 21494973 Change-Id: I710b8e18196961d77d8a29f0c345531d480936fe
Diffstat (limited to 'src/com/android/launcher3/BaseContainerView.java')
-rw-r--r--src/com/android/launcher3/BaseContainerView.java96
1 files changed, 58 insertions, 38 deletions
diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java
index bd1c625e3..4b7b97775 100644
--- a/src/com/android/launcher3/BaseContainerView.java
+++ b/src/com/android/launcher3/BaseContainerView.java
@@ -19,16 +19,25 @@ package com.android.launcher3;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
-import android.widget.FrameLayout;
+import android.widget.LinearLayout;
/**
* A base container view, which supports resizing.
*/
-public class BaseContainerView extends FrameLayout implements Insettable {
+public abstract class BaseContainerView extends LinearLayout implements Insettable {
- protected Rect mInsets = new Rect();
- protected Rect mFixedBounds = new Rect();
- protected int mFixedBoundsContainerInset;
+ // The window insets
+ private 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 Rect mSearchBarBounds = new Rect();
+ // The bounds of the container
+ protected Rect mContentBounds = new Rect();
+ // The padding to apply to the container to achieve the bounds
+ protected Rect mContentPadding = new Rect();
+ // The inset to apply to the edges and between the search bar and the container
+ private int mContainerBoundsInset;
+ private boolean mHasSearchBar;
public BaseContainerView(Context context) {
this(context, null);
@@ -40,62 +49,73 @@ public class BaseContainerView extends FrameLayout implements Insettable {
public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- mFixedBoundsContainerInset = context.getResources().getDimensionPixelSize(
- R.dimen.container_fixed_bounds_inset);
+ mContainerBoundsInset = getResources().getDimensionPixelSize(R.dimen.container_bounds_inset);
}
@Override
final public void setInsets(Rect insets) {
mInsets.set(insets);
- onUpdateBackgrounds();
- onUpdatePaddings();
+ updateBackgroundAndPaddings();
+ }
+
+ protected void setHasSearchBar() {
+ mHasSearchBar = true;
}
/**
- * Sets the fixed bounds for this container view.
+ * Sets the search bar bounds for this container view to match.
*/
- final public void setFixedBounds(Rect fixedBounds) {
- if (!fixedBounds.isEmpty() && !fixedBounds.equals(mFixedBounds)) {
- mFixedBounds.set(fixedBounds);
- if (Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
- mFixedBounds.top = mInsets.top;
- mFixedBounds.bottom = mInsets.bottom;
- }
- // To ensure that the child RecyclerView has the full width to handle touches right to
- // the edge of the screen, we only apply the top and bottom padding to the bounds
- mFixedBounds.top += mFixedBoundsContainerInset;
- mFixedBounds.bottom += mFixedBoundsContainerInset;
- onFixedBoundsUpdated();
- }
+ final public void setSearchBarBounds(Rect bounds) {
+ mSearchBarBounds.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() {
- onUpdateBackgrounds();
- onUpdatePaddings();
+ updateBackgroundAndPaddings();
}
});
}
/**
- * Update the UI in response to a change in the fixed bounds.
+ * Update the backgrounds and padding in response to a change in the bounds or insets.
*/
- protected void onFixedBoundsUpdated() {
- // Do nothing
- }
+ protected void updateBackgroundAndPaddings() {
+ Rect padding;
+ Rect searchBarBounds = new Rect(mSearchBarBounds);
+ if (mSearchBarBounds.isEmpty()) {
+ // Use the normal bounds
+ padding = new Rect(mInsets.left + mContainerBoundsInset,
+ (mHasSearchBar ? 0 : (mInsets.top + mContainerBoundsInset)),
+ mInsets.right + mContainerBoundsInset,
+ mInsets.bottom + mContainerBoundsInset);
- /**
- * Update the paddings in response to a change in the bounds or insets.
- */
- protected void onUpdatePaddings() {
- // Do nothing
+ // Special case -- we have the search bar, but no specific bounds, so just give it
+ // the inset bounds without a height.
+ searchBarBounds.set(mInsets.left + mContainerBoundsInset,
+ mInsets.top + mContainerBoundsInset,
+ getMeasuredWidth() - (mInsets.right + mContainerBoundsInset), 0);
+ } else {
+ // Use the search bounds, if there is a search bar, the bounds will contain
+ // the offsets for the insets so we can ignore that
+ padding = new Rect(mSearchBarBounds.left,
+ (mHasSearchBar ? 0 : (mInsets.top + mContainerBoundsInset)),
+ getMeasuredWidth() - mSearchBarBounds.right,
+ mInsets.bottom + mContainerBoundsInset);
+ }
+ if (!padding.equals(mContentPadding) || !searchBarBounds.equals(mSearchBarBounds)) {
+ mContentPadding.set(padding);
+ mContentBounds.set(padding.left, padding.top,
+ getMeasuredWidth() - padding.right,
+ getMeasuredHeight() - padding.bottom);
+ mSearchBarBounds.set(searchBarBounds);
+ onUpdateBackgroundAndPaddings(mSearchBarBounds, padding);
+ }
}
/**
- * Update the backgrounds in response to a change in the bounds or insets.
+ * To be implemented by container views to update themselves when the bounds changes.
*/
- protected void onUpdateBackgrounds() {
- // Do nothing
- }
+ protected abstract void onUpdateBackgroundAndPaddings(Rect searchBarBounds, Rect padding);
} \ No newline at end of file