package com.itant.shiwushu;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatImageView;
import android.view.WindowManager;
import android.widget.TextView;

import com.itant.shiwushu.bean.User;
import com.itant.shiwushu.manager.UserManager;
import com.itant.shiwushu.tool.ColorTool;
import com.itant.shiwushu.ui.login.LoginActivity;

/**
 * Created by Jason on 2018/10/2.
 */

public class WelcomeActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        int color = ColorTool.getColorPrimary(this);
        AppCompatImageView iv_welcome = findViewById(R.id.iv_welcome);
        iv_welcome.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN);

        TextView tv_welcome = findViewById(R.id.tv_welcome);
        tv_welcome.setTextColor(color);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                /*if (SafeTool.isDeviceRoot() || SafeTool.isNetworkProxy(WelcomeActivity.this)) {
                    ToastManager.getInstance().toastShort("为了您的账户安全，请勿使用Root设备或VPN网络");
                }*/

                // 防止MainActivity启动时statusbar闪烁，闪烁是由于前一个界面为全屏造成的.解决方法就是将前一个界面在退出前设置为非全屏.
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

                // 判断是否已登录
                User user = UserManager.getInstance().getUser();
                if (user != null) {
                    startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                } else {
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                }
                finish();

            }
        }, 2000);
    }
}
