1 /* 2 * Copyright (C) 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 package com.android.launcher3.taskbar; 17 18 import android.content.Context; 19 import android.graphics.Canvas; 20 import android.util.AttributeSet; 21 import android.view.View; 22 23 import com.android.launcher3.views.ActivityContext; 24 25 /** 26 * View that handles scrimming the taskbar and the inverted corners it draws. The scrim is used 27 * when bubbles is expanded. 28 */ 29 public class TaskbarScrimView extends View { 30 private final TaskbarBackgroundRenderer mRenderer; 31 32 private boolean mShowScrim; 33 TaskbarScrimView(Context context)34 public TaskbarScrimView(Context context) { 35 this(context, null); 36 } 37 TaskbarScrimView(Context context, AttributeSet attrs)38 public TaskbarScrimView(Context context, AttributeSet attrs) { 39 this(context, attrs, 0); 40 } 41 TaskbarScrimView(Context context, AttributeSet attrs, int defStyleAttr)42 public TaskbarScrimView(Context context, AttributeSet attrs, int defStyleAttr) { 43 this(context, attrs, defStyleAttr, 0); 44 } 45 TaskbarScrimView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)46 public TaskbarScrimView(Context context, AttributeSet attrs, int defStyleAttr, 47 int defStyleRes) { 48 super(context, attrs, defStyleAttr, defStyleRes); 49 mRenderer = new TaskbarBackgroundRenderer(ActivityContext.lookupContext(context)); 50 mRenderer.getPaint().setColor(getResources().getColor( 51 android.R.color.system_neutral1_1000)); 52 } 53 54 @Override onDraw(Canvas canvas)55 protected void onDraw(Canvas canvas) { 56 super.onDraw(canvas); 57 58 if (mShowScrim) { 59 mRenderer.draw(canvas); 60 } 61 } 62 63 /** 64 * Sets the alpha of the taskbar scrim. 65 * @param alpha the alpha of the scrim. 66 */ setScrimAlpha(float alpha)67 protected void setScrimAlpha(float alpha) { 68 mShowScrim = alpha > 0f; 69 mRenderer.getPaint().setAlpha((int) (alpha * 255)); 70 invalidate(); 71 } 72 getScrimAlpha()73 protected float getScrimAlpha() { 74 return mRenderer.getPaint().getAlpha() / 255f; 75 } 76 77 /** 78 * Sets the roundness of the round corner above Taskbar. 79 * @param cornerRoundness 0 has no round corner, 1 has complete round corner. 80 */ setCornerRoundness(float cornerRoundness)81 protected void setCornerRoundness(float cornerRoundness) { 82 mRenderer.setCornerRoundness(cornerRoundness); 83 invalidate(); 84 } 85 } 86