Code snippets » History » Version 2

« Previous - Version 2/3 (diff) - Next » - Current version
Marien Wolthius, 08/27/2014 10:15 AM


Code snippets

Example output of the JSON interface (with line breaks for readability)
{"showInfoArea":true,
"applicationTitle":"Remote Monitor",
"connectionStatus":"Connected to cep-qcpe",
"connectingMsg":"Connecting...",
"alertLightState":"systemstate_orange.gif",
"dashboardOperatorMessages":["\u003chtml\u003e\u003cb\u003eUpcoming: Load\u0026nbsp;\u003c/b\u003eA3 \u003cimg src\u003d\u0027sef_icon.gif\u0027 border\u003d\u00270\u0027 alt\u003d\u0027\u0027/\u003e, 100 g/m², TopColor, White\u003c/html\u003e","\u003chtml\u003e\u003cb\u003eUpcoming: Load\u0026nbsp;\u0027A4 tab\u0027, \u003c/b\u003e223x297 \u003cimg src\u003d\u0027lef_icon.gif\u0027 border\u003d\u00270\u0027 alt\u003d\u0027\u0027/\u003e, tab inclusive, cyclic\u0026nbsp;(5), 160 g/m², TopColor, White\u003c/html\u003e"],
"systemMode":"systemstate_ready.gif",
"systemState":"Ready",
"scheduleResourceStates":[{"mAvailability":"AVAILABLE","mDurationInSeconds":277},{"mAvailability":"UNCERTAIN","mDurationInSeconds":34},{"mAvailability":"UNAVAILABLE","mDurationInSeconds":174}],"productName":"nemo_imagePRESS-C7010VPS-series.gif"}

Alterations to HelloNotification to display our custom messages (images attached to this page)
/** Notifications for testing **/
    private static final String[][] TESTS = new String[][]{
        {"Red","Niagara","Paper is jammed in tray #59","0"},
        {"Yellow","Niagara","Media in tray #42 is running out","25"},
        {"Yellow","Getrude","Coffee is running low","5"},
        {"Yellow","Yankee","There is no such thing as a too long test message, I do no think there would be much of an argument against it anyway, it's all bits and bytes and electrons flying about.","45"},
        {"Red","Philip","This is not fun any more, I want to go home","15"}
    };

    /*
     * Adds specific data to the notification list
     * @author Marien
     * 
     */
    private void addSpecificData(String errorLevel, String device, String message, int responseTimeMinutes){
        if(errorLevel != "Red"){ message = "(in "+responseTimeMinutes+" min) "+message; };

        String notificationTitle = errorLevel + ": "+ device;
        long time = System.currentTimeMillis();
        long sourceId = NotificationUtil.getSourceId(this,
                HelloNotificationExtensionService.EXTENSION_SPECIFIC_ID);
        if (sourceId == NotificationUtil.INVALID_ID) {
            Log.e(HelloNotificationExtensionService.LOG_TAG, "Failed to insert data");
            return;
        }

        String profileImage = ExtensionUtils.getUriString(this,R.drawable.notification_image_none);

        if(errorLevel == "Yellow"){
            profileImage = ExtensionUtils.getUriString(this,R.drawable.notification_image_yellow);
        }else if(errorLevel =="Red"){
            profileImage = ExtensionUtils.getUriString(this,R.drawable.notification_image_red);
        }

        // Build the notification.
        ContentValues eventValues = new ContentValues();
        eventValues.put(Notification.EventColumns.EVENT_READ_STATUS, false);
        eventValues.put(Notification.EventColumns.DISPLAY_NAME, notificationTitle);
        eventValues.put(Notification.EventColumns.MESSAGE, message);
        eventValues.put(Notification.EventColumns.PERSONAL, 1);
        eventValues.put(Notification.EventColumns.PROFILE_IMAGE_URI, profileImage);
        eventValues.put(Notification.EventColumns.PUBLISHED_TIME, time);
        eventValues.put(Notification.EventColumns.SOURCE_ID, sourceId);

        NotificationUtil.addEvent(this, eventValues);

    }

    private void addRandomSpecificData(){
        Random rand = new Random();
        int i = rand.nextInt(5);
        addSpecificData(TESTS[i][0],TESTS[i][1],TESTS[i][2],Integer.parseInt(TESTS[i][3]));
    }

notification_image_red.png - Goes into res/drawable_nodpi (33.6 KB) Marien Wolthius, 08/27/2014 10:14 AM

notification_image_yellow.png - Goes into res/drawable_nodpi (33.6 KB) Marien Wolthius, 08/27/2014 10:14 AM

notification_image_none.png - Goes into res/drawable_nodpi (33.6 KB) Marien Wolthius, 08/27/2014 10:14 AM