Hardware Reference
In-Depth Information
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import com.android.future.usb.*;
// UI components
import android.view.View;
import android.widget.ToggleButton;
Part 2 of the code starts the new class activity and inherits functionality from the parent class of the activity by
extending the original class's functionality. This part also creates the object variable needed by the rest of the code
to set up the ADK functionality, and create containers to hold user interface object registrations and debugging tags.
Debugging tags are used to show what program sent a flag to the ADB. A function named Log sends the flag to the
ADB as a string and can be read by issuing the command adb logcat in a command terminal on computer connected
to the Android device when the ADB is available.
Listing 4-6. CH4ExamplesActivity.java, Part 2 of 7
public class CH4ExamplesActivity extends Activity {
// ADK input and output declaration
UsbAccessory ARDUINO_ADK; // the Accessory object
ParcelFileDescriptor ADKstreamObj;
FileInputStream ReciveFromADK;
FileOutputStream SendtoADK;
// setup and logging
private static final String ACTION_USB_PERMISSION = "MEGA_ADK.USB_PERMISSION";
private static final String TAG = "MEGA ADK"; // debug tag sent Log
private UsbManager UsbManagerOBJ;
private PendingIntent Needed_Permission;
private boolean IsPermissionNeeded;
// UI components
private ToggleButton buttonLED;
Part 3 is a collection of functions used for program handling. The constructor and destructor are defined in
this section along with definitions of how to handle the program when paused and resumed. These functions are
overridden from the originals contained in the original activity class so that the extra functionality of the ADK protocol
can be added.
The @Override lines tell the program that the function below is different from the function that is defined in
the parent class; however, by using super. functionName we make sure that the parent's function is also called in
the new code. In the onCreate function, the accessory is set up, the main view is registered to the program, and the
user interface objects are linked. Because of the differences in the user interface layout between different projects, a
registerUIobjects function has been created to contain and handle these differences.
Listing 4-6. CH4ExamplesActivity.java, Part 3 of 7
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupAccessory();
Search WWH ::




Custom Search