summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/allapps/AllAppsRecyclerView.java')
-rw-r--r--src/com/android/launcher3/allapps/AllAppsRecyclerView.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
index 1cde7bfc0..e33b4db5e 100644
--- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
@@ -15,8 +15,11 @@
*/
package com.android.launcher3.allapps;
+import android.animation.ObjectAnimator;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -26,6 +29,7 @@ import android.view.View;
import com.android.launcher3.BaseRecyclerView;
import com.android.launcher3.BaseRecyclerViewFastScrollBar;
import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.R;
import com.android.launcher3.Stats;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.Thunk;
@@ -57,6 +61,9 @@ public class AllAppsRecyclerView extends BaseRecyclerView
private ScrollPositionState mScrollPosState = new ScrollPositionState();
+ private AllAppsBackgroundDrawable mEmptySearchBackground;
+ private int mEmptySearchBackgroundTopOffset;
+
public AllAppsRecyclerView(Context context) {
this(context, null);
}
@@ -72,7 +79,11 @@ public class AllAppsRecyclerView extends BaseRecyclerView
public AllAppsRecyclerView(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr);
+
+ Resources res = getResources();
mScrollbar.setDetachThumbOnFastScroll();
+ mEmptySearchBackgroundTopOffset = res.getDimensionPixelSize(
+ R.dimen.all_apps_empty_search_bg_top_offset);
}
/**
@@ -118,6 +129,30 @@ public class AllAppsRecyclerView extends BaseRecyclerView
}
@Override
+ public void onDraw(Canvas c) {
+ // Draw the background
+ if (mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) {
+ c.clipRect(mBackgroundPadding.left, mBackgroundPadding.top,
+ getWidth() - mBackgroundPadding.right,
+ getHeight() - mBackgroundPadding.bottom);
+
+ mEmptySearchBackground.draw(c);
+ }
+
+ super.onDraw(c);
+ }
+
+ @Override
+ protected boolean verifyDrawable(Drawable who) {
+ return who == mEmptySearchBackground || super.verifyDrawable(who);
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ updateEmptySearchBackgroundBounds();
+ }
+
+ @Override
protected void onFinishInflate() {
super.onFinishInflate();
@@ -137,6 +172,25 @@ public class AllAppsRecyclerView extends BaseRecyclerView
}
}
+ public void onSearchResultsChanged() {
+ // Always scroll the view to the top so the user can see the changed results
+ scrollToTop();
+
+ if (mApps.hasNoFilteredResults()) {
+ if (mEmptySearchBackground == null) {
+ mEmptySearchBackground = new AllAppsBackgroundDrawable(getContext());
+ mEmptySearchBackground.setAlpha(0);
+ mEmptySearchBackground.setCallback(this);
+ updateEmptySearchBackgroundBounds();
+ }
+ mEmptySearchBackground.animateBgAlpha(1f, 150);
+ } else if (mEmptySearchBackground != null) {
+ // For the time being, we just immediately hide the background to ensure that it does
+ // not overlap with the results
+ mEmptySearchBackground.setBgAlpha(0f);
+ }
+ }
+
/**
* Maps the touch (from 0..1) to the adapter position that should be visible.
*/
@@ -386,4 +440,20 @@ public class AllAppsRecyclerView extends BaseRecyclerView
return 0;
}
}
+
+ /**
+ * Updates the bounds of the empty search background.
+ */
+ private void updateEmptySearchBackgroundBounds() {
+ if (mEmptySearchBackground == null) {
+ return;
+ }
+
+ // Center the empty search background on this new view bounds
+ int x = (getMeasuredWidth() - mEmptySearchBackground.getIntrinsicWidth()) / 2;
+ int y = mEmptySearchBackgroundTopOffset;
+ mEmptySearchBackground.setBounds(x, y,
+ x + mEmptySearchBackground.getIntrinsicWidth(),
+ y + mEmptySearchBackground.getIntrinsicHeight());
+ }
}