Merge "Fixed a bug where the navigation notification would flicker" into oc-dev

This commit is contained in:
Selim Cinek
2017-06-08 14:07:14 +00:00
committed by Android (Google) Code Review
12 changed files with 58 additions and 40 deletions

View File

@@ -49,11 +49,11 @@ import com.android.systemui.statusbar.policy.RemoteInputView;
*/ */
public class NotificationContentView extends FrameLayout { public class NotificationContentView extends FrameLayout {
private static final int VISIBLE_TYPE_CONTRACTED = 0; public static final int VISIBLE_TYPE_CONTRACTED = 0;
private static final int VISIBLE_TYPE_EXPANDED = 1; public static final int VISIBLE_TYPE_EXPANDED = 1;
private static final int VISIBLE_TYPE_HEADSUP = 2; public static final int VISIBLE_TYPE_HEADSUP = 2;
private static final int VISIBLE_TYPE_SINGLELINE = 3; private static final int VISIBLE_TYPE_SINGLELINE = 3;
private static final int VISIBLE_TYPE_AMBIENT = 4; public static final int VISIBLE_TYPE_AMBIENT = 4;
private static final int VISIBLE_TYPE_AMBIENT_SINGLELINE = 5; private static final int VISIBLE_TYPE_AMBIENT_SINGLELINE = 5;
public static final int UNDEFINED = -1; public static final int UNDEFINED = -1;
@@ -928,7 +928,7 @@ public class NotificationContentView extends FrameLayout {
} }
} }
private NotificationViewWrapper getVisibleWrapper(int visibleType) { public NotificationViewWrapper getVisibleWrapper(int visibleType) {
switch (visibleType) { switch (visibleType) {
case VISIBLE_TYPE_EXPANDED: case VISIBLE_TYPE_EXPANDED:
return mExpandedWrapper; return mExpandedWrapper;
@@ -1085,16 +1085,16 @@ public class NotificationContentView extends FrameLayout {
mBeforeN = entry.targetSdk < Build.VERSION_CODES.N; mBeforeN = entry.targetSdk < Build.VERSION_CODES.N;
updateAllSingleLineViews(); updateAllSingleLineViews();
if (mContractedChild != null) { if (mContractedChild != null) {
mContractedWrapper.notifyContentUpdated(entry.row); mContractedWrapper.onContentUpdated(entry.row);
} }
if (mExpandedChild != null) { if (mExpandedChild != null) {
mExpandedWrapper.notifyContentUpdated(entry.row); mExpandedWrapper.onContentUpdated(entry.row);
} }
if (mHeadsUpChild != null) { if (mHeadsUpChild != null) {
mHeadsUpWrapper.notifyContentUpdated(entry.row); mHeadsUpWrapper.onContentUpdated(entry.row);
} }
if (mAmbientChild != null) { if (mAmbientChild != null) {
mAmbientWrapper.notifyContentUpdated(entry.row); mAmbientWrapper.onContentUpdated(entry.row);
} }
applyRemoteInput(entry); applyRemoteInput(entry);
updateLegacy(); updateLegacy();

View File

@@ -36,8 +36,8 @@ public class NotificationBigPictureTemplateViewWrapper extends NotificationTempl
} }
@Override @Override
public void notifyContentUpdated(ExpandableNotificationRow row) { public void onContentUpdated(ExpandableNotificationRow row) {
super.notifyContentUpdated(row); super.onContentUpdated(row);
updateImageTag(row.getStatusBarNotification()); updateImageTag(row.getStatusBarNotification());
} }

View File

@@ -41,11 +41,11 @@ public class NotificationBigTextTemplateViewWrapper extends NotificationTemplate
} }
@Override @Override
public void notifyContentUpdated(ExpandableNotificationRow row) { public void onContentUpdated(ExpandableNotificationRow row) {
// Reinspect the notification. Before the super call, because the super call also updates // Reinspect the notification. Before the super call, because the super call also updates
// the transformation types and we need to have our values set by then. // the transformation types and we need to have our values set by then.
resolveViews(row.getStatusBarNotification()); resolveViews(row.getStatusBarNotification());
super.notifyContentUpdated(row); super.onContentUpdated(row);
} }
@Override @Override

View File

@@ -128,8 +128,8 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
} }
@Override @Override
public void notifyContentUpdated(ExpandableNotificationRow row) { public void onContentUpdated(ExpandableNotificationRow row) {
super.notifyContentUpdated(row); super.onContentUpdated(row);
mIsLowPriority = row.isLowPriority(); mIsLowPriority = row.isLowPriority();
mTransformLowPriorityTitle = !row.isChildInGroup() && !row.isSummaryWithChildren(); mTransformLowPriorityTitle = !row.isChildInGroup() && !row.isSummaryWithChildren();
ArraySet<View> previousViews = mTransformationHelper.getAllTransformingViews(); ArraySet<View> previousViews = mTransformationHelper.getAllTransformingViews();

View File

@@ -36,7 +36,6 @@ import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.util.Assert; import com.android.systemui.util.Assert;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
@@ -207,7 +206,8 @@ public class NotificationInflater {
}; };
applyRemoteView(result, reInflateFlags, flag, row, redactAmbient, applyRemoteView(result, reInflateFlags, flag, row, redactAmbient,
isNewView, remoteViewClickHandler, callback, entry, privateLayout, isNewView, remoteViewClickHandler, callback, entry, privateLayout,
privateLayout.getContractedChild(), privateLayout.getContractedChild(), privateLayout.getVisibleWrapper(
NotificationContentView.VISIBLE_TYPE_CONTRACTED),
runningInflations, applyCallback); runningInflations, applyCallback);
} }
@@ -229,7 +229,9 @@ public class NotificationInflater {
}; };
applyRemoteView(result, reInflateFlags, flag, row, applyRemoteView(result, reInflateFlags, flag, row,
redactAmbient, isNewView, remoteViewClickHandler, callback, entry, redactAmbient, isNewView, remoteViewClickHandler, callback, entry,
privateLayout, privateLayout.getExpandedChild(), runningInflations, privateLayout, privateLayout.getExpandedChild(),
privateLayout.getVisibleWrapper(
NotificationContentView.VISIBLE_TYPE_EXPANDED), runningInflations,
applyCallback); applyCallback);
} }
} }
@@ -252,7 +254,9 @@ public class NotificationInflater {
}; };
applyRemoteView(result, reInflateFlags, flag, row, applyRemoteView(result, reInflateFlags, flag, row,
redactAmbient, isNewView, remoteViewClickHandler, callback, entry, redactAmbient, isNewView, remoteViewClickHandler, callback, entry,
privateLayout, privateLayout.getHeadsUpChild(), runningInflations, privateLayout, privateLayout.getHeadsUpChild(),
privateLayout.getVisibleWrapper(
NotificationContentView.VISIBLE_TYPE_HEADSUP), runningInflations,
applyCallback); applyCallback);
} }
} }
@@ -274,8 +278,9 @@ public class NotificationInflater {
}; };
applyRemoteView(result, reInflateFlags, flag, row, applyRemoteView(result, reInflateFlags, flag, row,
redactAmbient, isNewView, remoteViewClickHandler, callback, entry, redactAmbient, isNewView, remoteViewClickHandler, callback, entry,
publicLayout, publicLayout.getContractedChild(), runningInflations, publicLayout, publicLayout.getContractedChild(),
applyCallback); publicLayout.getVisibleWrapper(NotificationContentView.VISIBLE_TYPE_CONTRACTED),
runningInflations, applyCallback);
} }
flag = FLAG_REINFLATE_AMBIENT_VIEW; flag = FLAG_REINFLATE_AMBIENT_VIEW;
@@ -296,7 +301,8 @@ public class NotificationInflater {
}; };
applyRemoteView(result, reInflateFlags, flag, row, applyRemoteView(result, reInflateFlags, flag, row,
redactAmbient, isNewView, remoteViewClickHandler, callback, entry, redactAmbient, isNewView, remoteViewClickHandler, callback, entry,
newParent, newParent.getAmbientChild(), runningInflations, newParent, newParent.getAmbientChild(), newParent.getVisibleWrapper(
NotificationContentView.VISIBLE_TYPE_AMBIENT), runningInflations,
applyCallback); applyCallback);
} }
@@ -316,6 +322,7 @@ public class NotificationInflater {
RemoteViews.OnClickHandler remoteViewClickHandler, RemoteViews.OnClickHandler remoteViewClickHandler,
@Nullable final InflationCallback callback, NotificationData.Entry entry, @Nullable final InflationCallback callback, NotificationData.Entry entry,
NotificationContentView parentLayout, View existingView, NotificationContentView parentLayout, View existingView,
NotificationViewWrapper existingWrapper,
final HashMap<Integer, CancellationSignal> runningInflations, final HashMap<Integer, CancellationSignal> runningInflations,
ApplyCallback applyCallback) { ApplyCallback applyCallback) {
RemoteViews.OnViewAppliedListener listener RemoteViews.OnViewAppliedListener listener
@@ -326,6 +333,8 @@ public class NotificationInflater {
if (isNewView) { if (isNewView) {
v.setIsRootNamespace(true); v.setIsRootNamespace(true);
applyCallback.setResultView(v); applyCallback.setResultView(v);
} else if (existingWrapper != null) {
existingWrapper.onReinflated();
} }
runningInflations.remove(inflationId); runningInflations.remove(inflationId);
finishIfDone(result, reInflateFlags, runningInflations, callback, row, finishIfDone(result, reInflateFlags, runningInflations, callback, row,

View File

@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.notification; package com.android.systemui.statusbar.notification;
import android.content.Context; import android.content.Context;
import android.service.notification.StatusBarNotification;
import android.view.View; import android.view.View;
import com.android.systemui.statusbar.ExpandableNotificationRow; import com.android.systemui.statusbar.ExpandableNotificationRow;
@@ -40,11 +39,11 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
} }
@Override @Override
public void notifyContentUpdated(ExpandableNotificationRow row) { public void onContentUpdated(ExpandableNotificationRow row) {
// Reinspect the notification. Before the super call, because the super call also updates // Reinspect the notification. Before the super call, because the super call also updates
// the transformation types and we need to have our values set by then. // the transformation types and we need to have our values set by then.
resolveViews(); resolveViews();
super.notifyContentUpdated(row); super.onContentUpdated(row);
} }
@Override @Override

View File

@@ -70,11 +70,11 @@ public class NotificationMessagingTemplateViewWrapper extends NotificationTempla
} }
@Override @Override
public void notifyContentUpdated(ExpandableNotificationRow row) { public void onContentUpdated(ExpandableNotificationRow row) {
// Reinspect the notification. Before the super call, because the super call also updates // Reinspect the notification. Before the super call, because the super call also updates
// the transformation types and we need to have our values set by then. // the transformation types and we need to have our values set by then.
resolveViews(); resolveViews();
super.notifyContentUpdated(row); super.onContentUpdated(row);
} }
@Override @Override

