NekoX/TMessagesProj/src/main/java/org/telegram/ui/Cells/PhotoEditToolCell.java

150 lines
6.1 KiB
Java
Raw Normal View History

2015-02-01 19:51:02 +01:00
/*
* This is the source code of Telegram for Android v. 2.0.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2015-02-01 19:51:02 +01:00
*/
package org.telegram.ui.Cells;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
2015-02-01 19:51:02 +01:00
import android.content.Context;
import android.text.TextUtils;
2015-02-01 19:51:02 +01:00
import android.util.TypedValue;
import android.view.Gravity;
2020-07-26 10:03:38 +02:00
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
2015-02-01 19:51:02 +01:00
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2021-09-20 00:10:42 +02:00
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.PhotoEditorSeekBar;
2015-02-01 19:51:02 +01:00
public class PhotoEditToolCell extends FrameLayout {
2015-02-01 19:51:02 +01:00
2021-09-20 00:10:42 +02:00
private final Theme.ResourcesProvider resourcesProvider;
2015-02-01 19:51:02 +01:00
private TextView nameTextView;
private TextView valueTextView;
private PhotoEditorSeekBar seekBar;
private AnimatorSet valueAnimation;
private Runnable hideValueRunnable = new Runnable() {
@Override
public void run() {
valueTextView.setTag(null);
valueAnimation = new AnimatorSet();
valueAnimation.playTogether(
2020-07-26 10:03:38 +02:00
ObjectAnimator.ofFloat(valueTextView, View.ALPHA, 0.0f),
ObjectAnimator.ofFloat(nameTextView, View.ALPHA, 1.0f));
valueAnimation.setDuration(250);
valueAnimation.setInterpolator(new DecelerateInterpolator());
valueAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animation.equals(valueAnimation)) {
valueAnimation = null;
}
}
});
valueAnimation.start();
}
};
2015-02-01 19:51:02 +01:00
2021-09-20 00:10:42 +02:00
public PhotoEditToolCell(Context context, Theme.ResourcesProvider resourcesProvider) {
2015-02-01 19:51:02 +01:00
super(context);
2021-09-20 00:10:42 +02:00
this.resourcesProvider = resourcesProvider;
2015-02-01 19:51:02 +01:00
nameTextView = new TextView(context);
nameTextView.setGravity(Gravity.RIGHT);
2015-02-01 19:51:02 +01:00
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
addView(nameTextView, LayoutHelper.createFrame(80, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 0, 0, 0, 0));
valueTextView = new TextView(context);
2021-09-20 00:10:42 +02:00
valueTextView.setTextColor(getThemedColor(Theme.key_dialogFloatingButton));
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
valueTextView.setGravity(Gravity.RIGHT);
2017-03-31 01:58:05 +02:00
valueTextView.setSingleLine(true);
addView(valueTextView, LayoutHelper.createFrame(80, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 0, 0, 0, 0));
seekBar = new PhotoEditorSeekBar(context);
addView(seekBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 40, Gravity.LEFT | Gravity.CENTER_VERTICAL, 96, 0, 24, 0));
}
public void setSeekBarDelegate(final PhotoEditorSeekBar.PhotoEditorSeekBarDelegate photoEditorSeekBarDelegate) {
2020-07-26 10:03:38 +02:00
seekBar.setDelegate((i, progress) -> {
photoEditorSeekBarDelegate.onProgressChanged(i, progress);
if (progress > 0) {
valueTextView.setText("+" + progress);
} else {
valueTextView.setText("" + progress);
}
if (valueTextView.getTag() == null) {
if (valueAnimation != null) {
valueAnimation.cancel();
}
2020-07-26 10:03:38 +02:00
valueTextView.setTag(1);
valueAnimation = new AnimatorSet();
valueAnimation.playTogether(
ObjectAnimator.ofFloat(valueTextView, View.ALPHA, 1.0f),
ObjectAnimator.ofFloat(nameTextView, View.ALPHA, 0.0f));
valueAnimation.setDuration(250);
valueAnimation.setInterpolator(new DecelerateInterpolator());
valueAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
AndroidUtilities.runOnUIThread(hideValueRunnable, 1000);
}
2020-07-26 10:03:38 +02:00
});
valueAnimation.start();
} else {
AndroidUtilities.cancelRunOnUIThread(hideValueRunnable);
AndroidUtilities.runOnUIThread(hideValueRunnable, 1000);
}
});
}
@Override
public void setTag(Object tag) {
super.setTag(tag);
seekBar.setTag(tag);
2015-02-01 19:51:02 +01:00
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40), MeasureSpec.EXACTLY));
2015-02-01 19:51:02 +01:00
}
public void setIconAndTextAndValue(String text, float value, int min, int max) {
if (valueAnimation != null) {
valueAnimation.cancel();
valueAnimation = null;
}
AndroidUtilities.cancelRunOnUIThread(hideValueRunnable);
valueTextView.setTag(null);
nameTextView.setText(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase());
if (value > 0) {
valueTextView.setText("+" + (int) value);
} else {
valueTextView.setText("" + (int) value);
}
valueTextView.setAlpha(0.0f);
nameTextView.setAlpha(1.0f);
seekBar.setMinMax(min, max);
seekBar.setProgress((int) value, false);
}
2021-09-20 00:10:42 +02:00
private int getThemedColor(String key) {
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
return color != null ? color : Theme.getColor(key);
}
2015-02-01 19:51:02 +01:00
}