package sto.android.app;

import java.io.UnsupportedEncodingException;
import java.util.Calendar;

import android.content.Context;
import android.content.Intent;

public class RX70Scanner {

	public static RX70Scanner instance = null;

	public StoJNI.ScanCallBack scanCallBack;

	public static synchronized RX70Scanner getInstance() {
		if (instance == null) {
			instance = new RX70Scanner();
		}
		return instance;
	}

	private static boolean bScanning = false;
	boolean m_soft = false;

	Context m_contextContext = null;

	public void Barcode_open() {
		close();
		close();
		open();
	}

	public void Barcode_Close() {

		close();

	}

	public void Barcode_StartScan() {
		SetScannerStop();
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SetScannerStart();
	}

	public void Barcode_StopScan() {
		SetScannerStop();
	}

	public void ScanResults(byte[] str) {
		if (scanCallBack == null)
			return;
		String info = "";
		try {
			info = new String(str, "UTF-8");
			if (info != null && info.length() > 0) {
				scanCallBack.onScanResults(info);
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

	}

	public int Barcode_Write(byte[] data) {
		return write(data);
	}

	private native void open();

	private native void close();

	private native void SetScannerStart();

	private native void SetScannerStop();

	public native void setpowerstate(int controll);

	public native int write(byte[] data);

	public native int GetPlatform();
	public native String GetMachineCode(Context mContext);

	static {
		System.loadLibrary("RX70Dev");
	}
	
	
	public void SetSystemTime (Context context,String mm ){
		long lDate=Long.valueOf(mm);
		 java.util.Date nowTime = new java.util.Date(lDate);
	  
	 	  
	 	  Calendar cal=Calendar.getInstance(); 
	 	 cal.setTime(nowTime);
	 	 
	 	 int year = cal.get(Calendar.YEAR);//获取年份
	        int month=cal.get(Calendar.MONTH)+1;//获取月份
	        int day=cal.get(Calendar.DATE);//获取日
	        int hour=cal.get(Calendar.HOUR_OF_DAY);//小时
	        int minute=cal.get(Calendar.MINUTE);//分           
	        int second=cal.get(Calendar.SECOND);//秒
	        

			Intent intent = new Intent("com.System.TimeSetting");
			intent.putExtra("year", year);
			intent.putExtra("month", month);
			intent.putExtra("day", day);
			intent.putExtra("hour", hour);
			intent.putExtra("minute", minute);
			intent.putExtra("second", second);
			context.sendBroadcast(intent);
	}
}
