1 /* 2 * Copyright (C) 2022 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.statusbar.pipeline.mobile.ui.viewmodel 18 19 import android.graphics.Color 20 import com.android.systemui.statusbar.phone.StatusBarLocation 21 import com.android.systemui.statusbar.pipeline.StatusBarPipelineFlags 22 import com.android.systemui.statusbar.pipeline.mobile.ui.VerboseMobileViewLogger 23 24 /** 25 * A view model for an individual mobile icon that embeds the notion of a [StatusBarLocation]. This 26 * allows the mobile icon to change some view parameters at different locations 27 * 28 * @param commonImpl for convenience, this class wraps a base interface that can provides all of the 29 * common implementations between locations. See [MobileIconViewModel] 30 * @property locationName the name of the location of this VM, used for logging. 31 * @property verboseLogger an optional logger to log extremely verbose view updates. 32 */ 33 abstract class LocationBasedMobileViewModel( 34 val commonImpl: MobileIconViewModelCommon, 35 statusBarPipelineFlags: StatusBarPipelineFlags, 36 debugTint: Int, 37 val locationName: String, 38 val verboseLogger: VerboseMobileViewLogger?, 39 ) : MobileIconViewModelCommon by commonImpl { 40 val useDebugColoring: Boolean = statusBarPipelineFlags.useDebugColoring() 41 42 val defaultColor: Int = 43 if (useDebugColoring) { 44 debugTint 45 } else { 46 Color.WHITE 47 } 48 49 companion object { viewModelForLocationnull50 fun viewModelForLocation( 51 commonImpl: MobileIconViewModelCommon, 52 statusBarPipelineFlags: StatusBarPipelineFlags, 53 verboseMobileViewLogger: VerboseMobileViewLogger, 54 loc: StatusBarLocation, 55 ): LocationBasedMobileViewModel = 56 when (loc) { 57 StatusBarLocation.HOME -> 58 HomeMobileIconViewModel( 59 commonImpl, 60 statusBarPipelineFlags, 61 verboseMobileViewLogger, 62 ) 63 StatusBarLocation.KEYGUARD -> 64 KeyguardMobileIconViewModel(commonImpl, statusBarPipelineFlags) 65 StatusBarLocation.QS -> QsMobileIconViewModel(commonImpl, statusBarPipelineFlags) 66 } 67 } 68 } 69 70 class HomeMobileIconViewModel( 71 commonImpl: MobileIconViewModelCommon, 72 statusBarPipelineFlags: StatusBarPipelineFlags, 73 verboseMobileViewLogger: VerboseMobileViewLogger, 74 ) : 75 MobileIconViewModelCommon, 76 LocationBasedMobileViewModel( 77 commonImpl, 78 statusBarPipelineFlags, 79 debugTint = Color.CYAN, 80 locationName = "Home", 81 verboseMobileViewLogger, 82 ) 83 84 class QsMobileIconViewModel( 85 commonImpl: MobileIconViewModelCommon, 86 statusBarPipelineFlags: StatusBarPipelineFlags, 87 ) : 88 MobileIconViewModelCommon, 89 LocationBasedMobileViewModel( 90 commonImpl, 91 statusBarPipelineFlags, 92 debugTint = Color.GREEN, 93 locationName = "QS", 94 // Only do verbose logging for the Home location. 95 verboseLogger = null, 96 ) 97 98 class KeyguardMobileIconViewModel( 99 commonImpl: MobileIconViewModelCommon, 100 statusBarPipelineFlags: StatusBarPipelineFlags, 101 ) : 102 MobileIconViewModelCommon, 103 LocationBasedMobileViewModel( 104 commonImpl, 105 statusBarPipelineFlags, 106 debugTint = Color.MAGENTA, 107 locationName = "Keyguard", 108 // Only do verbose logging for the Home location. 109 verboseLogger = null, 110 ) 111