[Search] Hide A-Z list when search is entered from QSB

preview attached to bug report

Bug: 201781284
Test: manual
Change-Id: I572360d2d49b38577a7d77115aede4c3269d42e9
This commit is contained in:
sfufa@google.com
2021-10-13 13:01:18 -07:00
parent 3b6b03b756
commit 7a620d3673
5 changed files with 68 additions and 8 deletions

View File

@@ -47,6 +47,7 @@ public class FloatingHeaderView extends LinearLayout implements
ValueAnimator.AnimatorUpdateListener, PluginListener<AllAppsRow>, Insettable,
OnHeightUpdatedListener {
private static final long ALL_APPS_CONTENT_ANIM_DURATION = 150;
private final Rect mRVClip = new Rect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
private final Rect mHeaderClip = new Rect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
private final ValueAnimator mAnimator = ValueAnimator.ofInt(0, 0);
@@ -108,6 +109,14 @@ public class FloatingHeaderView extends LinearLayout implements
// enabled or disabled, and represent the current set of all rows.
private FloatingHeaderRow[] mAllRows = FloatingHeaderRow.NO_ROWS;
// members for handling suggestion state
private final ValueAnimator mAllAppsContentAnimator = ValueAnimator.ofFloat(0, 0);
private View mAllAppsButton;
private int mAllAppsContentFadeInOffset;
private boolean mInSuggestionMode = false;
public FloatingHeaderView(@NonNull Context context) {
this(context, null);
}
@@ -118,12 +127,20 @@ public class FloatingHeaderView extends LinearLayout implements
.getDimensionPixelSize(R.dimen.all_apps_header_top_padding);
mHeaderProtectionSupported = context.getResources().getBoolean(
R.bool.config_header_protection_supported);
mAllAppsContentFadeInOffset = context.getResources()
.getDimensionPixelSize(R.dimen.all_apps_content_fade_in_offset);
mAllAppsContentAnimator.setDuration(ALL_APPS_CONTENT_ANIM_DURATION);
mAllAppsContentAnimator.addUpdateListener(this::onAllAppsContentAnimationUpdate);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mTabLayout = findViewById(R.id.tabs);
mAllAppsButton = findViewById(R.id.all_apps_button);
if (mAllAppsButton != null) {
mAllAppsButton.setOnClickListener(this::onAllAppsButtonClicked);
}
// Find all floating header rows.
ArrayList<FloatingHeaderRow> rows = new ArrayList<>();
@@ -312,6 +329,7 @@ public class FloatingHeaderView extends LinearLayout implements
}
mTabLayout.setTranslationY(mTranslationY);
setSuggestionMode(false);
int clipHeight = mHeaderTopPadding - getPaddingBottom();
mRVClip.top = mTabsHidden ? clipHeight : 0;
@@ -347,6 +365,7 @@ public class FloatingHeaderView extends LinearLayout implements
mTranslationY = 0;
applyVerticalMove();
}
setSuggestionMode(false);
mHeaderCollapsed = false;
mSnappedScrolledY = -mMaxTranslation;
mCurrentRV.scrollToTop();
@@ -442,6 +461,38 @@ public class FloatingHeaderView extends LinearLayout implements
}
return Math.max(getHeight() - getPaddingTop() + mTranslationY, 0);
}
/**
* When suggestion mode is enabled, hides AllApps content view and shows AllApps button.
*/
public void setSuggestionMode(boolean isSuggestMode) {
if (mInSuggestionMode == isSuggestMode || mAllAppsButton == null) return;
if (!FeatureFlags.ENABLE_ONE_SEARCH.get()) return;
AllAppsContainerView allApps = (AllAppsContainerView) getParent();
mInSuggestionMode = isSuggestMode;
if (isSuggestMode) {
mTabLayout.setVisibility(GONE);
mAllAppsButton.setVisibility(VISIBLE);
allApps.getContentView().setVisibility(GONE);
} else {
mTabLayout.setVisibility(mTabsHidden ? GONE : VISIBLE);
mAllAppsButton.setVisibility(GONE);
allApps.getContentView().setVisibility(VISIBLE);
}
}
private void onAllAppsButtonClicked(View view) {
setSuggestionMode(false);
mAllAppsContentAnimator.start();
}
private void onAllAppsContentAnimationUpdate(ValueAnimator valueAnimator) {
float prog = valueAnimator.getAnimatedFraction();
View allAppsList = ((AllAppsContainerView) getParent()).getContentView();
allAppsList.setAlpha(255 * prog);
allAppsList.setTranslationY((1 - prog) * mAllAppsContentFadeInOffset);
}
}