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.wifi.ui.view 18 19 import android.annotation.SuppressLint 20 import android.content.Context 21 import android.util.AttributeSet 22 import android.view.LayoutInflater 23 import com.android.systemui.R 24 import com.android.systemui.statusbar.StatusBarIconView 25 import com.android.systemui.statusbar.pipeline.shared.ui.view.ModernStatusBarView 26 import com.android.systemui.statusbar.pipeline.wifi.ui.binder.WifiViewBinder 27 import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.LocationBasedWifiViewModel 28 29 /** 30 * A new and more modern implementation of [com.android.systemui.statusbar.StatusBarWifiView] that 31 * is updated by [WifiViewBinder]. 32 */ 33 class ModernStatusBarWifiView( 34 context: Context, 35 attrs: AttributeSet?, 36 ) : ModernStatusBarView(context, attrs) { 37 38 override fun toString(): String { 39 return "ModernStatusBarWifiView(" + 40 "slot='$slot', " + 41 "isCollecting=${binding.isCollecting()}, " + 42 "visibleState=${StatusBarIconView.getVisibleStateString(visibleState)}); " + 43 "viewString=${super.toString()}" 44 } 45 46 companion object { 47 /** 48 * Inflates a new instance of [ModernStatusBarWifiView], binds it to a view model, and 49 * returns it. 50 */ 51 @SuppressLint("InflateParams") 52 @JvmStatic 53 fun constructAndBind( 54 context: Context, 55 slot: String, 56 wifiViewModel: LocationBasedWifiViewModel, 57 ): ModernStatusBarWifiView { 58 return (LayoutInflater.from(context).inflate(R.layout.new_status_bar_wifi_group, null) 59 as ModernStatusBarWifiView) 60 .also { it.initView(slot) { WifiViewBinder.bind(it, wifiViewModel) } } 61 } 62 } 63 } 64