package com.xunao.effectdemo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieAnimationView;
import com.umeng.analytics.MobclickAgent;
import com.xunao.effectdemo.App;
import com.xunao.effectdemo.R;
import com.xunao.effectdemo.bean.World;

import cn.jpush.android.api.JPushInterface;

/**
 * author : 程中强
 * e-mail : 740479946@qq.com
 * date : 2022/8/2317:47
 * desc :
 * version: 1.0
 */
public class StarsActivity extends Activity {

	LottieAnimationView animationView;
	private ImageView imv4,imv5,imv6;
	private Animation mShowAction,animationBig;
	private int i = 0;
	private TextView tv;
	private RelativeLayout rl;
	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_stars);


		animationView = findViewById(R.id.lottie_view);
		animationView.setRepeatCount(0);
		animationView.setOnClickListener(v->animationView.playAnimation());
		tv = findViewById(R.id.tv_score);
		imv4 = findViewById(R.id.imv_star_4);
		imv5 = findViewById(R.id.imv_star_5);
		imv6 = findViewById(R.id.imv_star_6);
		rl = findViewById(R.id.rl_main);
		startAnim(imv4,0);
		startAnim(imv5,500);
		startAnim(imv6,1000);
		rl.setOnClickListener(v->{
			startBig(imv4,0);
			startBig(imv5,500);
			startBig(imv6,1000);
		});

	}

	void startAnim(ImageView imv,int time){
		imv.clearAnimation();
		mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, 6.0f, Animation.RELATIVE_TO_SELF, 0.0f);
		mShowAction.setDuration(500);

		mShowAction.setStartOffset(time);
		mShowAction.setAnimationListener(new Animation.AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {
//				i++;
			}

			@Override
			public void onAnimationEnd(Animation animation) {

				i++;
				tv.setText("+"+i);
//				startBig(imv,time);
			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}
		});
		imv.startAnimation(mShowAction);
	}

	void startBig(ImageView imv,int time){

		animationBig = new ScaleAnimation(0f, 1f, 0f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		animationBig.setDuration(500);
		animationBig.setStartOffset(time);
		animationBig.setAnimationListener(new Animation.AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				imv.clearAnimation();
			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}
		});
		imv.startAnimation(animationBig);
	}
}
