package com.android.launcher3;
+import android.animation.ObjectAnimator;
+import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
+import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
private static int DRAG_VIEW_DROP_DURATION = 285;
- protected final int mTransitionDuration;
-
protected Launcher mLauncher;
private int mBottomDragPadding;
protected TextView mText;
protected ColorStateList mOriginalTextColor;
protected TransitionDrawable mDrawable;
+ private ObjectAnimator mCurrentColorAnim;
+
public ButtonDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
-
- Resources r = getResources();
- mTransitionDuration = r.getInteger(R.integer.config_dropTargetBgTransitionDuration);
- mBottomDragPadding = r.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
+ mBottomDragPadding = getResources().getDimensionPixelSize(R.dimen.drop_target_drag_padding);
}
@Override
@Override
public final void onDragEnter(DragObject d) {
d.dragView.setColor(mHoverColor);
- mDrawable.startTransition(mTransitionDuration);
- setTextColor(mHoverColor);
+ if (Utilities.isLmpOrAbove()) {
+ mDrawable.startTransition(DragView.COLOR_CHANGE_DURATION);
+ animateTextColor(mHoverColor);
+ } else {
+ mDrawable.startTransition(0);
+ setTextColor(mHoverColor);
+ }
}
@Override
}
protected void resetHoverColor() {
- mDrawable.resetTransition();
- setTextColor(mOriginalTextColor);
+ if (Utilities.isLmpOrAbove()) {
+ mDrawable.reverseTransition(DragView.COLOR_CHANGE_DURATION);
+ animateTextColor(mOriginalTextColor.getDefaultColor());
+ } else {
+ mDrawable.resetTransition();
+ setTextColor(mOriginalTextColor);
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ private void animateTextColor(int targetColor) {
+ if (mCurrentColorAnim != null) {
+ mCurrentColorAnim.cancel();
+ }
+ mCurrentColorAnim = ObjectAnimator.ofArgb(this, "textColor", targetColor);
+ mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);
+ mCurrentColorAnim.start();
}
@Override
public final void onDragStart(DragSource source, Object info, int dragAction) {
mActive = supportsDrop(source, info);
mDrawable.resetTransition();
+ if (mCurrentColorAnim != null) {
+ mCurrentColorAnim.cancel();
+ mCurrentColorAnim = null;
+ }
setTextColor(mOriginalTextColor);
((ViewGroup) getParent()).setVisibility(mActive ? View.VISIBLE : View.GONE);
}
LauncherAppState.getInstance().getAccessibilityDelegate()
.handleAccessibleDrop(this, null, getAccessibilityDropConfirmation());
}
+
+ public int getTextColor() {
+ return getTextColors().getDefaultColor();
+ }
}
package com.android.launcher3;
+import android.animation.FloatArrayEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.annotation.TargetApi;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Point;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
+import android.os.Build;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import com.android.launcher3.util.Thunk;
+import java.util.Arrays;
+
public class DragView extends View {
+ public static int COLOR_CHANGE_DURATION = 200;
+
@Thunk static float sDragAlpha = 1f;
private Bitmap mBitmap;
// size. This is ignored for non-icons.
private float mIntrinsicIconScale = 1f;
+ private float[] mCurrentFilter;
+ private ValueAnimator mFilterAnimator;
+
/**
* Construct the drag view.
* <p>
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
}
if (color != 0) {
- mPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
+ ColorMatrix m1 = new ColorMatrix();
+ m1.setSaturation(0);
+
+ ColorMatrix m2 = new ColorMatrix();
+ m2.setScale(Color.red(color) / 255f, Color.green(color) / 255f,
+ Color.blue(color) / 255f, Color.alpha(color) / 255f);
+ m1.postConcat(m2);
+
+ if (Utilities.isLmpOrAbove()) {
+ animateFilterTo(m1.getArray());
+ } else {
+ mPaint.setColorFilter(new ColorMatrixColorFilter(m1));
+ invalidate();
+ }
} else {
- mPaint.setColorFilter(null);
+ if (!Utilities.isLmpOrAbove() || mCurrentFilter == null) {
+ mPaint.setColorFilter(null);
+ invalidate();
+ } else {
+ animateFilterTo(new ColorMatrix().getArray());
+ }
}
- invalidate();
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ private void animateFilterTo(float[] targetFilter) {
+ float[] oldFilter = mCurrentFilter == null ? new ColorMatrix().getArray() : mCurrentFilter;
+ mCurrentFilter = Arrays.copyOf(oldFilter, oldFilter.length);
+
+ if (mFilterAnimator != null) {
+ mFilterAnimator.cancel();
+ }
+ mFilterAnimator = ValueAnimator.ofObject(new FloatArrayEvaluator(mCurrentFilter),
+ oldFilter, targetFilter);
+ mFilterAnimator.setDuration(COLOR_CHANGE_DURATION);
+ mFilterAnimator.addUpdateListener(new AnimatorUpdateListener() {
+
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
+ invalidate();
+ }
+ });
+ mFilterAnimator.start();
}
public boolean hasDrawn() {
}
}
}
-