package com.example.uartscantest;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.tool.SerialPortPreferences;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class HomeActivity extends Activity {
	TextView status;
    TextView mymsg;
    Button start;
    Button stop;

    static int DecodeCnt = 0;
    
    private static final String TAG = "HomeActivity";
    private int selectPosition = -1;
    
    public boolean ExitFlag = false;
    public boolean RetryScan = false;
    public boolean BusyFlag = false;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        
        status = (TextView) findViewById(R.id.device_status);
        mymsg = (TextView) findViewById(R.id.device_msg);
        start = (Button) findViewById(R.id.start_scan);
        stop = (Button) findViewById(R.id.stop_scan);
		//myScan = new ScanActivity(this, myHandler);
        
        final Button buttonSetup = (Button)findViewById(R.id.ButtonSetup);
        buttonSetup.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(HomeActivity.this, SerialPortPreferences.class));
			}
		});
        
        final Button buttonInto = (Button)findViewById(R.id.ButtonInto);
        buttonInto.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(HomeActivity.this,ConsoleActivity.class));
			}
		});

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }
    
    private void Sleep(long ms)
    {
        try {Thread.sleep(ms);} catch (InterruptedException e) {e.printStackTrace();}
    }

    public boolean onKeyDown(int keyCode, KeyEvent event)  
    {
    	/**home键和返回键事件**/
        if( (keyCode == KeyEvent.KEYCODE_BACK ) ||  (keyCode == KeyEvent.KEYCODE_HOME ) ) 
        { 
            System.exit(0); 
        }
        return false;  
    }
}
