Unifying and maintaining the text-alpha and text visibility property
Bug: 76228194 Change-Id: I70be5f9fd22c53864a9a0308f256baa7dc1f3ab7
This commit is contained in:
@@ -65,27 +65,6 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|
|||||||
|
|
||||||
private static final int[] STATE_PRESSED = new int[] {android.R.attr.state_pressed};
|
private static final int[] STATE_PRESSED = new int[] {android.R.attr.state_pressed};
|
||||||
|
|
||||||
private final BaseDraggingActivity mActivity;
|
|
||||||
private Drawable mIcon;
|
|
||||||
private final boolean mCenterVertically;
|
|
||||||
|
|
||||||
private final CheckLongPressHelper mLongPressHelper;
|
|
||||||
private final StylusEventHelper mStylusEventHelper;
|
|
||||||
private final float mSlop;
|
|
||||||
|
|
||||||
private final boolean mLayoutHorizontal;
|
|
||||||
private final int mIconSize;
|
|
||||||
@ViewDebug.ExportedProperty(category = "launcher")
|
|
||||||
private int mTextColor;
|
|
||||||
private boolean mIsIconVisible = true;
|
|
||||||
|
|
||||||
private BadgeInfo mBadgeInfo;
|
|
||||||
private BadgeRenderer mBadgeRenderer;
|
|
||||||
private int mBadgeColor;
|
|
||||||
private float mBadgeScale;
|
|
||||||
private boolean mForceHideBadge;
|
|
||||||
private Point mTempSpaceForBadgeOffset = new Point();
|
|
||||||
private Rect mTempIconBounds = new Rect();
|
|
||||||
|
|
||||||
private static final Property<BubbleTextView, Float> BADGE_SCALE_PROPERTY
|
private static final Property<BubbleTextView, Float> BADGE_SCALE_PROPERTY
|
||||||
= new Property<BubbleTextView, Float>(Float.TYPE, "badgeScale") {
|
= new Property<BubbleTextView, Float>(Float.TYPE, "badgeScale") {
|
||||||
@@ -101,19 +80,45 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final Property<BubbleTextView, Integer> TEXT_ALPHA_PROPERTY
|
public static final Property<BubbleTextView, Float> TEXT_ALPHA_PROPERTY
|
||||||
= new Property<BubbleTextView, Integer>(Integer.class, "textAlpha") {
|
= new Property<BubbleTextView, Float>(Float.class, "textAlpha") {
|
||||||
@Override
|
@Override
|
||||||
public Integer get(BubbleTextView bubbleTextView) {
|
public Float get(BubbleTextView bubbleTextView) {
|
||||||
return bubbleTextView.getTextAlpha();
|
return bubbleTextView.mTextAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(BubbleTextView bubbleTextView, Integer alpha) {
|
public void set(BubbleTextView bubbleTextView, Float alpha) {
|
||||||
bubbleTextView.setTextAlpha(alpha);
|
bubbleTextView.setTextAlpha(alpha);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final BaseDraggingActivity mActivity;
|
||||||
|
private Drawable mIcon;
|
||||||
|
private final boolean mCenterVertically;
|
||||||
|
|
||||||
|
private final CheckLongPressHelper mLongPressHelper;
|
||||||
|
private final StylusEventHelper mStylusEventHelper;
|
||||||
|
private final float mSlop;
|
||||||
|
|
||||||
|
private final boolean mLayoutHorizontal;
|
||||||
|
private final int mIconSize;
|
||||||
|
|
||||||
|
@ViewDebug.ExportedProperty(category = "launcher")
|
||||||
|
private boolean mIsIconVisible = true;
|
||||||
|
@ViewDebug.ExportedProperty(category = "launcher")
|
||||||
|
private int mTextColor;
|
||||||
|
@ViewDebug.ExportedProperty(category = "launcher")
|
||||||
|
private float mTextAlpha = 1;
|
||||||
|
|
||||||
|
private BadgeInfo mBadgeInfo;
|
||||||
|
private BadgeRenderer mBadgeRenderer;
|
||||||
|
private int mBadgeColor;
|
||||||
|
private float mBadgeScale;
|
||||||
|
private boolean mForceHideBadge;
|
||||||
|
private Point mTempSpaceForBadgeOffset = new Point();
|
||||||
|
private Rect mTempIconBounds = new Rect();
|
||||||
|
|
||||||
@ViewDebug.ExportedProperty(category = "launcher")
|
@ViewDebug.ExportedProperty(category = "launcher")
|
||||||
private boolean mStayPressed;
|
private boolean mStayPressed;
|
||||||
@ViewDebug.ExportedProperty(category = "launcher")
|
@ViewDebug.ExportedProperty(category = "launcher")
|
||||||
@@ -166,7 +171,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|
|||||||
|
|
||||||
setEllipsize(TruncateAt.END);
|
setEllipsize(TruncateAt.END);
|
||||||
setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
|
setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
|
||||||
|
setTextAlpha(1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -404,13 +409,17 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|
|||||||
@Override
|
@Override
|
||||||
public void setTextColor(int color) {
|
public void setTextColor(int color) {
|
||||||
mTextColor = color;
|
mTextColor = color;
|
||||||
super.setTextColor(color);
|
super.setTextColor(getModifiedColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTextColor(ColorStateList colors) {
|
public void setTextColor(ColorStateList colors) {
|
||||||
mTextColor = colors.getDefaultColor();
|
mTextColor = colors.getDefaultColor();
|
||||||
super.setTextColor(colors);
|
if (Float.compare(mTextAlpha, 1) == 0) {
|
||||||
|
super.setTextColor(colors);
|
||||||
|
} else {
|
||||||
|
super.setTextColor(getModifiedColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldTextBeVisible() {
|
public boolean shouldTextBeVisible() {
|
||||||
@@ -421,19 +430,21 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTextVisibility(boolean visible) {
|
public void setTextVisibility(boolean visible) {
|
||||||
if (visible) {
|
setTextAlpha(visible ? 1 : 0);
|
||||||
super.setTextColor(mTextColor);
|
}
|
||||||
} else {
|
|
||||||
setTextAlpha(0);
|
private void setTextAlpha(float alpha) {
|
||||||
|
mTextAlpha = alpha;
|
||||||
|
super.setTextColor(getModifiedColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getModifiedColor() {
|
||||||
|
if (mTextAlpha == 0) {
|
||||||
|
// Special case to prevent text shadows in high contrast mode
|
||||||
|
return Color.TRANSPARENT;
|
||||||
}
|
}
|
||||||
}
|
return ColorUtils.setAlphaComponent(
|
||||||
|
mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
|
||||||
public void setTextAlpha(int alpha) {
|
|
||||||
super.setTextColor(ColorUtils.setAlphaComponent(mTextColor, alpha));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getTextAlpha() {
|
|
||||||
return Color.alpha(getCurrentTextColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -441,8 +452,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|
|||||||
* @param fadeIn Whether the text should fade in or fade out.
|
* @param fadeIn Whether the text should fade in or fade out.
|
||||||
*/
|
*/
|
||||||
public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
|
public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
|
||||||
int toAlpha = shouldTextBeVisible() && fadeIn ? Color.alpha(mTextColor) : 0;
|
float toAlpha = shouldTextBeVisible() && fadeIn ? 1 : 0;
|
||||||
return ObjectAnimator.ofInt(this, TEXT_ALPHA_PROPERTY, toAlpha);
|
return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, toAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.launcher3.folder;
|
package com.android.launcher3.folder;
|
||||||
|
|
||||||
|
import static com.android.launcher3.BubbleTextView.TEXT_ALPHA_PROPERTY;
|
||||||
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
||||||
import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
|
import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
|
||||||
|
|
||||||
@@ -172,9 +173,8 @@ public class FolderAnimationManager {
|
|||||||
AnimatorSet a = LauncherAnimUtils.createAnimatorSet();
|
AnimatorSet a = LauncherAnimUtils.createAnimatorSet();
|
||||||
|
|
||||||
// Initialize the Folder items' text.
|
// Initialize the Folder items' text.
|
||||||
PropertyResetListener colorResetListener = new PropertyResetListener<>(
|
PropertyResetListener colorResetListener =
|
||||||
BubbleTextView.TEXT_ALPHA_PROPERTY,
|
new PropertyResetListener<>(TEXT_ALPHA_PROPERTY, 1f);
|
||||||
Color.alpha(Themes.getAttrColor(mContext, android.R.attr.textColorSecondary)));
|
|
||||||
for (BubbleTextView icon : mFolder.getItemsOnPage(mFolder.mContent.getCurrentPage())) {
|
for (BubbleTextView icon : mFolder.getItemsOnPage(mFolder.mContent.getCurrentPage())) {
|
||||||
if (mIsOpening) {
|
if (mIsOpening) {
|
||||||
icon.setTextVisibility(false);
|
icon.setTextVisibility(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user