1 /* 2 * Copyright (C) 2023 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.celllayout.board 17 18 import android.graphics.Point 19 import android.graphics.Rect 20 21 /** Represents a widget in a CellLayoutBoard */ 22 data class WidgetRect( 23 val type: Char, 24 val bounds: Rect, 25 ) { 26 val spanX: Int = bounds.right - bounds.left + 1 27 val spanY: Int = bounds.top - bounds.bottom + 1 28 val cellY: Int = bounds.bottom 29 val cellX: Int = bounds.left 30 shouldIgnorenull31 fun shouldIgnore() = type == CellType.IGNORE 32 33 fun contains(x: Int, y: Int) = bounds.contains(x, y) 34 } 35 36 /** 37 * [A-Z]: Represents a folder and number of icons in the folder is represented by the order of 38 * letter in the alphabet, A=2, B=3, C=4 ... etc. 39 */ 40 data class FolderPoint(val coord: Point, val type: Char) { 41 val numberIconsInside: Int = type.code - 'A'.code + 2 42 } 43 44 /** Represents an icon in a CellLayoutBoard */ 45 data class IconPoint(val coord: Point, val type: Char = CellType.ICON) 46 47 object CellType { 48 // The cells marked by this will be filled by 1x1 widgets and will be ignored when 49 // validating 50 const val IGNORE = 'x' 51 52 // The cells marked by this will be filled by app icons 53 const val ICON = 'i' 54 55 // The cells marked by FOLDER will be filled by folders with 27 app icons inside 56 const val FOLDER = 'Z' 57 58 // Empty space 59 const val EMPTY = '-' 60 61 // Widget that will be saved as "main widget" for easier retrieval 62 const val MAIN_WIDGET = 'm' // Everything else will be consider a widget 63 } 64