2017-02-07 11:40:22 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3.folder;
|
|
|
|
|
|
2019-03-04 09:14:40 -08:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
2017-02-07 11:40:22 -08:00
|
|
|
import com.android.launcher3.FolderInfo;
|
|
|
|
|
import com.android.launcher3.InvariantDeviceProfile;
|
2017-09-08 11:59:05 -07:00
|
|
|
|
|
|
|
|
import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
|
2017-02-07 11:40:22 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verifies whether an item in a Folder is displayed in the FolderIcon preview.
|
|
|
|
|
*/
|
|
|
|
|
public class FolderIconPreviewVerifier {
|
|
|
|
|
|
2019-03-04 09:14:40 -08:00
|
|
|
private static final String TAG = "FolderPreviewVerifier";
|
|
|
|
|
|
2017-07-06 16:31:56 -07:00
|
|
|
private final int mMaxGridCountX;
|
|
|
|
|
private final int mMaxGridCountY;
|
|
|
|
|
private final int mMaxItemsPerPage;
|
2019-03-04 09:14:40 -08:00
|
|
|
private final int[] mGridSize = new int[] { 1, 1 };
|
2017-07-06 16:31:56 -07:00
|
|
|
|
2019-03-04 09:14:40 -08:00
|
|
|
private int mNumItemsInFolder;
|
2017-07-06 16:31:56 -07:00
|
|
|
private int mGridCountX;
|
2017-07-13 19:26:46 +00:00
|
|
|
private boolean mDisplayingUpperLeftQuadrant = false;
|
2017-07-06 16:31:56 -07:00
|
|
|
|
2019-03-04 09:14:40 -08:00
|
|
|
/**
|
|
|
|
|
* Note: must call {@link #setFolderInfo(FolderInfo)} manually for verifier to work.
|
|
|
|
|
*/
|
2017-02-07 11:40:22 -08:00
|
|
|
public FolderIconPreviewVerifier(InvariantDeviceProfile profile) {
|
2017-07-06 16:31:56 -07:00
|
|
|
mMaxGridCountX = profile.numFolderColumns;
|
|
|
|
|
mMaxGridCountY = profile.numFolderRows;
|
|
|
|
|
mMaxItemsPerPage = mMaxGridCountX * mMaxGridCountY;
|
2017-02-07 11:40:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setFolderInfo(FolderInfo info) {
|
2017-07-13 17:54:54 -07:00
|
|
|
int numItemsInFolder = info.contents.size();
|
2019-03-04 09:14:40 -08:00
|
|
|
if (numItemsInFolder != mNumItemsInFolder) {
|
|
|
|
|
FolderPagedView.calculateGridSize(numItemsInFolder, 0, 0, mMaxGridCountX,
|
|
|
|
|
mMaxGridCountY, mMaxItemsPerPage, mGridSize);
|
|
|
|
|
mGridCountX = mGridSize[0];
|
2017-07-13 17:54:54 -07:00
|
|
|
|
2019-03-04 09:14:40 -08:00
|
|
|
mDisplayingUpperLeftQuadrant = numItemsInFolder > MAX_NUM_ITEMS_IN_PREVIEW;
|
|
|
|
|
mNumItemsInFolder = numItemsInFolder;
|
|
|
|
|
}
|
2017-02-07 11:40:22 -08:00
|
|
|
}
|
|
|
|
|
|
2017-07-06 16:31:56 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether the item with {@param rank} is in the default Folder icon preview.
|
|
|
|
|
*/
|
2017-02-07 11:40:22 -08:00
|
|
|
public boolean isItemInPreview(int rank) {
|
2017-07-06 16:31:56 -07:00
|
|
|
return isItemInPreview(0, rank);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param page The page the item is on.
|
|
|
|
|
* @param rank The rank of the item.
|
|
|
|
|
* @return True iff the icon is in the 2x2 upper left quadrant of the Folder.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isItemInPreview(int page, int rank) {
|
2019-03-04 09:14:40 -08:00
|
|
|
if (mGridSize[0] == 1) {
|
|
|
|
|
Log.w(TAG, "setFolderInfo not called before checking if item is in preview.");
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 19:26:46 +00:00
|
|
|
// First page items are laid out such that the first 4 items are always in the upper
|
|
|
|
|
// left quadrant. For all other pages, we need to check the row and col.
|
|
|
|
|
if (page > 0 || mDisplayingUpperLeftQuadrant) {
|
2017-07-06 16:31:56 -07:00
|
|
|
int col = rank % mGridCountX;
|
|
|
|
|
int row = rank / mGridCountX;
|
|
|
|
|
return col < 2 && row < 2;
|
|
|
|
|
}
|
2017-09-08 11:59:05 -07:00
|
|
|
return rank < MAX_NUM_ITEMS_IN_PREVIEW;
|
2017-02-07 11:40:22 -08:00
|
|
|
}
|
|
|
|
|
}
|