Code example for SparseArray

Methods: getremovesize

0
     * Gets UsbDeviceConnection by a hierarchy device number 
     * @param devNum hierarchy device number 
     * @return UsbDeviceConnection or null 
     */ 
    public UsbDeviceConnection connection(int ch) {
        if(ch >= mConnection.size()) { return null; }
        return mConnection.get(ch);
    } 
 
    /** 
     * Check whether a device is connected or not 
     * @param devNum hierarchy device number 
     * @return true:connected, false:not connected 
     */ 
    public boolean deviceIsConnected(int devNum) {
        if(connection(devNum) == null) return false;
        return true; 
    } 
 
    /** 
     * Connect a USB device 
     * @return UsbDeviceConnection or null 
     */ 
    public boolean openDevice() { 
        return openDevice(0, 0, 0); 
    } 
 
    /** 
     * Connect a USB device by a hierarchy device and interface number 
     * @param devNum hierarchy device number 
     * @return UsbDeviceConnection or null 
     */ 
    public boolean openDevice(int devNum) {
        return openDevice(devNum, 0, 0);
    } 
 
    /** 
     * Connect a USB device by a hierarchy device and interface number 
     * @param devNum hierarchy device number 
     * @param intfNum hierarchy interface number 
     * @param ch channel number 
     * @return UsbDeviceConnection or null 
     */ 
    public boolean openDevice(int devNum, int intfNum, int ch) {
        UsbDevice dev = device(devNum);
        if(dev == null) { return false; }
        UsbDeviceConnection con = mManager.openDevice(dev);
        if(con == null) { return false; }
        if(con.claimInterface(intface(devNum, intfNum), true)) {
            mConnection.put(ch,con);
            return true; 
        } else { 
            if(DEBUG_SHOW){ Log.d(TAG, "Cannot get claim interface("+devNum+","+intfNum+")"); }
            mConnection.remove(devNum);
            return false; 
        } 
    } 
 
    public boolean close(int devNum) {
        UsbDeviceConnection con = connection(devNum);
        if(con == null) return false;
        mConnection.remove(devNum);
        con.close();
        if(DEBUG_SHOW){ Log.d(TAG, "Close("+devNum+")"); }
        return true; 
    }