Example usage for android.hardware.usb UsbDevice hashCode

List of usage examples for android.hardware.usb UsbDevice hashCode

Introduction

In this page you can find the example usage for android.hardware.usb UsbDevice hashCode.

Prototype

@Override
    public int hashCode() 

Source Link

Usage

From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java

private void getDeviceName(CallbackContext callbackContext) {
    Activity activity = cordova.getActivity();
    UsbManager mUsbManager = (UsbManager) activity.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> map = mUsbManager.getDeviceList();
    Iterator<UsbDevice> it = map.values().iterator();
    while (it.hasNext()) {
        UsbDevice device = it.next();
        // use device info
        Log.v(POCKETDUINO, "!!!--- USB Device Name ---!!!");
        Log.v(POCKETDUINO, device.getDeviceName());
        Log.v(POCKETDUINO, "!!!--- USB Device Product ID ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.getProductId()));
        Log.v(POCKETDUINO, "!!!--- USB Device Vendor ID ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.getVendorId()));
        Log.v(POCKETDUINO, "!!!--- USB Device Hash Code ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.hashCode()));
    }/*from  ww  w. ja  v a2  s . co  m*/
}

From source file:com.googlecode.android_scripting.facade.USBHostSerialFacade.java

/**
 * collectUSBDevices: start USB connection, from usbserialConnect {{{1
 *///from   w  ww  . ja va  2 s .  c  o  m
private String connectUSBDevice(String hash) {
    Integer nHash;
    String ret = "";
    boolean deviceFound = false;

    PendingIntent mPermissionIntent = PendingIntent.getBroadcast(mService, 0, new Intent(ACTION_USB_PERMISSION),
            0);
    Map<String, UsbDevice> map = mUsbManager.getDeviceList();

    if (hash.equals("")) {
        nHash = 0;
    } else {
        nHash = Integer.parseInt(hash);
    }

    Log.d("USBHostSerial: collectUSBDevices()");
    for (UsbDevice device : map.values()) {
        Log.d("USBHostSerial: try to check " + device.hashCode());
        if (!(nHash == 0) && (nHash != device.hashCode())) {
            continue;
        }
        Log.d("USBHostSerial: requestPermission to =>" + device.getDeviceName());

        UsbSerialConnection conn;
        try {
            conn = new UsbSerialConnection();
        } catch (IOException e) {
            Log.d("can't create UsbSerialConnection object");
            continue;
        }
        conn.mDevice = device;
        conn.options = new String(options);
        addConnection(conn);

        mUsbManager.requestPermission(device, mPermissionIntent);
        deviceFound = true;
        ret += ",\"" + conn.getUUID() + "\"";
    }
    if (!deviceFound) {
        connectionFailed();
        return "device not found";
    }
    return "[\"OK\"" + ret + "]";
}

From source file:com.googlecode.android_scripting.facade.USBHostSerialFacade.java

/**
 * usbserialGetDeviceList: {{{1//from  w ww.j  av a2s  .  c  o  m
 */
@Rpc(description = "Returns USB devices reported by USB Host API.", returns = "Map of id and string information ',' separated")
public Map<String, String> usbserialGetDeviceList() {
    Map<String, String> ret = new HashMap<String, String>();
    Map<String, UsbDevice> map = mUsbManager.getDeviceList();
    for (Map.Entry<String, UsbDevice> entry : map.entrySet()) {
        UsbDevice dev = entry.getValue();
        String v = "[\"";
        v += dev.getDeviceName();
        v += String.format("\",\"%04X", dev.getVendorId());
        v += String.format("\",\"%04X", dev.getProductId());
        v += "\",\"" + dev.hashCode();
        v += "\"]";
        ret.put(entry.getKey(), v);
    }
    return ret;
}

From source file:com.googlecode.android_scripting.facade.USBHostSerialFacade.java

/**
 * getConnection (UsbDevice): obtain connection object from the connection entries {{{1
 *///  w  ww  . j a v  a 2 s .co m
private UsbSerialConnection getConnection(UsbDevice device) throws IOException {
    for (Map.Entry<String, UsbSerialConnection> entry : connections.entrySet()) {
        UsbSerialConnection conn;
        conn = entry.getValue();
        if (conn.mDevice == device) {
            return conn;
        }
        if (conn.mDevice.hashCode() == device.hashCode()) {
            return conn;
        }
        Log.d(String.format("USB Host Serial: %s != %s", conn.mDevice.getDeviceName(), device.getDeviceName()));
    }
    return null;
}