Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
| 18 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.app.INotificationManager; |
| 22 | import android.app.NotificationChannel; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 23 | import android.app.NotificationChannelGroup; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 24 | import android.app.NotificationManager; |
| 25 | import android.content.Context; |
| 26 | import android.content.pm.ApplicationInfo; |
| 27 | import android.content.pm.PackageInfo; |
| 28 | import android.content.pm.PackageManager; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 29 | import android.content.pm.ParceledListSlice; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 30 | import android.content.res.ColorStateList; |
| 31 | import android.content.res.TypedArray; |
| 32 | import android.graphics.Canvas; |
| 33 | import android.graphics.drawable.Drawable; |
| 34 | import android.os.Handler; |
| 35 | import android.os.RemoteException; |
| 36 | import android.os.ServiceManager; |
| 37 | import android.service.notification.NotificationListenerService; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 38 | import android.util.AttributeSet; |
| 39 | import android.util.Log; |
| 40 | import android.view.View; |
| 41 | import android.view.ViewAnimationUtils; |
| 42 | import android.view.ViewGroup; |
| 43 | import android.view.View.OnClickListener; |
| 44 | import android.widget.CompoundButton; |
| 45 | import android.widget.ImageView; |
| 46 | import android.widget.LinearLayout; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 47 | import android.widget.SeekBar; |
| 48 | import android.widget.Switch; |
| 49 | import android.widget.TextView; |
| 50 | |
| 51 | import com.android.internal.logging.MetricsLogger; |
| 52 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 53 | import com.android.settingslib.Utils; |
| 54 | import com.android.systemui.Interpolators; |
| 55 | import com.android.systemui.R; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 56 | import com.android.systemui.statusbar.NotificationGuts.OnSettingsClickListener; |
| 57 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
| 58 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 59 | import java.lang.IllegalArgumentException; |
| 60 | import java.util.List; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 61 | import java.util.Set; |
| 62 | |
| 63 | /** |
| 64 | * The guts of a notification revealed when performing a long press. |
| 65 | */ |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 66 | public class NotificationInfo extends LinearLayout implements NotificationGuts.GutsContent { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 67 | private static final String TAG = "InfoGuts"; |
| 68 | |
| 69 | private INotificationManager mINotificationManager; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 70 | private String mPkg; |
| 71 | private int mAppUid; |
| 72 | private List<NotificationChannel> mNotificationChannels; |
| 73 | private NotificationChannel mSingleNotificationChannel; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 74 | private int mStartingUserImportance; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 75 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 76 | private TextView mNumChannelsView; |
| 77 | private View mChannelDisabledView; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 78 | private Switch mChannelEnabledSwitch; |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame^] | 79 | private CheckSaveListener mCheckSaveListener; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 80 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 81 | private NotificationGuts mGutsContainer; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 82 | |
| 83 | public NotificationInfo(Context context, AttributeSet attrs) { |
| 84 | super(context, attrs); |
| 85 | } |
| 86 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame^] | 87 | // Specify a CheckSaveListener to override when/if the user's changes are committed. |
| 88 | public interface CheckSaveListener { |
| 89 | // Invoked when importance has changed and the NotificationInfo wants to try to save it. |
| 90 | // Listener should run saveImportance unless the change should be canceled. |
| 91 | void checkSave(Runnable saveImportance); |
| 92 | } |
| 93 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 94 | public interface OnSettingsClickListener { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 95 | void onClick(View v, NotificationChannel channel, int appUid); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 98 | public void bindNotification(final PackageManager pm, |
| 99 | final INotificationManager iNotificationManager, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 100 | final String pkg, |
| 101 | final List<NotificationChannel> notificationChannels, |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 102 | OnSettingsClickListener onSettingsClick, |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame^] | 103 | OnClickListener onDoneClick, |
| 104 | CheckSaveListener checkSaveListener, |
| 105 | final Set<String> nonBlockablePkgs) |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 106 | throws RemoteException { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 107 | mINotificationManager = iNotificationManager; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 108 | mPkg = pkg; |
| 109 | mNotificationChannels = notificationChannels; |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame^] | 110 | mCheckSaveListener = checkSaveListener; |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 111 | boolean isSingleDefaultChannel = false; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 112 | if (mNotificationChannels.isEmpty()) { |
| 113 | throw new IllegalArgumentException("bindNotification requires at least one channel"); |
| 114 | } else if (mNotificationChannels.size() == 1) { |
| 115 | mSingleNotificationChannel = mNotificationChannels.get(0); |
| 116 | mStartingUserImportance = mSingleNotificationChannel.getImportance(); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 117 | isSingleDefaultChannel = mSingleNotificationChannel.getId() |
| 118 | .equals(NotificationChannel.DEFAULT_CHANNEL_ID); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 119 | } else { |
| 120 | mSingleNotificationChannel = null; |
| 121 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 122 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 123 | String appName = mPkg; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 124 | Drawable pkgicon = null; |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 125 | CharSequence channelNameText = ""; |
| 126 | ApplicationInfo info = null; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 127 | try { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 128 | info = pm.getApplicationInfo(mPkg, |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 129 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 130 | | PackageManager.MATCH_DISABLED_COMPONENTS |
| 131 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 132 | | PackageManager.MATCH_DIRECT_BOOT_AWARE); |
| 133 | if (info != null) { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 134 | mAppUid = info.uid; |
Geoffrey Pitsch | 1f7fb1a | 2017-02-13 16:57:40 -0500 | [diff] [blame] | 135 | appName = String.valueOf(pm.getApplicationLabel(info)); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 136 | pkgicon = pm.getApplicationIcon(info); |
| 137 | } |
| 138 | } catch (PackageManager.NameNotFoundException e) { |
| 139 | // app is gone, just show package name and generic icon |
| 140 | pkgicon = pm.getDefaultActivityIcon(); |
| 141 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 142 | ((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon); |
| 143 | |
| 144 | int numChannels = 1; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 145 | numChannels = iNotificationManager.getNumNotificationChannelsForPackage( |
| 146 | pkg, mAppUid, false /* includeDeleted */); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 147 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 148 | String channelsDescText; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 149 | mNumChannelsView = (TextView) (findViewById(R.id.num_channels_desc)); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 150 | if (isSingleDefaultChannel) { |
| 151 | channelsDescText = mContext.getString(R.string.notification_default_channel_desc); |
| 152 | } else { |
| 153 | switch (mNotificationChannels.size()) { |
| 154 | case 1: |
| 155 | channelsDescText = String.format(mContext.getResources().getQuantityString( |
| 156 | R.plurals.notification_num_channels_desc, numChannels), numChannels); |
| 157 | break; |
| 158 | case 2: |
| 159 | channelsDescText = mContext.getString( |
| 160 | R.string.notification_channels_list_desc_2, |
| 161 | mNotificationChannels.get(0).getName(), |
| 162 | mNotificationChannels.get(1).getName()); |
| 163 | break; |
| 164 | default: |
| 165 | final int numOthers = mNotificationChannels.size() - 2; |
| 166 | channelsDescText = String.format( |
| 167 | mContext.getResources().getQuantityString( |
| 168 | R.plurals.notification_channels_list_desc_2_and_others, |
| 169 | numOthers), |
| 170 | mNotificationChannels.get(0).getName(), |
| 171 | mNotificationChannels.get(1).getName(), |
| 172 | numOthers); |
| 173 | } |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 174 | } |
| 175 | mNumChannelsView.setText(channelsDescText); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 176 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 177 | if (mSingleNotificationChannel == null) { |
| 178 | // Multiple channels don't use a channel name for the title. |
| 179 | channelNameText = mContext.getString(R.string.notification_num_channels, |
| 180 | mNotificationChannels.size()); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 181 | } else if (isSingleDefaultChannel) { |
| 182 | // If this is the default channel, don't use our channel-specific text. |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 183 | channelNameText = mContext.getString(R.string.notification_header_default_channel); |
| 184 | } else { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 185 | channelNameText = mSingleNotificationChannel.getName(); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 186 | } |
Geoffrey Pitsch | 1f7fb1a | 2017-02-13 16:57:40 -0500 | [diff] [blame] | 187 | ((TextView) findViewById(R.id.pkgname)).setText(appName); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 188 | ((TextView) findViewById(R.id.channel_name)).setText(channelNameText); |
| 189 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 190 | // Set group information if this channel has an associated group. |
| 191 | CharSequence groupName = null; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 192 | if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) { |
| 193 | final NotificationChannelGroup notificationChannelGroup = |
| 194 | iNotificationManager.getNotificationChannelGroupForPackage( |
| 195 | mSingleNotificationChannel.getGroup(), pkg, mAppUid); |
| 196 | if (notificationChannelGroup != null) { |
| 197 | groupName = notificationChannelGroup.getName(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 198 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 199 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 200 | TextView groupNameView = ((TextView) findViewById(R.id.group_name)); |
| 201 | TextView groupDividerView = ((TextView) findViewById(R.id.pkg_group_divider)); |
| 202 | if (groupName != null) { |
| 203 | groupNameView.setText(groupName); |
| 204 | groupNameView.setVisibility(View.VISIBLE); |
| 205 | groupDividerView.setVisibility(View.VISIBLE); |
| 206 | } else { |
| 207 | groupNameView.setVisibility(View.GONE); |
| 208 | groupDividerView.setVisibility(View.GONE); |
| 209 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 210 | |
| 211 | boolean nonBlockable = false; |
| 212 | try { |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 213 | final PackageInfo pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES); |
| 214 | nonBlockable = Utils.isSystemPackage(getResources(), pm, pkgInfo); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 215 | } catch (PackageManager.NameNotFoundException e) { |
| 216 | // unlikely. |
| 217 | } |
| 218 | if (nonBlockablePkgs != null) { |
| 219 | nonBlockable |= nonBlockablePkgs.contains(pkg); |
| 220 | } |
| 221 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 222 | bindButtons(nonBlockable); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 223 | |
| 224 | // Top-level importance group |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 225 | mChannelDisabledView = findViewById(R.id.channel_disabled); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 226 | updateSecondaryText(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 227 | |
| 228 | // Settings button. |
| 229 | final TextView settingsButton = (TextView) findViewById(R.id.more_settings); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 230 | if (mAppUid >= 0 && onSettingsClick != null) { |
| 231 | final int appUidF = mAppUid; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 232 | settingsButton.setOnClickListener( |
| 233 | (View view) -> { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 234 | onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 235 | }); |
| 236 | if (numChannels > 1) { |
| 237 | settingsButton.setText(R.string.notification_all_categories); |
| 238 | } else { |
| 239 | settingsButton.setText(R.string.notification_more_settings); |
| 240 | } |
| 241 | |
| 242 | } else { |
| 243 | settingsButton.setVisibility(View.GONE); |
| 244 | } |
| 245 | |
| 246 | // Done button. |
| 247 | final TextView doneButton = (TextView) findViewById(R.id.done); |
| 248 | doneButton.setText(R.string.notification_done); |
| 249 | doneButton.setOnClickListener(onDoneClick); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame^] | 252 | private boolean hasImportanceChanged() { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 253 | return mSingleNotificationChannel != null && |
| 254 | mStartingUserImportance != getSelectedImportance(); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 257 | private void saveImportance() { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 258 | if (mSingleNotificationChannel == null) { |
| 259 | return; |
| 260 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 261 | int selectedImportance = getSelectedImportance(); |
| 262 | if (selectedImportance == mStartingUserImportance) { |
| 263 | return; |
| 264 | } |
| 265 | MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE, |
| 266 | selectedImportance - mStartingUserImportance); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 267 | mSingleNotificationChannel.setImportance(selectedImportance); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 268 | try { |
| 269 | mINotificationManager.updateNotificationChannelForPackage( |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 270 | mPkg, mAppUid, mSingleNotificationChannel); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 271 | } catch (RemoteException e) { |
| 272 | // :( |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | private int getSelectedImportance() { |
| 277 | if (!mChannelEnabledSwitch.isChecked()) { |
| 278 | return NotificationManager.IMPORTANCE_NONE; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 279 | } else { |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 280 | return mStartingUserImportance; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 284 | private void bindButtons(final boolean nonBlockable) { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 285 | // Enabled Switch |
| 286 | mChannelEnabledSwitch = (Switch) findViewById(R.id.channel_enabled_switch); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 287 | mChannelEnabledSwitch.setChecked( |
| 288 | mStartingUserImportance != NotificationManager.IMPORTANCE_NONE); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 289 | final boolean visible = !nonBlockable && mSingleNotificationChannel != null; |
| 290 | mChannelEnabledSwitch.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 291 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 292 | // Callback when checked. |
| 293 | mChannelEnabledSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 294 | if (mGutsContainer != null) { |
| 295 | mGutsContainer.resetFalsingCheck(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 296 | } |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 297 | updateSecondaryText(); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 298 | }); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 301 | private void updateSecondaryText() { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 302 | final boolean disabled = mSingleNotificationChannel != null && |
| 303 | getSelectedImportance() == NotificationManager.IMPORTANCE_NONE; |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 304 | if (disabled) { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 305 | mChannelDisabledView.setVisibility(View.VISIBLE); |
| 306 | mNumChannelsView.setVisibility(View.GONE); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 307 | } else { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 308 | mChannelDisabledView.setVisibility(View.GONE); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 309 | mNumChannelsView.setVisibility(View.VISIBLE); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
| 313 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 314 | public void setGutsParent(NotificationGuts guts) { |
| 315 | mGutsContainer = guts; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Override |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 319 | public boolean willBeRemoved() { |
| 320 | return !mChannelEnabledSwitch.isChecked(); |
| 321 | } |
| 322 | |
| 323 | @Override |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 324 | public View getContentView() { |
| 325 | return this; |
| 326 | } |
| 327 | |
| 328 | @Override |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 329 | public boolean handleCloseControls(boolean save) { |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame^] | 330 | if (save && hasImportanceChanged()) { |
| 331 | if (mCheckSaveListener != null) { |
| 332 | mCheckSaveListener.checkSave(() -> { saveImportance(); }); |
| 333 | } else { |
| 334 | saveImportance(); |
| 335 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 336 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 337 | return false; |
| 338 | } |
| 339 | } |