1 /* 2 * Copyright (C) 2020 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.qs.dagger; 18 19 import static com.android.systemui.util.Utils.useQsMediaPlayer; 20 21 import android.content.Context; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 25 import com.android.systemui.R; 26 import com.android.systemui.battery.BatteryMeterView; 27 import com.android.systemui.dagger.qualifiers.RootView; 28 import com.android.systemui.plugins.qs.QS; 29 import com.android.systemui.privacy.OngoingPrivacyChip; 30 import com.android.systemui.qs.FooterActionsController; 31 import com.android.systemui.qs.FooterActionsController.ExpansionState; 32 import com.android.systemui.qs.FooterActionsControllerBuilder; 33 import com.android.systemui.qs.FooterActionsView; 34 import com.android.systemui.qs.QSContainerImpl; 35 import com.android.systemui.qs.QSFooter; 36 import com.android.systemui.qs.QSFooterView; 37 import com.android.systemui.qs.QSFooterViewController; 38 import com.android.systemui.qs.QSFragment; 39 import com.android.systemui.qs.QSPanel; 40 import com.android.systemui.qs.QuickQSPanel; 41 import com.android.systemui.qs.QuickStatusBarHeader; 42 import com.android.systemui.qs.customize.QSCustomizer; 43 import com.android.systemui.statusbar.phone.StatusIconContainer; 44 45 import javax.inject.Named; 46 47 import dagger.Binds; 48 import dagger.Module; 49 import dagger.Provides; 50 51 /** 52 * Dagger Module for {@link QSFragmentComponent}. 53 */ 54 @Module 55 public interface QSFragmentModule { 56 String QS_SECURITY_FOOTER_VIEW = "qs_security_footer"; 57 String QQS_FOOTER = "qqs_footer"; 58 String QS_FOOTER = "qs_footer"; 59 String QS_USING_MEDIA_PLAYER = "qs_using_media_player"; 60 61 /** 62 * Provide a context themed using the QS theme 63 */ 64 @Provides 65 @QSThemedContext provideThemedContext(@ootView View view)66 static Context provideThemedContext(@RootView View view) { 67 return view.getContext(); 68 } 69 70 /** */ 71 @Provides 72 @QSThemedContext provideThemedLayoutInflater(@SThemedContext Context context)73 static LayoutInflater provideThemedLayoutInflater(@QSThemedContext Context context) { 74 return LayoutInflater.from(context); 75 } 76 77 /** */ 78 @Provides 79 @RootView provideRootView(QSFragment qsFragment)80 static View provideRootView(QSFragment qsFragment) { 81 return qsFragment.getView(); 82 } 83 84 /** */ 85 @Provides provideQSPanel(@ootView View view)86 static QSPanel provideQSPanel(@RootView View view) { 87 return view.findViewById(R.id.quick_settings_panel); 88 } 89 90 /** */ 91 @Provides providesQSContainerImpl(@ootView View view)92 static QSContainerImpl providesQSContainerImpl(@RootView View view) { 93 return view.findViewById(R.id.quick_settings_container); 94 } 95 96 /** */ 97 @Binds bindQS(QSFragment qsFragment)98 QS bindQS(QSFragment qsFragment); 99 100 /** */ 101 @Provides providesQuickStatusBarHeader(@ootView View view)102 static QuickStatusBarHeader providesQuickStatusBarHeader(@RootView View view) { 103 return view.findViewById(R.id.header); 104 } 105 106 /** */ 107 @Provides providesQuickQSPanel(QuickStatusBarHeader quickStatusBarHeader)108 static QuickQSPanel providesQuickQSPanel(QuickStatusBarHeader quickStatusBarHeader) { 109 return quickStatusBarHeader.findViewById(R.id.quick_qs_panel); 110 } 111 112 /** */ 113 @Provides providesBatteryMeterView(QuickStatusBarHeader quickStatusBarHeader)114 static BatteryMeterView providesBatteryMeterView(QuickStatusBarHeader quickStatusBarHeader) { 115 return quickStatusBarHeader.findViewById(R.id.batteryRemainingIcon); 116 } 117 118 /** */ 119 @Provides providesQSFooterView(@ootView View view)120 static QSFooterView providesQSFooterView(@RootView View view) { 121 return view.findViewById(R.id.qs_footer); 122 } 123 124 /** */ 125 @Provides 126 @Named(QS_FOOTER) providesQSFooterActionsView(@ootView View view)127 static FooterActionsView providesQSFooterActionsView(@RootView View view) { 128 return view.findViewById(R.id.qs_footer_actions); 129 } 130 131 /** */ 132 @Provides 133 @Named(QQS_FOOTER) providesQQSFooterActionsView(@ootView View view)134 static FooterActionsView providesQQSFooterActionsView(@RootView View view) { 135 return view.findViewById(R.id.qqs_footer_actions); 136 } 137 138 /** */ 139 @Provides 140 @Named(QQS_FOOTER) providesQQSFooterActionsController( FooterActionsControllerBuilder footerActionsControllerBuilder, @Named(QQS_FOOTER) FooterActionsView qqsFooterActionsView)141 static FooterActionsController providesQQSFooterActionsController( 142 FooterActionsControllerBuilder footerActionsControllerBuilder, 143 @Named(QQS_FOOTER) FooterActionsView qqsFooterActionsView) { 144 return footerActionsControllerBuilder 145 .withView(qqsFooterActionsView) 146 .withButtonsVisibleWhen(ExpansionState.COLLAPSED) 147 .build(); 148 } 149 150 /** */ 151 @Provides 152 @Named(QS_FOOTER) providesQSFooterActionsController( FooterActionsControllerBuilder footerActionsControllerBuilder, @Named(QS_FOOTER) FooterActionsView qsFooterActionsView)153 static FooterActionsController providesQSFooterActionsController( 154 FooterActionsControllerBuilder footerActionsControllerBuilder, 155 @Named(QS_FOOTER) FooterActionsView qsFooterActionsView) { 156 return footerActionsControllerBuilder 157 .withView(qsFooterActionsView) 158 .withButtonsVisibleWhen(ExpansionState.EXPANDED) 159 .build(); 160 } 161 162 /** */ 163 @Provides 164 @QSScope providesQSFooter(QSFooterViewController qsFooterViewController)165 static QSFooter providesQSFooter(QSFooterViewController qsFooterViewController) { 166 qsFooterViewController.init(); 167 return qsFooterViewController; 168 } 169 170 /** */ 171 @Provides 172 @QSScope providesQSCutomizer(@ootView View view)173 static QSCustomizer providesQSCutomizer(@RootView View view) { 174 return view.findViewById(R.id.qs_customize); 175 } 176 177 /** */ 178 @Provides 179 @QSScope 180 @Named(QS_SECURITY_FOOTER_VIEW) providesQSSecurityFooterView( @SThemedContext LayoutInflater layoutInflater, QSPanel qsPanel )181 static View providesQSSecurityFooterView( 182 @QSThemedContext LayoutInflater layoutInflater, 183 QSPanel qsPanel 184 ) { 185 return layoutInflater.inflate(R.layout.quick_settings_security_footer, qsPanel, false); 186 } 187 188 /** */ 189 @Provides 190 @Named(QS_USING_MEDIA_PLAYER) providesQSUsingMediaPlayer(Context context)191 static boolean providesQSUsingMediaPlayer(Context context) { 192 return useQsMediaPlayer(context); 193 } 194 195 /** */ 196 @Provides 197 @QSScope providesPrivacyChip(QuickStatusBarHeader qsHeader)198 static OngoingPrivacyChip providesPrivacyChip(QuickStatusBarHeader qsHeader) { 199 return qsHeader.findViewById(R.id.privacy_chip); 200 } 201 202 /** */ 203 @Provides 204 @QSScope providesStatusIconContainer(QuickStatusBarHeader qsHeader)205 static StatusIconContainer providesStatusIconContainer(QuickStatusBarHeader qsHeader) { 206 return qsHeader.findViewById(R.id.statusIcons); 207 } 208 }