package com.app.wallpaper.myact;

import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.animation.DecelerateInterpolator;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import com.app.wallpaper.databinding.ActivityLogin2Binding;

public class LoginActivity extends AppCompatActivity {
    private ActivityLogin2Binding binding;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityLogin2Binding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        EdgeToEdge.enable(this);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                // 使用 ValueAnimator 创建进度条动画
                ValueAnimator animation = ValueAnimator.ofInt(0, binding.progressBar.getMax());
                animation.setDuration(2500); // 动画时长
                animation.setInterpolator(new DecelerateInterpolator()); // 减速插值器
                animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        binding.progressBar.setProgress((int) animation.getAnimatedValue());
                    }
                });
                animation.start();
                // 动画结束后跳转到新页面
                animation.addListener(new android.animation.Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(android.animation.Animator animation) {}

                    @Override
                    public void onAnimationEnd(android.animation.Animator animation) {
                        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                        startActivity(intent);
                        finish(); // 可选：结束当前 Activity
                    }
                    @Override
                    public void onAnimationCancel(android.animation.Animator animation) {}

                    @Override
                    public void onAnimationRepeat(android.animation.Animator animation) {}
                });
            }
        }, 1000);
    }

}