Hardware Reference
In-Depth Information
DataFromArduino.append(str);
}// end handleMessage(Message msg)
}; // end Handler IncomingDataHandler = new Handler()
Completing the Application
Now that the framework is complete, the rest of this section focuses on the creation of a serial monitor replica for use
with the ADK protocol. The best place to start is with the user interface to get a feel for how the interaction will work,
and at the same time prepare the resources to link to the Java portion of the application. The Arduino IDE has a serial
monitor for ease of development; it is capable of printing any information at specified points in the code, and it is
also capable of sending data to the Arduino. The application for the ADK side has to mimic the same functionality as
the serial monitor. Two different text boxes are used: one for incoming data and one for outgoing; a single button is
used to send the data from the outgoing text box. At bare minimum, three objects are needed to create the same user
interface experience: two Android EditText boxes for the data and a regular button to send. To add a little extra flair,
the program includes a second button for clearing the data in the user interface.
Figure 4-6 shows what user interface layout was chosen for this application. The send and clear buttons are
at the bottom right, the input box it placed next to them at the bottom left, and the rest of the screen is filled with
the data-revived box. For simplicity, the autoscroll is not implemented along with the line-ending options or the
baud select. The TextEdit boxes automatically wrap the characters to a new line when used in a multiple-line
configuration, as is need for the incoming data box, and will scroll automatically when the end of the box is reached.
There is no speed setting because the ADK protocol's speed is set globally for all accessory devices. Listing 4-12
shows the main.xml file that produces the user interface shown in Figure 4-6 . There are a few settings for each object.
To better describe each of the objects, the example is divided it to three parts, ordered as they appear in the XML file.
The XML file for Listing 4-12 replaces that used for the prior examples.
Figure 4-6. Layout for the ADK monitor
 
Search WWH ::




Custom Search