blob: 52a2fc5ac0135380da84c3c473dee61a73c71509 [file] [log] [blame]
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Steven Ng2f5648a2021-02-08 17:18:25 +000016package com.android.launcher3.widget.picker;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070017
Sunny Goyalf3ac7032020-03-13 13:01:33 -070018import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
vadimt9f48a8e2019-12-11 11:52:37 -080019import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL;
20
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
23import android.animation.PropertyValuesHolder;
24import android.content.Context;
Steven Ng391404f2021-02-17 15:58:23 +000025import android.content.pm.LauncherApps;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070026import android.graphics.Rect;
Steven Ng391404f2021-02-17 15:58:23 +000027import android.os.Process;
28import android.os.UserHandle;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070029import android.util.AttributeSet;
Sunny Goyalde753212018-05-15 13:55:57 -070030import android.util.Pair;
Steven Ng391404f2021-02-17 15:58:23 +000031import android.util.SparseArray;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070032import android.view.LayoutInflater;
33import android.view.MotionEvent;
Sunny Goyalde753212018-05-15 13:55:57 -070034import android.view.View;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070035import android.view.animation.AnimationUtils;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070036import android.view.animation.Interpolator;
Steven Ng167f81b2021-02-23 10:48:46 +000037import android.widget.EditText;
38import android.widget.TextView;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070039
Steven Ng391404f2021-02-17 15:58:23 +000040import androidx.annotation.Nullable;
Tony Wickham9791bd12019-04-05 13:52:35 -070041import androidx.annotation.VisibleForTesting;
Steven Ng391404f2021-02-17 15:58:23 +000042import androidx.recyclerview.widget.RecyclerView;
Tony Wickham9791bd12019-04-05 13:52:35 -070043
Steven Nge8d92342021-02-19 21:29:18 +000044import com.android.launcher3.DeviceProfile;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070045import com.android.launcher3.Insettable;
46import com.android.launcher3.Launcher;
47import com.android.launcher3.LauncherAppState;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070048import com.android.launcher3.R;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070049import com.android.launcher3.anim.PendingAnimation;
vadimt9f48a8e2019-12-11 11:52:37 -080050import com.android.launcher3.compat.AccessibilityManagerCompat;
Sunny Goyal3661bfa2018-03-01 16:29:15 -080051import com.android.launcher3.views.RecyclerViewFastScroller;
52import com.android.launcher3.views.TopRoundedCornerView;
Steven Ng2f5648a2021-02-08 17:18:25 +000053import com.android.launcher3.widget.BaseWidgetSheet;
Yogisha Dixit741fae92021-02-22 14:03:44 +000054import com.android.launcher3.widget.LauncherAppWidgetHost.ProviderChangedListener;
Steven Ng391404f2021-02-17 15:58:23 +000055import com.android.launcher3.widget.model.WidgetsListBaseEntry;
56import com.android.launcher3.workprofile.PersonalWorkPagedView;
57import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.OnActivePageChangedListener;
58
59import java.util.List;
60import java.util.function.Predicate;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070061
62/**
63 * Popup for showing the full list of available widgets
64 */
65public class WidgetsFullSheet extends BaseWidgetSheet
Steven Ng167f81b2021-02-23 10:48:46 +000066 implements Insettable, ProviderChangedListener, OnActivePageChangedListener,
67 WidgetsRecyclerView.HeaderViewDimensionsProvider {
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070068
69 private static final long DEFAULT_OPEN_DURATION = 267;
70 private static final long FADE_IN_DURATION = 150;
71 private static final float VERTICAL_START_POSITION = 0.3f;
72
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070073 private final Rect mInsets = new Rect();
Steven Ng391404f2021-02-17 15:58:23 +000074 private final boolean mHasWorkProfile;
75 private final SparseArray<AdapterHolder> mAdapters = new SparseArray();
76 private final UserHandle mCurrentUser = Process.myUserHandle();
77 private final Predicate<WidgetsListBaseEntry> mPrimaryWidgetsFilter = entry ->
78 mCurrentUser.equals(entry.mPkgItem.user);
79 private final Predicate<WidgetsListBaseEntry> mWorkWidgetsFilter =
80 mPrimaryWidgetsFilter.negate();
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070081
Steven Ng391404f2021-02-17 15:58:23 +000082 @Nullable private PersonalWorkPagedView mViewPager;
Steven Ng167f81b2021-02-23 10:48:46 +000083 private int mInitialTabsHeight = 0;
84 private View mTabsView;
85 private SearchAndRecommendationViewHolder mSearchAndRecommendationViewHolder;
86 private SearchAndRecommendationsScrollController mSearchAndRecommendationsScrollController;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070087
88 public WidgetsFullSheet(Context context, AttributeSet attrs, int defStyleAttr) {
89 super(context, attrs, defStyleAttr);
Steven Ng391404f2021-02-17 15:58:23 +000090 mHasWorkProfile = context.getSystemService(LauncherApps.class).getProfiles().size() > 1;
91 mAdapters.put(AdapterHolder.PRIMARY, new AdapterHolder(AdapterHolder.PRIMARY));
92 mAdapters.put(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK));
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070093 }
94
95 public WidgetsFullSheet(Context context, AttributeSet attrs) {
96 this(context, attrs, 0);
97 }
98
99 @Override
100 protected void onFinishInflate() {
101 super.onFinishInflate();
102 mContent = findViewById(R.id.container);
Sunny Goyal016d7e92018-03-09 11:09:20 -0800103 TopRoundedCornerView springLayout = (TopRoundedCornerView) mContent;
Steven Ng391404f2021-02-17 15:58:23 +0000104
105 LayoutInflater layoutInflater = LayoutInflater.from(getContext());
106 int contentLayoutRes = mHasWorkProfile ? R.layout.widgets_full_sheet_paged_view
107 : R.layout.widgets_full_sheet_recyclerview;
Steven Ng167f81b2021-02-23 10:48:46 +0000108 layoutInflater.inflate(contentLayoutRes, springLayout, true);
Steven Ng391404f2021-02-17 15:58:23 +0000109
Steven Ng167f81b2021-02-23 10:48:46 +0000110 RecyclerViewFastScroller fastScroller = findViewById(R.id.fast_scroller);
Steven Ng391404f2021-02-17 15:58:23 +0000111 if (mHasWorkProfile) {
112 mViewPager = findViewById(R.id.widgets_view_pager);
113 // Temporarily disable swipe gesture until widgets list horizontal scrollviews per
114 // app are replaced by gird views.
115 mViewPager.setSwipeGestureEnabled(false);
116 mViewPager.initParentViews(this);
117 mViewPager.getPageIndicator().setOnActivePageChangedListener(this);
118 mViewPager.getPageIndicator().setActiveMarker(AdapterHolder.PRIMARY);
Steven Ng167f81b2021-02-23 10:48:46 +0000119 mTabsView = findViewById(R.id.tabs);
Steven Ng391404f2021-02-17 15:58:23 +0000120 findViewById(R.id.tab_personal)
121 .setOnClickListener((View view) -> mViewPager.snapToPage(0));
122 findViewById(R.id.tab_work)
123 .setOnClickListener((View view) -> mViewPager.snapToPage(1));
Steven Ng167f81b2021-02-23 10:48:46 +0000124 fastScroller.setIsRecyclerViewFirstChildInParent(false);
Steven Ng391404f2021-02-17 15:58:23 +0000125 springLayout.addSpringView(R.id.primary_widgets_list_view);
126 springLayout.addSpringView(R.id.work_widgets_list_view);
127 } else {
128 mViewPager = null;
129 springLayout.addSpringView(R.id.primary_widgets_list_view);
130 }
131
Steven Ng167f81b2021-02-23 10:48:46 +0000132 layoutInflater.inflate(R.layout.widgets_full_sheet_search_and_recommendations, springLayout,
133 true);
134 springLayout.addSpringView(R.id.search_and_recommendations_container);
135
136 mSearchAndRecommendationViewHolder = new SearchAndRecommendationViewHolder(
137 findViewById(R.id.search_and_recommendations_container));
138 mSearchAndRecommendationsScrollController = new SearchAndRecommendationsScrollController(
139 mHasWorkProfile,
140 mSearchAndRecommendationViewHolder,
141 findViewById(R.id.primary_widgets_list_view),
142 mHasWorkProfile ? findViewById(R.id.work_widgets_list_view) : null,
143 mTabsView,
144 mViewPager);
145 fastScroller.setOnFastScrollChangeListener(mSearchAndRecommendationsScrollController);
146
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700147 onWidgetsBound();
148 }
149
Steven Ng391404f2021-02-17 15:58:23 +0000150 @Override
151 public void onActivePageChanged(int currentActivePage) {
Steven Ng7f7b2f72021-03-03 14:51:36 +0000152 WidgetsRecyclerView currentRecyclerView =
153 mAdapters.get(currentActivePage).mWidgetsRecyclerView;
154 currentRecyclerView.bindFastScrollbar();
155 mSearchAndRecommendationsScrollController.setCurrentRecyclerView(currentRecyclerView);
Steven Ng167f81b2021-02-23 10:48:46 +0000156
157 reset();
158 }
159
160 private void reset() {
161 mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView.scrollToTop();
162 if (mHasWorkProfile) {
163 mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView.scrollToTop();
164 }
Steven Ng7f7b2f72021-03-03 14:51:36 +0000165 mSearchAndRecommendationsScrollController.reset();
Steven Ng391404f2021-02-17 15:58:23 +0000166 }
167
Sunny Goyal8b37c572020-03-31 12:12:14 -0700168 @VisibleForTesting
169 public WidgetsRecyclerView getRecyclerView() {
Steven Ng391404f2021-02-17 15:58:23 +0000170 if (!mHasWorkProfile || mViewPager.getCurrentPage() == AdapterHolder.PRIMARY) {
171 return mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView;
172 }
173 return mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView;
Sunny Goyal8b37c572020-03-31 12:12:14 -0700174 }
175
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700176 @Override
Sunny Goyalde753212018-05-15 13:55:57 -0700177 protected Pair<View, String> getAccessibilityTarget() {
Steven Ng391404f2021-02-17 15:58:23 +0000178 return Pair.create(getRecyclerView(), getContext().getString(
Sunny Goyalde753212018-05-15 13:55:57 -0700179 mIsOpen ? R.string.widgets_list : R.string.widgets_list_closed));
180 }
181
182 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700183 protected void onAttachedToWindow() {
184 super.onAttachedToWindow();
185 mLauncher.getAppWidgetHost().addProviderChangeListener(this);
186 notifyWidgetProvidersChanged();
187 }
188
189 @Override
190 protected void onDetachedFromWindow() {
191 super.onDetachedFromWindow();
192 mLauncher.getAppWidgetHost().removeProviderChangeListener(this);
193 }
194
195 @Override
196 public void setInsets(Rect insets) {
197 mInsets.set(insets);
198
Steven Ng391404f2021-02-17 15:58:23 +0000199 setBottomPadding(mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView, insets.bottom);
200 if (mHasWorkProfile) {
201 setBottomPadding(mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView, insets.bottom);
202 }
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700203 if (insets.bottom > 0) {
204 setupNavBarColor();
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800205 } else {
206 clearNavBarColor();
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700207 }
Sunny Goyal3661bfa2018-03-01 16:29:15 -0800208
209 ((TopRoundedCornerView) mContent).setNavBarScrimHeight(mInsets.bottom);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700210 requestLayout();
211 }
212
Steven Ng391404f2021-02-17 15:58:23 +0000213 private void setBottomPadding(RecyclerView recyclerView, int bottomPadding) {
214 recyclerView.setPadding(
215 recyclerView.getPaddingLeft(),
216 recyclerView.getPaddingTop(),
217 recyclerView.getPaddingRight(),
218 bottomPadding);
219 }
220
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700221 @Override
222 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Steven Nge8d92342021-02-19 21:29:18 +0000223 DeviceProfile deviceProfile = mLauncher.getDeviceProfile();
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700224 int widthUsed;
225 if (mInsets.bottom > 0) {
Sunny Goyal786940a2020-06-02 02:31:31 -0700226 widthUsed = mInsets.left + mInsets.right;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700227 } else {
Steven Nge8d92342021-02-19 21:29:18 +0000228 Rect padding = deviceProfile.workspacePadding;
Sunny Goyal07b69292018-01-08 14:19:34 -0800229 widthUsed = Math.max(padding.left + padding.right,
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700230 2 * (mInsets.left + mInsets.right));
231 }
232
Steven Nge8d92342021-02-19 21:29:18 +0000233 int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700234 measureChildWithMargins(mContent, widthMeasureSpec,
235 widthUsed, heightMeasureSpec, heightUsed);
Sunny Goyal6639a5d2018-02-28 15:09:36 -0800236 setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
237 MeasureSpec.getSize(heightMeasureSpec));
Steven Nge8d92342021-02-19 21:29:18 +0000238
Steven Ng11773f42021-02-25 22:54:37 +0000239 int paddingPx = 2 * getResources().getDimensionPixelOffset(
240 R.dimen.widget_cell_horizontal_padding);
241 int maxSpansPerRow = getMeasuredWidth() / (deviceProfile.cellWidthPx + paddingPx);
Steven Nge8d92342021-02-19 21:29:18 +0000242 mAdapters.get(AdapterHolder.PRIMARY).mWidgetsListAdapter.setMaxHorizontalSpansPerRow(
243 maxSpansPerRow);
244 if (mHasWorkProfile) {
245 mAdapters.get(AdapterHolder.WORK).mWidgetsListAdapter.setMaxHorizontalSpansPerRow(
246 maxSpansPerRow);
247 }
Steven Ng7f7b2f72021-03-03 14:51:36 +0000248
249 if (mInitialTabsHeight == 0 && mTabsView != null) {
250 mInitialTabsHeight = measureHeightWithVerticalMargins(mTabsView);
251 }
252
253 mSearchAndRecommendationsScrollController.updateMarginAndPadding();
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700254 }
255
256 @Override
257 protected void onLayout(boolean changed, int l, int t, int r, int b) {
258 int width = r - l;
259 int height = b - t;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700260
261 // Content is laid out as center bottom aligned
262 int contentWidth = mContent.getMeasuredWidth();
Sunny Goyal786940a2020-06-02 02:31:31 -0700263 int contentLeft = (width - contentWidth - mInsets.left - mInsets.right) / 2 + mInsets.left;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700264 mContent.layout(contentLeft, height - mContent.getMeasuredHeight(),
265 contentLeft + contentWidth, height);
266
267 setTranslationShift(mTranslationShift);
268 }
269
270 @Override
271 public void notifyWidgetProvidersChanged() {
272 mLauncher.refreshAndBindWidgetsForPackageUser(null);
273 }
274
275 @Override
Sunny Goyal202ae0b2019-02-04 16:26:42 -0800276 public void onWidgetsBound() {
Steven Ng391404f2021-02-17 15:58:23 +0000277 List<WidgetsListBaseEntry> allWidgets = mLauncher.getPopupDataProvider().getAllWidgets();
278
279 AdapterHolder primaryUserAdapterHolder = mAdapters.get(AdapterHolder.PRIMARY);
280 primaryUserAdapterHolder.setup(findViewById(R.id.primary_widgets_list_view));
281 primaryUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets);
282 if (mHasWorkProfile) {
283 AdapterHolder workUserAdapterHolder = mAdapters.get(AdapterHolder.WORK);
284 workUserAdapterHolder.setup(findViewById(R.id.work_widgets_list_view));
285 workUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets);
286 onActivePageChanged(mViewPager.getCurrentPage());
287 }
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700288 }
289
290 private void open(boolean animate) {
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700291 if (animate) {
Sunny Goyaldb6cdb02018-07-13 11:03:04 -0700292 if (getPopupContainer().getInsets().bottom > 0) {
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700293 mContent.setAlpha(0);
294 setTranslationShift(VERTICAL_START_POSITION);
295 }
296 mOpenCloseAnimator.setValues(
297 PropertyValuesHolder.ofFloat(TRANSLATION_SHIFT, TRANSLATION_SHIFT_OPENED));
298 mOpenCloseAnimator
299 .setDuration(DEFAULT_OPEN_DURATION)
300 .setInterpolator(AnimationUtils.loadInterpolator(
301 getContext(), android.R.interpolator.linear_out_slow_in));
302 mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() {
303 @Override
304 public void onAnimationEnd(Animator animation) {
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700305 mOpenCloseAnimator.removeListener(this);
306 }
307 });
Sunny Goyal6639a5d2018-02-28 15:09:36 -0800308 post(() -> {
Sunny Goyal6639a5d2018-02-28 15:09:36 -0800309 mOpenCloseAnimator.start();
310 mContent.animate().alpha(1).setDuration(FADE_IN_DURATION);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700311 });
312 } else {
313 setTranslationShift(TRANSLATION_SHIFT_OPENED);
Sunny Goyalde753212018-05-15 13:55:57 -0700314 post(this::announceAccessibilityChanges);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700315 }
316 }
317
318 @Override
319 protected void handleClose(boolean animate) {
320 handleClose(animate, DEFAULT_OPEN_DURATION);
321 }
322
323 @Override
324 protected boolean isOfType(int type) {
325 return (type & TYPE_WIDGETS_FULL_SHEET) != 0;
326 }
327
328 @Override
329 public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
330 // Disable swipe down when recycler view is scrolling
331 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
332 mNoIntercept = false;
Steven Ng391404f2021-02-17 15:58:23 +0000333 RecyclerViewFastScroller scroller = getRecyclerView().getScrollbar();
Steven Ng2f5648a2021-02-08 17:18:25 +0000334 if (scroller.getThumbOffsetY() >= 0
335 && getPopupContainer().isEventOverView(scroller, ev)) {
Sunny Goyal3661bfa2018-03-01 16:29:15 -0800336 mNoIntercept = true;
Sunny Goyaldb6cdb02018-07-13 11:03:04 -0700337 } else if (getPopupContainer().isEventOverView(mContent, ev)) {
Steven Ng391404f2021-02-17 15:58:23 +0000338 mNoIntercept = !getRecyclerView().shouldContainerScroll(ev, getPopupContainer());
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700339 }
340 }
341 return super.onControllerInterceptTouchEvent(ev);
342 }
343
Steven Ng2f5648a2021-02-08 17:18:25 +0000344 /** Shows the {@link WidgetsFullSheet} on the launcher. */
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700345 public static WidgetsFullSheet show(Launcher launcher, boolean animate) {
346 WidgetsFullSheet sheet = (WidgetsFullSheet) launcher.getLayoutInflater()
347 .inflate(R.layout.widgets_full_sheet, launcher.getDragLayer(), false);
Sunny Goyal1642f712018-09-18 11:40:35 -0700348 sheet.attachToContainer();
Sunny Goyalde753212018-05-15 13:55:57 -0700349 sheet.mIsOpen = true;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700350 sheet.open(animate);
351 return sheet;
352 }
Sunny Goyalaeb16432017-10-16 11:46:41 -0700353
Steven Ng2f5648a2021-02-08 17:18:25 +0000354 /** Gets the {@link WidgetsRecyclerView} which shows all widgets in {@link WidgetsFullSheet}. */
Vadim Tryshev2ce6a132018-06-18 19:14:44 -0700355 @VisibleForTesting
356 public static WidgetsRecyclerView getWidgetsView(Launcher launcher) {
Steven Ng391404f2021-02-17 15:58:23 +0000357 return launcher.findViewById(R.id.primary_widgets_list_view);
Vadim Tryshev2ce6a132018-06-18 19:14:44 -0700358 }
359
Sunny Goyalaeb16432017-10-16 11:46:41 -0700360 @Override
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700361 public void addHintCloseAnim(
362 float distanceToMove, Interpolator interpolator, PendingAnimation target) {
Steven Ng391404f2021-02-17 15:58:23 +0000363 target.setFloat(getRecyclerView(), VIEW_TRANSLATE_Y, -distanceToMove, interpolator);
364 target.setViewAlpha(getRecyclerView(), 0.5f, interpolator);
Tony Wickham9791bd12019-04-05 13:52:35 -0700365 }
vadimt9f48a8e2019-12-11 11:52:37 -0800366
367 @Override
368 protected void onCloseComplete() {
369 super.onCloseComplete();
370 AccessibilityManagerCompat.sendStateEventToTest(getContext(), NORMAL_STATE_ORDINAL);
371 }
Steven Ng391404f2021-02-17 15:58:23 +0000372
Steven Ng167f81b2021-02-23 10:48:46 +0000373 @Override
374 public int getHeaderViewHeight() {
375 // No need to check work profile here because mInitialTabHeight is always 0 if there is no
376 // work profile.
377 return mInitialTabsHeight
Steven Ng7f7b2f72021-03-03 14:51:36 +0000378 + measureHeightWithVerticalMargins(mSearchAndRecommendationViewHolder.mContainer);
379 }
380
381 /** private the height, in pixel, + the vertical margins of a given view. */
382 private static int measureHeightWithVerticalMargins(View view) {
383 MarginLayoutParams marginLayoutParams = (MarginLayoutParams) view.getLayoutParams();
384 return view.getMeasuredHeight() + marginLayoutParams.bottomMargin
385 + marginLayoutParams.topMargin;
Steven Ng167f81b2021-02-23 10:48:46 +0000386 }
387
Steven Ng391404f2021-02-17 15:58:23 +0000388 /** A holder class for holding adapters & their corresponding recycler view. */
389 private final class AdapterHolder {
390 static final int PRIMARY = 0;
391 static final int WORK = 1;
392
393 private final int mAdapterType;
394 private final WidgetsListAdapter mWidgetsListAdapter;
395
396 private WidgetsRecyclerView mWidgetsRecyclerView;
397
398 AdapterHolder(int adapterType) {
399 mAdapterType = adapterType;
400
401 Context context = getContext();
402 LauncherAppState apps = LauncherAppState.getInstance(context);
403 mWidgetsListAdapter = new WidgetsListAdapter(
404 context,
405 LayoutInflater.from(context),
406 apps.getWidgetCache(),
407 apps.getIconCache(),
408 /* iconClickListener= */ WidgetsFullSheet.this,
409 /* iconLongClickListener= */ WidgetsFullSheet.this);
410 mWidgetsListAdapter.setFilter(
411 mAdapterType == PRIMARY ? mPrimaryWidgetsFilter : mWorkWidgetsFilter);
412 }
413
414 void setup(WidgetsRecyclerView recyclerView) {
415 mWidgetsRecyclerView = recyclerView;
416 mWidgetsRecyclerView.setAdapter(mWidgetsListAdapter);
Steven Ng167f81b2021-02-23 10:48:46 +0000417 mWidgetsRecyclerView.setHeaderViewDimensionsProvider(WidgetsFullSheet.this);
Steven Ng391404f2021-02-17 15:58:23 +0000418 mWidgetsRecyclerView.setEdgeEffectFactory(
419 ((TopRoundedCornerView) mContent).createEdgeEffectFactory());
420 mWidgetsListAdapter.setApplyBitmapDeferred(false, mWidgetsRecyclerView);
421 }
422 }
Steven Ng167f81b2021-02-23 10:48:46 +0000423
424 final class SearchAndRecommendationViewHolder {
425 final View mContainer;
426 final View mCollapseHandle;
427 final EditText mSearchBar;
428 final TextView mHeaderTitle;
429
430 SearchAndRecommendationViewHolder(View searchAndRecommendationContainer) {
431 mContainer = searchAndRecommendationContainer;
432 mCollapseHandle = mContainer.findViewById(R.id.collapse_handle);
433 mSearchBar = mContainer.findViewById(R.id.widgets_search_bar);
434 mHeaderTitle = mContainer.findViewById(R.id.title);
435 }
436 }
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700437}