View Single Post
  #3  
Old 03-11-2011, 08:48 AM
hikerbob's Avatar
hikerbob (Bob)
Registered User

hikerbob is offline
 
Join Date: Jan 2008
Location: Redlands, Australia
Posts: 253
Some Android code snippets

As mentioned earlier I've added a new button and some code to send commands. Not a good structure there currently it's expedient but likley to be short lived. I'd also renamed the project and code to BluetoothFocus rather than BluetoothChat so some of the naming won't match the samples.

This stuff should be in bluetoothchat.java under src. The moveAxis procedure in new, the other is an altered version of setupChat from that file. I've not managed to append integers to a string reliably yet so I send
multiple messages which is ugly. moveAxis does not relate to focus control, it's a test bed for my learning's so I will have to redo a buch of things when I work out how to do them.

Under // Layout Views the buttons are defined
private Button mInButton;
private Button mOutButton;

Then further down behaviours are setup.

private void moveAxis(Integer pIncrement) {
Integer lPosition;
// TextView view = (TextView) findViewById(R.id.edit_text_out);
lPosition = iPosition + pIncrement;
sendMessage(":E");
sendMessage(lPosition.toString());
sendMessage("* ");
// Replace this with a read position call
iPosition = lPosition;
}

private void setupFocus() {
Log.d(TAG, "setupFocus()");

// Initialize the array adapter for the conversation thread
mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
mConversationView = (ListView) findViewById(R.id.in);
mConversationView.setAdapter(mConve rsationArrayAdapter);

// Initialize the compose field with a listener for the return key
mOutEditText = (EditText) findViewById(R.id.edit_text_out);
mOutEditText.setOnEditorActionListe ner(mWriteListener);


// Initialize the In button with a listener that for click events
mInButton = (Button) findViewById(R.id.button_in);
mInButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
moveAxis(-10);
}
});

// Initialize the Out button with a listener that for click events
mOutButton = (Button) findViewById(R.id.button_out);
mOutButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
moveAxis(10);
}
});
Reply With Quote