package com.example.displaydemo;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.displaydemo.base.BaseActivity;
import com.pavolibrary.commands.Constant;
import com.pavolibrary.utils.LogUtils;


public class MainActivity extends BaseActivity implements View.OnClickListener {

    private static final String TAG = "MainActivity";

    private TextView tv_sdkversion;


    private Button btn_pd108;
    private Button btn_pd220;
    private Button btn_pd280;
    private Button btn_pd500;

    @Override
    public int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        String appName = getString(R.string.app_name);
        String appVersion;
        PackageManager manager = this.getPackageManager();
        try {
            PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
            appVersion = info.versionName;
            setTitle(appName + " v" + appVersion);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        tv_sdkversion = findViewById(R.id.textSdkVersion);

        btn_pd108 = findViewById(R.id.btn_pd108);
        btn_pd220 = findViewById(R.id.btn_pd220);
        btn_pd280 = findViewById(R.id.btn_pd280);
        btn_pd500 = findViewById(R.id.btn_pd500);
    }

    @Override
    public void initData() {
        LogUtils.isWrite = false;  //写日志到文本 sdcard/log/dsp/
        LogUtils.isDeBug = true;
        verifyStoragePermissions(this);  //申请存储权限

        tv_sdkversion.setText("SDK Version: " + Constant.getSdkVersion());
    }

    @Override
    protected void initListener() {
        btn_pd108.setOnClickListener(this);
        btn_pd220.setOnClickListener(this);
        btn_pd280.setOnClickListener(this);
        btn_pd500.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn_pd108:
                intent = new Intent(MainActivity.this, PD108Activity.class);
                startActivity(intent);
                break;
            case R.id.btn_pd220:
                intent = new Intent(MainActivity.this, PD220Activity.class);
                startActivity(intent);
                break;
            case R.id.btn_pd280:
                intent = new Intent(MainActivity.this, PD280Activity.class);
                startActivity(intent);
                break;
            case R.id.btn_pd500:
                intent = new Intent(MainActivity.this, PD500Activity.class);
                startActivity(intent);
                break;
        }
    }

}
