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;
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
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;
|
2015-02-26 02:32:51 +01:00
|
|
|
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;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2016-06-24 12:27:15 +02:00
|
|
|
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;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2017-07-23 14:56:38 +02:00
|
|
|
import org.telegram.ui.Components.PhotoEditorSeekBar;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2016-06-24 12:27:15 +02: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;
|
2017-07-23 14:56:38 +02:00
|
|
|
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);
|
2017-07-23 14:56:38 +02:00
|
|
|
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);
|
2017-07-23 14:56:38 +02:00
|
|
|
nameTextView.setGravity(Gravity.RIGHT);
|
2015-02-01 19:51:02 +01:00
|
|
|
nameTextView.setTextColor(0xffffffff);
|
2017-07-23 14:56:38 +02:00
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
2015-02-26 02:32:51 +01:00
|
|
|
nameTextView.setMaxLines(1);
|
|
|
|
nameTextView.setSingleLine(true);
|
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
2017-07-23 14:56:38 +02:00
|
|
|
addView(nameTextView, LayoutHelper.createFrame(80, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 0, 0, 0, 0));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
valueTextView = new TextView(context);
|
2021-09-20 00:10:42 +02:00
|
|
|
valueTextView.setTextColor(getThemedColor(Theme.key_dialogFloatingButton));
|
2017-07-23 14:56:38 +02:00
|
|
|
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
|
|
|
valueTextView.setGravity(Gravity.RIGHT);
|
2017-03-31 01:58:05 +02:00
|
|
|
valueTextView.setSingleLine(true);
|
2017-07-23 14:56:38 +02:00
|
|
|
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();
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
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);
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
});
|
|
|
|
valueAnimation.start();
|
|
|
|
} else {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(hideValueRunnable);
|
|
|
|
AndroidUtilities.runOnUIThread(hideValueRunnable, 1000);
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2017-07-23 14:56:38 +02:00
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40), MeasureSpec.EXACTLY));
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2017-07-23 14:56:38 +02: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) {
|
2015-02-26 02:32:51 +01:00
|
|
|
valueTextView.setText("+" + (int) value);
|
|
|
|
} else {
|
|
|
|
valueTextView.setText("" + (int) value);
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
valueTextView.setAlpha(0.0f);
|
|
|
|
nameTextView.setAlpha(1.0f);
|
|
|
|
seekBar.setMinMax(min, max);
|
|
|
|
seekBar.setProgress((int) value, false);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
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
|
|
|
}
|