package com.example.terminalprotocol;

import java.io.UnsupportedEncodingException;

import com.sdses.JniCommonInterface;

import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class test_base extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test_base);
	}
	
	public void btn_getModel(View v)
	{
		EditText modelEditText=(EditText)findViewById(R.id.et_model);
		byte[] TerminalModel=new byte[64];
		long res=JniCommonInterface.TerminalGetModel(TerminalModel);
		if(res!=0)
		{
			Toast.makeText(this, "获取设备型号失败，错误代码："+res, 0).show();
			return;
		}		
		try {
			modelEditText.setText(new String(TerminalModel,"GBK"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void btn_SAMId(View v)
	{
		EditText modelEditText=(EditText)findViewById(R.id.et_SAMId);
		byte[] SamIdStr=new byte[64];
		long res=JniCommonInterface.SamGetIdStr(SamIdStr);
		if(res!=0)
		{
			Toast.makeText(this, "获取设备模块号失败，错误代码："+res, 0).show();
			return;
		}
		try {
			modelEditText.setText(new String(SamIdStr,"GBK"));
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}		
	}
	
	public void btn_Handle(View v)
	{
		EditText handleEditText=(EditText)findViewById(R.id.et_Handle);
		long res=JniCommonInterface.GetCurrentDevice();
		if(res<=0)
		{
			Toast.makeText(this, "获取当前设备句柄失败，错误代码："+res, 0).show();
			return;
		}
		Toast.makeText(this, "获取当前设备句成功", 0).show();
		String handle=String.valueOf(res) ;
		handleEditText.setText(handle);
	}
}
