package com.nsgk.ruralWeb;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.nsgk.ruralWeb.sys.NSConstants;

public class WelcomeActivity extends AppCompatActivity {
    private ImageView imageView;
    private LinearLayout llcenter;

    private Handler handler = new Handler() {
        @SuppressLint("HandlerLeak")
        @Override
        public void handleMessage(@NonNull Message msg) {

            switch (msg.what) {
                case 1:
                    finish();
                    Intent intent = new Intent(WelcomeActivity.this, FullscreenActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
                    break;
                default:
                    throw new IllegalStateException("Unexpected value: " + msg.what);
            }
        }
    };

    private String GetTrimString(String str)
    {
        if(null == str || str.isEmpty())
            return null;
        str = str.trim();
        if(str.isEmpty())
            return null;
        return str;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_welcome);
        imageView = findViewById(R.id.imageView);
        llcenter = findViewById(R.id.llcenter);

        // 动态设置启动页版权信息
        String text = GetTrimString(NSConstants.AppCopyright());
        if(null != text)
        {
            TextView copyrightText = findViewById(R.id.welcome_text_copyright);
            copyrightText.setText(text);
        }
        // 动态设置启动页厂商名称
        text = GetTrimString(NSConstants.AppVendor());
        if(null != text)
        {
            TextView vendorText = findViewById(R.id.welcome_text_vendor);
            vendorText.setText(text);
        }

        Animation animation = AnimationUtils.loadAnimation(this, R.anim.img_anim);
        animation.start();
        handler.sendEmptyMessageDelayed(1, 1000);
    }
}
