blob: e96bef36ba18c9a3fdaf68aaac45c946d83d0c32 [file] [log] [blame]
Lyn Han3cd75d72020-02-15 19:10:12 -08001/*
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
17package com.android.systemui.bubbles;
18
Lyn Han9f66c3b2020-03-05 23:59:29 -080019import static android.view.Display.INVALID_DISPLAY;
Lyn Han3cd75d72020-02-15 19:10:12 -080020import static android.view.View.GONE;
Lyn Hancd4f87e2020-02-19 20:33:45 -080021
22import static com.android.systemui.bubbles.BadgedImageView.DEFAULT_PATH_SIZE;
Lyn Han3cd75d72020-02-15 19:10:12 -080023
24import android.content.Context;
25import android.content.res.TypedArray;
Lyn Hancd4f87e2020-02-19 20:33:45 -080026import android.graphics.Bitmap;
Lyn Han3cd75d72020-02-15 19:10:12 -080027import android.graphics.Color;
Lyn Hancd4f87e2020-02-19 20:33:45 -080028import android.graphics.Matrix;
29import android.graphics.Path;
Lyn Han3cd75d72020-02-15 19:10:12 -080030import android.graphics.drawable.AdaptiveIconDrawable;
31import android.graphics.drawable.ColorDrawable;
32import android.graphics.drawable.InsetDrawable;
Lyn Hancd4f87e2020-02-19 20:33:45 -080033import android.util.PathParser;
34import android.util.TypedValue;
Lyn Han3cd75d72020-02-15 19:10:12 -080035import android.view.LayoutInflater;
36import android.view.View;
37import android.view.ViewGroup;
Lyn Han3cd75d72020-02-15 19:10:12 -080038import android.widget.ImageView;
39
40import com.android.systemui.R;
41
42/**
43 * Class for showing aged out bubbles.
44 */
45public class BubbleOverflow implements BubbleViewProvider {
Lyn Hancd4f87e2020-02-19 20:33:45 -080046 public static final String KEY = "Overflow";
Lyn Han3cd75d72020-02-15 19:10:12 -080047
Lyn Hancd4f87e2020-02-19 20:33:45 -080048 private BadgedImageView mOverflowBtn;
Lyn Han9f66c3b2020-03-05 23:59:29 -080049 private BubbleExpandedView mExpandedView;
Lyn Han3cd75d72020-02-15 19:10:12 -080050 private LayoutInflater mInflater;
51 private Context mContext;
Lyn Hancd4f87e2020-02-19 20:33:45 -080052 private Bitmap mIcon;
53 private Path mPath;
54 private int mBitmapSize;
55 private int mIconBitmapSize;
56 private int mDotColor;
Lyn Han3cd75d72020-02-15 19:10:12 -080057
58 public BubbleOverflow(Context context) {
59 mContext = context;
60 mInflater = LayoutInflater.from(context);
Lyn Hancd4f87e2020-02-19 20:33:45 -080061 mBitmapSize = mContext.getResources().getDimensionPixelSize(R.dimen.bubble_bitmap_size);
62 mIconBitmapSize = mContext.getResources().getDimensionPixelSize(
63 R.dimen.bubble_overflow_icon_bitmap_size);
Lyn Han3cd75d72020-02-15 19:10:12 -080064 }
65
Mady Mellor0122cc92020-02-27 12:15:39 -080066 void setUpOverflow(ViewGroup parentViewGroup, BubbleStackView stackView) {
Lyn Han9f66c3b2020-03-05 23:59:29 -080067 mExpandedView = (BubbleExpandedView) mInflater.inflate(
Lyn Han3cd75d72020-02-15 19:10:12 -080068 R.layout.bubble_expanded_view, parentViewGroup /* root */,
69 false /* attachToRoot */);
Lyn Han9f66c3b2020-03-05 23:59:29 -080070 mExpandedView.setOverflow(true);
71 mExpandedView.setStackView(stackView);
Lyn Han3cd75d72020-02-15 19:10:12 -080072
Lyn Hancd4f87e2020-02-19 20:33:45 -080073 updateIcon(mContext, parentViewGroup);
74 }
75
Lyn Hancd4f87e2020-02-19 20:33:45 -080076 void updateIcon(Context context, ViewGroup parentViewGroup) {
77 mInflater = LayoutInflater.from(context);
78 mOverflowBtn = (BadgedImageView) mInflater.inflate(R.layout.bubble_overflow_button,
Lyn Han3cd75d72020-02-15 19:10:12 -080079 parentViewGroup /* root */,
80 false /* attachToRoot */);
Lyn Hane5706962020-05-05 13:45:13 -070081 mOverflowBtn.setContentDescription(mContext.getResources().getString(
82 R.string.bubble_overflow_button_content_description));
Lyn Han3cd75d72020-02-15 19:10:12 -080083
Lyn Hancd4f87e2020-02-19 20:33:45 -080084 TypedArray ta = mContext.obtainStyledAttributes(
85 new int[]{android.R.attr.colorBackgroundFloating});
86 int bgColor = ta.getColor(0, Color.WHITE /* default */);
87 ta.recycle();
88
89 TypedValue typedValue = new TypedValue();
90 context.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true);
91 int colorAccent = mContext.getColor(typedValue.resourceId);
92 mOverflowBtn.getDrawable().setTint(colorAccent);
93 mDotColor = colorAccent;
94
95 ColorDrawable bg = new ColorDrawable(bgColor);
96 InsetDrawable fg = new InsetDrawable(mOverflowBtn.getDrawable(),
97 mBitmapSize - mIconBitmapSize /* inset */);
98 AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(bg, fg);
99
100 BubbleIconFactory iconFactory = new BubbleIconFactory(context);
101 mIcon = iconFactory.createBadgedIconBitmap(adaptiveIconDrawable,
102 null /* user */,
103 true /* shrinkNonAdaptiveIcons */).icon;
104
105 float scale = iconFactory.getNormalizer().getScale(mOverflowBtn.getDrawable(),
106 null /* outBounds */, null /* path */, null /* outMaskShape */);
107 float radius = DEFAULT_PATH_SIZE / 2f;
108 mPath = PathParser.createPathFromPathData(
109 context.getResources().getString(com.android.internal.R.string.config_icon_mask));
110 Matrix matrix = new Matrix();
111 matrix.setScale(scale /* x scale */, scale /* y scale */, radius /* pivot x */,
112 radius /* pivot y */);
113 mPath.transform(matrix);
114
Lyn Han3cd75d72020-02-15 19:10:12 -0800115 mOverflowBtn.setVisibility(GONE);
Joshua Tsuji2ed260e2020-03-26 14:26:01 -0400116 mOverflowBtn.setRenderedBubble(this);
Lyn Han3cd75d72020-02-15 19:10:12 -0800117 }
118
119 ImageView getBtn() {
120 return mOverflowBtn;
121 }
122
123 void setBtnVisible(int visible) {
124 mOverflowBtn.setVisibility(visible);
125 }
126
Lyn Hancd4f87e2020-02-19 20:33:45 -0800127 @Override
Lyn Han3cd75d72020-02-15 19:10:12 -0800128 public BubbleExpandedView getExpandedView() {
Lyn Han9f66c3b2020-03-05 23:59:29 -0800129 return mExpandedView;
Lyn Han3cd75d72020-02-15 19:10:12 -0800130 }
131
Lyn Hancd4f87e2020-02-19 20:33:45 -0800132 @Override
133 public int getDotColor() {
134 return mDotColor;
135 }
136
137 @Override
138 public Bitmap getBadgedImage() {
139 return mIcon;
140 }
141
142 @Override
143 public boolean showDot() {
144 return false;
145 }
146
147 @Override
148 public Path getDotPath() {
149 return mPath;
150 }
151
152 @Override
Lyn Han3cd75d72020-02-15 19:10:12 -0800153 public void setContentVisibility(boolean visible) {
Lyn Han9f66c3b2020-03-05 23:59:29 -0800154 mExpandedView.setContentVisibility(visible);
Lyn Han3cd75d72020-02-15 19:10:12 -0800155 }
156
Lyn Hancd4f87e2020-02-19 20:33:45 -0800157 @Override
Lyn Han3cd75d72020-02-15 19:10:12 -0800158 public void logUIEvent(int bubbleCount, int action, float normalX, float normalY,
159 int index) {
160 // TODO(b/149133814) Log overflow UI events.
161 }
162
Lyn Hancd4f87e2020-02-19 20:33:45 -0800163 @Override
Lyn Han3cd75d72020-02-15 19:10:12 -0800164 public View getIconView() {
165 return mOverflowBtn;
166 }
167
Lyn Hancd4f87e2020-02-19 20:33:45 -0800168 @Override
Lyn Han3cd75d72020-02-15 19:10:12 -0800169 public String getKey() {
Lyn Hancd4f87e2020-02-19 20:33:45 -0800170 return BubbleOverflow.KEY;
Lyn Han3cd75d72020-02-15 19:10:12 -0800171 }
Lyn Han9f66c3b2020-03-05 23:59:29 -0800172
173 @Override
174 public int getDisplayId() {
175 return mExpandedView != null ? mExpandedView.getVirtualDisplayId() : INVALID_DISPLAY;
176 }
Lyn Han3cd75d72020-02-15 19:10:12 -0800177}