1 /* 2 * Copyright (C) 2019 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.volume; 18 19 import android.content.Context; 20 import android.graphics.CornerPathEffect; 21 import android.graphics.Paint; 22 import android.graphics.drawable.ShapeDrawable; 23 import android.util.AttributeSet; 24 import android.util.TypedValue; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.LinearLayout; 28 29 import androidx.core.content.ContextCompat; 30 31 import com.android.systemui.R; 32 import com.android.systemui.recents.TriangleShape; 33 34 /** 35 * Tool tip view that draws an arrow that points to the volume dialog. 36 */ 37 public class VolumeToolTipView extends LinearLayout { VolumeToolTipView(Context context)38 public VolumeToolTipView(Context context) { 39 super(context); 40 } 41 VolumeToolTipView(Context context, AttributeSet attrs)42 public VolumeToolTipView(Context context, AttributeSet attrs) { 43 super(context, attrs); 44 } 45 VolumeToolTipView(Context context, AttributeSet attrs, int defStyleAttr)46 public VolumeToolTipView(Context context, AttributeSet attrs, int defStyleAttr) { 47 super(context, attrs, defStyleAttr); 48 } 49 VolumeToolTipView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)50 public VolumeToolTipView(Context context, AttributeSet attrs, int defStyleAttr, 51 int defStyleRes) { 52 super(context, attrs, defStyleAttr, defStyleRes); 53 } 54 55 @Override onFinishInflate()56 protected void onFinishInflate() { 57 super.onFinishInflate(); 58 drawArrow(); 59 } 60 drawArrow()61 private void drawArrow() { 62 View arrowView = findViewById(R.id.arrow); 63 ViewGroup.LayoutParams arrowLp = arrowView.getLayoutParams(); 64 ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.createHorizontal( 65 arrowLp.width, arrowLp.height, false)); 66 Paint arrowPaint = arrowDrawable.getPaint(); 67 TypedValue typedValue = new TypedValue(); 68 getContext().getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true); 69 arrowPaint.setColor(ContextCompat.getColor(getContext(), typedValue.resourceId)); 70 // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable. 71 arrowPaint.setPathEffect(new CornerPathEffect( 72 getResources().getDimension(R.dimen.volume_tool_tip_arrow_corner_radius))); 73 arrowView.setBackground(arrowDrawable); 74 75 } 76 } 77