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 17 package com.android.systemui 18 19 import android.view.Surface 20 import android.view.Surface.Rotation 21 import com.android.systemui.statusbar.commandline.ParseableCommand 22 import com.android.systemui.statusbar.commandline.Type 23 import java.io.PrintWriter 24 25 class StatusBarInsetsCommand( 26 private val callback: Callback, 27 ) : ParseableCommand(NAME) { 28 29 val bottomMargin: BottomMarginCommand? by subCommand(BottomMarginCommand()) 30 executenull31 override fun execute(pw: PrintWriter) { 32 callback.onExecute(command = this, pw) 33 } 34 35 interface Callback { onExecutenull36 fun onExecute(command: StatusBarInsetsCommand, printWriter: PrintWriter) 37 } 38 39 companion object { 40 const val NAME = "status-bar-insets" 41 } 42 } 43 44 class BottomMarginCommand : ParseableCommand(NAME) { 45 46 private val rotationDegrees: Int? by 47 param( 48 longName = "rotation", 49 shortName = "r", 50 description = "For which rotation the margin should be set. One of 0, 90, 180, 270", 51 valueParser = Type.Int, 52 ) 53 54 @Rotation 55 val rotationValue: Int? 56 get() = ROTATION_DEGREES_TO_VALUE_MAPPING[rotationDegrees] 57 58 val marginBottomDp: Float? by 59 param( 60 longName = "margin", 61 shortName = "m", 62 description = "Margin amount, in dp. Can be a fractional value, such as 10.5", 63 valueParser = Type.Float, 64 ) 65 executenull66 override fun execute(pw: PrintWriter) { 67 // Not needed for a subcommand 68 } 69 70 companion object { 71 const val NAME = "bottom-margin" 72 private val ROTATION_DEGREES_TO_VALUE_MAPPING = 73 mapOf( 74 0 to Surface.ROTATION_0, 75 90 to Surface.ROTATION_90, 76 180 to Surface.ROTATION_180, 77 270 to Surface.ROTATION_270, 78 ) 79 80 val ROTATION_DEGREES_OPTIONS: Set<Int> = ROTATION_DEGREES_TO_VALUE_MAPPING.keys 81 } 82 } 83