otorLeft; int pwmBtnMotorRight; String commandLeft; String commandRight ; String commandHorn; boolean BT_is_connect;
@ Overridevoid onCreate (Bundle savedInstanceState)
{. onCreate (savedInstanceState); (R.layout.activity_buttons);=(String) getResources (). getText (R.string.default_MAC);=nteger.parseInt ((String) getResources ( ) .getText (R.string.default_pwmBtnMotorLeft));=Integer.parseInt ((String) getResources (). getText (R.string.default_pwmBtnMotorRight));=(String) getResources (). getText (R.string.default_commandLeft) ;=(String) getResources (). getText (R.string.default_commandRight);=(String) getResources (). getText (R.string.default_commandHorn); ();=new cBluetooth (this, mHandler) ;. checkBTState ( ); _ forward=(Button) findViewById (R.id.forward); _ backward=(Button) findViewById (R.id.backward); _ left=(Button) findViewById (R.id.left); _ right=(Button) findViewById (R.id.right); _ forward.setOnTouchListener (new OnTouchListener ()
{boolean onTouch (View v, MotionEvent event) (event.getAction () == MotionEvent.ACTION_MOVE)=pwmBtnMotorLeft;=pwmBtnMotorRight; (BT_is_connect) bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));
} if (event.getAction () == MotionEvent.ACTION_UP)
{= 0;=0;(BT_is_connect)bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));
} false; _left.setOnTouchListener (new OnTouchListener ()
{boolean onTouch (View v, MotionEvent event) (event.getAction () == MotionEvent.ACTION_MOVE)=-pwmBtnMotorLeft;=pwmBtnMotorRight; (BT_is_connect) bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));if (event.getAction () == MotionEvent.ACTION_UP)
{= 0;=0; (BT_is_connect) bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));false;
} _ right.setOnTouchListener (new OnTouchListener ()
{boolean onTouch (View v, MotionEvent event) (event.getAction () == MotionEvent.ACTION_MOVE)=pwmBtnMotorLeft;=-pwmBtnMotorRight; (BT_is_connect) bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));
} if (event.getAction () == MotionEvent.ACTION_UP)
{= 0;=0; (BT_is_connect) bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));false;_backward.setOnTouchListener(new OnTouchListener ()
{boolean onTouch (View v, MotionEvent event) (event.getAction () == MotionEvent.ACTION_MOVE)=-pwmBtnMotorLeft;=-pwmBtnMotorRight; (BT_is_connect) bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));
} if (event.getAction () == MotionEvent.ACTION_UP)=0;=0; (BT_is_connect) bl.sendData(String.valueOf(commandLeft+motorLeft+laquo;rraquo;+commandRight+motorRight+laquo;rraquo;));false;= (ToggleButton) findViewById (R.id.LightButton) ;. setOnClickListener (new OnClickListener ()
{void onClick (View v) (LightButton.isChecked ()) (BT_is_connect) bl.sendData (String.valueOf (commandHorn + 1 r ));
} (BT_is_connect) bl.sendData (String.valueOf (commandHorn + 0 r )) ;. postDelayed (sRunnable, 600000); static class MyHandler extends Handler
{final WeakReference lt; ActivityButtons gt; mActivity; MyHandler (ActivityButtons activity)=new WeakReference lt; ActivityButtons gt; (activity);
}
@ Overridevoid handleMessage (Message msg)
{activity=mActivity.get (); (activity!=null) (msg.what) cBluetooth.BL_NOT_AVAILABLE: .d (cBluetooth.TAG, Bluetooth is not available. Exit );.makeText (activity.getBaseContext (), Bluetooth is not available raquo ;, Toast.LENGTH_SHORT) .show () ;. finish () ;; cBluetooth.BL_INCORRECT_ADDRESS: .d (cBluetooth.TAG, Incorrect MAC address ) ; .makeText (activity.getBaseContext (), Incorrect Bluetooth address raquo ;, Toast.LENGTH_SHORT) .show () ;; cBluetooth.BL_REQUEST_ENABLE: .d (cBluetooth.TAG, Request Bluetooth Enable ) ;. getDefaultAdapter () ; enableBtIntent=new Intent (BluetoothAdapter.ACTION_REQUEST_ENABLE) ;. startActivityForResult (enableBtIntent, 1) ;; cBluetooth.BL_SOCKET_FAILED: .makeText (activity.getBaseContext (), Socket failed raquo ;, Toast.LENGTH_SHORT) .show () ;;
} final MyHandler mHandler=new MyHandler (this); final static Runnable sRunnable=new Runnable ()
{void run () {}
}; void loadPref ()
{mySharedPreferences=Pref...