Merge "Removing unused invert helpers" into pi-dev

am: 25185596cf

Change-Id: I2eddd097a0173983a9d5e15b2be8c53947f2d6cb
This commit is contained in:
Selim Cinek
2018-05-16 18:32:34 -07:00
committed by android-build-merger
9 changed files with 2 additions and 365 deletions

View File

@@ -1,126 +0,0 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.systemui;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.view.View;
import java.util.ArrayList;
/**
* Helper to invert the colors of views and fade between the states.
*/
public class ViewInvertHelper {
private final Paint mDarkPaint = new Paint();
private final ColorMatrix mMatrix = new ColorMatrix();
private final ColorMatrix mGrayscaleMatrix = new ColorMatrix();
private final long mFadeDuration;
private final ArrayList<View> mTargets = new ArrayList<>();
public ViewInvertHelper(View v, long fadeDuration) {
this(v.getContext(), fadeDuration);
addTarget(v);
}
public ViewInvertHelper(Context context, long fadeDuration) {
mFadeDuration = fadeDuration;
}
private static ArrayList<View> constructArray(View target) {
final ArrayList<View> views = new ArrayList<>();
views.add(target);
return views;
}
public void clearTargets() {
mTargets.clear();
}
public void addTarget(View target) {
mTargets.add(target);
}
public void fade(final boolean invert, long delay) {
float startIntensity = invert ? 0f : 1f;
float endIntensity = invert ? 1f : 0f;
ValueAnimator animator = ValueAnimator.ofFloat(startIntensity, endIntensity);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
updateInvertPaint((Float) animation.getAnimatedValue());
for (int i = 0; i < mTargets.size(); i++) {
mTargets.get(i).setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
}
}
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (!invert) {
for (int i = 0; i < mTargets.size(); i++) {
mTargets.get(i).setLayerType(View.LAYER_TYPE_NONE, null);
}
}
}
});
animator.setDuration(mFadeDuration);
animator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
animator.setStartDelay(delay);
animator.start();
}
public void update(boolean invert) {
if (invert) {
updateInvertPaint(1f);
for (int i = 0; i < mTargets.size(); i++) {
mTargets.get(i).setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
}
} else {
for (int i = 0; i < mTargets.size(); i++) {
mTargets.get(i).setLayerType(View.LAYER_TYPE_NONE, null);
}
}
}
private void updateInvertPaint(float intensity) {
float components = 1 - 2 * intensity;
final float[] invert = {
components, 0f, 0f, 0f, 255f * intensity,
0f, components, 0f, 0f, 255f * intensity,
0f, 0f, components, 0f, 255f * intensity,
0f, 0f, 0f, 1f, 0f
};
mMatrix.set(invert);
mGrayscaleMatrix.setSaturation(1 - intensity);
mMatrix.preConcat(mGrayscaleMatrix);
mDarkPaint.setColorFilter(new ColorMatrixColorFilter(mMatrix));
}
public void setInverted(boolean invert, boolean fade, long delay) {
if (fade) {
fade(invert, delay);
} else {
update(invert);
}
}
}

View File

@@ -422,7 +422,6 @@ public class NotificationContentView extends FrameLayout {
mContractedChild = child;
mContractedWrapper = NotificationViewWrapper.wrap(getContext(), child,
mContainingNotification);
mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */);
}
private NotificationViewWrapper getWrapperForView(View child) {
@@ -1106,18 +1105,6 @@ public class NotificationContentView extends FrameLayout {
return;
}
mDark = dark;
if (mVisibleType == VISIBLE_TYPE_CONTRACTED || !dark) {
mContractedWrapper.setDark(dark, fade, delay);
}
if (mVisibleType == VISIBLE_TYPE_EXPANDED || (mExpandedChild != null && !dark)) {
mExpandedWrapper.setDark(dark, fade, delay);
}
if (mVisibleType == VISIBLE_TYPE_HEADSUP || (mHeadsUpChild != null && !dark)) {
mHeadsUpWrapper.setDark(dark, fade, delay);
}
if (mSingleLineView != null && (mVisibleType == VISIBLE_TYPE_SINGLELINE || !dark)) {
mSingleLineView.setDark(dark, fade, delay);
}
selectLayout(!dark && fade /* animate */, false /* force */);
}

View File

