linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 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.statusbar; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Beth Thibodeau | 750ec58 | 2019-09-18 15:14:09 -0400 | [diff] [blame] | 21 | import android.content.res.ColorStateList; |
| 22 | import android.graphics.drawable.GradientDrawable; |
| 23 | import android.graphics.drawable.RippleDrawable; |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 24 | import android.service.notification.StatusBarNotification; |
| 25 | import android.util.FeatureFlagUtils; |
| 26 | import android.view.View; |
| 27 | import android.view.ViewGroup; |
| 28 | import android.view.ViewParent; |
Beth Thibodeau | 750ec58 | 2019-09-18 15:14:09 -0400 | [diff] [blame] | 29 | import android.widget.ImageView; |
| 30 | import android.widget.LinearLayout; |
| 31 | import android.widget.TextView; |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 32 | |
Beth Thibodeau | 750ec58 | 2019-09-18 15:14:09 -0400 | [diff] [blame] | 33 | import com.android.internal.R; |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 34 | import com.android.settingslib.media.MediaOutputSliceConstants; |
| 35 | import com.android.systemui.Dependency; |
| 36 | import com.android.systemui.plugins.ActivityStarter; |
| 37 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
| 38 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 39 | |
| 40 | /** |
| 41 | * Class for handling MediaTransfer state over a set of notifications. |
| 42 | */ |
| 43 | public 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 Thibodeau | 750ec58 | 2019-09-18 15:14:09 -0400 | [diff] [blame] | 61 | StatusBarNotification statusBarNotification = |
| 62 | getRowForParent(parent).getStatusBarNotification(); |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 63 | 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 | } |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | public MediaTransferManager(Context context) { |
| 74 | mContext = context; |
| 75 | mActivityStarter = Dependency.get(ActivityStarter.class); |
| 76 | } |
| 77 | |
Beth Thibodeau | 750ec58 | 2019-09-18 15:14:09 -0400 | [diff] [blame] | 78 | 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 | |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 88 | /** |
| 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 Thibodeau | 750ec58 | 2019-09-18 15:14:09 -0400 | [diff] [blame] | 106 | |
| 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); |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 124 | } |
| 125 | } |