1 /* 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 17 package com.android.systemui.statusbar.notification.row; 18 19 import androidx.annotation.NonNull; 20 import androidx.annotation.Nullable; 21 import androidx.core.os.CancellationSignal; 22 23 import com.android.systemui.statusbar.notification.collection.NotificationEntry; 24 import com.android.systemui.statusbar.notification.row.NotifBindPipeline.BindCallback; 25 26 /** 27 * A {@link BindRequester} is a general superclass for something that notifies 28 * {@link NotifBindPipeline} when it needs it to kick off a bind run. 29 */ 30 public abstract class BindRequester { 31 private @Nullable BindRequestListener mBindRequestListener; 32 33 /** 34 * Notifies the listener that some parameters/state has changed for some notification and that 35 * content needs to be bound again. 36 * 37 * The caller can also specify a callback for when the entire bind pipeline completes, i.e. 38 * when the change is fully propagated to the final view. The caller can cancel this 39 * callback with the returned cancellation signal. 40 * 41 * @param callback callback after bind completely finishes 42 * @return cancellation signal to cancel callback 43 */ requestRebind( @onNull NotificationEntry entry, @Nullable BindCallback callback)44 public final CancellationSignal requestRebind( 45 @NonNull NotificationEntry entry, 46 @Nullable BindCallback callback) { 47 CancellationSignal signal = new CancellationSignal(); 48 if (mBindRequestListener != null) { 49 mBindRequestListener.onBindRequest(entry, signal, callback); 50 } 51 return signal; 52 } 53 setBindRequestListener(BindRequestListener listener)54 final void setBindRequestListener(BindRequestListener listener) { 55 mBindRequestListener = listener; 56 } 57 58 /** 59 * Listener interface for when content needs to be bound again. 60 */ 61 public interface BindRequestListener { 62 63 /** 64 * Called when {@link #requestRebind} is called. 65 * 66 * @param entry notification that has outdated content 67 * @param signal cancellation signal to cancel callback 68 * @param callback callback after content is fully updated 69 */ onBindRequest( @onNull NotificationEntry entry, @NonNull CancellationSignal signal, @Nullable BindCallback callback)70 void onBindRequest( 71 @NonNull NotificationEntry entry, 72 @NonNull CancellationSignal signal, 73 @Nullable BindCallback callback); 74 75 } 76 } 77