1 /* 2 * Copyright (C) 2024 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.wallpaper.picker.common.preview.ui.view 18 19 import android.content.Context 20 import android.util.AttributeSet 21 import android.view.SurfaceView 22 23 /** 24 * [SurfaceView] that keeps the surface at a fixed size, and resizes it according to view size 25 * changes using the Hardware Scaler, rather than resizing the surface itself. It enables better 26 * efficiency in cases where resizing is frequently needed. It sets the surface at a fixed size 27 * based on the size it is initialized at. 28 */ 29 class CustomizationSurfaceView(context: Context, attrs: AttributeSet? = null) : 30 SurfaceView(context, attrs) { 31 onSizeChangednull32 override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { 33 super.onSizeChanged(w, h, oldw, oldh) 34 35 // TODO (b/348462236): investigate effect on scale transition and touch forwarding layout 36 if (oldw == 0 && oldh == 0) { 37 holder.surfaceFrame.let { 38 if (it.isEmpty) holder.setFixedSize(width, height) 39 else holder.setFixedSize(it.width(), it.height()) 40 } 41 } 42 } 43 } 44