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.view 18 19 import android.content.Context 20 import android.util.AttributeSet 21 import android.view.LayoutInflater 22 import android.widget.ImageView 23 import com.android.settingslib.flags.Flags.newStatusBarIcons 24 import com.android.systemui.res.R 25 import com.android.systemui.statusbar.StatusBarIconView.getVisibleStateString 26 import com.android.systemui.statusbar.pipeline.mobile.ui.MobileViewLogger 27 import com.android.systemui.statusbar.pipeline.mobile.ui.binder.MobileIconBinder 28 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.LocationBasedMobileViewModel 29 import com.android.systemui.statusbar.pipeline.shared.ui.view.ModernStatusBarView 30 31 class ModernStatusBarMobileView( 32 context: Context, 33 attrs: AttributeSet?, 34 ) : ModernStatusBarView(context, attrs) { 35 36 var subId: Int = -1 37 toStringnull38 override fun toString(): String { 39 return "ModernStatusBarMobileView(" + 40 "slot='$slot', " + 41 "subId=$subId, " + 42 "isCollecting=${binding.isCollecting()}, " + 43 "visibleState=${getVisibleStateString(visibleState)}); " + 44 "viewString=${super.toString()}" 45 } 46 47 companion object { 48 49 /** 50 * Inflates a new instance of [ModernStatusBarMobileView], binds it to [viewModel], and 51 * returns it. 52 */ 53 @JvmStatic constructAndBindnull54 fun constructAndBind( 55 context: Context, 56 logger: MobileViewLogger, 57 slot: String, 58 viewModel: LocationBasedMobileViewModel, 59 ): ModernStatusBarMobileView { 60 return (LayoutInflater.from(context) 61 .inflate(R.layout.status_bar_mobile_signal_group_new, null) 62 as ModernStatusBarMobileView) 63 .also { 64 // Flag-specific configuration 65 if (newStatusBarIcons()) { 66 // New icon (with no embedded whitespace) is slightly shorter 67 // (but actually taller) 68 val iconView = it.requireViewById<ImageView>(R.id.mobile_signal) 69 val lp = iconView.layoutParams 70 lp.height = 71 context.resources.getDimensionPixelSize( 72 R.dimen.status_bar_mobile_signal_size_updated 73 ) 74 } 75 76 it.subId = viewModel.subscriptionId 77 it.initView(slot) { 78 MobileIconBinder.bind(view = it, viewModel = viewModel, logger = logger) 79 } 80 logger.logNewViewBinding(it, viewModel) 81 } 82 } 83 } 84 } 85