samples/android/app/src/main/java/com/amazon/sampleapp/impl/CarControl/CarControlDataProvider.java
/**
     * Initialize data from car control configuration.
     */
Initialize data from car control configuration.
Initialize data from car control configuration .
public static void initialize(String json) throws Exception {
        try {
            JSONObject config = parseFileAsJSONObject(json);
            JSONObject carConfig = config.getJSONObject("aace.carControl");
            JSONArray endpoints = carConfig.getJSONArray("endpoints");
            for (int i=0; i<endpoints.length(); i++) {
                JSONObject endpoint = endpoints.getJSONObject(i);
                if (endpoint != null) {
                    String endpointId = endpoint.getString("endpointId");
                    JSONArray capabilities = endpoint.getJSONArray("capabilities");
                    for (int c=0; c<capabilities.length(); c++) {
                        JSONObject capability = capabilities.getJSONObject(c);
                        if (capability != null) {
                            String controller = capability.getString("interface");
                            if (controller.equals("Alexa.ModeController")) {
                                String controllerId = capability.getString("instance");
                                JSONObject configuration = capability.getJSONObject("configuration");
                                if (configuration != null) {
                                    JSONArray supportedModes = configuration.getJSONArray("supportedModes");
                                    if (supportedModes != null && supportedModes.length() > 0) {
                                        ModeController modeController = new ModeController();
                                        for (int m=0; m<supportedModes.length(); m++) {
                                            modeController.addMode(supportedModes.getJSONObject(m).getString("value"));
                                        }
                                        m_modeControllers.put(genKey(endpointId, controllerId), modeController);
                                    }
                                }
                            } else
                            if (controller.equals("Alexa.RangeController")) {
                                String controllerId = capability.getString("instance");
                                JSONObject configuration = capability.getJSONObject("configuration");
                                if (configuration != null) {
                                    JSONObject supportedRange = configuration.getJSONObject("supportedRange");
                                    if (supportedRange != null && supportedRange.length() > 0) {
                                        double min = supportedRange.getDouble("minimumValue");
                                        double max = supportedRange.getDouble("maximumValue");
                                        RangeController rangeController = new RangeController(min, max);
                                        m_rangeControllers.put(genKey(endpointId, controllerId), rangeController);
                                    }
                                }
                            } else
                            if (controller.equals("Alexa.ToggleController")) {
                                String controllerId = capability.getString("instance");
                                m_boolControllers.put(genKey(endpointId, controllerId), new BoolController());
                            } else
                            if (controller.equals("Alexa.PowerController")) {
                                m_boolControllers.put(genKey(endpointId), new BoolController());
                            }
                        }
                    }
                }
            }
        } catch (JSONException e) {
            throw e;
        }
    }
public static void initialize ( String json ) throws Exception { try { JSONObject config = parseFileAsJSONObject ( json ) ; JSONObject carConfig = config . getJSONObject ( "aace.carControl" ) ; JSONArray endpoints = carConfig . getJSONArray ( "endpoints" ) ; for ( int i = 0 ; i < endpoints . length ( ) ; i ++ ) { JSONObject endpoint = endpoints . getJSONObject ( i ) ; if ( endpoint != null ) { String endpointId = endpoint . getString ( "endpointId" ) ; JSONArray capabilities = endpoint . getJSONArray ( "capabilities" ) ; for ( int c = 0 ; c < capabilities . length ( ) ; c ++ ) { JSONObject capability = capabilities . getJSONObject ( c ) ; if ( capability != null ) { String controller = capability . getString ( "interface" ) ; if ( controller . equals ( "Alexa.ModeController" ) ) { String controllerId = capability . getString ( "instance" ) ; JSONObject configuration = capability . getJSONObject ( "configuration" ) ; if ( configuration != null ) { JSONArray supportedModes = configuration . getJSONArray ( "supportedModes" ) ; if ( supportedModes != null && supportedModes . length ( ) > 0 ) { ModeController modeController = new ModeController ( ) ; for ( int m = 0 ; m < supportedModes . length ( ) ; m ++ ) { modeController . addMode ( supportedModes . getJSONObject ( m ) . getString ( "value" ) ) ; } m_modeControllers . put ( genKey ( endpointId , controllerId ) , modeController ) ; } } } else if ( controller . equals ( "Alexa.RangeController" ) ) { String controllerId = capability . getString ( "instance" ) ; JSONObject configuration = capability . getJSONObject ( "configuration" ) ; if ( configuration != null ) { JSONObject supportedRange = configuration . getJSONObject ( "supportedRange" ) ; if ( supportedRange != null && supportedRange . length ( ) > 0 ) { double min = supportedRange . getDouble ( "minimumValue" ) ; double max = supportedRange . getDouble ( "maximumValue" ) ; RangeController rangeController = new RangeController ( min , max ) ; m_rangeControllers . put ( genKey ( endpointId , controllerId ) , rangeController ) ; } } } else if ( controller . equals ( "Alexa.ToggleController" ) ) { String controllerId = capability . getString ( "instance" ) ; m_boolControllers . put ( genKey ( endpointId , controllerId ) , new BoolController ( ) ) ; } else if ( controller . equals ( "Alexa.PowerController" ) ) { m_boolControllers . put ( genKey ( endpointId ) , new BoolController ( ) ) ; } } } } } } catch ( JSONException e ) { throw e ; } }
Initialize data from car control configuration.
Initialize data from car control configuration .