summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorBeth Thibodeau <ethibodeau@google.com>2019-08-06 13:28:50 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-08-06 13:28:50 -0700
commit3ea5a1fcbe53265ee85b412596a734a6e2322542 (patch)
treec1b5426d022fec47b081f7e4c45dd6a226923bc1 /core/java
parentf5fa3cf7cf4286d5a6ccb1435971ba528275c338 (diff)
parentf7ad427d8b816c336776487786cfa095189ec1a4 (diff)
Merge "Stop timer when notification is not visible" into qt-r1-dev
am: f7ad427d8b Change-Id: I601b736974dffc1a4f5b8ced66d1d97127a42541
Diffstat (limited to 'core/java')
-rw-r--r--core/java/com/android/internal/widget/MediaNotificationView.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/core/java/com/android/internal/widget/MediaNotificationView.java b/core/java/com/android/internal/widget/MediaNotificationView.java
index e7d240a1035e..9bb45012b61a 100644
--- a/core/java/com/android/internal/widget/MediaNotificationView.java
+++ b/core/java/com/android/internal/widget/MediaNotificationView.java
@@ -26,6 +26,8 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RemoteViews;
+import java.util.ArrayList;
+
/**
* A TextView that can float around an image on the end.
*
@@ -42,6 +44,7 @@ public class MediaNotificationView extends FrameLayout {
private View mMainColumn;
private View mMediaContent;
private int mImagePushIn;
+ private ArrayList<VisibilityChangeListener> mListeners;
public MediaNotificationView(Context context) {
this(context, null);
@@ -168,4 +171,50 @@ public class MediaNotificationView extends FrameLayout {
mMainColumn = findViewById(com.android.internal.R.id.notification_main_column);
mMediaContent = findViewById(com.android.internal.R.id.notification_media_content);
}
+
+ @Override
+ public void onVisibilityAggregated(boolean isVisible) {
+ super.onVisibilityAggregated(isVisible);
+ if (mListeners != null) {
+ for (int i = 0; i < mListeners.size(); i++) {
+ mListeners.get(i).onAggregatedVisibilityChanged(isVisible);
+ }
+ }
+ }
+
+ /**
+ * Add a listener to receive updates on the visibility of this view
+ *
+ * @param listener The listener to add.
+ */
+ public void addVisibilityListener(VisibilityChangeListener listener) {
+ if (mListeners == null) {
+ mListeners = new ArrayList<>();
+ }
+ if (!mListeners.contains(listener)) {
+ mListeners.add(listener);
+ }
+ }
+
+ /**
+ * Remove the specified listener
+ *
+ * @param listener The listener to remove.
+ */
+ public void removeVisibilityListener(VisibilityChangeListener listener) {
+ if (mListeners != null) {
+ mListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Interface for receiving updates when the view's visibility changes
+ */
+ public interface VisibilityChangeListener {
+ /**
+ * Method called when the visibility of this view has changed
+ * @param isVisible true if the view is now visible
+ */
+ void onAggregatedVisibilityChanged(boolean isVisible);
+ }
}