package com.iq.intelligence.study;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;

public class IntoActivity extends AppCompatActivity {

    static int splashTimeOut = 2000 ;
    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.page_into);

        progressBar = findViewById(R.id.h_progress);

        View dectorView = getWindow().getDecorView();
        dectorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_FULLSCREEN |
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        CardView logo = findViewById(R.id.logo);
        TextView appNameText = findViewById(R.id.appName);

        new Handler().postDelayed(() -> {

        }, splashTimeOut);

        CountDownTimer countDownTimer = new CountDownTimer(splashTimeOut, 100) {

            @Override
            public void onTick(long millisUntilFinished) {
                float l1 = (float)millisUntilFinished / splashTimeOut;
                float v = 100-l1 * 100;
                progressBar.setProgress((int) v);
            }

            @Override
            public void onFinish() {
                progressBar.setProgress(100);
                Intent mainActivity = new Intent(IntoActivity.this, MainActivity.class);
                mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(mainActivity);
                finish();
            }
        };
        countDownTimer.start();


        Animation myAnim = AnimationUtils.loadAnimation(this,R.anim.goto_alpha);
        logo.startAnimation(myAnim);
        appNameText.startAnimation(myAnim);
    }
}
