Hardware Reference
In-Depth Information
res/xml/accessory_filter.xml
The accessory_filter.xml file is created in a folder that is added after program creation in the workspace location
res/xml . The information contained in this file is used by the manifest to load values for comparison into variables
used by the main program when an accessory is detected and determines if the accessory belongs to the program. The
code uses the manufacturer, model number, and version to detect a match. The description, URI, and serial number
can be accessible to the program, but are not needed here. This file changes the accessory that the code will respond
to upon a system event. The manifest and this file remain fairly consistent, although there are minor changes between
programs that have user interaction and utilize ADK accessories. Listing 4-3 shows this file for our app.
Listing 4-3. accessory_filter.xml
<?xml version= "1.0" encoding= "UTF-8" ?>
<resources>
<!-- match to Arduino sketch's accessory declaration object -->
<usb-accessory manufacturer= "Manufacturer" model= "Model" version= "1.0" />
</resources>
<!-- end of accessory-filter.xml -->
res/layout/main.xml
This is the first file of the Android application that is different from one program to another, because this file defines
the user interface. There can be multiple layout files in an Android application containing different objects to display
information or receive interaction from the user. This file's initial section creates the layout area with specifications
on how much of the device's screen is used. Following the layout area definition are tags for defining an object's ID,
placement, and size, and the function to use when a user interface object is manipulated, either from the user or code.
There is a plethora of defining parameters for each object, such as the ability to define what function to run in the
Java code when a button is pressed. The tag for the toggle button used in this example demonstrates implementing
a called function; when the toggle button is pressed, a blinkLED function is called in the Java code. Eclipse has the
ability to graphically lay out objects for the application and generates the required XML needed. Look over and
compare the Listing 4-4 to the generated XML for main.xml and replace it.
Listing 4-4. main.xml Replacing the Autogenerated Original
<?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" >
<ToggleButton
android:id="@+id/toggleButtonLED"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:layout_marginTop="89dp"
android:onClick="blinkLED"
android:text="@string/ToggleButton"
android:textSize="50dp" />
</RelativeLayout>
<!-- end of main.xml -->
 
Search WWH ::




Custom Search