@@ -33,10 +33,8 @@ import android.view.accessibility.AccessibilityNodeInfo;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.phone.NotificationIconContainer;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import com.android.systemui.statusbar.stack.AmbientState;
import com.android.systemui.statusbar.stack.AnimationProperties;
import com.android.systemui.statusbar.stack.ExpandableViewState;
@@ -60,7 +58,6 @@ public class NotificationShelf extends ActivatableNotificationView implements
private static final String TAG = "NotificationShelf";
private static final long SHELF_IN_TRANSLATION_DURATION = 200;
private ViewInvertHelper mViewInvertHelper;
private boolean mDark;
private NotificationIconContainer mShelfIcons;
private ShelfState mShelfState;
@@ -105,8 +102,6 @@ public class NotificationShelf extends ActivatableNotificationView implements
setClipChildren(false);
setClipToPadding(false);
mShelfIcons.setIsStaticLayout(false);
mViewInvertHelper = new ViewInvertHelper(mShelfIcons,
NotificationPanelView.DOZE_ANIMATION_DURATION);
mShelfState = new ShelfState();
setBottomRoundness(1.0f, false /* animate */);
initDimens();

View File

@@ -25,11 +25,9 @@ import android.widget.TextView;
import com.android.keyguard.AlphaOptimizedLinearLayout;
import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.CrossFadeHelper;
import com.android.systemui.statusbar.TransformableView;
import com.android.systemui.statusbar.ViewTransformationHelper;
import com.android.systemui.statusbar.phone.NotificationPanelView;
/**
* A hybrid view which may contain information about one ore more notifications.
@@ -41,7 +39,6 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout
protected TextView mTitleView;
protected TextView mTextView;
private ViewInvertHelper mInvertHelper;
public HybridNotificationView(Context context) {
this(context, null);
@@ -73,7 +70,6 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout
super.onFinishInflate();
mTitleView = (TextView) findViewById(R.id.notification_title);
mTextView = (TextView) findViewById(R.id.notification_text);
mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION);
mTransformationHelper = new ViewTransformationHelper();
mTransformationHelper.setCustomTransformation(
new ViewTransformationHelper.CustomTransformation() {
@@ -126,10 +122,6 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout
requestLayout();
}
public void setDark(boolean dark, boolean fade, long delay) {
mInvertHelper.setInverted(dark, fade, delay);
}
@Override
public TransformState getCurrentState(int fadingView) {
return mTransformationHelper.getCurrentState(fadingView);

View File

@@ -16,81 +16,25 @@
package com.android.systemui.statusbar.notification;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.view.View;
import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.phone.NotificationPanelView;
/**
* Wraps a notification containing a custom view.
*/
public class NotificationCustomViewWrapper extends NotificationViewWrapper {
private final ViewInvertHelper mInvertHelper;
private final Paint mGreyPaint = new Paint();
private boolean mIsLegacy;
private int mLegacyColor;
protected NotificationCustomViewWrapper(Context ctx, View view, ExpandableNotificationRow row) {
super(ctx, view, row);
mInvertHelper = new ViewInvertHelper(view, NotificationPanelView.DOZE_ANIMATION_DURATION);
mLegacyColor = row.getContext().getColor(R.color.notification_legacy_background_color);
}
@Override
public void setDark(boolean dark, boolean fade, long delay) {
if (dark == mDark && mDarkInitialized) {
return;
}
super.setDark(dark, fade, delay);
if (!mIsLegacy && mShouldInvertDark) {
if (fade) {
mInvertHelper.fade(dark, delay);
} else {
mInvertHelper.update(dark);
}
} else {
mView.setLayerType(dark ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
if (fade) {
fadeGrayscale(dark, delay);
} else {
updateGrayscale(dark);
}
}
}
protected void fadeGrayscale(final boolean dark, long delay) {
getDozer().startIntensityAnimation(animation -> {
getDozer().updateGrayscaleMatrix((float) animation.getAnimatedValue());
mGreyPaint.setColorFilter(
new ColorMatrixColorFilter(getDozer().getGrayscaleColorMatrix()));
mView.setLayerPaint(mGreyPaint);
}, dark, delay, new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (!dark) {
mView.setLayerType(View.LAYER_TYPE_NONE, null);
}
}
});
}
protected void updateGrayscale(boolean dark) {
if (dark) {
getDozer().updateGrayscaleMatrix(1f);
mGreyPaint.setColorFilter(
new ColorMatrixColorFilter(getDozer().getGrayscaleColorMatrix()));
mView.setLayerPaint(mGreyPaint);
}
}
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);

View File

