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 
17 package com.android.intentresolver.grid;
18 
19 import android.view.View;
20 import android.view.View.MeasureSpec;
21 import android.view.ViewGroup;
22 
23 /**
24  * Used to bind types for group of items including:
25  * {@link ChooserGridAdapter#VIEW_TYPE_DIRECT_SHARE},
26  * and {@link ChooserGridAdapter#VIEW_TYPE_CALLER_AND_RANK}.
27  */
28 public abstract class ItemGroupViewHolder extends ViewHolderBase {
29     protected int mMeasuredRowHeight;
30     private int[] mItemIndices;
31     protected final View[] mCells;
32     private final int mColumnCount;
33 
ItemGroupViewHolder(int cellCount, View itemView, int viewType)34     public ItemGroupViewHolder(int cellCount, View itemView, int viewType) {
35         super(itemView, viewType);
36         this.mCells = new View[cellCount];
37         this.mItemIndices = new int[cellCount];
38         this.mColumnCount = cellCount;
39     }
40 
addView(int index, View v)41     public abstract ViewGroup addView(int index, View v);
42 
getViewGroup()43     public abstract ViewGroup getViewGroup();
44 
getRowByIndex(int index)45     public abstract ViewGroup getRowByIndex(int index);
46 
getRow(int rowNumber)47     public abstract ViewGroup getRow(int rowNumber);
48 
setViewVisibility(int i, int visibility)49     public abstract void setViewVisibility(int i, int visibility);
50 
getColumnCount()51     public int getColumnCount() {
52         return mColumnCount;
53     }
54 
measure()55     public void measure() {
56         final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
57         getViewGroup().measure(spec, spec);
58         mMeasuredRowHeight = getViewGroup().getMeasuredHeight();
59     }
60 
getMeasuredRowHeight()61     public int getMeasuredRowHeight() {
62         return mMeasuredRowHeight;
63     }
64 
setItemIndex(int itemIndex, int listIndex)65     public void setItemIndex(int itemIndex, int listIndex) {
66         mItemIndices[itemIndex] = listIndex;
67     }
68 
getItemIndex(int itemIndex)69     public int getItemIndex(int itemIndex) {
70         return mItemIndices[itemIndex];
71     }
72 
getView(int index)73     public View getView(int index) {
74         return mCells[index];
75     }
76 }
77