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 package com.android.wallpaper.picker
17 
18 import android.content.Context
19 import android.util.AttributeSet
20 import android.view.SurfaceControl
21 import android.view.SurfaceView
22 
23 /** A `SurfaceView` which allows the surface alpha to be adjusted by setting view alpha. */
24 class FadeAnimationSurfaceView(context: Context, attrs: AttributeSet) :
25     SurfaceView(context, attrs) {
26 
onSetAlphanull27     override fun onSetAlpha(alpha: Int): Boolean {
28         requestUpdateSurfacePositionAndScale()
29         return super.onSetAlpha(alpha)
30     }
31 
onSetSurfacePositionAndScalenull32     override fun onSetSurfacePositionAndScale(
33         transaction: SurfaceControl.Transaction,
34         surface: SurfaceControl,
35         positionLeft: Int,
36         positionTop: Int,
37         postScaleX: Float,
38         postScaleY: Float
39     ) {
40         super.onSetSurfacePositionAndScale(
41             transaction,
42             surface,
43             positionLeft,
44             positionTop,
45             postScaleX,
46             postScaleY
47         )
48         transaction.setAlpha(surface, alpha)
49     }
50 }
51