• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 
17 package com.android.launcher3.allapps;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.ViewGroup;
22 import android.widget.ImageView;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.constraintlayout.widget.ConstraintLayout;
26 
27 import com.android.launcher3.R;
28 import com.android.launcher3.views.ActivityContext;
29 
30 public class FloatingMaskView extends ConstraintLayout {
31 
32     private final ActivityContext mActivityContext;
33     private ImageView mBottomBox;
34 
FloatingMaskView(Context context)35     public FloatingMaskView(Context context) {
36         this(context, null, 0);
37     }
38 
FloatingMaskView(Context context, AttributeSet attrs)39     public FloatingMaskView(Context context, AttributeSet attrs) {
40         this(context, attrs, 0);
41     }
42 
FloatingMaskView(Context context, AttributeSet attrs, int defStyleAttr)43     public FloatingMaskView(Context context, AttributeSet attrs, int defStyleAttr) {
44         super(context, attrs, defStyleAttr);
45         mActivityContext = ActivityContext.lookupContext(context);
46     }
47 
48     @Override
onFinishInflate()49     protected void onFinishInflate() {
50         super.onFinishInflate();
51         mBottomBox = findViewById(R.id.bottom_box);
52     }
53 
54     @Override
onLayout(boolean changed, int left, int top, int right, int bottom)55     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
56         super.onLayout(changed, left, top, right, bottom);
57         setParameters((ViewGroup.MarginLayoutParams) getLayoutParams(),
58                 mActivityContext.getAppsView().getActiveRecyclerView());
59     }
60 
61     @VisibleForTesting
setParameters(ViewGroup.MarginLayoutParams lp, AllAppsRecyclerView recyclerView)62     void setParameters(ViewGroup.MarginLayoutParams lp, AllAppsRecyclerView recyclerView) {
63         if (lp != null) {
64             lp.rightMargin = recyclerView.getPaddingRight();
65             lp.leftMargin = recyclerView.getPaddingLeft();
66             getBottomBox().setMinimumHeight(recyclerView.getPaddingBottom());
67         }
68     }
69 
70     @VisibleForTesting
getBottomBox()71     ImageView getBottomBox() {
72         return mBottomBox;
73     }
74 }
75