AnimateableViewBounds.java revision 606b3da71ab64e489e8f65e0b1092138dbfaf7b7
1/* 2 * Copyright (C) 2014 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 17package com.android.systemui.recents.views; 18 19import android.animation.ObjectAnimator; 20import android.graphics.Outline; 21import android.graphics.Rect; 22import android.view.View; 23import android.view.ViewOutlineProvider; 24import com.android.systemui.recents.RecentsConfiguration; 25 26/* An outline provider that has a clip and outline that can be animated. */ 27public class AnimateableViewBounds extends ViewOutlineProvider { 28 29 RecentsConfiguration mConfig; 30 31 TaskView mSourceView; 32 Rect mClipRect = new Rect(); 33 Rect mClipBounds = new Rect(); 34 int mCornerRadius; 35 float mAlpha = 1f; 36 final float mMinAlpha = 0.25f; 37 38 ObjectAnimator mClipBottomAnimator; 39 40 public AnimateableViewBounds(TaskView source, int cornerRadius) { 41 mConfig = RecentsConfiguration.getInstance(); 42 mSourceView = source; 43 mCornerRadius = cornerRadius; 44 setClipBottom(getClipBottom()); 45 } 46 47 @Override 48 public void getOutline(View view, Outline outline) { 49 outline.setAlpha(mMinAlpha + mAlpha / (1f - mMinAlpha)); 50 outline.setRoundRect(mClipRect.left, mClipRect.top, 51 mSourceView.getWidth() - mClipRect.right, 52 mSourceView.getHeight() - mClipRect.bottom, 53 mCornerRadius); 54 } 55 56 /** Sets the view outline alpha. */ 57 void setAlpha(float alpha) { 58 if (Float.compare(alpha, mAlpha) != 0) { 59 mAlpha = alpha; 60 mSourceView.invalidateOutline(); 61 } 62 } 63 64 /** Sets the bottom clip. */ 65 public void setClipBottom(int bottom) { 66 if (bottom != mClipRect.bottom) { 67 mClipRect.bottom = bottom; 68 mSourceView.invalidateOutline(); 69 updateClipBounds(); 70 if (!mConfig.useHardwareLayers) { 71 mSourceView.mThumbnailView.updateVisibility( 72 bottom - mSourceView.getPaddingBottom()); 73 } 74 } 75 } 76 77 /** Returns the bottom clip. */ 78 public int getClipBottom() { 79 return mClipRect.bottom; 80 } 81 82 private void updateClipBounds() { 83 mClipBounds.set(mClipRect.left, mClipRect.top, 84 mSourceView.getWidth() - mClipRect.right, 85 mSourceView.getHeight() - mClipRect.bottom); 86 mSourceView.setClipBounds(mClipBounds); 87 } 88} 89