what-the-bank/sources/com/prolificinteractive/materialcalendarview/TitleChanger.java

135 lines
5.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.prolificinteractive.materialcalendarview;
import android.animation.Animator;
import android.content.res.Resources;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.ViewPropertyAnimator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.TextView;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.prolificinteractive.materialcalendarview.format.TitleFormatter;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public class TitleChanger {
public static final int DEFAULT_ANIMATION_DELAY = 400;
public static final int DEFAULT_Y_TRANSLATION_DP = 20;
private final int animDelay;
private final int animDuration;
private final TextView title;
private TitleFormatter titleFormatter;
private final int translate;
private final Interpolator interpolator = new DecelerateInterpolator(2.0f);
private int orientation = 0;
private long lastAnimTime = 0;
private CalendarDay previousMonth = null;
public TitleChanger(TextView textView) {
this.title = textView;
Resources resources = textView.getResources();
this.animDelay = DEFAULT_ANIMATION_DELAY;
this.animDuration = resources.getInteger(android.R.integer.config_shortAnimTime) / 2;
this.translate = (int) TypedValue.applyDimension(1, 20.0f, resources.getDisplayMetrics());
}
public void change(CalendarDay calendarDay) {
long currentTimeMillis = System.currentTimeMillis();
if (calendarDay == null) {
return;
}
if (TextUtils.isEmpty(this.title.getText()) || currentTimeMillis - this.lastAnimTime < this.animDelay) {
doChange(currentTimeMillis, calendarDay, false);
}
if (calendarDay.equals(this.previousMonth)) {
return;
}
if (calendarDay.getMonth() == this.previousMonth.getMonth() && calendarDay.getYear() == this.previousMonth.getYear()) {
return;
}
doChange(currentTimeMillis, calendarDay, true);
}
private void doChange(long j, CalendarDay calendarDay, boolean z) {
this.title.animate().cancel();
doTranslation(this.title, 0);
this.title.setAlpha(1.0f);
this.lastAnimTime = j;
CharSequence format = this.titleFormatter.format(calendarDay);
if (!z) {
this.title.setText(format);
} else {
int i = this.translate * (this.previousMonth.isBefore(calendarDay) ? 1 : -1);
ViewPropertyAnimator animate = this.title.animate();
if (this.orientation == 1) {
animate.translationX(-i);
} else {
animate.translationY(-i);
}
animate.alpha(BitmapDescriptorFactory.HUE_RED).setDuration(this.animDuration).setInterpolator(this.interpolator).setListener(new AnimatorListener(this, format, i) { // from class: com.prolificinteractive.materialcalendarview.TitleChanger.1
final TitleChanger this$0;
final CharSequence val$newTitle;
final int val$translation;
{
this.this$0 = this;
this.val$newTitle = format;
this.val$translation = i;
}
@Override // com.prolificinteractive.materialcalendarview.AnimatorListener, android.animation.Animator.AnimatorListener
public void onAnimationCancel(Animator animator) {
TitleChanger titleChanger = this.this$0;
titleChanger.doTranslation(titleChanger.title, 0);
this.this$0.title.setAlpha(1.0f);
}
@Override // com.prolificinteractive.materialcalendarview.AnimatorListener, android.animation.Animator.AnimatorListener
public void onAnimationEnd(Animator animator) {
this.this$0.title.setText(this.val$newTitle);
TitleChanger titleChanger = this.this$0;
titleChanger.doTranslation(titleChanger.title, this.val$translation);
ViewPropertyAnimator animate2 = this.this$0.title.animate();
if (this.this$0.orientation == 1) {
animate2.translationX(BitmapDescriptorFactory.HUE_RED);
} else {
animate2.translationY(BitmapDescriptorFactory.HUE_RED);
}
animate2.alpha(1.0f).setDuration(this.this$0.animDuration).setInterpolator(this.this$0.interpolator).setListener(new AnimatorListener()).start();
}
}).start();
}
this.previousMonth = calendarDay;
}
/* JADX INFO: Access modifiers changed from: private */
public void doTranslation(TextView textView, int i) {
if (this.orientation == 1) {
textView.setTranslationX(i);
} else {
textView.setTranslationY(i);
}
}
public void setTitleFormatter(TitleFormatter titleFormatter) {
this.titleFormatter = titleFormatter;
}
public void setPreviousMonth(CalendarDay calendarDay) {
this.previousMonth = calendarDay;
}
public void setOrientation(int i) {
this.orientation = i;
}
public TitleFormatter getTitleFormatter() {
return this.titleFormatter;
}
public int getOrientation() {
return this.orientation;
}
}