app/src/main/java/com/michael/bci/ActivityRecognizedService.java
@SuppressWarnings(value = "unchecked")

    /*
    In the handleDetectedActivities method we connect to the RabbitMQ 'activity' Queue and send timestamped
    data of each activity that has been detected and how confident Google Play Services is that the user is
    performing that activity by calling getConfidence() on a DetectedActivity instance.
     */
    private void handleDetectedActivities(List<DetectedActivity> probableActivities) {

        try {

            Calendar calendar = Calendar.getInstance(); //Get calendar using current time zone and locale of the system.
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS"); //format and parse date-time
            long unixTime = System.currentTimeMillis() / 1000L; //Unix Timestamp

            for (DetectedActivity activity : probableActivities) {
                Channel channel = getChannel();
                Log.d(TAG, "RMQ: Connection/Channel 2 for EEG" +channel);

                /*Encode a JSON object using Map so order of the object entries is preserved*/
                Map obj=new HashMap();
                //LinkedHashMap<String, java.io.Serializable> obj = new LinkedHashMap<>();
                /* Create a new String using the date-time format */
                String dateString = simpleDateFormat.format(calendar.getTime());
                obj.put("TS", dateString); // Create a Timestamp

                switch (activity.getType())
                {
                    case DetectedActivity.IN_VEHICLE: {
                        obj.put("In Vehicle ", activity.getConfidence());
                        Log.e("ActivityRecognition", "In Vehicle " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.ON_BICYCLE: {
                        obj.put("On Bicycle ", activity.getConfidence());
                        Log.e("ActivityRecognition", "On Bicycle " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.STILL: {
                        obj.put("Still ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Still " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.TILTING: {
                        obj.put("Tilting ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Tilting " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.WALKING: {
                        obj.put("Walking ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Walking " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.RUNNING: {
                        obj.put("Running ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Running " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.ON_FOOT: {
                        obj.put("On Foot ", activity.getConfidence());
                        Log.e("ActivityRecognition", "On Foot" + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.UNKNOWN: {
                        obj.put("Unknown ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Unknown " + activity.getConfidence());
                        break;
                    }
                }
                obj.put("UnixTS", unixTime); // Create a Unix Timestamp
                obj.put("TS", dateString); // Create a Formatted Timestamp

                channel.basicPublish(EXCHANGE_NAME, "white",null, JSONValue.toJSONString(obj).getBytes(StandardCharsets.UTF_8));

                /* For now lets just close connection every time */
                //RabbitmqConnection.CloseConnection();
                //CloseChannel();
            }
        } catch (Exception e) {
            e.printStackTrace();
            // If we hit any issues, close the RabbitMQ channel, so that it is re-created on the next read.
            try {
                CloseChannel();
                Log.d(TAG, "RMQ: Close Loop Channel for Activity");
            } catch (IOException | TimeoutException ioException) {
                ioException.printStackTrace();
            }
        }
    }
/*
    Suppress due to an unchecked 'put(K,V)' warning because org.json.simple.JSONObject uses raw type
    collections internally - need to change to a library which supports generics to be more type safe.
    */
Suppress due to an unchecked 'put(K,V)' warning because org.json.simple.JSONObject uses raw type
collections internally - need to change to a library which supports generics to be more type safe.
Suppress due to an unchecked ' put ( K V ) ' warning because org . json . simple . JSONObject uses raw type collections internally - need to change to a library which supports generics to be more type safe .
@SuppressWarnings(value = "unchecked")
    /*
    In the handleDetectedActivities method we connect to the RabbitMQ 'activity' Queue and send timestamped
    data of each activity that has been detected and how confident Google Play Services is that the user is
    performing that activity by calling getConfidence() on a DetectedActivity instance.
     */
    private void handleDetectedActivities(List<DetectedActivity> probableActivities) {
        try {
            Calendar calendar = Calendar.getInstance(); 
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS"); 
            long unixTime = System.currentTimeMillis() / 1000L; 
            for (DetectedActivity activity : probableActivities) {
                Channel channel = getChannel();
                Log.d(TAG, "RMQ: Connection/Channel 2 for EEG" +channel);
                /*Encode a JSON object using Map so order of the object entries is preserved*/
                Map obj=new HashMap();
                /* Create a new String using the date-time format */
                String dateString = simpleDateFormat.format(calendar.getTime());
                obj.put("TS", dateString); 
                switch (activity.getType())
                {
                    case DetectedActivity.IN_VEHICLE: {
                        obj.put("In Vehicle ", activity.getConfidence());
                        Log.e("ActivityRecognition", "In Vehicle " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.ON_BICYCLE: {
                        obj.put("On Bicycle ", activity.getConfidence());
                        Log.e("ActivityRecognition", "On Bicycle " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.STILL: {
                        obj.put("Still ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Still " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.TILTING: {
                        obj.put("Tilting ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Tilting " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.WALKING: {
                        obj.put("Walking ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Walking " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.RUNNING: {
                        obj.put("Running ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Running " + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.ON_FOOT: {
                        obj.put("On Foot ", activity.getConfidence());
                        Log.e("ActivityRecognition", "On Foot" + activity.getConfidence());
                        break;
                    }
                    case DetectedActivity.UNKNOWN: {
                        obj.put("Unknown ", activity.getConfidence());
                        Log.e("ActivityRecognition", "Unknown " + activity.getConfidence());
                        break;
                    }
                }
                obj.put("UnixTS", unixTime); 
                obj.put("TS", dateString); 
                channel.basicPublish(EXCHANGE_NAME, "white",null, JSONValue.toJSONString(obj).getBytes(StandardCharsets.UTF_8));
                /* For now lets just close connection every time */
            }
        } catch (Exception e) {
            e.printStackTrace();
            try {
                CloseChannel();
                Log.d(TAG, "RMQ: Close Loop Channel for Activity");
            } catch (IOException | TimeoutException ioException) {
                ioException.printStackTrace();
            }
        }
    }
@ SuppressWarnings ( value = "unchecked" ) /*
    In the handleDetectedActivities method we connect to the RabbitMQ 'activity' Queue and send timestamped
    data of each activity that has been detected and how confident Google Play Services is that the user is
    performing that activity by calling getConfidence() on a DetectedActivity instance.
     */ private void handleDetectedActivities ( List < DetectedActivity > probableActivities ) { try { Calendar calendar = Calendar . getInstance ( ) ; SimpleDateFormat simpleDateFormat = new SimpleDateFormat ( "yyyy-MM-dd-HH-mm-ss-SSS" ) ; long unixTime = System . currentTimeMillis ( ) / 1000L ; for ( DetectedActivity activity : probableActivities ) { Channel channel = getChannel ( ) ; Log . d ( TAG , "RMQ: Connection/Channel 2 for EEG" + channel ) ; /*Encode a JSON object using Map so order of the object entries is preserved*/ Map obj = new HashMap ( ) ; /* Create a new String using the date-time format */ String dateString = simpleDateFormat . format ( calendar . getTime ( ) ) ; obj . put ( "TS" , dateString ) ; switch ( activity . getType ( ) ) { case DetectedActivity . IN_VEHICLE : { obj . put ( "In Vehicle " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "In Vehicle " + activity . getConfidence ( ) ) ; break ; } case DetectedActivity . ON_BICYCLE : { obj . put ( "On Bicycle " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "On Bicycle " + activity . getConfidence ( ) ) ; break ; } case DetectedActivity . STILL : { obj . put ( "Still " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "Still " + activity . getConfidence ( ) ) ; break ; } case DetectedActivity . TILTING : { obj . put ( "Tilting " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "Tilting " + activity . getConfidence ( ) ) ; break ; } case DetectedActivity . WALKING : { obj . put ( "Walking " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "Walking " + activity . getConfidence ( ) ) ; break ; } case DetectedActivity . RUNNING : { obj . put ( "Running " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "Running " + activity . getConfidence ( ) ) ; break ; } case DetectedActivity . ON_FOOT : { obj . put ( "On Foot " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "On Foot" + activity . getConfidence ( ) ) ; break ; } case DetectedActivity . UNKNOWN : { obj . put ( "Unknown " , activity . getConfidence ( ) ) ; Log . e ( "ActivityRecognition" , "Unknown " + activity . getConfidence ( ) ) ; break ; } } obj . put ( "UnixTS" , unixTime ) ; obj . put ( "TS" , dateString ) ; channel . basicPublish ( EXCHANGE_NAME , "white" , null , JSONValue . toJSONString ( obj ) . getBytes ( StandardCharsets . UTF_8 ) ) ; /* For now lets just close connection every time */ } } catch ( Exception e ) { e . printStackTrace ( ) ; try { CloseChannel ( ) ; Log . d ( TAG , "RMQ: Close Loop Channel for Activity" ) ; } catch ( IOException | TimeoutException ioException ) { ioException . printStackTrace ( ) ; } } }
Suppress due to an unchecked 'put(K,V)' warning because org.json.simple.JSONObject uses raw type
collections internally - need to change to a library which supports generics to be more type safe.
Suppress due to an unchecked ' put ( K V ) ' warning because org . json . simple . JSONObject uses raw type collections internally - need to change to a library which supports generics to be more type safe .
//Get calendar using current time zone and locale of the system. //format and parse date-time //Unix Timestamp //LinkedHashMap<String, java.io.Serializable> obj = new LinkedHashMap<>(); // Create a Timestamp // Create a Unix Timestamp // Create a Formatted Timestamp //RabbitmqConnection.CloseConnection(); //CloseChannel(); // If we hit any issues, close the RabbitMQ channel, so that it is re-created on the next read.