package macampcorp.macamp.activities;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class CrashActivity extends AppCompatActivity {
    protected ImageView mImage;
    protected ImageView mBsod;
    protected View      mRoot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crash);
        mImage=findViewById(R.id.im_anim);
        mBsod=findViewById(R.id.im_bsod);
        mRoot=findViewById(R.id.ll_root);

        ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(mImage, "scaleX", 0);
        ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(mImage, "scaleY", 0);
        scaleDownX.setDuration(300);
        scaleDownY.setDuration(300);

        AnimatorSet scaleDown = new AnimatorSet();
        scaleDown.play(scaleDownX).with(scaleDownY);
        final MediaPlayer mp = MediaPlayer.create(this, R.raw.boom);
        mp.start();
        scaleDown.start();

        final Activity t = this;
        final Handler handler = new Handler();
        final Runnable r = new Runnable()
        {
            public void run()
            {
                mRoot.setBackgroundColor(0xff0000fe);
                mBsod.setVisibility(View.VISIBLE);
                closeAfter(6000);
            }
        };
        handler.postDelayed(r, 5000);
    }

    public void closeAfter(int x)
    {
        final Activity t = this;
        final Handler handler = new Handler();
        final Runnable r = new Runnable()
        {
            public void run()
            {
                finish();
            }
        };
        handler.postDelayed(r, x);
    }

    public static void start(Activity a)
    {
        Intent it = new Intent(a, CrashActivity.class);
        a.startActivity(it);
    }

    protected void hideActionBar()
    {
        View decorView = getWindow().getDecorView();
// Hide the status bar.
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
        ActionBar actionBar = getActionBar();
        actionBar.hide();
    }
}
