Example usage for android.os Bundle setClassLoader

List of usage examples for android.os Bundle setClassLoader

Introduction

In this page you can find the example usage for android.os Bundle setClassLoader.

Prototype

@Override
public void setClassLoader(ClassLoader loader) 

Source Link

Document

Changes the ClassLoader this Bundle uses when instantiating objects.

Usage

From source file:com.nbplus.iotlib.IoTInterface.java

private void handleDeviceConnectedNotification(Bundle b) {
    if (b == null) {
        Log.w(TAG, "bundle data is null");
        return;//w w w . j  av a  2 s  .  c  om
    }

    String deviceUuid = b.getString(IoTServiceCommand.KEY_DEVICE_UUID);
    if (StringUtils.isEmptyString(deviceUuid)) {
        Log.w(TAG, "deviceUuid is null");
        return;
    }

    if (mKeepAliveDeviceList.containsKey(deviceUuid)) {
        Log.d(TAG, "Keep alive device connection success.");
        mKeepAliveDeviceList.get(deviceUuid).setScenarioPosition(0);
        mKeepAliveDeviceList.get(deviceUuid)
                .setDeviceScenario(getKeepAliveDeviceScenario(mKeepAliveDeviceList.get(deviceUuid)));
        proceedKeepAliveDeviceCommand(deviceUuid);

        mBondedKeepaliveDeviceNumbers--;
        if (mBondedWithServerList.size() == 0
                || (mBondedEmergencyDeviceNumbers <= 0 && mBondedKeepaliveDeviceNumbers <= 0)) {
            Bundle extras = new Bundle();
            extras.putBoolean(IoTServiceCommand.KEY_DATA, false);
            sendMessageToService(IoTServiceCommand.SCANNING_STOP, extras);
        }
        return;
    }

    if (mCurrentRetrieveDevice == null || !deviceUuid.equals(mCurrentRetrieveDevice.getDeviceId())) {
        Log.w(TAG, "current retrieve device is empty or not matched..");
        if (mCurrentRetrieveDevice != null) {
            Log.w(TAG, "mCurrentRetrieveDevice.getDeviceId() = " + mCurrentRetrieveDevice.getDeviceId());
        }
        Log.w(TAG, "connected device getDeviceId() = " + deviceUuid);

        Bundle extras = new Bundle();
        IoTHandleData data = new IoTHandleData();
        data.setDeviceId(deviceUuid);
        //data.setDeviceTypeId(mCurrentRetrieveDevice.getDeviceTypeId());

        extras.putParcelable(IoTServiceCommand.KEY_DATA, data);
        sendMessageToService(IoTServiceCommand.DEVICE_DISCONNECT, extras);
        return;
    }

    mConnectionRetryCount = 0;
    b.setClassLoader(ArrayList.class.getClassLoader());
    HashMap<String, ArrayList<String>> disCoveredServices = (HashMap<String, ArrayList<String>>) b
            .getSerializable(IoTServiceCommand.KEY_DATA);
    if (disCoveredServices == null || disCoveredServices.size() == 0) {
        Log.w(TAG, "empty disCoveredServices list");
        Bundle extras = new Bundle();
        IoTHandleData data = new IoTHandleData();
        data.setDeviceId(deviceUuid);
        data.setDeviceTypeId(mCurrentRetrieveDevice.getDeviceTypeId());

        extras.putParcelable(IoTServiceCommand.KEY_DATA, data);
        sendMessageToService(IoTServiceCommand.DEVICE_DISCONNECT, extras);
        return;
    }

    // check.. has known scenario.
    ArrayList<IoTDeviceScenario> deviceScenario = null;
    mCurrentRetrieveDevice.setDiscoveredServices(disCoveredServices);
    if (mIsEmergencyDataCollecting) {
        deviceScenario = getEmergencyDeviceScenario(mCurrentRetrieveDevice);
    } else {
        deviceScenario = getKnownIoTDeviceScenarios(mCurrentRetrieveDevice);
    }

    if (deviceScenario == null) {
        Log.w(TAG, "I have no scenario for this device = " + mCurrentRetrieveDevice.getDeviceName());
        Bundle extras = new Bundle();
        IoTHandleData data = new IoTHandleData();
        data.setDeviceId(deviceUuid);
        data.setDeviceTypeId(mCurrentRetrieveDevice.getDeviceTypeId());

        extras.putParcelable(IoTServiceCommand.KEY_DATA, data);
        sendMessageToService(IoTServiceCommand.DEVICE_DISCONNECT, extras);
        return;
    }
    mCurrentRetrieveDevice.setDeviceScenario(deviceScenario);
    mCurrentRetrieveDevice.setScenarioPosition(0);

    proceedDeviceCommand();
}