1 /* 2 * Copyright 2021 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.quickstep.views; 18 19 import android.content.Context; 20 import android.graphics.Canvas; 21 import android.graphics.Paint; 22 import android.graphics.Rect; 23 import android.graphics.drawable.Drawable; 24 import android.util.AttributeSet; 25 import android.util.TypedValue; 26 import android.widget.FrameLayout; 27 28 import androidx.annotation.Nullable; 29 30 public class SplitPlaceholderView extends FrameLayout { 31 32 private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 33 private final Rect mTempRect = new Rect(); 34 35 @Nullable 36 private IconView mIconView; 37 SplitPlaceholderView(Context context, AttributeSet attrs)38 public SplitPlaceholderView(Context context, AttributeSet attrs) { 39 super(context, attrs); 40 41 mPaint.setColor(getThemeBackgroundColor(context)); 42 setWillNotDraw(false); 43 } 44 45 @Override dispatchDraw(Canvas canvas)46 protected void dispatchDraw(Canvas canvas) { 47 // Call this before super call to draw below the children. 48 drawBackground(canvas); 49 50 super.dispatchDraw(canvas); 51 52 if (mIconView != null) { 53 // Center the icon view in the visible area. 54 getLocalVisibleRect(mTempRect); 55 FloatingTaskView parent = (FloatingTaskView) getParent(); 56 parent.centerIconView(mIconView, mTempRect.centerX(), mTempRect.centerY()); 57 } 58 } 59 60 @Nullable getIconView()61 public IconView getIconView() { 62 return mIconView; 63 } 64 setIcon(Drawable drawable, int iconSize)65 public void setIcon(Drawable drawable, int iconSize) { 66 if (mIconView == null) { 67 mIconView = new IconView(getContext()); 68 addView(mIconView); 69 } 70 mIconView.setDrawable(drawable); 71 mIconView.setDrawableSize(iconSize, iconSize); 72 FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(iconSize, iconSize); 73 mIconView.setLayoutParams(params); 74 } 75 drawBackground(Canvas canvas)76 private void drawBackground(Canvas canvas) { 77 FloatingTaskView parent = (FloatingTaskView) getParent(); 78 parent.drawRoundedRect(canvas, mPaint); 79 } 80 getThemeBackgroundColor(Context context)81 private static int getThemeBackgroundColor(Context context) { 82 final TypedValue value = new TypedValue(); 83 context.getTheme().resolveAttribute(android.R.attr.colorBackground, value, true); 84 return value.data; 85 } 86 } 87