Merge "Merge "Stop timer when notification is not visible" into qt-r1-dev am: f7ad427d8b" into qt-qpr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a0c8c12db4
@@ -26,6 +26,8 @@ import android.widget.FrameLayout;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A TextView that can float around an image on the end.
|
* 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 mMainColumn;
|
||||||
private View mMediaContent;
|
private View mMediaContent;
|
||||||
private int mImagePushIn;
|
private int mImagePushIn;
|
||||||
|
private ArrayList<VisibilityChangeListener> mListeners;
|
||||||
|
|
||||||
public MediaNotificationView(Context context) {
|
public MediaNotificationView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -168,4 +171,50 @@ public class MediaNotificationView extends FrameLayout {
|
|||||||
mMainColumn = findViewById(com.android.internal.R.id.notification_main_column);
|
mMainColumn = findViewById(com.android.internal.R.id.notification_main_column);
|
||||||
mMediaContent = findViewById(com.android.internal.R.id.notification_media_content);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1367,7 +1367,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
|||||||
if (isChildInGroup()) {
|
if (isChildInGroup()) {
|
||||||
mTranslationWhenRemoved += getNotificationParent().getTranslationY();
|
mTranslationWhenRemoved += getNotificationParent().getTranslationY();
|
||||||
}
|
}
|
||||||
mPrivateLayout.setRemoved();
|
for (NotificationContentView l : mLayouts) {
|
||||||
|
l.setRemoved();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean wasChildInGroupWhenRemoved() {
|
public boolean wasChildInGroupWhenRemoved() {
|
||||||
|
|||||||
@@ -1542,6 +1542,15 @@ public class NotificationContentView extends FrameLayout {
|
|||||||
if (mHeadsUpRemoteInput != null) {
|
if (mHeadsUpRemoteInput != null) {
|
||||||
mHeadsUpRemoteInput.setRemoved();
|
mHeadsUpRemoteInput.setRemoved();
|
||||||
}
|
}
|
||||||
|
if (mExpandedWrapper != null) {
|
||||||
|
mExpandedWrapper.setRemoved();
|
||||||
|
}
|
||||||
|
if (mContractedWrapper != null) {
|
||||||
|
mContractedWrapper.setRemoved();
|
||||||
|
}
|
||||||
|
if (mHeadsUpWrapper != null) {
|
||||||
|
mHeadsUpWrapper.setRemoved();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContentHeightAnimating(boolean animating) {
|
public void setContentHeightAnimating(boolean animating) {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import com.android.internal.R;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
import com.android.internal.widget.MediaNotificationView;
|
||||||
import com.android.systemui.Dependency;
|
import com.android.systemui.Dependency;
|
||||||
import com.android.systemui.statusbar.NotificationMediaManager;
|
import com.android.systemui.statusbar.NotificationMediaManager;
|
||||||
import com.android.systemui.statusbar.TransformableView;
|
import com.android.systemui.statusbar.TransformableView;
|
||||||
@@ -67,6 +68,7 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
private View mSeekBarView;
|
private View mSeekBarView;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private MetricsLogger mMetricsLogger;
|
private MetricsLogger mMetricsLogger;
|
||||||
|
private boolean mIsViewVisible;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected SeekBar.OnSeekBarChangeListener mSeekListener =
|
protected SeekBar.OnSeekBarChangeListener mSeekListener =
|
||||||
@@ -88,11 +90,46 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private MediaNotificationView.VisibilityChangeListener mVisibilityListener =
|
||||||
|
new MediaNotificationView.VisibilityChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onAggregatedVisibilityChanged(boolean isVisible) {
|
||||||
|
mIsViewVisible = isVisible;
|
||||||
|
if (isVisible && mMediaController != null) {
|
||||||
|
// Restart timer if we're currently playing and didn't already have one going
|
||||||
|
PlaybackState state = mMediaController.getPlaybackState();
|
||||||
|
if (state != null && state.getState() == PlaybackState.STATE_PLAYING
|
||||||
|
&& mSeekBarTimer == null && mSeekBarView != null
|
||||||
|
&& mSeekBarView.getVisibility() != View.GONE) {
|
||||||
|
startTimer();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private View.OnAttachStateChangeListener mAttachStateListener =
|
||||||
|
new View.OnAttachStateChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onViewAttachedToWindow(View v) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewDetachedFromWindow(View v) {
|
||||||
|
mIsViewVisible = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private MediaController.Callback mMediaCallback = new MediaController.Callback() {
|
private MediaController.Callback mMediaCallback = new MediaController.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSessionDestroyed() {
|
public void onSessionDestroyed() {
|
||||||
clearTimer();
|
clearTimer();
|
||||||
mMediaController.unregisterCallback(this);
|
mMediaController.unregisterCallback(this);
|
||||||
|
if (mView instanceof MediaNotificationView) {
|
||||||
|
((MediaNotificationView) mView).removeVisibilityListener(mVisibilityListener);
|
||||||
|
mView.removeOnAttachStateChangeListener(mAttachStateListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -126,10 +163,17 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
mContext = ctx;
|
mContext = ctx;
|
||||||
mMediaManager = Dependency.get(NotificationMediaManager.class);
|
mMediaManager = Dependency.get(NotificationMediaManager.class);
|
||||||
mMetricsLogger = Dependency.get(MetricsLogger.class);
|
mMetricsLogger = Dependency.get(MetricsLogger.class);
|
||||||
|
|
||||||
|
if (mView instanceof MediaNotificationView) {
|
||||||
|
MediaNotificationView mediaView = (MediaNotificationView) mView;
|
||||||
|
mediaView.addVisibilityListener(mVisibilityListener);
|
||||||
|
mView.addOnAttachStateChangeListener(mAttachStateListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveViews() {
|
private void resolveViews() {
|
||||||
mActions = mView.findViewById(com.android.internal.R.id.media_actions);
|
mActions = mView.findViewById(com.android.internal.R.id.media_actions);
|
||||||
|
mIsViewVisible = mView.isShown();
|
||||||
|
|
||||||
final MediaSession.Token token = mRow.getEntry().notification.getNotification().extras
|
final MediaSession.Token token = mRow.getEntry().notification.getNotification().extras
|
||||||
.getParcelable(Notification.EXTRA_MEDIA_SESSION);
|
.getParcelable(Notification.EXTRA_MEDIA_SESSION);
|
||||||
@@ -208,24 +252,37 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
|
|
||||||
private void startTimer() {
|
private void startTimer() {
|
||||||
clearTimer();
|
clearTimer();
|
||||||
mSeekBarTimer = new Timer(true /* isDaemon */);
|
if (mIsViewVisible) {
|
||||||
mSeekBarTimer.schedule(new TimerTask() {
|
mSeekBarTimer = new Timer(true /* isDaemon */);
|
||||||
@Override
|
mSeekBarTimer.schedule(new TimerTask() {
|
||||||
public void run() {
|
@Override
|
||||||
mHandler.post(mOnUpdateTimerTick);
|
public void run() {
|
||||||
}
|
mHandler.post(mOnUpdateTimerTick);
|
||||||
}, 0, PROGRESS_UPDATE_INTERVAL);
|
}
|
||||||
|
}, 0, PROGRESS_UPDATE_INTERVAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearTimer() {
|
private void clearTimer() {
|
||||||
if (mSeekBarTimer != null) {
|
if (mSeekBarTimer != null) {
|
||||||
// TODO: also trigger this when the notification panel is collapsed
|
|
||||||
mSeekBarTimer.cancel();
|
mSeekBarTimer.cancel();
|
||||||
mSeekBarTimer.purge();
|
mSeekBarTimer.purge();
|
||||||
mSeekBarTimer = null;
|
mSeekBarTimer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRemoved() {
|
||||||
|
clearTimer();
|
||||||
|
if (mMediaController != null) {
|
||||||
|
mMediaController.unregisterCallback(mMediaCallback);
|
||||||
|
}
|
||||||
|
if (mView instanceof MediaNotificationView) {
|
||||||
|
((MediaNotificationView) mView).removeVisibilityListener(mVisibilityListener);
|
||||||
|
mView.removeOnAttachStateChangeListener(mAttachStateListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean canSeekMedia(@Nullable PlaybackState state) {
|
private boolean canSeekMedia(@Nullable PlaybackState state) {
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -261,7 +318,6 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (mMediaController != null && mSeekBar != null) {
|
if (mMediaController != null && mSeekBar != null) {
|
||||||
PlaybackState playbackState = mMediaController.getPlaybackState();
|
PlaybackState playbackState = mMediaController.getPlaybackState();
|
||||||
|
|
||||||
if (playbackState != null) {
|
if (playbackState != null) {
|
||||||
updatePlaybackUi(playbackState);
|
updatePlaybackUi(playbackState);
|
||||||
} else {
|
} else {
|
||||||
@@ -274,6 +330,10 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
};
|
};
|
||||||
|
|
||||||
private void updatePlaybackUi(PlaybackState state) {
|
private void updatePlaybackUi(PlaybackState state) {
|
||||||
|
if (mSeekBar == null || mSeekBarElapsedTime == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
long position = state.getPosition();
|
long position = state.getPosition();
|
||||||
mSeekBar.setProgress((int) position);
|
mSeekBar.setProgress((int) position);
|
||||||
|
|
||||||
|
|||||||
@@ -261,6 +261,12 @@ public abstract class NotificationViewWrapper implements TransformableView {
|
|||||||
mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
|
mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to indicate this view is removed
|
||||||
|
*/
|
||||||
|
public void setRemoved() {
|
||||||
|
}
|
||||||
|
|
||||||
public int getCustomBackgroundColor() {
|
public int getCustomBackgroundColor() {
|
||||||
// Parent notifications should always use the normal background color
|
// Parent notifications should always use the normal background color
|
||||||
return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor;
|
return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor;
|
||||||
|
|||||||
Reference in New Issue
Block a user