Hardware Reference
In-Depth Information
The Android application needs a different
main.xml
file and a
strings.xml
file. Listing 8-4 is the
main.xml
file
that needs to be created. The graph is created in a nested layout inside of the main relative layout within the
main.xml
file. The
LinearLayout
tag defines the space that will be used to place the graph created at run time. An Edit text box
is used to display the incoming data from the Arduino and has the same functionality as the data-display box for the
ADK monitor program. Two buttons are also created in the
main.xml
file for the layout: one to sync the data stored
on the SD card and receive current updates while plugged in, and the other to clear the data from the screen. Both
buttons are set up to call a respective function in the activity class.
Listing 8-4.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
http://schemas.android.com/apk/res/android
"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.72" >
<LinearLayout
android:id="@+id/chart"
android:layout_width="fill_parent"
android:layout_height="500dp"
android:layout_alignParentTop="true"
/>
<EditText
android:id="@+id/incomingData"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_above="@+id/syncbutton"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scrollbars="vertical"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="top"
android:inputType="textMultiLine|textNoSuggestions"
android:hint="@string/hint" />
<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="clearScreen"
android:text="@string/clear" />
<Button
android:id="@+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"