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.keyguard.ui.view.layout.sections 18 19 import android.content.Context 20 import android.view.View 21 import android.view.ViewGroup.LayoutParams.WRAP_CONTENT 22 import android.widget.FrameLayout 23 import androidx.constraintlayout.widget.ConstraintLayout 24 import androidx.constraintlayout.widget.ConstraintSet 25 import androidx.constraintlayout.widget.ConstraintSet.BOTTOM 26 import androidx.constraintlayout.widget.ConstraintSet.END 27 import androidx.constraintlayout.widget.ConstraintSet.MATCH_CONSTRAINT 28 import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID 29 import androidx.constraintlayout.widget.ConstraintSet.START 30 import androidx.constraintlayout.widget.ConstraintSet.TOP 31 import com.android.systemui.keyguard.MigrateClocksToBlueprint 32 import com.android.systemui.keyguard.shared.model.KeyguardSection 33 import com.android.systemui.media.controls.ui.controller.KeyguardMediaController 34 import com.android.systemui.res.R 35 import com.android.systemui.shade.NotificationPanelView 36 import javax.inject.Inject 37 38 /** Aligns media on left side for split shade, below smartspace, date, and weather. */ 39 class SplitShadeMediaSection 40 @Inject 41 constructor( 42 private val context: Context, 43 private val notificationPanelView: NotificationPanelView, 44 private val keyguardMediaController: KeyguardMediaController 45 ) : KeyguardSection() { 46 private val mediaContainerId = R.id.status_view_media_container 47 addViewsnull48 override fun addViews(constraintLayout: ConstraintLayout) { 49 if (!MigrateClocksToBlueprint.isEnabled) { 50 return 51 } 52 53 notificationPanelView.findViewById<View>(mediaContainerId)?.let { 54 notificationPanelView.removeView(it) 55 } 56 57 val mediaFrame = 58 FrameLayout(context, null).apply { 59 id = mediaContainerId 60 val padding = context.resources.getDimensionPixelSize(R.dimen.qs_media_padding) 61 val horizontalPadding = 62 padding + 63 context.resources.getDimensionPixelSize( 64 R.dimen.status_view_margin_horizontal 65 ) 66 67 setPaddingRelative(horizontalPadding, padding, horizontalPadding, padding) 68 } 69 constraintLayout.addView(mediaFrame) 70 keyguardMediaController.attachSplitShadeContainer(mediaFrame) 71 } 72 bindDatanull73 override fun bindData(constraintLayout: ConstraintLayout) {} 74 applyConstraintsnull75 override fun applyConstraints(constraintSet: ConstraintSet) { 76 if (!MigrateClocksToBlueprint.isEnabled) { 77 return 78 } 79 80 constraintSet.apply { 81 constrainWidth(mediaContainerId, MATCH_CONSTRAINT) 82 constrainHeight(mediaContainerId, WRAP_CONTENT) 83 connect(mediaContainerId, TOP, R.id.smart_space_barrier_bottom, BOTTOM) 84 connect(mediaContainerId, START, PARENT_ID, START) 85 connect(mediaContainerId, END, R.id.split_shade_guideline, END) 86 } 87 } 88 removeViewsnull89 override fun removeViews(constraintLayout: ConstraintLayout) { 90 if (!MigrateClocksToBlueprint.isEnabled) { 91 return 92 } 93 94 constraintLayout.removeView(mediaContainerId) 95 } 96 } 97