1 /*
2  * Copyright (C) 2021 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.widget.picker;
17 
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.view.MotionEvent;
21 import android.widget.LinearLayout;
22 
23 /**
24  * A {@link LinearLayout} container for holding search and widgets recommendation.
25  *
26  * <p>This class intercepts touch events and dispatch them to the right view.
27  */
28 public class SearchAndRecommendationsView extends LinearLayout {
29     private SearchAndRecommendationsScrollController mController;
30 
SearchAndRecommendationsView(Context context)31     public SearchAndRecommendationsView(Context context) {
32         this(context, /* attrs= */ null);
33     }
34 
SearchAndRecommendationsView(Context context, AttributeSet attrs)35     public SearchAndRecommendationsView(Context context, AttributeSet attrs) {
36         this(context, attrs, /* defStyleAttr= */ 0);
37     }
38 
SearchAndRecommendationsView(Context context, AttributeSet attrs, int defStyleAttr)39     public SearchAndRecommendationsView(Context context, AttributeSet attrs, int defStyleAttr) {
40         this(context, attrs, defStyleAttr, /* defStyleRes= */ 0);
41     }
42 
SearchAndRecommendationsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)43     public SearchAndRecommendationsView(Context context, AttributeSet attrs, int defStyleAttr,
44             int defStyleRes) {
45         super(context, attrs, defStyleAttr, defStyleRes);
46     }
47 
setSearchAndRecommendationScrollController( SearchAndRecommendationsScrollController controller)48     public void setSearchAndRecommendationScrollController(
49             SearchAndRecommendationsScrollController controller) {
50         mController = controller;
51     }
52 
53     @Override
onInterceptTouchEvent(MotionEvent event)54     public boolean onInterceptTouchEvent(MotionEvent event) {
55         return mController.onInterceptTouchEvent(event) || super.onInterceptTouchEvent(event);
56     }
57 
58     @Override
onTouchEvent(MotionEvent event)59     public boolean onTouchEvent(MotionEvent event) {
60         return mController.onTouchEvent(event) || super.onTouchEvent(event);
61     }
62 }
63