package com.snap.wall.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import com.snap.wall.R;
import com.snap.wall.mytool.Comutils;
import android.os.CountDownTimer;

public class OneActivity extends AppCompatActivity {
    private static final long TOTAL_TIME = 2000;
    // 进度更新间隔（50毫秒）
    private static final long UPDATE_INTERVAL = 50;

    private ProgressBar progressBar;
    private TextView tvProgress;
    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Comutils.initFull(this, false);
        setContentView(R.layout.activity_one);
        progressBar = findViewById(R.id.progressbar);
        tvProgress = findViewById(R.id.tv_progress);
        progressBar.setMax(100);
        startCountDown();
    }
    private void startCountDown() {
        countDownTimer = new CountDownTimer(TOTAL_TIME, UPDATE_INTERVAL) {
            @Override
            public void onTick(long millisUntilFinished) {
                long elapsedTime = TOTAL_TIME - millisUntilFinished;
                int progress = (int) (elapsedTime * 100 / TOTAL_TIME);
                progressBar.setProgress(progress);
                tvProgress.setText(progress + "%");
            }

            @Override
            public void onFinish() {
                progressBar.setProgress(100);
                tvProgress.setText("100%");
                Intent intent = new Intent(OneActivity.this, PrimaryActivity.class);
                startActivity(intent);
                finish();
            }
        }.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
    }
}