1 /* 2 * Copyright (C) 2022 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 */ 16 package com.android.launcher3.taskbar.allapps; 17 18 import android.content.Context; 19 import android.util.AttributeSet; 20 import android.view.View; 21 22 import androidx.annotation.Nullable; 23 24 import com.android.launcher3.R; 25 import com.android.launcher3.allapps.ActivityAllAppsContainerView; 26 import com.android.launcher3.config.FeatureFlags; 27 import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext; 28 29 import java.util.Optional; 30 31 /** All apps container accessible from taskbar. */ 32 public class TaskbarAllAppsContainerView extends 33 ActivityAllAppsContainerView<TaskbarOverlayContext> { 34 35 private @Nullable OnInvalidateHeaderListener mOnInvalidateHeaderListener; 36 TaskbarAllAppsContainerView(Context context, AttributeSet attrs)37 public TaskbarAllAppsContainerView(Context context, AttributeSet attrs) { 38 this(context, attrs, 0); 39 } 40 TaskbarAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr)41 public TaskbarAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) { 42 super(context, attrs, defStyleAttr); 43 } 44 setOnInvalidateHeaderListener(OnInvalidateHeaderListener onInvalidateHeaderListener)45 void setOnInvalidateHeaderListener(OnInvalidateHeaderListener onInvalidateHeaderListener) { 46 mOnInvalidateHeaderListener = onInvalidateHeaderListener; 47 } 48 49 @Override inflateSearchBar()50 protected View inflateSearchBar() { 51 if (isSearchSupported()) { 52 return super.inflateSearchBar(); 53 } 54 55 // Remove top padding of header, since we do not have any search 56 mHeader.setPadding(mHeader.getPaddingLeft(), 0, 57 mHeader.getPaddingRight(), mHeader.getPaddingBottom()); 58 59 TaskbarAllAppsFallbackSearchContainer searchView = 60 new TaskbarAllAppsFallbackSearchContainer(getContext(), null); 61 searchView.setId(R.id.search_container_all_apps); 62 searchView.setVisibility(GONE); 63 return searchView; 64 } 65 66 @Override invalidateHeader()67 public void invalidateHeader() { 68 super.invalidateHeader(); 69 Optional.ofNullable(mOnInvalidateHeaderListener).ifPresent( 70 OnInvalidateHeaderListener::onInvalidateHeader); 71 } 72 73 @Override isSearchSupported()74 protected boolean isSearchSupported() { 75 return FeatureFlags.ENABLE_ALL_APPS_SEARCH_IN_TASKBAR.get(); 76 } 77 78 @Override isInAllApps()79 public boolean isInAllApps() { 80 // All apps is always open 81 return true; 82 } 83 84 interface OnInvalidateHeaderListener { onInvalidateHeader()85 void onInvalidateHeader(); 86 } 87 } 88