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.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.LinearLayout 23 import com.android.systemui.res.R 24 import com.android.systemui.statusbar.StatusBarIconView.STATE_ICON 25 import com.android.systemui.statusbar.pipeline.mobile.ui.MobileViewLogger 26 import com.android.systemui.statusbar.pipeline.mobile.ui.binder.MobileIconBinder 27 import com.android.systemui.statusbar.pipeline.mobile.ui.binder.ShadeCarrierBinder 28 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.ShadeCarrierGroupMobileIconViewModel 29 import com.android.systemui.util.AutoMarqueeTextView 30 31 /** 32 * ViewGroup containing a mobile carrier name and icon in the Shade Header. Can be multiple 33 * instances as children under [ShadeCarrierGroup] 34 */ 35 class ModernShadeCarrierGroupMobileView( 36 context: Context, 37 attrs: AttributeSet?, 38 ) : LinearLayout(context, attrs) { 39 40 var subId: Int = -1 41 toStringnull42 override fun toString(): String { 43 return "ModernShadeCarrierGroupMobileView(" + 44 "subId=$subId, " + 45 "viewString=${super.toString()}" 46 } 47 48 companion object { 49 50 /** 51 * Inflates a new instance of [ModernShadeCarrierGroupMobileView], binds it to [viewModel], 52 * and returns it. 53 */ 54 @JvmStatic constructAndBindnull55 fun constructAndBind( 56 context: Context, 57 logger: MobileViewLogger, 58 slot: String, 59 viewModel: ShadeCarrierGroupMobileIconViewModel, 60 ): ModernShadeCarrierGroupMobileView { 61 return (LayoutInflater.from(context).inflate(R.layout.shade_carrier_new, null) 62 as ModernShadeCarrierGroupMobileView) 63 .also { 64 it.subId = viewModel.subscriptionId 65 66 val iconView = it.requireViewById<ModernStatusBarMobileView>(R.id.mobile_combo) 67 iconView.initView(slot) { 68 MobileIconBinder.bind(iconView, viewModel, STATE_ICON, logger) 69 } 70 logger.logNewViewBinding(it, viewModel) 71 72 val textView = it.requireViewById<AutoMarqueeTextView>(R.id.mobile_carrier_text) 73 ShadeCarrierBinder.bind(textView, viewModel) 74 } 75 } 76 } 77 } 78