package com.philisense.rdgo.ui.out;

import android.app.Activity;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.philisense.rdgo.R;
import com.philisense.rdgo.databinding.ActivityOutReplaceBinding;
import com.scandecode.ScanDecode;
import com.scandecode.inf.ScanInterface;

public class OutReplaceActivity extends AppCompatActivity {

    ActivityOutReplaceBinding mBinding;
    private ScanDecode scanDecode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_out_replace);
        Toolbar toolbar = mBinding.include.toolbar;
        toolbar.setTitle("已出库扫码");
        setSupportActionBar(toolbar);

        toolbar.setNavigationOnClickListener(new View.OnClickListener(){
            public void onClick(View view){
                finish();
            }
        });

        // 初始化扫描
        try {
            scanDecode = new ScanDecode(this);
            scanDecode.initService("true");
        }catch (Exception e) {
            Snackbar.make(mBinding.putOutLayout,"本机没有扫码功能",Snackbar.LENGTH_LONG).show();
        }



        scanDecode.getBarCode(new ScanInterface.OnScanListener() {
            @Override
            public void getBarcode(String s) {
                scanDecode.stopScan();
                OutReplaceOrderActivity.start(OutReplaceActivity.this, s);
                finish();
            }
        });




        mBinding.determine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s=mBinding.edit.getText().toString().trim();
                OutReplaceOrderActivity.start(OutReplaceActivity.this, s);
                finish();

            }
        });




    }

    public static void start(Activity context) {
        Intent intent = new Intent(context, OutReplaceActivity.class);
        ActivityCompat.startActivity(context, intent,null);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        try {
            scanDecode.onDestroy();
        }catch (Exception e) {
        }
    }
}
