blob: 926ae71194d952621f36b1d4b1abf3fa14295442 [file] [log] [blame]
linanson2bcd4032019-01-14 15:22:04 +08001/*
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
17package com.android.systemui.statusbar;
18
19import android.content.Context;
20import android.content.Intent;
Beth Thibodeau750ec582019-09-18 15:14:09 -040021import android.content.res.ColorStateList;
22import android.graphics.drawable.GradientDrawable;
23import android.graphics.drawable.RippleDrawable;
linanson2bcd4032019-01-14 15:22:04 +080024import android.service.notification.StatusBarNotification;
25import android.util.FeatureFlagUtils;
26import android.view.View;
27import android.view.ViewGroup;
28import android.view.ViewParent;
Beth Thibodeau750ec582019-09-18 15:14:09 -040029import android.widget.ImageView;
30import android.widget.LinearLayout;
31import android.widget.TextView;
linanson2bcd4032019-01-14 15:22:04 +080032
Beth Thibodeau750ec582019-09-18 15:14:09 -040033import com.android.internal.R;
linanson2bcd4032019-01-14 15:22:04 +080034import com.android.settingslib.media.MediaOutputSliceConstants;
35import com.android.systemui.Dependency;
36import com.android.systemui.plugins.ActivityStarter;
37import com.android.systemui.statusbar.notification.collection.NotificationEntry;
38import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
39
40/**
41 * Class for handling MediaTransfer state over a set of notifications.
42 */
43public class MediaTransferManager {
44 private final Context mContext;
45 private final ActivityStarter mActivityStarter;
46
47 private final View.OnClickListener mOnClickHandler = new View.OnClickListener() {
48 @Override
49 public void onClick(View view) {
50 if (handleMediaTransfer(view)) {
51 return;
52 }
53 }
54
55 private boolean handleMediaTransfer(View view) {
56 if (view.findViewById(com.android.internal.R.id.media_seamless) == null) {
57 return false;
58 }
59
60 ViewParent parent = view.getParent();
Beth Thibodeau750ec582019-09-18 15:14:09 -040061 StatusBarNotification statusBarNotification =
62 getRowForParent(parent).getStatusBarNotification();
linanson2bcd4032019-01-14 15:22:04 +080063 final Intent intent = new Intent()
64 .setAction(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT)
65 .putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME,
66 statusBarNotification.getPackageName());
67 mActivityStarter.startActivity(intent, false, true /* dismissShade */,
68 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
69 return true;
70 }
linanson2bcd4032019-01-14 15:22:04 +080071 };
72
73 public MediaTransferManager(Context context) {
74 mContext = context;
75 mActivityStarter = Dependency.get(ActivityStarter.class);
76 }
77
Beth Thibodeau750ec582019-09-18 15:14:09 -040078 private ExpandableNotificationRow getRowForParent(ViewParent parent) {
79 while (parent != null) {
80 if (parent instanceof ExpandableNotificationRow) {
81 return ((ExpandableNotificationRow) parent);
82 }
83 parent = parent.getParent();
84 }
85 return null;
86 }
87
linanson2bcd4032019-01-14 15:22:04 +080088 /**
89 * apply the action button for MediaTransfer
90 *
91 * @param root The parent container of the view.
92 * @param entry The entry of MediaTransfer action button.
93 */
94 public void applyMediaTransferView(ViewGroup root, NotificationEntry entry) {
95 if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SEAMLESS_TRANSFER)) {
96 return;
97 }
98
99 View view = root.findViewById(com.android.internal.R.id.media_seamless);
100 if (view == null) {
101 return;
102 }
103
104 view.setVisibility(View.VISIBLE);
105 view.setOnClickListener(mOnClickHandler);
Beth Thibodeau750ec582019-09-18 15:14:09 -0400106
107 ExpandableNotificationRow enr = getRowForParent(view.getParent());
108 int color = enr.getNotificationHeader().getOriginalIconColor();
109 ColorStateList tintList = ColorStateList.valueOf(color);
110
111 // Update the outline color
112 LinearLayout viewLayout = (LinearLayout) view;
113 RippleDrawable bkgDrawable = (RippleDrawable) viewLayout.getBackground();
114 GradientDrawable rect = (GradientDrawable) bkgDrawable.getDrawable(0);
115 rect.setStroke(2, color);
116
117 // Update the image color
118 ImageView image = view.findViewById(R.id.media_seamless_image);
119 image.setImageTintList(tintList);
120
121 // Update the text color
122 TextView text = view.findViewById(R.id.media_seamless_text);
123 text.setTextColor(tintList);
linanson2bcd4032019-01-14 15:22:04 +0800124 }
125}