package com.chinapnr.pos.pay.demo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import timber.log.Timber;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {


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

    private void initView() {
//        btnPay = findViewById(R.id.btn_pay);
//        btnPay.setOnClickListener(this);
        findViewById(R.id.btn_manager).setOnClickListener(this);
        findViewById(R.id.btn_trans).setOnClickListener(this);
        findViewById(R.id.btn_data).setOnClickListener(this);
        findViewById(R.id.btn_hw).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_manager:
                startActivity(new Intent(MainActivity.this, ManagerActivity.class));
                break;
            case R.id.btn_trans:
                startActivity(new Intent(MainActivity.this, TransActivity.class));
                break;
            case R.id.btn_data:
                startActivity(new Intent(MainActivity.this, DataActivity.class));
                break;
            case R.id.btn_hw:
                startActivity(new Intent(MainActivity.this, HwActivity.class));
                break;
//            case R.id.btn_bind:
//                PnrDevice.getInstance(getApplicationContext()).init();
//                break;
            default:
                break;
        }
    }

    @Override
    public void onBackPressed() {
        exitBy2Click();

    }

    private long mExitTime;

    public boolean exitBy2Click() {
        Timber.e("双击退出函数");
        if ((System.currentTimeMillis() - mExitTime) > 2000) {
            Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
            mExitTime = System.currentTimeMillis();
        } else {
//            PnrDevice.getInstance(this).init();
            System.exit(0);
            return false;
        }
        return true;
    }

}