package com.example.terminalprotocol;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sdses.JniCommonInterface;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class test 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);
	}
}
	
	
	
	
	
	
	/*
	private GridView gridViewtest;
	private String[] from = { "image_test", "text_test" };
	private int[] to = { R.id.image_test, R.id.text_test};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);
		
		gridViewtest = (GridView) findViewById(R.id.gridView_test);
		SimpleAdapter adapter = new SimpleAdapter(this, getList(),
				R.layout.test_item, from, to);
		gridViewtest.setAdapter(adapter);

		gridViewtest.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long id) {
				// TODO Auto-generated method stub
				switch (position) {
				case 0:
					Intent i = new Intent(getApplicationContext(), test_base.class);
					startActivity(i);
					break;			
				default:
					break;
				}
			}
		});

	}

	public List<? extends Map<String, ?>> getList() {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = null;
		int[] imagestest = { R.drawable.x};
		String[] textstest = new String[] { "基本功能" };
		for (int i = 0; i < imagestest.length; i++) {
			map = new HashMap<String, Object>();
			map.put("image_test", imagestest[i]);
			map.put("text_test", textstest[i]);
			list.add(map);
		}
		return list;
	}
	*/
