1 /* 2 * Copyright (C) 2020 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.bubbles; 18 19 import android.content.Context; 20 import android.content.res.TypedArray; 21 import android.graphics.Color; 22 import android.util.AttributeSet; 23 import android.view.Gravity; 24 import android.view.View; 25 import android.widget.LinearLayout; 26 import android.widget.TextView; 27 28 import com.android.internal.util.ContrastColorUtil; 29 import com.android.systemui.R; 30 31 /** 32 * Educational view to highlight the manage button that allows a user to configure the settings 33 * for the bubble. Shown only the first time a user expands a bubble. 34 */ 35 public class BubbleManageEducationView extends LinearLayout { 36 37 private View mManageView; 38 private TextView mTitleTextView; 39 private TextView mDescTextView; 40 BubbleManageEducationView(Context context)41 public BubbleManageEducationView(Context context) { 42 this(context, null); 43 } 44 BubbleManageEducationView(Context context, AttributeSet attrs)45 public BubbleManageEducationView(Context context, AttributeSet attrs) { 46 this(context, attrs, 0); 47 } 48 BubbleManageEducationView(Context context, AttributeSet attrs, int defStyleAttr)49 public BubbleManageEducationView(Context context, AttributeSet attrs, int defStyleAttr) { 50 this(context, attrs, defStyleAttr, 0); 51 } 52 BubbleManageEducationView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)53 public BubbleManageEducationView(Context context, AttributeSet attrs, int defStyleAttr, 54 int defStyleRes) { 55 super(context, attrs, defStyleAttr, defStyleRes); 56 } 57 58 @Override onFinishInflate()59 protected void onFinishInflate() { 60 super.onFinishInflate(); 61 62 mManageView = findViewById(R.id.manage_education_view); 63 mTitleTextView = findViewById(R.id.user_education_title); 64 mDescTextView = findViewById(R.id.user_education_description); 65 66 final TypedArray ta = mContext.obtainStyledAttributes( 67 new int[] {android.R.attr.colorAccent, 68 android.R.attr.textColorPrimaryInverse}); 69 final int bgColor = ta.getColor(0, Color.BLACK); 70 int textColor = ta.getColor(1, Color.WHITE); 71 ta.recycle(); 72 73 textColor = ContrastColorUtil.ensureTextContrast(textColor, bgColor, true); 74 mTitleTextView.setTextColor(textColor); 75 mDescTextView.setTextColor(textColor); 76 } 77 78 /** 79 * Specifies the position for the manage view. 80 */ setManageViewPosition(int x, int y)81 public void setManageViewPosition(int x, int y) { 82 mManageView.setTranslationX(x); 83 mManageView.setTranslationY(y); 84 } 85 86 /** 87 * @return the height of the view that shows the educational text and pointer. 88 */ getManageViewHeight()89 public int getManageViewHeight() { 90 return mManageView.getHeight(); 91 } 92 93 @Override setLayoutDirection(int direction)94 public void setLayoutDirection(int direction) { 95 super.setLayoutDirection(direction); 96 if (getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { 97 mManageView.setBackgroundResource(R.drawable.bubble_stack_user_education_bg_rtl); 98 mTitleTextView.setGravity(Gravity.RIGHT); 99 mDescTextView.setGravity(Gravity.RIGHT); 100 } else { 101 mManageView.setBackgroundResource(R.drawable.bubble_stack_user_education_bg); 102 mTitleTextView.setGravity(Gravity.LEFT); 103 mDescTextView.setGravity(Gravity.LEFT); 104 } 105 } 106 } 107