View File

@@ -133,11 +133,11 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
} }
@Override @Override
public void notifyContentUpdated(ExpandableNotificationRow row) { public void onContentUpdated(ExpandableNotificationRow row) {
// Reinspect the notification. Before the super call, because the super call also updates // Reinspect the notification. Before the super call, because the super call also updates
// the transformation types and we need to have our values set by then. // the transformation types and we need to have our values set by then.
resolveTemplateViews(row.getStatusBarNotification()); resolveTemplateViews(row.getStatusBarNotification());
super.notifyContentUpdated(row); super.onContentUpdated(row);
} }
@Override @Override

View File

@@ -66,6 +66,7 @@ public abstract class NotificationViewWrapper implements TransformableView {
mView = view; mView = view;
mRow = row; mRow = row;
mDozer = createDozer(ctx); mDozer = createDozer(ctx);
onReinflated();
} }
protected NotificationDozeHelper createDozer(Context ctx) { protected NotificationDozeHelper createDozer(Context ctx) {
@@ -92,12 +93,15 @@ public abstract class NotificationViewWrapper implements TransformableView {
* Notifies this wrapper that the content of the view might have changed. * Notifies this wrapper that the content of the view might have changed.
* @param row the row this wrapper is attached to * @param row the row this wrapper is attached to
*/ */
public void notifyContentUpdated(ExpandableNotificationRow row) { public void onContentUpdated(ExpandableNotificationRow row) {
mDarkInitialized = false; mDarkInitialized = false;
Drawable background = mView.getBackground(); }
public void onReinflated() {
if (shouldClearBackgroundOnReapply()) { if (shouldClearBackgroundOnReapply()) {
mBackgroundColor = 0; mBackgroundColor = 0;
} }
Drawable background = mView.getBackground();
if (background instanceof ColorDrawable) { if (background instanceof ColorDrawable) {
mBackgroundColor = ((ColorDrawable) background).getColor(); mBackgroundColor = ((ColorDrawable) background).getColor();
mView.setBackground(null); mView.setBackground(null);

View File

@@ -297,7 +297,7 @@ public class NotificationChildrenContainer extends ViewGroup {
} else { } else {
header.reapply(getContext(), mNotificationHeader); header.reapply(getContext(), mNotificationHeader);
} }
mNotificationHeaderWrapper.notifyContentUpdated(mContainingNotification); mNotificationHeaderWrapper.onContentUpdated(mContainingNotification);
recreateLowPriorityHeader(builder); recreateLowPriorityHeader(builder);
recreateAmbientHeader(builder); recreateAmbientHeader(builder);
updateHeaderVisibility(false /* animate */); updateHeaderVisibility(false /* animate */);
@@ -316,14 +316,14 @@ public class NotificationChildrenContainer extends ViewGroup {
mNotificationHeaderAmbient = (ViewGroup) header.apply(getContext(), this); mNotificationHeaderAmbient = (ViewGroup) header.apply(getContext(), this);
mNotificationHeaderWrapperAmbient = NotificationViewWrapper.wrap(getContext(), mNotificationHeaderWrapperAmbient = NotificationViewWrapper.wrap(getContext(),
mNotificationHeaderAmbient, mContainingNotification); mNotificationHeaderAmbient, mContainingNotification);
mNotificationHeaderWrapperAmbient.notifyContentUpdated(mContainingNotification); mNotificationHeaderWrapperAmbient.onContentUpdated(mContainingNotification);
addView(mNotificationHeaderAmbient, 0); addView(mNotificationHeaderAmbient, 0);
invalidate(); invalidate();
} else { } else {
header.reapply(getContext(), mNotificationHeaderAmbient); header.reapply(getContext(), mNotificationHeaderAmbient);
} }
resetHeaderVisibilityIfNeeded(mNotificationHeaderAmbient, calculateDesiredHeader()); resetHeaderVisibilityIfNeeded(mNotificationHeaderAmbient, calculateDesiredHeader());
mNotificationHeaderWrapperAmbient.notifyContentUpdated(mContainingNotification); mNotificationHeaderWrapperAmbient.onContentUpdated(mContainingNotification);
} }
/** /**
@@ -354,7 +354,7 @@ public class NotificationChildrenContainer extends ViewGroup {
} else { } else {
header.reapply(getContext(), mNotificationHeaderLowPriority); header.reapply(getContext(), mNotificationHeaderLowPriority);
} }
mNotificationHeaderWrapperLowPriority.notifyContentUpdated(mContainingNotification); mNotificationHeaderWrapperLowPriority.onContentUpdated(mContainingNotification);
resetHeaderVisibilityIfNeeded(mNotificationHeaderLowPriority, calculateDesiredHeader()); resetHeaderVisibilityIfNeeded(mNotificationHeaderLowPriority, calculateDesiredHeader());
} else { } else {
removeView(mNotificationHeaderLowPriority); removeView(mNotificationHeaderLowPriority);

View File

@@ -53,11 +53,14 @@ public class NotificationCustomViewWrapperTest extends SysuiTestCase {
RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.custom_view_dark); RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.custom_view_dark);
View v = views.apply(mContext, null); View v = views.apply(mContext, null);
NotificationViewWrapper wrap = NotificationCustomViewWrapper.wrap(mContext, v, mRow); NotificationViewWrapper wrap = NotificationCustomViewWrapper.wrap(mContext, v, mRow);
wrap.notifyContentUpdated(mRow); wrap.onContentUpdated(mRow);
Assert.assertTrue(wrap.getCustomBackgroundColor() != 0); Assert.assertTrue("No background set, when applying custom background view",
wrap.getCustomBackgroundColor() != 0);
views.reapply(mContext, v); views.reapply(mContext, v);
wrap.notifyContentUpdated(mRow); wrap.onReinflated();
Assert.assertTrue(wrap.getCustomBackgroundColor() != 0); wrap.onContentUpdated(mRow);
Assert.assertTrue("Reapplying a custom remote view lost it's background!",
wrap.getCustomBackgroundColor() != 0);
} }
} }

View File

@@ -24,6 +24,7 @@ import android.view.View;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.ExpandableNotificationRow; import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -35,7 +36,9 @@ public class NotificationViewWrapperTest extends SysuiTestCase {
@Test @Test
public void constructor_doesntUseViewContext() throws Exception { public void constructor_doesntUseViewContext() throws Exception {
new TestableNotificationViewWrapper(mContext, null /* view */, null /* row */); new TestableNotificationViewWrapper(mContext,
new View(mContext),
new NotificationTestHelper(getContext()).createRow());
} }
static class TestableNotificationViewWrapper extends NotificationViewWrapper { static class TestableNotificationViewWrapper extends NotificationViewWrapper {