1 /* 2 * Copyright (C) 2018 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.egg.paint 18 19 import android.content.Context 20 import android.transition.Transition 21 import android.transition.TransitionListenerAdapter 22 import android.util.AttributeSet 23 import android.view.* 24 import android.widget.FrameLayout 25 26 class ToolbarView : FrameLayout { 27 var inTransition = false 28 var transitionListener: Transition.TransitionListener = object : TransitionListenerAdapter() { onTransitionStartnull29 override fun onTransitionStart(transition: Transition?) { 30 inTransition = true 31 } onTransitionEndnull32 override fun onTransitionEnd(transition: Transition?) { 33 inTransition = false 34 } 35 } 36 37 constructor(context: Context) : super(context) { 38 } 39 40 constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { 41 } 42 43 constructor( 44 context: Context, 45 attrs: AttributeSet, 46 defStyle: Int 47 ) : super(context, attrs, defStyle) { 48 } 49 50 @Suppress("DEPRECATION") onApplyWindowInsetsnull51 override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets { 52 var lp = layoutParams as FrameLayout.LayoutParams? 53 if (lp != null && insets != null) { 54 if (insets.hasStableInsets()) { 55 lp.topMargin = insets.stableInsetTop 56 lp.bottomMargin = insets.stableInsetBottom 57 } else { 58 lp.topMargin = insets.systemWindowInsetTop 59 lp.bottomMargin = insets.systemWindowInsetBottom 60 } 61 layoutParams = lp 62 } 63 64 return super.onApplyWindowInsets(insets) 65 } 66 } 67