package com.fusi24.entryPermitScanner.util;

import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;

import com.fusi24.entryPermitScanner.R;

public abstract class LFScanProcessing extends LFSerialPortActivity {

    protected int soundid;
    protected SoundPool soundpool = null;
    protected AudioAttributes attributes = null;

    public String rfidCardNumber = "";

    protected void initSound(){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            attributes = new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
                    .build();

            soundpool = new SoundPool.Builder()
                    .setMaxStreams(1)
                    .setAudioAttributes(attributes)
                    .build();
        } else {
            soundpool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 100);
        }
        soundid = soundpool.load(this, R.raw.rfid_beep, 1);
    }

    @Override
    protected void onStart() {
        super.onStart();

        // Start Reception
        if (getSessionManager().isSerialPort2()){
            PowerUtil.power("1", true);
        } else {
            // Serial Port 3
            PowerUtil.power("1", false);
        }
        this.open();
    }

    @Override
    protected void onStop() {
        super.onStop();

        // Stop Reception
        this.close();
        if (getSessionManager().isSerialPort2()){
            PowerUtil.power("0", true);
        } else {
            // Serial Port 3
            PowerUtil.power("0", false);
        }
    }
}
