• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 
17 package com.android.launcher3.folder;
18 
19 import com.android.launcher3.FolderInfo;
20 import com.android.launcher3.InvariantDeviceProfile;
21 
22 import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
23 
24 /**
25  * Verifies whether an item in a Folder is displayed in the FolderIcon preview.
26  */
27 public class FolderIconPreviewVerifier {
28 
29     private final int mMaxGridCountX;
30     private final int mMaxGridCountY;
31     private final int mMaxItemsPerPage;
32     private final int[] mGridSize = new int[2];
33 
34     private int mGridCountX;
35     private boolean mDisplayingUpperLeftQuadrant = false;
36 
FolderIconPreviewVerifier(InvariantDeviceProfile profile)37     public FolderIconPreviewVerifier(InvariantDeviceProfile profile) {
38         mMaxGridCountX = profile.numFolderColumns;
39         mMaxGridCountY = profile.numFolderRows;
40         mMaxItemsPerPage = mMaxGridCountX * mMaxGridCountY;
41     }
42 
setFolderInfo(FolderInfo info)43     public void setFolderInfo(FolderInfo info) {
44         int numItemsInFolder = info.contents.size();
45         FolderPagedView.calculateGridSize(numItemsInFolder, 0, 0, mMaxGridCountX,
46                 mMaxGridCountY, mMaxItemsPerPage, mGridSize);
47         mGridCountX = mGridSize[0];
48 
49         mDisplayingUpperLeftQuadrant = numItemsInFolder > MAX_NUM_ITEMS_IN_PREVIEW;
50     }
51 
52     /**
53      * Returns whether the item with {@param rank} is in the default Folder icon preview.
54      */
isItemInPreview(int rank)55     public boolean isItemInPreview(int rank) {
56         return isItemInPreview(0, rank);
57     }
58 
59     /**
60      * @param page The page the item is on.
61      * @param rank The rank of the item.
62      * @return True iff the icon is in the 2x2 upper left quadrant of the Folder.
63      */
isItemInPreview(int page, int rank)64     public boolean isItemInPreview(int page, int rank) {
65         // First page items are laid out such that the first 4 items are always in the upper
66         // left quadrant. For all other pages, we need to check the row and col.
67         if (page > 0 || mDisplayingUpperLeftQuadrant) {
68             int col = rank % mGridCountX;
69             int row = rank / mGridCountX;
70             return col < 2 && row < 2;
71         }
72         return rank < MAX_NUM_ITEMS_IN_PREVIEW;
73     }
74 }
75