@@ -16,10 +16,10 @@
package com.android.systemui.statusbar.notification;
import static com.android.systemui.statusbar.notification.TransformState.TRANSFORM_Y;
import android.app.Notification;
import android.content.Context;
import android.graphics.ColorFilter;
import android.graphics.PorterDuffColorFilter;
import android.util.ArraySet;
import android.view.NotificationHeaderView;
import android.view.View;
@@ -32,16 +32,12 @@ import android.widget.TextView;
import com.android.internal.widget.NotificationExpandButton;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.TransformableView;
import com.android.systemui.statusbar.ViewTransformationHelper;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import java.util.Stack;
import static com.android.systemui.statusbar.notification.TransformState.TRANSFORM_Y;
/**
* Wraps a notification header view.
*/
@@ -50,7 +46,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
private static final Interpolator LOW_PRIORITY_HEADER_CLOSE
= new PathInterpolator(0.4f, 0f, 0.7f, 1f);
protected final ViewInvertHelper mInvertHelper;
protected final ViewTransformationHelper mTransformationHelper;
private final int mTranslationForHeader;
@@ -70,7 +65,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
super(ctx, view, row);
mShowExpandButtonAtEnd = ctx.getResources().getBoolean(
R.bool.config_showNotificationExpandButtonAtEnd);
mInvertHelper = new ViewInvertHelper(ctx, NotificationPanelView.DOZE_ANIMATION_DURATION);
mTransformationHelper = new ViewTransformationHelper();
// we want to avoid that the header clashes with the other text when transforming
@@ -99,7 +93,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
}
}, TRANSFORMING_VIEW_TITLE);
resolveHeaderViews();
updateInvertHelper();
addAppOpsOnClickListener(row);
mTranslationForHeader = ctx.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.notification_content_margin)
@@ -107,16 +100,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
com.android.internal.R.dimen.notification_content_margin_top);
}
@Override
protected NotificationDozeHelper createDozer(Context ctx) {
return new NotificationIconDozeHelper(ctx);
}
@Override
protected NotificationIconDozeHelper getDozer() {
return (NotificationIconDozeHelper) super.getDozer();
}
protected void resolveHeaderViews() {
mIcon = mView.findViewById(com.android.internal.R.id.icon);
mHeaderText = mView.findViewById(com.android.internal.R.id.header_text);
@@ -125,7 +108,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
mNotificationHeader = mView.findViewById(com.android.internal.R.id.notification_header);
mNotificationHeader.setShowExpandButtonAtEnd(mShowExpandButtonAtEnd);
mColor = mNotificationHeader.getOriginalIconColor();
getDozer().setColor(mColor);
}
private void addAppOpsOnClickListener(ExpandableNotificationRow row) {
@@ -141,7 +123,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
// Reinspect the notification.
resolveHeaderViews();
updateInvertHelper();
updateTransformedTypes();
addRemainingTransformTypes();
updateCropToPaddingForImageViews();
@@ -192,16 +173,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
}
}
protected void updateInvertHelper() {
mInvertHelper.clearTargets();
for (int i = 0; i < mNotificationHeader.getChildCount(); i++) {
View child = mNotificationHeader.getChildAt(i);
if (child != mIcon) {
mInvertHelper.addTarget(child);
}
}
}
protected void updateTransformedTypes() {
mTransformationHelper.reset();
mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_ICON, mIcon);
@@ -211,27 +182,6 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
}
}
@Override
public void setDark(boolean dark, boolean fade, long delay) {
if (dark == mDark && mDarkInitialized) {
return;
}
super.setDark(dark, fade, delay);
if (fade) {
mInvertHelper.fade(dark, delay);
} else {
mInvertHelper.update(dark);
}
if (mIcon != null && !mRow.isChildInGroup()) {
// We don't update the color for children views / their icon is invisible anyway.
// It also may lead to bugs where the icon isn't correctly greyed out.
boolean hadColorFilter = mNotificationHeader.getOriginalIconColor()
!= NotificationHeaderView.NO_COLOR;
getDozer().setImageDark(mIcon, dark, fade, delay, !hadColorFilter);
}
}
@Override
public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {
mExpandButton.setVisibility(expandable ? View.VISIBLE : View.GONE);

View File

@@ -45,8 +45,6 @@ import com.android.systemui.statusbar.ViewTransformationHelper;
*/
public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapper {
private static final int mDarkProgressTint = 0xffffffff;
protected ImageView mPicture;
private ProgressBar mProgressBar;
private TextView mTitle;
@@ -274,15 +272,6 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
super.onContentUpdated(row);
}
@Override
protected void updateInvertHelper() {
super.updateInvertHelper();
View mainColumn = mView.findViewById(com.android.internal.R.id.notification_main_column);
if (mainColumn != null) {
mInvertHelper.addTarget(mainColumn);
}
}
@Override
protected void updateTransformedTypes() {
// This also clears the existing types
@@ -305,65 +294,6 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
}
}
@Override
public void setDark(boolean dark, boolean fade, long delay) {
if (dark == mDark && mDarkInitialized) {
return;
}
super.setDark(dark, fade, delay);
setPictureDark(dark, fade, delay);
setProgressBarDark(dark, fade, delay);
}
private void setProgressBarDark(boolean dark, boolean fade, long delay) {
if (mProgressBar != null) {
if (fade) {
fadeProgressDark(mProgressBar, dark, delay);
} else {
updateProgressDark(mProgressBar, dark);
}
}
}
private void fadeProgressDark(final ProgressBar target, final boolean dark, long delay) {
getDozer().startIntensityAnimation(animation -> {
float t = (float) animation.getAnimatedValue();
updateProgressDark(target, t);
}, dark, delay, null /* listener */);
}
private void updateProgressDark(ProgressBar target, float intensity) {
int color = interpolateColor(mColor, mDarkProgressTint, intensity);
target.getIndeterminateDrawable().mutate().setTint(color);
target.getProgressDrawable().mutate().setTint(color);
}
private void updateProgressDark(ProgressBar target, boolean dark) {
updateProgressDark(target, dark ? 1f : 0f);
}
private void setPictureDark(boolean dark, boolean fade, long delay) {
if (mPicture != null) {
getDozer().setImageDark(mPicture, dark, fade, delay, true /* useGrayscale */);
}
}
private static int interpolateColor(int source, int target, float t) {
int aSource = Color.alpha(source);
int rSource = Color.red(source);
int gSource = Color.green(source);
int bSource = Color.blue(source);
int aTarget = Color.alpha(target);
int rTarget = Color.red(target);
int gTarget = Color.green(target);
int bTarget = Color.blue(target);
return Color.argb(
(int) (aSource * (1f - t) + aTarget * t),
(int) (rSource * (1f - t) + rTarget * t),
(int) (gSource * (1f - t) + gTarget * t),
(int) (bSource * (1f - t) + bTarget * t));
}
@Override
public void setContentHeight(int contentHeight, int minHeightHint) {
super.setContentHeight(contentHeight, minHeightHint);

View File

@@ -17,10 +17,8 @@
package com.android.systemui.statusbar.notification;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.ColorUtils;
import android.view.NotificationHeaderView;
import android.view.View;
@@ -36,12 +34,8 @@ public abstract class NotificationViewWrapper implements TransformableView {
protected final View mView;
protected final ExpandableNotificationRow mRow;
private final NotificationDozeHelper mDozer;
protected boolean mDark;
private int mBackgroundColor = 0;
protected boolean mShouldInvertDark;
protected boolean mDarkInitialized = false;
public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) {
if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {
@@ -65,36 +59,14 @@ public abstract class NotificationViewWrapper implements TransformableView {
protected NotificationViewWrapper(Context ctx, View view, ExpandableNotificationRow row) {
mView = view;
mRow = row;
mDozer = createDozer(ctx);
onReinflated();
}
protected NotificationDozeHelper createDozer(Context ctx) {
return new NotificationDozeHelper();
}
protected NotificationDozeHelper getDozer() {
return mDozer;
}
/**
* In dark mode, we draw as little as possible, assuming a black background.
*
* @param dark whether we should display ourselves in dark mode
* @param fade whether to animate the transition if the mode changes
* @param delay if fading, the delay of the animation
*/
public void setDark(boolean dark, boolean fade, long delay) {
mDark = dark;
mDarkInitialized = true;
}
/**
* Notifies this wrapper that the content of the view might have changed.
* @param row the row this wrapper is attached to
*/
public void onContentUpdated(ExpandableNotificationRow row) {
mDarkInitialized = false;
}
public void onReinflated() {
@@ -106,18 +78,12 @@ public abstract class NotificationViewWrapper implements TransformableView {
mBackgroundColor = ((ColorDrawable) background).getColor();
mView.setBackground(null);
}
mShouldInvertDark = mBackgroundColor == 0 || isColorLight(mBackgroundColor);
}
protected boolean shouldClearBackgroundOnReapply() {
return true;
}
private boolean isColorLight(int backgroundColor) {
return Color.alpha(backgroundColor) == 0
|| ColorUtils.calculateLuminance(backgroundColor) > 0.5;
}
/**
* Update the appearance of the expand button.
*

View File

@@ -1168,7 +1168,6 @@ public class NotificationChildrenContainer extends ViewGroup {
if (mOverflowNumber != null) {
mHybridGroupManager.setOverflowNumberDark(mOverflowNumber, dark, fade, delay);
}
mNotificationHeaderWrapper.setDark(dark, fade, delay);
}
public void reInflateViews(OnClickListener listener, StatusBarNotification notification) {