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