Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 1 | package com.android.systemui.statusbar; |
| 2 | /* |
| 3 | * Copyright (C) 2017 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License |
| 16 | */ |
| 17 | |
| 18 | import java.util.ArrayList; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 19 | import java.util.List; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 20 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 21 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
| 22 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 23 | |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 24 | import android.animation.Animator; |
| 25 | import android.animation.AnimatorListenerAdapter; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 26 | import android.animation.AnimatorSet; |
| 27 | import android.animation.ObjectAnimator; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 28 | import android.content.Context; |
| 29 | import android.content.res.Resources; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 30 | import android.graphics.Typeface; |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 31 | import android.os.Bundle; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 32 | import android.service.notification.SnoozeCriterion; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 33 | import android.service.notification.StatusBarNotification; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 34 | import android.text.SpannableString; |
| 35 | import android.text.style.StyleSpan; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 36 | import android.util.AttributeSet; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 37 | import android.util.Log; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 38 | import android.view.LayoutInflater; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 39 | import android.view.View; |
| 40 | import android.view.ViewGroup; |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 41 | import android.view.accessibility.AccessibilityEvent; |
| 42 | import android.view.accessibility.AccessibilityNodeInfo; |
| 43 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 44 | import android.widget.ImageView; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 45 | import android.widget.LinearLayout; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 46 | import android.widget.TextView; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 47 | |
| 48 | import com.android.systemui.Interpolators; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 49 | import com.android.systemui.R; |
| 50 | |
| 51 | public class NotificationSnooze extends LinearLayout |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 52 | implements NotificationGuts.GutsContent, View.OnClickListener { |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 53 | |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 54 | /** |
| 55 | * If this changes more number increases, more assistant action resId's should be defined for |
| 56 | * accessibility purposes, see {@link #setSnoozeOptions(List)} |
| 57 | */ |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 58 | private static final int MAX_ASSISTANT_SUGGESTIONS = 1; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 59 | private NotificationGuts mGutsContainer; |
| 60 | private NotificationSwipeActionHelper mSnoozeListener; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 61 | private StatusBarNotification mSbn; |
| 62 | |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 63 | private TextView mSelectedOptionText; |
| 64 | private TextView mUndoButton; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 65 | private ImageView mExpandButton; |
| 66 | private View mDivider; |
| 67 | private ViewGroup mSnoozeOptionContainer; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 68 | private List<SnoozeOption> mSnoozeOptions; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 69 | private int mCollapsedHeight; |
Mady Mellor | 651fbde | 2017-05-18 14:02:51 -0700 | [diff] [blame] | 70 | private SnoozeOption mDefaultOption; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 71 | private SnoozeOption mSelectedOption; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 72 | private boolean mSnoozing; |
| 73 | private boolean mExpanded; |
| 74 | private AnimatorSet mExpandAnimation; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 75 | |
| 76 | public NotificationSnooze(Context context, AttributeSet attrs) { |
| 77 | super(context, attrs); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | protected void onFinishInflate() { |
| 82 | super.onFinishInflate(); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 83 | mCollapsedHeight = getResources().getDimensionPixelSize(R.dimen.snooze_snackbar_min_height); |
| 84 | findViewById(R.id.notification_snooze).setOnClickListener(this); |
| 85 | mSelectedOptionText = (TextView) findViewById(R.id.snooze_option_default); |
| 86 | mUndoButton = (TextView) findViewById(R.id.undo); |
| 87 | mUndoButton.setOnClickListener(this); |
| 88 | mExpandButton = (ImageView) findViewById(R.id.expand_button); |
| 89 | mDivider = findViewById(R.id.divider); |
| 90 | mDivider.setAlpha(0f); |
| 91 | mSnoozeOptionContainer = (ViewGroup) findViewById(R.id.snooze_options); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 92 | mSnoozeOptionContainer.setVisibility(View.INVISIBLE); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 93 | mSnoozeOptionContainer.setAlpha(0f); |
| 94 | |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 95 | // Create the different options based on list |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 96 | mSnoozeOptions = getDefaultSnoozeOptions(); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 97 | createOptionViews(); |
| 98 | |
Mady Mellor | 651fbde | 2017-05-18 14:02:51 -0700 | [diff] [blame] | 99 | setSelected(mDefaultOption); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 102 | @Override |
| 103 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 104 | super.onInitializeAccessibilityEvent(event); |
| 105 | if (mGutsContainer != null && mGutsContainer.isExposed()) { |
| 106 | if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 107 | event.getText().add(mSelectedOptionText.getText()); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 114 | super.onInitializeAccessibilityNodeInfo(info); |
| 115 | info.addAction(new AccessibilityAction(R.id.action_snooze_undo, |
| 116 | getResources().getString(R.string.snooze_undo))); |
| 117 | int count = mSnoozeOptions.size(); |
| 118 | for (int i = 0; i < count; i++) { |
| 119 | AccessibilityAction action = mSnoozeOptions.get(i).getAccessibilityAction(); |
| 120 | if (action != null) { |
| 121 | info.addAction(action); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 128 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 129 | return true; |
| 130 | } |
| 131 | if (action == R.id.action_snooze_undo) { |
| 132 | undoSnooze(mUndoButton); |
| 133 | return true; |
| 134 | } |
| 135 | for (int i = 0; i < mSnoozeOptions.size(); i++) { |
| 136 | SnoozeOption so = mSnoozeOptions.get(i); |
| 137 | if (so.getAccessibilityAction() != null |
| 138 | && so.getAccessibilityAction().getId() == action) { |
| 139 | setSelected(so); |
| 140 | return true; |
| 141 | } |
| 142 | } |
| 143 | return false; |
| 144 | } |
| 145 | |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 146 | public void setSnoozeOptions(final List<SnoozeCriterion> snoozeList) { |
| 147 | if (snoozeList == null) { |
| 148 | return; |
| 149 | } |
| 150 | mSnoozeOptions.clear(); |
| 151 | mSnoozeOptions = getDefaultSnoozeOptions(); |
| 152 | final int count = Math.min(MAX_ASSISTANT_SUGGESTIONS, snoozeList.size()); |
| 153 | for (int i = 0; i < count; i++) { |
| 154 | SnoozeCriterion sc = snoozeList.get(i); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 155 | AccessibilityAction action = new AccessibilityAction( |
| 156 | R.id.action_snooze_assistant_suggestion_1, sc.getExplanation()); |
| 157 | mSnoozeOptions.add(new NotificationSnoozeOption(sc, 0, sc.getExplanation(), |
| 158 | sc.getConfirmation(), action)); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 159 | } |
| 160 | createOptionViews(); |
| 161 | } |
| 162 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 163 | public boolean isExpanded() { |
| 164 | return mExpanded; |
| 165 | } |
| 166 | |
| 167 | public void setSnoozeListener(NotificationSwipeActionHelper listener) { |
| 168 | mSnoozeListener = listener; |
| 169 | } |
| 170 | |
| 171 | public void setStatusBarNotification(StatusBarNotification sbn) { |
| 172 | mSbn = sbn; |
| 173 | } |
| 174 | |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 175 | private ArrayList<SnoozeOption> getDefaultSnoozeOptions() { |
| 176 | ArrayList<SnoozeOption> options = new ArrayList<>(); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 177 | |
| 178 | options.add(createOption(15 /* minutes */, R.id.action_snooze_15_min)); |
| 179 | options.add(createOption(30 /* minutes */, R.id.action_snooze_30_min)); |
| 180 | mDefaultOption = createOption(60 /* minutes */, R.id.action_snooze_1_hour); |
Mady Mellor | 651fbde | 2017-05-18 14:02:51 -0700 | [diff] [blame] | 181 | options.add(mDefaultOption); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 182 | options.add(createOption(60 * 2 /* minutes */, R.id.action_snooze_2_hours)); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 183 | return options; |
| 184 | } |
| 185 | |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 186 | private SnoozeOption createOption(int minutes, int accessibilityActionId) { |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 187 | Resources res = getResources(); |
Mady Mellor | 6143b90 | 2017-05-10 17:16:28 -0700 | [diff] [blame] | 188 | boolean showInHours = minutes >= 60; |
| 189 | int pluralResId = showInHours |
| 190 | ? R.plurals.snoozeHourOptions |
| 191 | : R.plurals.snoozeMinuteOptions; |
| 192 | int count = showInHours ? (minutes / 60) : minutes; |
| 193 | String description = res.getQuantityString(pluralResId, count, count); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 194 | String resultText = String.format(res.getString(R.string.snoozed_for_time), description); |
| 195 | SpannableString string = new SpannableString(resultText); |
| 196 | string.setSpan(new StyleSpan(Typeface.BOLD), |
| 197 | resultText.length() - description.length(), resultText.length(), 0 /* flags */); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 198 | AccessibilityAction action = new AccessibilityAction(accessibilityActionId, description); |
| 199 | return new NotificationSnoozeOption(null, minutes, description, string, |
| 200 | action); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | private void createOptionViews() { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 204 | mSnoozeOptionContainer.removeAllViews(); |
| 205 | LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( |
| 206 | Context.LAYOUT_INFLATER_SERVICE); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 207 | for (int i = 0; i < mSnoozeOptions.size(); i++) { |
| 208 | SnoozeOption option = mSnoozeOptions.get(i); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 209 | TextView tv = (TextView) inflater.inflate(R.layout.notification_snooze_option, |
| 210 | mSnoozeOptionContainer, false); |
| 211 | mSnoozeOptionContainer.addView(tv); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 212 | tv.setText(option.getDescription()); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 213 | tv.setTag(option); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 214 | tv.setOnClickListener(this); |
| 215 | } |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 216 | } |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 217 | |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 218 | private void hideSelectedOption() { |
| 219 | final int childCount = mSnoozeOptionContainer.getChildCount(); |
| 220 | for (int i = 0; i < childCount; i++) { |
| 221 | final View child = mSnoozeOptionContainer.getChildAt(i); |
| 222 | child.setVisibility(child.getTag() == mSelectedOption ? View.GONE : View.VISIBLE); |
| 223 | } |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | private void showSnoozeOptions(boolean show) { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 227 | int drawableId = show ? com.android.internal.R.drawable.ic_collapse_notification |
| 228 | : com.android.internal.R.drawable.ic_expand_notification; |
| 229 | mExpandButton.setImageResource(drawableId); |
Selim Cinek | e8ea7f6 | 2017-04-28 19:22:17 -0700 | [diff] [blame] | 230 | if (mExpanded != show) { |
| 231 | mExpanded = show; |
| 232 | animateSnoozeOptions(show); |
| 233 | if (mGutsContainer != null) { |
| 234 | mGutsContainer.onHeightChanged(); |
| 235 | } |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | private void animateSnoozeOptions(boolean show) { |
| 240 | if (mExpandAnimation != null) { |
| 241 | mExpandAnimation.cancel(); |
| 242 | } |
| 243 | ObjectAnimator dividerAnim = ObjectAnimator.ofFloat(mDivider, View.ALPHA, |
| 244 | mDivider.getAlpha(), show ? 1f : 0f); |
| 245 | ObjectAnimator optionAnim = ObjectAnimator.ofFloat(mSnoozeOptionContainer, View.ALPHA, |
| 246 | mSnoozeOptionContainer.getAlpha(), show ? 1f : 0f); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 247 | mSnoozeOptionContainer.setVisibility(View.VISIBLE); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 248 | mExpandAnimation = new AnimatorSet(); |
| 249 | mExpandAnimation.playTogether(dividerAnim, optionAnim); |
| 250 | mExpandAnimation.setDuration(150); |
| 251 | mExpandAnimation.setInterpolator(show ? Interpolators.ALPHA_IN : Interpolators.ALPHA_OUT); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 252 | mExpandAnimation.addListener(new AnimatorListenerAdapter() { |
| 253 | boolean cancelled = false; |
| 254 | |
| 255 | @Override |
| 256 | public void onAnimationCancel(Animator animation) { |
| 257 | cancelled = true; |
| 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public void onAnimationEnd(Animator animation) { |
| 262 | if (!show && !cancelled) { |
| 263 | mSnoozeOptionContainer.setVisibility(View.INVISIBLE); |
| 264 | mSnoozeOptionContainer.setAlpha(0f); |
| 265 | } |
| 266 | } |
| 267 | }); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 268 | mExpandAnimation.start(); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 271 | private void setSelected(SnoozeOption option) { |
| 272 | mSelectedOption = option; |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 273 | mSelectedOptionText.setText(option.getConfirmation()); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 274 | showSnoozeOptions(false); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 275 | hideSelectedOption(); |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 276 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void onClick(View v) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 281 | if (mGutsContainer != null) { |
| 282 | mGutsContainer.resetFalsingCheck(); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 283 | } |
| 284 | final int id = v.getId(); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 285 | final SnoozeOption tag = (SnoozeOption) v.getTag(); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 286 | if (tag != null) { |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 287 | setSelected(tag); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 288 | } else if (id == R.id.notification_snooze) { |
| 289 | // Toggle snooze options |
| 290 | showSnoozeOptions(!mExpanded); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 291 | } else { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 292 | // Undo snooze was selected |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 293 | undoSnooze(v); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 297 | private void undoSnooze(View v) { |
| 298 | mSelectedOption = null; |
| 299 | int[] parentLoc = new int[2]; |
| 300 | int[] targetLoc = new int[2]; |
| 301 | mGutsContainer.getLocationOnScreen(parentLoc); |
| 302 | v.getLocationOnScreen(targetLoc); |
| 303 | final int centerX = v.getWidth() / 2; |
| 304 | final int centerY = v.getHeight() / 2; |
| 305 | final int x = targetLoc[0] - parentLoc[0] + centerX; |
| 306 | final int y = targetLoc[1] - parentLoc[1] + centerY; |
| 307 | showSnoozeOptions(false); |
| 308 | mGutsContainer.closeControls(x, y, false /* save */, false /* force */); |
| 309 | } |
| 310 | |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 311 | @Override |
| 312 | public int getActualHeight() { |
| 313 | return mExpanded ? getHeight() : mCollapsedHeight; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 316 | @Override |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 317 | public boolean willBeRemoved() { |
| 318 | return mSnoozing; |
| 319 | } |
| 320 | |
| 321 | @Override |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 322 | public View getContentView() { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 323 | // Reset the view before use |
Mady Mellor | 651fbde | 2017-05-18 14:02:51 -0700 | [diff] [blame] | 324 | setSelected(mDefaultOption); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 325 | return this; |
| 326 | } |
| 327 | |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 328 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 329 | public void setGutsParent(NotificationGuts guts) { |
| 330 | mGutsContainer = guts; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 333 | @Override |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 334 | public boolean handleCloseControls(boolean save, boolean force) { |
| 335 | if (mExpanded && !force) { |
| 336 | // Collapse expanded state on outside touch |
| 337 | showSnoozeOptions(false); |
| 338 | return true; |
| 339 | } else if (mSnoozeListener != null && mSelectedOption != null) { |
| 340 | // Snooze option selected so commit it |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 341 | mSnoozing = true; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 342 | mSnoozeListener.snooze(mSbn, mSelectedOption); |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 343 | return true; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 344 | } else { |
| 345 | // The view should actually be closed |
| 346 | setSelected(mSnoozeOptions.get(0)); |
| 347 | return false; // Return false here so that guts handles closing the view |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 348 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public boolean isLeavebehind() { |
| 353 | return true; |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 354 | } |
Mady Mellor | 920fd89 | 2017-06-06 09:35:03 -0700 | [diff] [blame^] | 355 | |
| 356 | public class NotificationSnoozeOption implements SnoozeOption { |
| 357 | private SnoozeCriterion mCriterion; |
| 358 | private int mMinutesToSnoozeFor; |
| 359 | private CharSequence mDescription; |
| 360 | private CharSequence mConfirmation; |
| 361 | private AccessibilityAction mAction; |
| 362 | |
| 363 | public NotificationSnoozeOption(SnoozeCriterion sc, int minToSnoozeFor, |
| 364 | CharSequence description, |
| 365 | CharSequence confirmation, AccessibilityAction action) { |
| 366 | mCriterion = sc; |
| 367 | mMinutesToSnoozeFor = minToSnoozeFor; |
| 368 | mDescription = description; |
| 369 | mConfirmation = confirmation; |
| 370 | mAction = action; |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public SnoozeCriterion getSnoozeCriterion() { |
| 375 | return mCriterion; |
| 376 | } |
| 377 | |
| 378 | @Override |
| 379 | public CharSequence getDescription() { |
| 380 | return mDescription; |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public CharSequence getConfirmation() { |
| 385 | return mConfirmation; |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public int getMinutesToSnoozeFor() { |
| 390 | return mMinutesToSnoozeFor; |
| 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public AccessibilityAction getAccessibilityAction() { |
| 395 | return mAction; |
| 396 | } |
| 397 | |
| 398 | } |
Mady Mellor | 04d7a0f | 2017-01-25 13:16:03 -0800 | [diff] [blame] | 399 | } |