diff options
author | Winson <winsonc@google.com> | 2015-08-19 17:26:21 -0700 |
---|---|---|
committer | Winson <winsonc@google.com> | 2015-08-28 12:34:55 -0700 |
commit | fee206f2419a0ffa90abf4f9f3f9e0b6d0b74906 (patch) | |
tree | 479fb593a01d34c844ca0bd201b47a9de04fb3af /src/com/android/launcher3/allapps/AllAppsRecyclerView.java | |
parent | a79b18ad36ca9025ac4862c492260a656f61c7cf (diff) | |
download | android_packages_apps_Trebuchet-fee206f2419a0ffa90abf4f9f3f9e0b6d0b74906.tar.gz android_packages_apps_Trebuchet-fee206f2419a0ffa90abf4f9f3f9e0b6d0b74906.tar.bz2 android_packages_apps_Trebuchet-fee206f2419a0ffa90abf4f9f3f9e0b6d0b74906.zip |
Adding graphic for all apps empty search screen.
Change-Id: I976a327a5984790c458b0f36d33c0b1ac16ec59c
Diffstat (limited to 'src/com/android/launcher3/allapps/AllAppsRecyclerView.java')
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsRecyclerView.java | 70 |
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()); + } } |