ADD week 5
This commit is contained in:
@ -0,0 +1,882 @@
|
||||
package com.google.android.material.badge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import com.google.android.material.R;
|
||||
import com.google.android.material.animation.AnimationUtils;
|
||||
import com.google.android.material.badge.BadgeState;
|
||||
import com.google.android.material.internal.TextDrawableHelper;
|
||||
import com.google.android.material.internal.ThemeEnforcement;
|
||||
import com.google.android.material.resources.MaterialResources;
|
||||
import com.google.android.material.resources.TextAppearance;
|
||||
import com.google.android.material.shape.MaterialShapeDrawable;
|
||||
import com.google.android.material.shape.ShapeAppearanceModel;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BadgeDrawable extends Drawable implements TextDrawableHelper.TextDrawableDelegate {
|
||||
public static final int BADGE_CONTENT_NOT_TRUNCATED = -2;
|
||||
static final int BADGE_RADIUS_NOT_SPECIFIED = -1;
|
||||
|
||||
@Deprecated
|
||||
public static final int BOTTOM_END = 8388693;
|
||||
|
||||
@Deprecated
|
||||
public static final int BOTTOM_START = 8388691;
|
||||
static final String DEFAULT_EXCEED_MAX_BADGE_NUMBER_SUFFIX = "+";
|
||||
static final String DEFAULT_EXCEED_MAX_BADGE_TEXT_SUFFIX = "…";
|
||||
private static final int DEFAULT_STYLE = R.style.Widget_MaterialComponents_Badge;
|
||||
private static final int DEFAULT_THEME_ATTR = R.attr.badgeStyle;
|
||||
private static final float FONT_SCALE_THRESHOLD = 0.3f;
|
||||
static final int OFFSET_ALIGNMENT_MODE_EDGE = 0;
|
||||
static final int OFFSET_ALIGNMENT_MODE_LEGACY = 1;
|
||||
private static final String TAG = "Badge";
|
||||
public static final int TOP_END = 8388661;
|
||||
public static final int TOP_START = 8388659;
|
||||
private WeakReference<View> anchorViewRef;
|
||||
private final Rect badgeBounds;
|
||||
private float badgeCenterX;
|
||||
private float badgeCenterY;
|
||||
private final WeakReference<Context> contextRef;
|
||||
private float cornerRadius;
|
||||
private WeakReference<FrameLayout> customBadgeParentRef;
|
||||
private float halfBadgeHeight;
|
||||
private float halfBadgeWidth;
|
||||
private int maxBadgeNumber;
|
||||
private final MaterialShapeDrawable shapeDrawable;
|
||||
private final BadgeState state;
|
||||
private final TextDrawableHelper textDrawableHelper;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface BadgeGravity {
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public int getOpacity() {
|
||||
return -3;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public boolean isStateful() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setColorFilter(ColorFilter colorFilter) {
|
||||
}
|
||||
|
||||
BadgeState.State getSavedState() {
|
||||
return this.state.getOverridingState();
|
||||
}
|
||||
|
||||
static BadgeDrawable createFromSavedState(Context context, BadgeState.State state) {
|
||||
return new BadgeDrawable(context, 0, DEFAULT_THEME_ATTR, DEFAULT_STYLE, state);
|
||||
}
|
||||
|
||||
public static BadgeDrawable create(Context context) {
|
||||
return new BadgeDrawable(context, 0, DEFAULT_THEME_ATTR, DEFAULT_STYLE, null);
|
||||
}
|
||||
|
||||
public static BadgeDrawable createFromResource(Context context, int i) {
|
||||
return new BadgeDrawable(context, i, DEFAULT_THEME_ATTR, DEFAULT_STYLE, null);
|
||||
}
|
||||
|
||||
public void setVisible(boolean z) {
|
||||
this.state.setVisible(z);
|
||||
onVisibilityUpdated();
|
||||
}
|
||||
|
||||
private void onVisibilityUpdated() {
|
||||
boolean isVisible = this.state.isVisible();
|
||||
setVisible(isVisible, false);
|
||||
if (!BadgeUtils.USE_COMPAT_PARENT || getCustomBadgeParent() == null || isVisible) {
|
||||
return;
|
||||
}
|
||||
((ViewGroup) getCustomBadgeParent().getParent()).invalidate();
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
onBadgeShapeAppearanceUpdated();
|
||||
onBadgeTextAppearanceUpdated();
|
||||
onMaxBadgeLengthUpdated();
|
||||
onBadgeContentUpdated();
|
||||
onAlphaUpdated();
|
||||
onBackgroundColorUpdated();
|
||||
onBadgeTextColorUpdated();
|
||||
onBadgeGravityUpdated();
|
||||
updateCenterAndBounds();
|
||||
onVisibilityUpdated();
|
||||
}
|
||||
|
||||
private BadgeDrawable(Context context, int i, int i2, int i3, BadgeState.State state) {
|
||||
int badgeShapeAppearanceResId;
|
||||
int badgeShapeAppearanceOverlayResId;
|
||||
this.contextRef = new WeakReference<>(context);
|
||||
ThemeEnforcement.checkMaterialTheme(context);
|
||||
this.badgeBounds = new Rect();
|
||||
TextDrawableHelper textDrawableHelper = new TextDrawableHelper(this);
|
||||
this.textDrawableHelper = textDrawableHelper;
|
||||
textDrawableHelper.getTextPaint().setTextAlign(Paint.Align.CENTER);
|
||||
BadgeState badgeState = new BadgeState(context, i, i2, i3, state);
|
||||
this.state = badgeState;
|
||||
if (hasBadgeContent()) {
|
||||
badgeShapeAppearanceResId = badgeState.getBadgeWithTextShapeAppearanceResId();
|
||||
} else {
|
||||
badgeShapeAppearanceResId = badgeState.getBadgeShapeAppearanceResId();
|
||||
}
|
||||
if (hasBadgeContent()) {
|
||||
badgeShapeAppearanceOverlayResId = badgeState.getBadgeWithTextShapeAppearanceOverlayResId();
|
||||
} else {
|
||||
badgeShapeAppearanceOverlayResId = badgeState.getBadgeShapeAppearanceOverlayResId();
|
||||
}
|
||||
this.shapeDrawable = new MaterialShapeDrawable(ShapeAppearanceModel.builder(context, badgeShapeAppearanceResId, badgeShapeAppearanceOverlayResId).build());
|
||||
restoreState();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void updateBadgeCoordinates(View view, ViewGroup viewGroup) {
|
||||
if (!(viewGroup instanceof FrameLayout)) {
|
||||
throw new IllegalArgumentException("customBadgeParent must be a FrameLayout");
|
||||
}
|
||||
updateBadgeCoordinates(view, (FrameLayout) viewGroup);
|
||||
}
|
||||
|
||||
public void updateBadgeCoordinates(View view) {
|
||||
updateBadgeCoordinates(view, (FrameLayout) null);
|
||||
}
|
||||
|
||||
public void updateBadgeCoordinates(View view, FrameLayout frameLayout) {
|
||||
this.anchorViewRef = new WeakReference<>(view);
|
||||
if (BadgeUtils.USE_COMPAT_PARENT && frameLayout == null) {
|
||||
tryWrapAnchorInCompatParent(view);
|
||||
} else {
|
||||
this.customBadgeParentRef = new WeakReference<>(frameLayout);
|
||||
}
|
||||
if (!BadgeUtils.USE_COMPAT_PARENT) {
|
||||
updateAnchorParentToNotClip(view);
|
||||
}
|
||||
updateCenterAndBounds();
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
private boolean isAnchorViewWrappedInCompatParent() {
|
||||
FrameLayout customBadgeParent = getCustomBadgeParent();
|
||||
return customBadgeParent != null && customBadgeParent.getId() == R.id.mtrl_anchor_parent;
|
||||
}
|
||||
|
||||
public FrameLayout getCustomBadgeParent() {
|
||||
WeakReference<FrameLayout> weakReference = this.customBadgeParentRef;
|
||||
if (weakReference != null) {
|
||||
return weakReference.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void tryWrapAnchorInCompatParent(final View view) {
|
||||
ViewGroup viewGroup = (ViewGroup) view.getParent();
|
||||
if (viewGroup == null || viewGroup.getId() != R.id.mtrl_anchor_parent) {
|
||||
WeakReference<FrameLayout> weakReference = this.customBadgeParentRef;
|
||||
if (weakReference == null || weakReference.get() != viewGroup) {
|
||||
updateAnchorParentToNotClip(view);
|
||||
final FrameLayout frameLayout = new FrameLayout(view.getContext());
|
||||
frameLayout.setId(R.id.mtrl_anchor_parent);
|
||||
frameLayout.setClipChildren(false);
|
||||
frameLayout.setClipToPadding(false);
|
||||
frameLayout.setLayoutParams(view.getLayoutParams());
|
||||
frameLayout.setMinimumWidth(view.getWidth());
|
||||
frameLayout.setMinimumHeight(view.getHeight());
|
||||
int indexOfChild = viewGroup.indexOfChild(view);
|
||||
viewGroup.removeViewAt(indexOfChild);
|
||||
view.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
|
||||
frameLayout.addView(view);
|
||||
viewGroup.addView(frameLayout, indexOfChild);
|
||||
this.customBadgeParentRef = new WeakReference<>(frameLayout);
|
||||
frameLayout.post(new Runnable() { // from class: com.google.android.material.badge.BadgeDrawable.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
BadgeDrawable.this.updateBadgeCoordinates(view, frameLayout);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateAnchorParentToNotClip(View view) {
|
||||
ViewGroup viewGroup = (ViewGroup) view.getParent();
|
||||
viewGroup.setClipChildren(false);
|
||||
viewGroup.setClipToPadding(false);
|
||||
}
|
||||
|
||||
public int getBackgroundColor() {
|
||||
return this.shapeDrawable.getFillColor().getDefaultColor();
|
||||
}
|
||||
|
||||
public void setBackgroundColor(int i) {
|
||||
this.state.setBackgroundColor(i);
|
||||
onBackgroundColorUpdated();
|
||||
}
|
||||
|
||||
private void onBackgroundColorUpdated() {
|
||||
ColorStateList valueOf = ColorStateList.valueOf(this.state.getBackgroundColor());
|
||||
if (this.shapeDrawable.getFillColor() != valueOf) {
|
||||
this.shapeDrawable.setFillColor(valueOf);
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
public int getBadgeTextColor() {
|
||||
return this.textDrawableHelper.getTextPaint().getColor();
|
||||
}
|
||||
|
||||
public void setBadgeTextColor(int i) {
|
||||
if (this.textDrawableHelper.getTextPaint().getColor() != i) {
|
||||
this.state.setBadgeTextColor(i);
|
||||
onBadgeTextColorUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void onBadgeTextColorUpdated() {
|
||||
this.textDrawableHelper.getTextPaint().setColor(this.state.getBadgeTextColor());
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public Locale getBadgeNumberLocale() {
|
||||
return this.state.getNumberLocale();
|
||||
}
|
||||
|
||||
public void setBadgeNumberLocale(Locale locale) {
|
||||
if (locale.equals(this.state.getNumberLocale())) {
|
||||
return;
|
||||
}
|
||||
this.state.setNumberLocale(locale);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public boolean hasNumber() {
|
||||
return !this.state.hasText() && this.state.hasNumber();
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
if (this.state.hasNumber()) {
|
||||
return this.state.getNumber();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setNumber(int i) {
|
||||
int max = Math.max(0, i);
|
||||
if (this.state.getNumber() != max) {
|
||||
this.state.setNumber(max);
|
||||
onNumberUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearNumber() {
|
||||
if (this.state.hasNumber()) {
|
||||
this.state.clearNumber();
|
||||
onNumberUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void onNumberUpdated() {
|
||||
if (hasText()) {
|
||||
return;
|
||||
}
|
||||
onBadgeContentUpdated();
|
||||
}
|
||||
|
||||
public boolean hasText() {
|
||||
return this.state.hasText();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.state.getText();
|
||||
}
|
||||
|
||||
public void setText(String str) {
|
||||
if (TextUtils.equals(this.state.getText(), str)) {
|
||||
return;
|
||||
}
|
||||
this.state.setText(str);
|
||||
onTextUpdated();
|
||||
}
|
||||
|
||||
public void clearText() {
|
||||
if (this.state.hasText()) {
|
||||
this.state.clearText();
|
||||
onTextUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void onTextUpdated() {
|
||||
onBadgeContentUpdated();
|
||||
}
|
||||
|
||||
public int getMaxCharacterCount() {
|
||||
return this.state.getMaxCharacterCount();
|
||||
}
|
||||
|
||||
public void setMaxCharacterCount(int i) {
|
||||
if (this.state.getMaxCharacterCount() != i) {
|
||||
this.state.setMaxCharacterCount(i);
|
||||
onMaxBadgeLengthUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxNumber() {
|
||||
return this.state.getMaxNumber();
|
||||
}
|
||||
|
||||
public void setMaxNumber(int i) {
|
||||
if (this.state.getMaxNumber() != i) {
|
||||
this.state.setMaxNumber(i);
|
||||
onMaxBadgeLengthUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void onMaxBadgeLengthUpdated() {
|
||||
updateMaxBadgeNumber();
|
||||
this.textDrawableHelper.setTextSizeDirty(true);
|
||||
updateCenterAndBounds();
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public int getBadgeGravity() {
|
||||
return this.state.getBadgeGravity();
|
||||
}
|
||||
|
||||
public void setBadgeGravity(int i) {
|
||||
if (i == 8388691 || i == 8388693) {
|
||||
Log.w(TAG, "Bottom badge gravities are deprecated; please use a top gravity instead.");
|
||||
}
|
||||
if (this.state.getBadgeGravity() != i) {
|
||||
this.state.setBadgeGravity(i);
|
||||
onBadgeGravityUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void onBadgeGravityUpdated() {
|
||||
WeakReference<View> weakReference = this.anchorViewRef;
|
||||
if (weakReference == null || weakReference.get() == null) {
|
||||
return;
|
||||
}
|
||||
View view = this.anchorViewRef.get();
|
||||
WeakReference<FrameLayout> weakReference2 = this.customBadgeParentRef;
|
||||
updateBadgeCoordinates(view, weakReference2 != null ? weakReference2.get() : null);
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public int getAlpha() {
|
||||
return this.state.getAlpha();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setAlpha(int i) {
|
||||
this.state.setAlpha(i);
|
||||
onAlphaUpdated();
|
||||
}
|
||||
|
||||
private void onAlphaUpdated() {
|
||||
this.textDrawableHelper.getTextPaint().setAlpha(getAlpha());
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public int getIntrinsicHeight() {
|
||||
return this.badgeBounds.height();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public int getIntrinsicWidth() {
|
||||
return this.badgeBounds.width();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void draw(Canvas canvas) {
|
||||
if (getBounds().isEmpty() || getAlpha() == 0 || !isVisible()) {
|
||||
return;
|
||||
}
|
||||
this.shapeDrawable.draw(canvas);
|
||||
if (hasBadgeContent()) {
|
||||
drawBadgeContent(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.internal.TextDrawableHelper.TextDrawableDelegate
|
||||
public void onTextSizeChange() {
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable, com.google.android.material.internal.TextDrawableHelper.TextDrawableDelegate
|
||||
public boolean onStateChange(int[] iArr) {
|
||||
return super.onStateChange(iArr);
|
||||
}
|
||||
|
||||
public void setContentDescriptionForText(CharSequence charSequence) {
|
||||
this.state.setContentDescriptionForText(charSequence);
|
||||
}
|
||||
|
||||
public void setContentDescriptionNumberless(CharSequence charSequence) {
|
||||
this.state.setContentDescriptionNumberless(charSequence);
|
||||
}
|
||||
|
||||
public void setContentDescriptionQuantityStringsResource(int i) {
|
||||
this.state.setContentDescriptionQuantityStringsResource(i);
|
||||
}
|
||||
|
||||
public void setContentDescriptionExceedsMaxBadgeNumberStringResource(int i) {
|
||||
this.state.setContentDescriptionExceedsMaxBadgeNumberStringResource(i);
|
||||
}
|
||||
|
||||
public CharSequence getContentDescription() {
|
||||
if (!isVisible()) {
|
||||
return null;
|
||||
}
|
||||
if (hasText()) {
|
||||
return getTextContentDescription();
|
||||
}
|
||||
if (hasNumber()) {
|
||||
return getNumberContentDescription();
|
||||
}
|
||||
return getEmptyContentDescription();
|
||||
}
|
||||
|
||||
private String getNumberContentDescription() {
|
||||
Context context;
|
||||
if (this.state.getContentDescriptionQuantityStrings() == 0 || (context = this.contextRef.get()) == null) {
|
||||
return null;
|
||||
}
|
||||
if (this.maxBadgeNumber == -2 || getNumber() <= this.maxBadgeNumber) {
|
||||
return context.getResources().getQuantityString(this.state.getContentDescriptionQuantityStrings(), getNumber(), Integer.valueOf(getNumber()));
|
||||
}
|
||||
return context.getString(this.state.getContentDescriptionExceedsMaxBadgeNumberStringResource(), Integer.valueOf(this.maxBadgeNumber));
|
||||
}
|
||||
|
||||
private CharSequence getTextContentDescription() {
|
||||
CharSequence contentDescriptionForText = this.state.getContentDescriptionForText();
|
||||
return contentDescriptionForText != null ? contentDescriptionForText : getText();
|
||||
}
|
||||
|
||||
private CharSequence getEmptyContentDescription() {
|
||||
return this.state.getContentDescriptionNumberless();
|
||||
}
|
||||
|
||||
public void setHorizontalPadding(int i) {
|
||||
if (i != this.state.getBadgeHorizontalPadding()) {
|
||||
this.state.setBadgeHorizontalPadding(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
}
|
||||
|
||||
public int getHorizontalPadding() {
|
||||
return this.state.getBadgeHorizontalPadding();
|
||||
}
|
||||
|
||||
public void setVerticalPadding(int i) {
|
||||
if (i != this.state.getBadgeVerticalPadding()) {
|
||||
this.state.setBadgeVerticalPadding(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
}
|
||||
|
||||
public int getVerticalPadding() {
|
||||
return this.state.getBadgeVerticalPadding();
|
||||
}
|
||||
|
||||
public void setHorizontalOffset(int i) {
|
||||
setHorizontalOffsetWithoutText(i);
|
||||
setHorizontalOffsetWithText(i);
|
||||
}
|
||||
|
||||
public int getHorizontalOffset() {
|
||||
return this.state.getHorizontalOffsetWithoutText();
|
||||
}
|
||||
|
||||
public void setHorizontalOffsetWithoutText(int i) {
|
||||
this.state.setHorizontalOffsetWithoutText(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
|
||||
public int getHorizontalOffsetWithoutText() {
|
||||
return this.state.getHorizontalOffsetWithoutText();
|
||||
}
|
||||
|
||||
public void setHorizontalOffsetWithText(int i) {
|
||||
this.state.setHorizontalOffsetWithText(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
|
||||
public int getHorizontalOffsetWithText() {
|
||||
return this.state.getHorizontalOffsetWithText();
|
||||
}
|
||||
|
||||
void setAdditionalHorizontalOffset(int i) {
|
||||
this.state.setAdditionalHorizontalOffset(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
|
||||
int getAdditionalHorizontalOffset() {
|
||||
return this.state.getAdditionalHorizontalOffset();
|
||||
}
|
||||
|
||||
public void setVerticalOffset(int i) {
|
||||
setVerticalOffsetWithoutText(i);
|
||||
setVerticalOffsetWithText(i);
|
||||
}
|
||||
|
||||
public int getVerticalOffset() {
|
||||
return this.state.getVerticalOffsetWithoutText();
|
||||
}
|
||||
|
||||
public void setVerticalOffsetWithoutText(int i) {
|
||||
this.state.setVerticalOffsetWithoutText(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
|
||||
public int getVerticalOffsetWithoutText() {
|
||||
return this.state.getVerticalOffsetWithoutText();
|
||||
}
|
||||
|
||||
public void setVerticalOffsetWithText(int i) {
|
||||
this.state.setVerticalOffsetWithText(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
|
||||
public int getVerticalOffsetWithText() {
|
||||
return this.state.getVerticalOffsetWithText();
|
||||
}
|
||||
|
||||
public void setLargeFontVerticalOffsetAdjustment(int i) {
|
||||
this.state.setLargeFontVerticalOffsetAdjustment(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
|
||||
public int getLargeFontVerticalOffsetAdjustment() {
|
||||
return this.state.getLargeFontVerticalOffsetAdjustment();
|
||||
}
|
||||
|
||||
void setAdditionalVerticalOffset(int i) {
|
||||
this.state.setAdditionalVerticalOffset(i);
|
||||
updateCenterAndBounds();
|
||||
}
|
||||
|
||||
int getAdditionalVerticalOffset() {
|
||||
return this.state.getAdditionalVerticalOffset();
|
||||
}
|
||||
|
||||
public void setAutoAdjustToWithinGrandparentBounds(boolean z) {
|
||||
if (this.state.isAutoAdjustedToGrandparentBounds() == z) {
|
||||
return;
|
||||
}
|
||||
this.state.setAutoAdjustToGrandparentBounds(z);
|
||||
WeakReference<View> weakReference = this.anchorViewRef;
|
||||
if (weakReference == null || weakReference.get() == null) {
|
||||
return;
|
||||
}
|
||||
autoAdjustWithinGrandparentBounds(this.anchorViewRef.get());
|
||||
}
|
||||
|
||||
public void setTextAppearance(int i) {
|
||||
this.state.setTextAppearanceResId(i);
|
||||
onBadgeTextAppearanceUpdated();
|
||||
}
|
||||
|
||||
private void onBadgeTextAppearanceUpdated() {
|
||||
TextAppearance textAppearance;
|
||||
Context context = this.contextRef.get();
|
||||
if (context == null || this.textDrawableHelper.getTextAppearance() == (textAppearance = new TextAppearance(context, this.state.getTextAppearanceResId()))) {
|
||||
return;
|
||||
}
|
||||
this.textDrawableHelper.setTextAppearance(textAppearance, context);
|
||||
onBadgeTextColorUpdated();
|
||||
updateCenterAndBounds();
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public void setBadgeWithoutTextShapeAppearance(int i) {
|
||||
this.state.setBadgeShapeAppearanceResId(i);
|
||||
onBadgeShapeAppearanceUpdated();
|
||||
}
|
||||
|
||||
public void setBadgeWithoutTextShapeAppearanceOverlay(int i) {
|
||||
this.state.setBadgeShapeAppearanceOverlayResId(i);
|
||||
onBadgeShapeAppearanceUpdated();
|
||||
}
|
||||
|
||||
public void setBadgeWithTextShapeAppearance(int i) {
|
||||
this.state.setBadgeWithTextShapeAppearanceResId(i);
|
||||
onBadgeShapeAppearanceUpdated();
|
||||
}
|
||||
|
||||
public void setBadgeWithTextShapeAppearanceOverlay(int i) {
|
||||
this.state.setBadgeWithTextShapeAppearanceOverlayResId(i);
|
||||
onBadgeShapeAppearanceUpdated();
|
||||
}
|
||||
|
||||
private void onBadgeShapeAppearanceUpdated() {
|
||||
int badgeShapeAppearanceResId;
|
||||
int badgeShapeAppearanceOverlayResId;
|
||||
Context context = this.contextRef.get();
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
MaterialShapeDrawable materialShapeDrawable = this.shapeDrawable;
|
||||
if (hasBadgeContent()) {
|
||||
badgeShapeAppearanceResId = this.state.getBadgeWithTextShapeAppearanceResId();
|
||||
} else {
|
||||
badgeShapeAppearanceResId = this.state.getBadgeShapeAppearanceResId();
|
||||
}
|
||||
if (hasBadgeContent()) {
|
||||
badgeShapeAppearanceOverlayResId = this.state.getBadgeWithTextShapeAppearanceOverlayResId();
|
||||
} else {
|
||||
badgeShapeAppearanceOverlayResId = this.state.getBadgeShapeAppearanceOverlayResId();
|
||||
}
|
||||
materialShapeDrawable.setShapeAppearanceModel(ShapeAppearanceModel.builder(context, badgeShapeAppearanceResId, badgeShapeAppearanceOverlayResId).build());
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
private void updateCenterAndBounds() {
|
||||
Context context = this.contextRef.get();
|
||||
WeakReference<View> weakReference = this.anchorViewRef;
|
||||
View view = weakReference != null ? weakReference.get() : null;
|
||||
if (context == null || view == null) {
|
||||
return;
|
||||
}
|
||||
Rect rect = new Rect();
|
||||
rect.set(this.badgeBounds);
|
||||
Rect rect2 = new Rect();
|
||||
view.getDrawingRect(rect2);
|
||||
WeakReference<FrameLayout> weakReference2 = this.customBadgeParentRef;
|
||||
FrameLayout frameLayout = weakReference2 != null ? weakReference2.get() : null;
|
||||
if (frameLayout != null || BadgeUtils.USE_COMPAT_PARENT) {
|
||||
if (frameLayout == null) {
|
||||
frameLayout = (ViewGroup) view.getParent();
|
||||
}
|
||||
frameLayout.offsetDescendantRectToMyCoords(view, rect2);
|
||||
}
|
||||
calculateCenterAndBounds(rect2, view);
|
||||
BadgeUtils.updateBadgeBounds(this.badgeBounds, this.badgeCenterX, this.badgeCenterY, this.halfBadgeWidth, this.halfBadgeHeight);
|
||||
float f = this.cornerRadius;
|
||||
if (f != -1.0f) {
|
||||
this.shapeDrawable.setCornerSize(f);
|
||||
}
|
||||
if (rect.equals(this.badgeBounds)) {
|
||||
return;
|
||||
}
|
||||
this.shapeDrawable.setBounds(this.badgeBounds);
|
||||
}
|
||||
|
||||
private int getTotalVerticalOffsetForState() {
|
||||
int verticalOffsetWithoutText = this.state.getVerticalOffsetWithoutText();
|
||||
if (hasBadgeContent()) {
|
||||
verticalOffsetWithoutText = this.state.getVerticalOffsetWithText();
|
||||
Context context = this.contextRef.get();
|
||||
if (context != null) {
|
||||
verticalOffsetWithoutText = AnimationUtils.lerp(verticalOffsetWithoutText, verticalOffsetWithoutText - this.state.getLargeFontVerticalOffsetAdjustment(), AnimationUtils.lerp(0.0f, 1.0f, FONT_SCALE_THRESHOLD, 1.0f, MaterialResources.getFontScale(context) - 1.0f));
|
||||
}
|
||||
}
|
||||
if (this.state.offsetAlignmentMode == 0) {
|
||||
verticalOffsetWithoutText -= Math.round(this.halfBadgeHeight);
|
||||
}
|
||||
return verticalOffsetWithoutText + this.state.getAdditionalVerticalOffset();
|
||||
}
|
||||
|
||||
private int getTotalHorizontalOffsetForState() {
|
||||
int horizontalOffsetWithoutText;
|
||||
if (hasBadgeContent()) {
|
||||
horizontalOffsetWithoutText = this.state.getHorizontalOffsetWithText();
|
||||
} else {
|
||||
horizontalOffsetWithoutText = this.state.getHorizontalOffsetWithoutText();
|
||||
}
|
||||
if (this.state.offsetAlignmentMode == 1) {
|
||||
horizontalOffsetWithoutText += hasBadgeContent() ? this.state.horizontalInsetWithText : this.state.horizontalInset;
|
||||
}
|
||||
return horizontalOffsetWithoutText + this.state.getAdditionalHorizontalOffset();
|
||||
}
|
||||
|
||||
private void calculateCenterAndBounds(Rect rect, View view) {
|
||||
float f;
|
||||
float f2;
|
||||
float f3 = hasBadgeContent() ? this.state.badgeWithTextRadius : this.state.badgeRadius;
|
||||
this.cornerRadius = f3;
|
||||
if (f3 != -1.0f) {
|
||||
this.halfBadgeWidth = f3;
|
||||
this.halfBadgeHeight = f3;
|
||||
} else {
|
||||
this.halfBadgeWidth = Math.round((hasBadgeContent() ? this.state.badgeWithTextWidth : this.state.badgeWidth) / 2.0f);
|
||||
this.halfBadgeHeight = Math.round((hasBadgeContent() ? this.state.badgeWithTextHeight : this.state.badgeHeight) / 2.0f);
|
||||
}
|
||||
if (hasBadgeContent()) {
|
||||
String badgeContent = getBadgeContent();
|
||||
this.halfBadgeWidth = Math.max(this.halfBadgeWidth, (this.textDrawableHelper.getTextWidth(badgeContent) / 2.0f) + this.state.getBadgeHorizontalPadding());
|
||||
float max = Math.max(this.halfBadgeHeight, (this.textDrawableHelper.getTextHeight(badgeContent) / 2.0f) + this.state.getBadgeVerticalPadding());
|
||||
this.halfBadgeHeight = max;
|
||||
this.halfBadgeWidth = Math.max(this.halfBadgeWidth, max);
|
||||
}
|
||||
int totalVerticalOffsetForState = getTotalVerticalOffsetForState();
|
||||
int badgeGravity = this.state.getBadgeGravity();
|
||||
if (badgeGravity == 8388691 || badgeGravity == 8388693) {
|
||||
this.badgeCenterY = rect.bottom - totalVerticalOffsetForState;
|
||||
} else {
|
||||
this.badgeCenterY = rect.top + totalVerticalOffsetForState;
|
||||
}
|
||||
int totalHorizontalOffsetForState = getTotalHorizontalOffsetForState();
|
||||
int badgeGravity2 = this.state.getBadgeGravity();
|
||||
if (badgeGravity2 == 8388659 || badgeGravity2 == 8388691) {
|
||||
if (ViewCompat.getLayoutDirection(view) == 0) {
|
||||
f = (rect.left - this.halfBadgeWidth) + totalHorizontalOffsetForState;
|
||||
} else {
|
||||
f = (rect.right + this.halfBadgeWidth) - totalHorizontalOffsetForState;
|
||||
}
|
||||
this.badgeCenterX = f;
|
||||
} else {
|
||||
if (ViewCompat.getLayoutDirection(view) == 0) {
|
||||
f2 = (rect.right + this.halfBadgeWidth) - totalHorizontalOffsetForState;
|
||||
} else {
|
||||
f2 = (rect.left - this.halfBadgeWidth) + totalHorizontalOffsetForState;
|
||||
}
|
||||
this.badgeCenterX = f2;
|
||||
}
|
||||
if (this.state.isAutoAdjustedToGrandparentBounds()) {
|
||||
autoAdjustWithinGrandparentBounds(view);
|
||||
}
|
||||
}
|
||||
|
||||
private void autoAdjustWithinGrandparentBounds(View view) {
|
||||
float f;
|
||||
float f2;
|
||||
View customBadgeParent = getCustomBadgeParent();
|
||||
if (customBadgeParent == null) {
|
||||
if (!(view.getParent() instanceof View)) {
|
||||
return;
|
||||
}
|
||||
float y = view.getY();
|
||||
f2 = view.getX();
|
||||
customBadgeParent = (View) view.getParent();
|
||||
f = y;
|
||||
} else if (!isAnchorViewWrappedInCompatParent()) {
|
||||
f = 0.0f;
|
||||
f2 = 0.0f;
|
||||
} else {
|
||||
if (!(customBadgeParent.getParent() instanceof View)) {
|
||||
return;
|
||||
}
|
||||
f = customBadgeParent.getY();
|
||||
f2 = customBadgeParent.getX();
|
||||
customBadgeParent = (View) customBadgeParent.getParent();
|
||||
}
|
||||
float topCutOff = getTopCutOff(customBadgeParent, f);
|
||||
float leftCutOff = getLeftCutOff(customBadgeParent, f2);
|
||||
float bottomCutOff = getBottomCutOff(customBadgeParent, f);
|
||||
float rightCutoff = getRightCutoff(customBadgeParent, f2);
|
||||
if (topCutOff < 0.0f) {
|
||||
this.badgeCenterY += Math.abs(topCutOff);
|
||||
}
|
||||
if (leftCutOff < 0.0f) {
|
||||
this.badgeCenterX += Math.abs(leftCutOff);
|
||||
}
|
||||
if (bottomCutOff > 0.0f) {
|
||||
this.badgeCenterY -= Math.abs(bottomCutOff);
|
||||
}
|
||||
if (rightCutoff > 0.0f) {
|
||||
this.badgeCenterX -= Math.abs(rightCutoff);
|
||||
}
|
||||
}
|
||||
|
||||
private float getTopCutOff(View view, float f) {
|
||||
return (this.badgeCenterY - this.halfBadgeHeight) + view.getY() + f;
|
||||
}
|
||||
|
||||
private float getLeftCutOff(View view, float f) {
|
||||
return (this.badgeCenterX - this.halfBadgeWidth) + view.getX() + f;
|
||||
}
|
||||
|
||||
private float getBottomCutOff(View view, float f) {
|
||||
if (!(view.getParent() instanceof View)) {
|
||||
return 0.0f;
|
||||
}
|
||||
return ((this.badgeCenterY + this.halfBadgeHeight) - (((View) view.getParent()).getHeight() - view.getY())) + f;
|
||||
}
|
||||
|
||||
private float getRightCutoff(View view, float f) {
|
||||
if (!(view.getParent() instanceof View)) {
|
||||
return 0.0f;
|
||||
}
|
||||
return ((this.badgeCenterX + this.halfBadgeWidth) - (((View) view.getParent()).getWidth() - view.getX())) + f;
|
||||
}
|
||||
|
||||
private void drawBadgeContent(Canvas canvas) {
|
||||
String badgeContent = getBadgeContent();
|
||||
if (badgeContent != null) {
|
||||
Rect rect = new Rect();
|
||||
this.textDrawableHelper.getTextPaint().getTextBounds(badgeContent, 0, badgeContent.length(), rect);
|
||||
float exactCenterY = this.badgeCenterY - rect.exactCenterY();
|
||||
canvas.drawText(badgeContent, this.badgeCenterX, rect.bottom <= 0 ? (int) exactCenterY : Math.round(exactCenterY), this.textDrawableHelper.getTextPaint());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasBadgeContent() {
|
||||
return hasText() || hasNumber();
|
||||
}
|
||||
|
||||
private String getBadgeContent() {
|
||||
if (hasText()) {
|
||||
return getTextBadgeText();
|
||||
}
|
||||
if (hasNumber()) {
|
||||
return getNumberBadgeText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getTextBadgeText() {
|
||||
String text = getText();
|
||||
int maxCharacterCount = getMaxCharacterCount();
|
||||
if (maxCharacterCount == -2 || text == null || text.length() <= maxCharacterCount) {
|
||||
return text;
|
||||
}
|
||||
Context context = this.contextRef.get();
|
||||
if (context == null) {
|
||||
return "";
|
||||
}
|
||||
return String.format(context.getString(R.string.m3_exceed_max_badge_text_suffix), text.substring(0, maxCharacterCount - 1), DEFAULT_EXCEED_MAX_BADGE_TEXT_SUFFIX);
|
||||
}
|
||||
|
||||
private String getNumberBadgeText() {
|
||||
if (this.maxBadgeNumber == -2 || getNumber() <= this.maxBadgeNumber) {
|
||||
return NumberFormat.getInstance(this.state.getNumberLocale()).format(getNumber());
|
||||
}
|
||||
Context context = this.contextRef.get();
|
||||
return context == null ? "" : String.format(this.state.getNumberLocale(), context.getString(R.string.mtrl_exceed_max_badge_number_suffix), Integer.valueOf(this.maxBadgeNumber), DEFAULT_EXCEED_MAX_BADGE_NUMBER_SUFFIX);
|
||||
}
|
||||
|
||||
private void onBadgeContentUpdated() {
|
||||
this.textDrawableHelper.setTextSizeDirty(true);
|
||||
onBadgeShapeAppearanceUpdated();
|
||||
updateCenterAndBounds();
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
private void updateMaxBadgeNumber() {
|
||||
if (getMaxCharacterCount() != -2) {
|
||||
this.maxBadgeNumber = ((int) Math.pow(10.0d, getMaxCharacterCount() - 1.0d)) - 1;
|
||||
} else {
|
||||
this.maxBadgeNumber = getMaxNumber();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,672 @@
|
||||
package com.google.android.material.badge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.AttributeSet;
|
||||
import com.google.android.material.R;
|
||||
import com.google.android.material.drawable.DrawableUtils;
|
||||
import com.google.android.material.internal.ThemeEnforcement;
|
||||
import com.google.android.material.resources.MaterialResources;
|
||||
import com.google.android.material.resources.TextAppearance;
|
||||
import java.util.Locale;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class BadgeState {
|
||||
private static final String BADGE_RESOURCE_TAG = "badge";
|
||||
final float badgeHeight;
|
||||
final float badgeRadius;
|
||||
final float badgeWidth;
|
||||
final float badgeWithTextHeight;
|
||||
final float badgeWithTextRadius;
|
||||
final float badgeWithTextWidth;
|
||||
private final State currentState;
|
||||
final int horizontalInset;
|
||||
final int horizontalInsetWithText;
|
||||
int offsetAlignmentMode;
|
||||
private final State overridingState;
|
||||
|
||||
State getOverridingState() {
|
||||
return this.overridingState;
|
||||
}
|
||||
|
||||
BadgeState(Context context, int i, int i2, int i3, State state) {
|
||||
CharSequence charSequence;
|
||||
int i4;
|
||||
int i5;
|
||||
int i6;
|
||||
int i7;
|
||||
int intValue;
|
||||
int intValue2;
|
||||
int intValue3;
|
||||
int intValue4;
|
||||
int intValue5;
|
||||
int intValue6;
|
||||
int intValue7;
|
||||
int intValue8;
|
||||
int intValue9;
|
||||
int intValue10;
|
||||
int intValue11;
|
||||
int intValue12;
|
||||
int intValue13;
|
||||
int intValue14;
|
||||
boolean booleanValue;
|
||||
Locale locale;
|
||||
Locale.Category category;
|
||||
State state2 = new State();
|
||||
this.currentState = state2;
|
||||
state = state == null ? new State() : state;
|
||||
if (i != 0) {
|
||||
state.badgeResId = i;
|
||||
}
|
||||
TypedArray generateTypedArray = generateTypedArray(context, state.badgeResId, i2, i3);
|
||||
Resources resources = context.getResources();
|
||||
this.badgeRadius = generateTypedArray.getDimensionPixelSize(R.styleable.Badge_badgeRadius, -1);
|
||||
this.horizontalInset = context.getResources().getDimensionPixelSize(R.dimen.mtrl_badge_horizontal_edge_offset);
|
||||
this.horizontalInsetWithText = context.getResources().getDimensionPixelSize(R.dimen.mtrl_badge_text_horizontal_edge_offset);
|
||||
this.badgeWithTextRadius = generateTypedArray.getDimensionPixelSize(R.styleable.Badge_badgeWithTextRadius, -1);
|
||||
this.badgeWidth = generateTypedArray.getDimension(R.styleable.Badge_badgeWidth, resources.getDimension(R.dimen.m3_badge_size));
|
||||
this.badgeWithTextWidth = generateTypedArray.getDimension(R.styleable.Badge_badgeWithTextWidth, resources.getDimension(R.dimen.m3_badge_with_text_size));
|
||||
this.badgeHeight = generateTypedArray.getDimension(R.styleable.Badge_badgeHeight, resources.getDimension(R.dimen.m3_badge_size));
|
||||
this.badgeWithTextHeight = generateTypedArray.getDimension(R.styleable.Badge_badgeWithTextHeight, resources.getDimension(R.dimen.m3_badge_with_text_size));
|
||||
boolean z = true;
|
||||
this.offsetAlignmentMode = generateTypedArray.getInt(R.styleable.Badge_offsetAlignmentMode, 1);
|
||||
state2.alpha = state.alpha == -2 ? 255 : state.alpha;
|
||||
if (state.number == -2) {
|
||||
if (generateTypedArray.hasValue(R.styleable.Badge_number)) {
|
||||
state2.number = generateTypedArray.getInt(R.styleable.Badge_number, 0);
|
||||
} else {
|
||||
state2.number = -1;
|
||||
}
|
||||
} else {
|
||||
state2.number = state.number;
|
||||
}
|
||||
if (state.text == null) {
|
||||
if (generateTypedArray.hasValue(R.styleable.Badge_badgeText)) {
|
||||
state2.text = generateTypedArray.getString(R.styleable.Badge_badgeText);
|
||||
}
|
||||
} else {
|
||||
state2.text = state.text;
|
||||
}
|
||||
state2.contentDescriptionForText = state.contentDescriptionForText;
|
||||
if (state.contentDescriptionNumberless == null) {
|
||||
charSequence = context.getString(R.string.mtrl_badge_numberless_content_description);
|
||||
} else {
|
||||
charSequence = state.contentDescriptionNumberless;
|
||||
}
|
||||
state2.contentDescriptionNumberless = charSequence;
|
||||
if (state.contentDescriptionQuantityStrings == 0) {
|
||||
i4 = R.plurals.mtrl_badge_content_description;
|
||||
} else {
|
||||
i4 = state.contentDescriptionQuantityStrings;
|
||||
}
|
||||
state2.contentDescriptionQuantityStrings = i4;
|
||||
if (state.contentDescriptionExceedsMaxBadgeNumberRes == 0) {
|
||||
i5 = R.string.mtrl_exceed_max_badge_number_content_description;
|
||||
} else {
|
||||
i5 = state.contentDescriptionExceedsMaxBadgeNumberRes;
|
||||
}
|
||||
state2.contentDescriptionExceedsMaxBadgeNumberRes = i5;
|
||||
if (state.isVisible != null && !state.isVisible.booleanValue()) {
|
||||
z = false;
|
||||
}
|
||||
state2.isVisible = Boolean.valueOf(z);
|
||||
if (state.maxCharacterCount == -2) {
|
||||
i6 = generateTypedArray.getInt(R.styleable.Badge_maxCharacterCount, -2);
|
||||
} else {
|
||||
i6 = state.maxCharacterCount;
|
||||
}
|
||||
state2.maxCharacterCount = i6;
|
||||
if (state.maxNumber == -2) {
|
||||
i7 = generateTypedArray.getInt(R.styleable.Badge_maxNumber, -2);
|
||||
} else {
|
||||
i7 = state.maxNumber;
|
||||
}
|
||||
state2.maxNumber = i7;
|
||||
if (state.badgeShapeAppearanceResId == null) {
|
||||
intValue = generateTypedArray.getResourceId(R.styleable.Badge_badgeShapeAppearance, R.style.ShapeAppearance_M3_Sys_Shape_Corner_Full);
|
||||
} else {
|
||||
intValue = state.badgeShapeAppearanceResId.intValue();
|
||||
}
|
||||
state2.badgeShapeAppearanceResId = Integer.valueOf(intValue);
|
||||
if (state.badgeShapeAppearanceOverlayResId == null) {
|
||||
intValue2 = generateTypedArray.getResourceId(R.styleable.Badge_badgeShapeAppearanceOverlay, 0);
|
||||
} else {
|
||||
intValue2 = state.badgeShapeAppearanceOverlayResId.intValue();
|
||||
}
|
||||
state2.badgeShapeAppearanceOverlayResId = Integer.valueOf(intValue2);
|
||||
if (state.badgeWithTextShapeAppearanceResId == null) {
|
||||
intValue3 = generateTypedArray.getResourceId(R.styleable.Badge_badgeWithTextShapeAppearance, R.style.ShapeAppearance_M3_Sys_Shape_Corner_Full);
|
||||
} else {
|
||||
intValue3 = state.badgeWithTextShapeAppearanceResId.intValue();
|
||||
}
|
||||
state2.badgeWithTextShapeAppearanceResId = Integer.valueOf(intValue3);
|
||||
if (state.badgeWithTextShapeAppearanceOverlayResId == null) {
|
||||
intValue4 = generateTypedArray.getResourceId(R.styleable.Badge_badgeWithTextShapeAppearanceOverlay, 0);
|
||||
} else {
|
||||
intValue4 = state.badgeWithTextShapeAppearanceOverlayResId.intValue();
|
||||
}
|
||||
state2.badgeWithTextShapeAppearanceOverlayResId = Integer.valueOf(intValue4);
|
||||
if (state.backgroundColor == null) {
|
||||
intValue5 = readColorFromAttributes(context, generateTypedArray, R.styleable.Badge_backgroundColor);
|
||||
} else {
|
||||
intValue5 = state.backgroundColor.intValue();
|
||||
}
|
||||
state2.backgroundColor = Integer.valueOf(intValue5);
|
||||
if (state.badgeTextAppearanceResId == null) {
|
||||
intValue6 = generateTypedArray.getResourceId(R.styleable.Badge_badgeTextAppearance, R.style.TextAppearance_MaterialComponents_Badge);
|
||||
} else {
|
||||
intValue6 = state.badgeTextAppearanceResId.intValue();
|
||||
}
|
||||
state2.badgeTextAppearanceResId = Integer.valueOf(intValue6);
|
||||
if (state.badgeTextColor == null) {
|
||||
if (generateTypedArray.hasValue(R.styleable.Badge_badgeTextColor)) {
|
||||
state2.badgeTextColor = Integer.valueOf(readColorFromAttributes(context, generateTypedArray, R.styleable.Badge_badgeTextColor));
|
||||
} else {
|
||||
state2.badgeTextColor = Integer.valueOf(new TextAppearance(context, state2.badgeTextAppearanceResId.intValue()).getTextColor().getDefaultColor());
|
||||
}
|
||||
} else {
|
||||
state2.badgeTextColor = state.badgeTextColor;
|
||||
}
|
||||
if (state.badgeGravity == null) {
|
||||
intValue7 = generateTypedArray.getInt(R.styleable.Badge_badgeGravity, 8388661);
|
||||
} else {
|
||||
intValue7 = state.badgeGravity.intValue();
|
||||
}
|
||||
state2.badgeGravity = Integer.valueOf(intValue7);
|
||||
if (state.badgeHorizontalPadding == null) {
|
||||
intValue8 = generateTypedArray.getDimensionPixelSize(R.styleable.Badge_badgeWidePadding, resources.getDimensionPixelSize(R.dimen.mtrl_badge_long_text_horizontal_padding));
|
||||
} else {
|
||||
intValue8 = state.badgeHorizontalPadding.intValue();
|
||||
}
|
||||
state2.badgeHorizontalPadding = Integer.valueOf(intValue8);
|
||||
if (state.badgeVerticalPadding == null) {
|
||||
intValue9 = generateTypedArray.getDimensionPixelSize(R.styleable.Badge_badgeVerticalPadding, resources.getDimensionPixelSize(R.dimen.m3_badge_with_text_vertical_padding));
|
||||
} else {
|
||||
intValue9 = state.badgeVerticalPadding.intValue();
|
||||
}
|
||||
state2.badgeVerticalPadding = Integer.valueOf(intValue9);
|
||||
if (state.horizontalOffsetWithoutText == null) {
|
||||
intValue10 = generateTypedArray.getDimensionPixelOffset(R.styleable.Badge_horizontalOffset, 0);
|
||||
} else {
|
||||
intValue10 = state.horizontalOffsetWithoutText.intValue();
|
||||
}
|
||||
state2.horizontalOffsetWithoutText = Integer.valueOf(intValue10);
|
||||
if (state.verticalOffsetWithoutText == null) {
|
||||
intValue11 = generateTypedArray.getDimensionPixelOffset(R.styleable.Badge_verticalOffset, 0);
|
||||
} else {
|
||||
intValue11 = state.verticalOffsetWithoutText.intValue();
|
||||
}
|
||||
state2.verticalOffsetWithoutText = Integer.valueOf(intValue11);
|
||||
if (state.horizontalOffsetWithText == null) {
|
||||
intValue12 = generateTypedArray.getDimensionPixelOffset(R.styleable.Badge_horizontalOffsetWithText, state2.horizontalOffsetWithoutText.intValue());
|
||||
} else {
|
||||
intValue12 = state.horizontalOffsetWithText.intValue();
|
||||
}
|
||||
state2.horizontalOffsetWithText = Integer.valueOf(intValue12);
|
||||
if (state.verticalOffsetWithText == null) {
|
||||
intValue13 = generateTypedArray.getDimensionPixelOffset(R.styleable.Badge_verticalOffsetWithText, state2.verticalOffsetWithoutText.intValue());
|
||||
} else {
|
||||
intValue13 = state.verticalOffsetWithText.intValue();
|
||||
}
|
||||
state2.verticalOffsetWithText = Integer.valueOf(intValue13);
|
||||
if (state.largeFontVerticalOffsetAdjustment == null) {
|
||||
intValue14 = generateTypedArray.getDimensionPixelOffset(R.styleable.Badge_largeFontVerticalOffsetAdjustment, 0);
|
||||
} else {
|
||||
intValue14 = state.largeFontVerticalOffsetAdjustment.intValue();
|
||||
}
|
||||
state2.largeFontVerticalOffsetAdjustment = Integer.valueOf(intValue14);
|
||||
state2.additionalHorizontalOffset = Integer.valueOf(state.additionalHorizontalOffset == null ? 0 : state.additionalHorizontalOffset.intValue());
|
||||
state2.additionalVerticalOffset = Integer.valueOf(state.additionalVerticalOffset == null ? 0 : state.additionalVerticalOffset.intValue());
|
||||
if (state.autoAdjustToWithinGrandparentBounds == null) {
|
||||
booleanValue = generateTypedArray.getBoolean(R.styleable.Badge_autoAdjustToWithinGrandparentBounds, false);
|
||||
} else {
|
||||
booleanValue = state.autoAdjustToWithinGrandparentBounds.booleanValue();
|
||||
}
|
||||
state2.autoAdjustToWithinGrandparentBounds = Boolean.valueOf(booleanValue);
|
||||
generateTypedArray.recycle();
|
||||
if (state.numberLocale == null) {
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
category = Locale.Category.FORMAT;
|
||||
locale = Locale.getDefault(category);
|
||||
} else {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
state2.numberLocale = locale;
|
||||
} else {
|
||||
state2.numberLocale = state.numberLocale;
|
||||
}
|
||||
this.overridingState = state;
|
||||
}
|
||||
|
||||
private TypedArray generateTypedArray(Context context, int i, int i2, int i3) {
|
||||
AttributeSet attributeSet;
|
||||
int i4;
|
||||
if (i != 0) {
|
||||
AttributeSet parseDrawableXml = DrawableUtils.parseDrawableXml(context, i, BADGE_RESOURCE_TAG);
|
||||
i4 = parseDrawableXml.getStyleAttribute();
|
||||
attributeSet = parseDrawableXml;
|
||||
} else {
|
||||
attributeSet = null;
|
||||
i4 = 0;
|
||||
}
|
||||
return ThemeEnforcement.obtainStyledAttributes(context, attributeSet, R.styleable.Badge, i2, i4 == 0 ? i3 : i4, new int[0]);
|
||||
}
|
||||
|
||||
boolean isVisible() {
|
||||
return this.currentState.isVisible.booleanValue();
|
||||
}
|
||||
|
||||
void setVisible(boolean z) {
|
||||
this.overridingState.isVisible = Boolean.valueOf(z);
|
||||
this.currentState.isVisible = Boolean.valueOf(z);
|
||||
}
|
||||
|
||||
boolean hasNumber() {
|
||||
return this.currentState.number != -1;
|
||||
}
|
||||
|
||||
int getNumber() {
|
||||
return this.currentState.number;
|
||||
}
|
||||
|
||||
void setNumber(int i) {
|
||||
this.overridingState.number = i;
|
||||
this.currentState.number = i;
|
||||
}
|
||||
|
||||
void clearNumber() {
|
||||
setNumber(-1);
|
||||
}
|
||||
|
||||
boolean hasText() {
|
||||
return this.currentState.text != null;
|
||||
}
|
||||
|
||||
String getText() {
|
||||
return this.currentState.text;
|
||||
}
|
||||
|
||||
void setText(String str) {
|
||||
this.overridingState.text = str;
|
||||
this.currentState.text = str;
|
||||
}
|
||||
|
||||
void clearText() {
|
||||
setText(null);
|
||||
}
|
||||
|
||||
int getAlpha() {
|
||||
return this.currentState.alpha;
|
||||
}
|
||||
|
||||
void setAlpha(int i) {
|
||||
this.overridingState.alpha = i;
|
||||
this.currentState.alpha = i;
|
||||
}
|
||||
|
||||
int getMaxCharacterCount() {
|
||||
return this.currentState.maxCharacterCount;
|
||||
}
|
||||
|
||||
void setMaxCharacterCount(int i) {
|
||||
this.overridingState.maxCharacterCount = i;
|
||||
this.currentState.maxCharacterCount = i;
|
||||
}
|
||||
|
||||
int getMaxNumber() {
|
||||
return this.currentState.maxNumber;
|
||||
}
|
||||
|
||||
void setMaxNumber(int i) {
|
||||
this.overridingState.maxNumber = i;
|
||||
this.currentState.maxNumber = i;
|
||||
}
|
||||
|
||||
int getBackgroundColor() {
|
||||
return this.currentState.backgroundColor.intValue();
|
||||
}
|
||||
|
||||
void setBackgroundColor(int i) {
|
||||
this.overridingState.backgroundColor = Integer.valueOf(i);
|
||||
this.currentState.backgroundColor = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeTextColor() {
|
||||
return this.currentState.badgeTextColor.intValue();
|
||||
}
|
||||
|
||||
void setBadgeTextColor(int i) {
|
||||
this.overridingState.badgeTextColor = Integer.valueOf(i);
|
||||
this.currentState.badgeTextColor = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getTextAppearanceResId() {
|
||||
return this.currentState.badgeTextAppearanceResId.intValue();
|
||||
}
|
||||
|
||||
void setTextAppearanceResId(int i) {
|
||||
this.overridingState.badgeTextAppearanceResId = Integer.valueOf(i);
|
||||
this.currentState.badgeTextAppearanceResId = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeShapeAppearanceResId() {
|
||||
return this.currentState.badgeShapeAppearanceResId.intValue();
|
||||
}
|
||||
|
||||
void setBadgeShapeAppearanceResId(int i) {
|
||||
this.overridingState.badgeShapeAppearanceResId = Integer.valueOf(i);
|
||||
this.currentState.badgeShapeAppearanceResId = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeShapeAppearanceOverlayResId() {
|
||||
return this.currentState.badgeShapeAppearanceOverlayResId.intValue();
|
||||
}
|
||||
|
||||
void setBadgeShapeAppearanceOverlayResId(int i) {
|
||||
this.overridingState.badgeShapeAppearanceOverlayResId = Integer.valueOf(i);
|
||||
this.currentState.badgeShapeAppearanceOverlayResId = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeWithTextShapeAppearanceResId() {
|
||||
return this.currentState.badgeWithTextShapeAppearanceResId.intValue();
|
||||
}
|
||||
|
||||
void setBadgeWithTextShapeAppearanceResId(int i) {
|
||||
this.overridingState.badgeWithTextShapeAppearanceResId = Integer.valueOf(i);
|
||||
this.currentState.badgeWithTextShapeAppearanceResId = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeWithTextShapeAppearanceOverlayResId() {
|
||||
return this.currentState.badgeWithTextShapeAppearanceOverlayResId.intValue();
|
||||
}
|
||||
|
||||
void setBadgeWithTextShapeAppearanceOverlayResId(int i) {
|
||||
this.overridingState.badgeWithTextShapeAppearanceOverlayResId = Integer.valueOf(i);
|
||||
this.currentState.badgeWithTextShapeAppearanceOverlayResId = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeGravity() {
|
||||
return this.currentState.badgeGravity.intValue();
|
||||
}
|
||||
|
||||
void setBadgeGravity(int i) {
|
||||
this.overridingState.badgeGravity = Integer.valueOf(i);
|
||||
this.currentState.badgeGravity = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeHorizontalPadding() {
|
||||
return this.currentState.badgeHorizontalPadding.intValue();
|
||||
}
|
||||
|
||||
void setBadgeHorizontalPadding(int i) {
|
||||
this.overridingState.badgeHorizontalPadding = Integer.valueOf(i);
|
||||
this.currentState.badgeHorizontalPadding = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getBadgeVerticalPadding() {
|
||||
return this.currentState.badgeVerticalPadding.intValue();
|
||||
}
|
||||
|
||||
void setBadgeVerticalPadding(int i) {
|
||||
this.overridingState.badgeVerticalPadding = Integer.valueOf(i);
|
||||
this.currentState.badgeVerticalPadding = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getHorizontalOffsetWithoutText() {
|
||||
return this.currentState.horizontalOffsetWithoutText.intValue();
|
||||
}
|
||||
|
||||
void setHorizontalOffsetWithoutText(int i) {
|
||||
this.overridingState.horizontalOffsetWithoutText = Integer.valueOf(i);
|
||||
this.currentState.horizontalOffsetWithoutText = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getVerticalOffsetWithoutText() {
|
||||
return this.currentState.verticalOffsetWithoutText.intValue();
|
||||
}
|
||||
|
||||
void setVerticalOffsetWithoutText(int i) {
|
||||
this.overridingState.verticalOffsetWithoutText = Integer.valueOf(i);
|
||||
this.currentState.verticalOffsetWithoutText = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getHorizontalOffsetWithText() {
|
||||
return this.currentState.horizontalOffsetWithText.intValue();
|
||||
}
|
||||
|
||||
void setHorizontalOffsetWithText(int i) {
|
||||
this.overridingState.horizontalOffsetWithText = Integer.valueOf(i);
|
||||
this.currentState.horizontalOffsetWithText = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getVerticalOffsetWithText() {
|
||||
return this.currentState.verticalOffsetWithText.intValue();
|
||||
}
|
||||
|
||||
void setVerticalOffsetWithText(int i) {
|
||||
this.overridingState.verticalOffsetWithText = Integer.valueOf(i);
|
||||
this.currentState.verticalOffsetWithText = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getLargeFontVerticalOffsetAdjustment() {
|
||||
return this.currentState.largeFontVerticalOffsetAdjustment.intValue();
|
||||
}
|
||||
|
||||
void setLargeFontVerticalOffsetAdjustment(int i) {
|
||||
this.overridingState.largeFontVerticalOffsetAdjustment = Integer.valueOf(i);
|
||||
this.currentState.largeFontVerticalOffsetAdjustment = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getAdditionalHorizontalOffset() {
|
||||
return this.currentState.additionalHorizontalOffset.intValue();
|
||||
}
|
||||
|
||||
void setAdditionalHorizontalOffset(int i) {
|
||||
this.overridingState.additionalHorizontalOffset = Integer.valueOf(i);
|
||||
this.currentState.additionalHorizontalOffset = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
int getAdditionalVerticalOffset() {
|
||||
return this.currentState.additionalVerticalOffset.intValue();
|
||||
}
|
||||
|
||||
void setAdditionalVerticalOffset(int i) {
|
||||
this.overridingState.additionalVerticalOffset = Integer.valueOf(i);
|
||||
this.currentState.additionalVerticalOffset = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
CharSequence getContentDescriptionForText() {
|
||||
return this.currentState.contentDescriptionForText;
|
||||
}
|
||||
|
||||
void setContentDescriptionForText(CharSequence charSequence) {
|
||||
this.overridingState.contentDescriptionForText = charSequence;
|
||||
this.currentState.contentDescriptionForText = charSequence;
|
||||
}
|
||||
|
||||
CharSequence getContentDescriptionNumberless() {
|
||||
return this.currentState.contentDescriptionNumberless;
|
||||
}
|
||||
|
||||
void setContentDescriptionNumberless(CharSequence charSequence) {
|
||||
this.overridingState.contentDescriptionNumberless = charSequence;
|
||||
this.currentState.contentDescriptionNumberless = charSequence;
|
||||
}
|
||||
|
||||
int getContentDescriptionQuantityStrings() {
|
||||
return this.currentState.contentDescriptionQuantityStrings;
|
||||
}
|
||||
|
||||
void setContentDescriptionQuantityStringsResource(int i) {
|
||||
this.overridingState.contentDescriptionQuantityStrings = i;
|
||||
this.currentState.contentDescriptionQuantityStrings = i;
|
||||
}
|
||||
|
||||
int getContentDescriptionExceedsMaxBadgeNumberStringResource() {
|
||||
return this.currentState.contentDescriptionExceedsMaxBadgeNumberRes;
|
||||
}
|
||||
|
||||
void setContentDescriptionExceedsMaxBadgeNumberStringResource(int i) {
|
||||
this.overridingState.contentDescriptionExceedsMaxBadgeNumberRes = i;
|
||||
this.currentState.contentDescriptionExceedsMaxBadgeNumberRes = i;
|
||||
}
|
||||
|
||||
Locale getNumberLocale() {
|
||||
return this.currentState.numberLocale;
|
||||
}
|
||||
|
||||
void setNumberLocale(Locale locale) {
|
||||
this.overridingState.numberLocale = locale;
|
||||
this.currentState.numberLocale = locale;
|
||||
}
|
||||
|
||||
boolean isAutoAdjustedToGrandparentBounds() {
|
||||
return this.currentState.autoAdjustToWithinGrandparentBounds.booleanValue();
|
||||
}
|
||||
|
||||
void setAutoAdjustToGrandparentBounds(boolean z) {
|
||||
this.overridingState.autoAdjustToWithinGrandparentBounds = Boolean.valueOf(z);
|
||||
this.currentState.autoAdjustToWithinGrandparentBounds = Boolean.valueOf(z);
|
||||
}
|
||||
|
||||
private static int readColorFromAttributes(Context context, TypedArray typedArray, int i) {
|
||||
return MaterialResources.getColorStateList(context, typedArray, i).getDefaultColor();
|
||||
}
|
||||
|
||||
public static final class State implements Parcelable {
|
||||
private static final int BADGE_NUMBER_NONE = -1;
|
||||
public static final Parcelable.Creator<State> CREATOR = new Parcelable.Creator<State>() { // from class: com.google.android.material.badge.BadgeState.State.1
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public State createFromParcel(Parcel parcel) {
|
||||
return new State(parcel);
|
||||
}
|
||||
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public State[] newArray(int i) {
|
||||
return new State[i];
|
||||
}
|
||||
};
|
||||
private static final int NOT_SET = -2;
|
||||
private Integer additionalHorizontalOffset;
|
||||
private Integer additionalVerticalOffset;
|
||||
private int alpha;
|
||||
private Boolean autoAdjustToWithinGrandparentBounds;
|
||||
private Integer backgroundColor;
|
||||
private Integer badgeGravity;
|
||||
private Integer badgeHorizontalPadding;
|
||||
private int badgeResId;
|
||||
private Integer badgeShapeAppearanceOverlayResId;
|
||||
private Integer badgeShapeAppearanceResId;
|
||||
private Integer badgeTextAppearanceResId;
|
||||
private Integer badgeTextColor;
|
||||
private Integer badgeVerticalPadding;
|
||||
private Integer badgeWithTextShapeAppearanceOverlayResId;
|
||||
private Integer badgeWithTextShapeAppearanceResId;
|
||||
private int contentDescriptionExceedsMaxBadgeNumberRes;
|
||||
private CharSequence contentDescriptionForText;
|
||||
private CharSequence contentDescriptionNumberless;
|
||||
private int contentDescriptionQuantityStrings;
|
||||
private Integer horizontalOffsetWithText;
|
||||
private Integer horizontalOffsetWithoutText;
|
||||
private Boolean isVisible;
|
||||
private Integer largeFontVerticalOffsetAdjustment;
|
||||
private int maxCharacterCount;
|
||||
private int maxNumber;
|
||||
private int number;
|
||||
private Locale numberLocale;
|
||||
private String text;
|
||||
private Integer verticalOffsetWithText;
|
||||
private Integer verticalOffsetWithoutText;
|
||||
|
||||
@Override // android.os.Parcelable
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public State() {
|
||||
this.alpha = 255;
|
||||
this.number = -2;
|
||||
this.maxCharacterCount = -2;
|
||||
this.maxNumber = -2;
|
||||
this.isVisible = true;
|
||||
}
|
||||
|
||||
State(Parcel parcel) {
|
||||
this.alpha = 255;
|
||||
this.number = -2;
|
||||
this.maxCharacterCount = -2;
|
||||
this.maxNumber = -2;
|
||||
this.isVisible = true;
|
||||
this.badgeResId = parcel.readInt();
|
||||
this.backgroundColor = (Integer) parcel.readSerializable();
|
||||
this.badgeTextColor = (Integer) parcel.readSerializable();
|
||||
this.badgeTextAppearanceResId = (Integer) parcel.readSerializable();
|
||||
this.badgeShapeAppearanceResId = (Integer) parcel.readSerializable();
|
||||
this.badgeShapeAppearanceOverlayResId = (Integer) parcel.readSerializable();
|
||||
this.badgeWithTextShapeAppearanceResId = (Integer) parcel.readSerializable();
|
||||
this.badgeWithTextShapeAppearanceOverlayResId = (Integer) parcel.readSerializable();
|
||||
this.alpha = parcel.readInt();
|
||||
this.text = parcel.readString();
|
||||
this.number = parcel.readInt();
|
||||
this.maxCharacterCount = parcel.readInt();
|
||||
this.maxNumber = parcel.readInt();
|
||||
this.contentDescriptionForText = parcel.readString();
|
||||
this.contentDescriptionNumberless = parcel.readString();
|
||||
this.contentDescriptionQuantityStrings = parcel.readInt();
|
||||
this.badgeGravity = (Integer) parcel.readSerializable();
|
||||
this.badgeHorizontalPadding = (Integer) parcel.readSerializable();
|
||||
this.badgeVerticalPadding = (Integer) parcel.readSerializable();
|
||||
this.horizontalOffsetWithoutText = (Integer) parcel.readSerializable();
|
||||
this.verticalOffsetWithoutText = (Integer) parcel.readSerializable();
|
||||
this.horizontalOffsetWithText = (Integer) parcel.readSerializable();
|
||||
this.verticalOffsetWithText = (Integer) parcel.readSerializable();
|
||||
this.largeFontVerticalOffsetAdjustment = (Integer) parcel.readSerializable();
|
||||
this.additionalHorizontalOffset = (Integer) parcel.readSerializable();
|
||||
this.additionalVerticalOffset = (Integer) parcel.readSerializable();
|
||||
this.isVisible = (Boolean) parcel.readSerializable();
|
||||
this.numberLocale = (Locale) parcel.readSerializable();
|
||||
this.autoAdjustToWithinGrandparentBounds = (Boolean) parcel.readSerializable();
|
||||
}
|
||||
|
||||
@Override // android.os.Parcelable
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeInt(this.badgeResId);
|
||||
parcel.writeSerializable(this.backgroundColor);
|
||||
parcel.writeSerializable(this.badgeTextColor);
|
||||
parcel.writeSerializable(this.badgeTextAppearanceResId);
|
||||
parcel.writeSerializable(this.badgeShapeAppearanceResId);
|
||||
parcel.writeSerializable(this.badgeShapeAppearanceOverlayResId);
|
||||
parcel.writeSerializable(this.badgeWithTextShapeAppearanceResId);
|
||||
parcel.writeSerializable(this.badgeWithTextShapeAppearanceOverlayResId);
|
||||
parcel.writeInt(this.alpha);
|
||||
parcel.writeString(this.text);
|
||||
parcel.writeInt(this.number);
|
||||
parcel.writeInt(this.maxCharacterCount);
|
||||
parcel.writeInt(this.maxNumber);
|
||||
CharSequence charSequence = this.contentDescriptionForText;
|
||||
parcel.writeString(charSequence != null ? charSequence.toString() : null);
|
||||
CharSequence charSequence2 = this.contentDescriptionNumberless;
|
||||
parcel.writeString(charSequence2 != null ? charSequence2.toString() : null);
|
||||
parcel.writeInt(this.contentDescriptionQuantityStrings);
|
||||
parcel.writeSerializable(this.badgeGravity);
|
||||
parcel.writeSerializable(this.badgeHorizontalPadding);
|
||||
parcel.writeSerializable(this.badgeVerticalPadding);
|
||||
parcel.writeSerializable(this.horizontalOffsetWithoutText);
|
||||
parcel.writeSerializable(this.verticalOffsetWithoutText);
|
||||
parcel.writeSerializable(this.horizontalOffsetWithText);
|
||||
parcel.writeSerializable(this.verticalOffsetWithText);
|
||||
parcel.writeSerializable(this.largeFontVerticalOffsetAdjustment);
|
||||
parcel.writeSerializable(this.additionalHorizontalOffset);
|
||||
parcel.writeSerializable(this.additionalVerticalOffset);
|
||||
parcel.writeSerializable(this.isVisible);
|
||||
parcel.writeSerializable(this.numberLocale);
|
||||
parcel.writeSerializable(this.autoAdjustToWithinGrandparentBounds);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
package com.google.android.material.badge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import androidx.appcompat.view.menu.ActionMenuItemView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.AccessibilityDelegateCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import com.google.android.material.R;
|
||||
import com.google.android.material.badge.BadgeState;
|
||||
import com.google.android.material.internal.ParcelableSparseArray;
|
||||
import com.google.android.material.internal.ToolbarUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BadgeUtils {
|
||||
private static final String LOG_TAG = "BadgeUtils";
|
||||
public static final boolean USE_COMPAT_PARENT = false;
|
||||
|
||||
private BadgeUtils() {
|
||||
}
|
||||
|
||||
public static void updateBadgeBounds(Rect rect, float f, float f2, float f3, float f4) {
|
||||
rect.set((int) (f - f3), (int) (f2 - f4), (int) (f + f3), (int) (f2 + f4));
|
||||
}
|
||||
|
||||
public static void attachBadgeDrawable(BadgeDrawable badgeDrawable, View view) {
|
||||
attachBadgeDrawable(badgeDrawable, view, (FrameLayout) null);
|
||||
}
|
||||
|
||||
public static void attachBadgeDrawable(BadgeDrawable badgeDrawable, View view, FrameLayout frameLayout) {
|
||||
setBadgeDrawableBounds(badgeDrawable, view, frameLayout);
|
||||
if (badgeDrawable.getCustomBadgeParent() != null) {
|
||||
badgeDrawable.getCustomBadgeParent().setForeground(badgeDrawable);
|
||||
} else {
|
||||
if (USE_COMPAT_PARENT) {
|
||||
throw new IllegalArgumentException("Trying to reference null customBadgeParent");
|
||||
}
|
||||
view.getOverlay().add(badgeDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void attachBadgeDrawable(BadgeDrawable badgeDrawable, Toolbar toolbar, int i) {
|
||||
attachBadgeDrawable(badgeDrawable, toolbar, i, null);
|
||||
}
|
||||
|
||||
public static void attachBadgeDrawable(final BadgeDrawable badgeDrawable, final Toolbar toolbar, final int i, final FrameLayout frameLayout) {
|
||||
toolbar.post(new Runnable() { // from class: com.google.android.material.badge.BadgeUtils.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
ActionMenuItemView actionMenuItemView = ToolbarUtils.getActionMenuItemView(Toolbar.this, i);
|
||||
if (actionMenuItemView != null) {
|
||||
BadgeUtils.setToolbarOffset(badgeDrawable, Toolbar.this.getResources());
|
||||
BadgeUtils.attachBadgeDrawable(badgeDrawable, actionMenuItemView, frameLayout);
|
||||
BadgeUtils.attachBadgeContentDescription(badgeDrawable, actionMenuItemView);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public static void attachBadgeContentDescription(final BadgeDrawable badgeDrawable, View view) {
|
||||
View.AccessibilityDelegate accessibilityDelegate;
|
||||
if (Build.VERSION.SDK_INT >= 29 && ViewCompat.hasAccessibilityDelegate(view)) {
|
||||
accessibilityDelegate = view.getAccessibilityDelegate();
|
||||
ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat(accessibilityDelegate) { // from class: com.google.android.material.badge.BadgeUtils.2
|
||||
@Override // androidx.core.view.AccessibilityDelegateCompat
|
||||
public void onInitializeAccessibilityNodeInfo(View view2, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
|
||||
super.onInitializeAccessibilityNodeInfo(view2, accessibilityNodeInfoCompat);
|
||||
accessibilityNodeInfoCompat.setContentDescription(badgeDrawable.getContentDescription());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat() { // from class: com.google.android.material.badge.BadgeUtils.3
|
||||
@Override // androidx.core.view.AccessibilityDelegateCompat
|
||||
public void onInitializeAccessibilityNodeInfo(View view2, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
|
||||
super.onInitializeAccessibilityNodeInfo(view2, accessibilityNodeInfoCompat);
|
||||
accessibilityNodeInfoCompat.setContentDescription(BadgeDrawable.this.getContentDescription());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void detachBadgeDrawable(BadgeDrawable badgeDrawable, View view) {
|
||||
if (badgeDrawable == null) {
|
||||
return;
|
||||
}
|
||||
if (USE_COMPAT_PARENT || badgeDrawable.getCustomBadgeParent() != null) {
|
||||
badgeDrawable.getCustomBadgeParent().setForeground(null);
|
||||
} else {
|
||||
view.getOverlay().remove(badgeDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void detachBadgeDrawable(BadgeDrawable badgeDrawable, Toolbar toolbar, int i) {
|
||||
if (badgeDrawable == null) {
|
||||
return;
|
||||
}
|
||||
ActionMenuItemView actionMenuItemView = ToolbarUtils.getActionMenuItemView(toolbar, i);
|
||||
if (actionMenuItemView != null) {
|
||||
removeToolbarOffset(badgeDrawable);
|
||||
detachBadgeDrawable(badgeDrawable, actionMenuItemView);
|
||||
detachBadgeContentDescription(actionMenuItemView);
|
||||
} else {
|
||||
Log.w(LOG_TAG, "Trying to remove badge from a null menuItemView: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void detachBadgeContentDescription(View view) {
|
||||
View.AccessibilityDelegate accessibilityDelegate;
|
||||
if (Build.VERSION.SDK_INT >= 29 && ViewCompat.hasAccessibilityDelegate(view)) {
|
||||
accessibilityDelegate = view.getAccessibilityDelegate();
|
||||
ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat(accessibilityDelegate) { // from class: com.google.android.material.badge.BadgeUtils.4
|
||||
@Override // androidx.core.view.AccessibilityDelegateCompat
|
||||
public void onInitializeAccessibilityNodeInfo(View view2, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
|
||||
super.onInitializeAccessibilityNodeInfo(view2, accessibilityNodeInfoCompat);
|
||||
accessibilityNodeInfoCompat.setContentDescription(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ViewCompat.setAccessibilityDelegate(view, null);
|
||||
}
|
||||
}
|
||||
|
||||
static void setToolbarOffset(BadgeDrawable badgeDrawable, Resources resources) {
|
||||
badgeDrawable.setAdditionalHorizontalOffset(resources.getDimensionPixelOffset(R.dimen.mtrl_badge_toolbar_action_menu_item_horizontal_offset));
|
||||
badgeDrawable.setAdditionalVerticalOffset(resources.getDimensionPixelOffset(R.dimen.mtrl_badge_toolbar_action_menu_item_vertical_offset));
|
||||
}
|
||||
|
||||
static void removeToolbarOffset(BadgeDrawable badgeDrawable) {
|
||||
badgeDrawable.setAdditionalHorizontalOffset(0);
|
||||
badgeDrawable.setAdditionalVerticalOffset(0);
|
||||
}
|
||||
|
||||
public static void setBadgeDrawableBounds(BadgeDrawable badgeDrawable, View view, FrameLayout frameLayout) {
|
||||
Rect rect = new Rect();
|
||||
view.getDrawingRect(rect);
|
||||
badgeDrawable.setBounds(rect);
|
||||
badgeDrawable.updateBadgeCoordinates(view, frameLayout);
|
||||
}
|
||||
|
||||
public static ParcelableSparseArray createParcelableBadgeStates(SparseArray<BadgeDrawable> sparseArray) {
|
||||
ParcelableSparseArray parcelableSparseArray = new ParcelableSparseArray();
|
||||
for (int i = 0; i < sparseArray.size(); i++) {
|
||||
int keyAt = sparseArray.keyAt(i);
|
||||
BadgeDrawable valueAt = sparseArray.valueAt(i);
|
||||
parcelableSparseArray.put(keyAt, valueAt != null ? valueAt.getSavedState() : null);
|
||||
}
|
||||
return parcelableSparseArray;
|
||||
}
|
||||
|
||||
public static SparseArray<BadgeDrawable> createBadgeDrawablesFromSavedStates(Context context, ParcelableSparseArray parcelableSparseArray) {
|
||||
SparseArray<BadgeDrawable> sparseArray = new SparseArray<>(parcelableSparseArray.size());
|
||||
for (int i = 0; i < parcelableSparseArray.size(); i++) {
|
||||
int keyAt = parcelableSparseArray.keyAt(i);
|
||||
BadgeState.State state = (BadgeState.State) parcelableSparseArray.valueAt(i);
|
||||
sparseArray.put(keyAt, state != null ? BadgeDrawable.createFromSavedState(context, state) : null);
|
||||
}
|
||||
return sparseArray;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.google.android.material.badge;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE})
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
/* loaded from: classes.dex */
|
||||
public @interface ExperimentalBadgeUtils {
|
||||
}
|
Reference in New Issue
Block a user