1 /* 2 * Copyright (C) 2020 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.systemui.qs 18 19 import android.content.Context 20 import android.util.AttributeSet 21 import com.android.systemui.R 22 23 open class SideLabelTileLayout( 24 context: Context, 25 attrs: AttributeSet? 26 ) : TileLayout(context, attrs) { 27 updateResourcesnull28 override fun updateResources(): Boolean { 29 return super.updateResources().also { 30 mMaxAllowedRows = context.resources.getInteger(R.integer.quick_settings_max_rows) 31 } 32 } 33 isFullnull34 override fun isFull(): Boolean { 35 return mRecords.size >= maxTiles() 36 } 37 useSidePaddingnull38 override fun useSidePadding(): Boolean { 39 return false 40 } 41 42 /** 43 * Return the position from the top of the layout of the tile with this index. 44 * 45 * This will return a position even for indices that go beyond [maxTiles], continuing the rows 46 * beyond that. 47 */ getPhantomTopPositionnull48 fun getPhantomTopPosition(index: Int): Int { 49 val row = index / mColumns 50 return getRowTop(row) 51 } 52 updateMaxRowsnull53 override fun updateMaxRows(allowedHeight: Int, tilesCount: Int): Boolean { 54 val previousRows = mRows 55 mRows = mMaxAllowedRows 56 // We want at most mMaxAllowedRows, but it could be that we don't have enough tiles to fit 57 // that many rows. In that case, we want 58 // `tilesCount = (mRows - 1) * mColumns + X` 59 // where X is some remainder between 1 and `mColumns - 1` 60 // Adding `mColumns - 1` will guarantee that the final value F will satisfy 61 // `mRows * mColumns <= F < (mRows + 1) * mColumns 62 if (mRows > (tilesCount + mColumns - 1) / mColumns) { 63 mRows = (tilesCount + mColumns - 1) / mColumns 64 } 65 return previousRows != mRows 66 } 67 }