Search in sources :

Example 6 with Category

use of com.codename1.rad.nodes.ActionNode.Category in project CodenameOne by codenameone.

the class VServAds method createAdRequest.

/**
 * {@inheritDoc}
 */
protected ConnectionRequest createAdRequest() {
    ConnectionRequest con = new ConnectionRequest() {

        protected void handleErrorResponseCode(int code, String message) {
            failed = true;
        }

        protected void handleException(Exception err) {
            failed = true;
            Log.e(err);
        }

        private String getString(Hashtable h, String n) {
            Object v = h.get(n);
            if (v == null) {
                return null;
            }
            if (v instanceof Vector) {
                return (String) ((Vector) v).elementAt(0);
            }
            return (String) v;
        }

        protected void readResponse(InputStream input) throws IOException {
            JSONParser parser = new JSONParser();
            Hashtable h = parser.parse(new InputStreamReader(input, "UTF-8"));
            if (h.size() == 0) {
                return;
            }
            backgroundColor = Integer.parseInt((String) ((Hashtable) ((Vector) h.get("style")).elementAt(0)).get("background-color"), 16);
            Hashtable actionHash = ((Hashtable) ((Vector) h.get("action")).elementAt(0));
            actionNotify = getString(actionHash, "notify");
            if (actionNotify == null) {
                actionNotify = getString(actionHash, "notify-once");
            }
            destination = (String) actionHash.get("data");
            Hashtable renderHash = ((Hashtable) ((Vector) h.get("render")).elementAt(0));
            contentType = (String) renderHash.get("type");
            renderNotify = getString(renderHash, "notify");
            if (renderNotify == null) {
                renderNotify = getString(renderHash, "notify-once");
            }
            imageURL = (String) renderHash.get("data");
        }
    };
    con.setUrl(URL);
    con.setPost(false);
    con.addArgument("zoneid", getZoneId());
    con.addArgument("ua", Display.getInstance().getProperty("User-Agent", ""));
    con.addArgument("app", "1");
    con.addArgument("aid", Display.getInstance().getProperty("androidId", ""));
    con.addArgument("uuid", Display.getInstance().getProperty("uuid", ""));
    con.addArgument("im", Display.getInstance().getProperty("imei", ""));
    con.addArgument("sw", "" + Display.getInstance().getDisplayWidth());
    con.addArgument("sh", "" + Display.getInstance().getDisplayHeight());
    con.addArgument("mn", Display.getInstance().getProperty("AppName", ""));
    con.addArgument("vs3", "1");
    con.addArgument("partnerid", "1");
    con.addArgument("zc", "" + category);
    if (countryCode != null) {
        con.addArgument("cc", countryCode);
    }
    if (networkCode != null) {
        con.addArgument("nc", networkCode);
    }
    if (locale != null) {
        con.addArgument("lc", locale);
    }
    return con;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) InputStreamReader(java.io.InputStreamReader) Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) JSONParser(com.codename1.io.JSONParser) Vector(java.util.Vector) IOException(java.io.IOException)

Example 7 with Category

use of com.codename1.rad.nodes.ActionNode.Category in project CodenameOne by codenameone.

the class IOSImplementation method initPushActionCategories.

public static void initPushActionCategories() {
    if (pushCallback instanceof PushActionsProvider) {
        PushActionsProvider actionsProvider = (PushActionsProvider) pushCallback;
        PushActionCategory[] categories = actionsProvider.getPushActionCategories();
        if (categories != null) {
            PushAction[] actions = PushActionCategory.getAllActions(categories);
            for (PushAction action : actions) {
                nativeInstance.registerPushAction(action.getId(), action.getTitle(), action.getTextInputPlaceholder(), action.getTextInputButtonText());
            }
            for (PushActionCategory category : categories) {
                nativeInstance.startPushActionCategory(category.getId());
                for (PushAction action : category.getActions()) {
                    nativeInstance.addPushActionToCategory(action.getId());
                }
                nativeInstance.endPushActionCategory();
            }
            nativeInstance.registerPushCategories();
        }
    }
}
Also used : PushActionsProvider(com.codename1.push.PushActionsProvider) PushActionCategory(com.codename1.push.PushActionCategory) PushAction(com.codename1.push.PushAction)

Example 8 with Category

use of com.codename1.rad.nodes.ActionNode.Category in project CodenameOne by codenameone.

the class PushBuilder method build.

/**
 * Builds the payload for this rich push notification.
 * @return The payload that can be passed as the message body to {@link Push}
 */
public String build() {
    StringBuilder sb = new StringBuilder();
    switch(type) {
        case 0:
        case 1:
            sb.append(body);
            break;
        case 2:
            sb.append(metaData);
            break;
        case 3:
            sb.append(metaData).append(";").append(body);
            break;
        case 4:
            sb.append(title).append(";").append(body);
            break;
        case 5:
            sb.append(body);
            break;
        case 6:
        case 100:
            sb.append(badge);
            break;
        case 101:
            sb.append(badge).append(" ").append(body);
            break;
        case 102:
            sb.append(badge).append(";").append(title).append(";").append(body);
            break;
    }
    if (isRichPush()) {
        String b = sb.toString();
        sb.setLength(0);
        Element el = new Element("push");
        el.setAttribute("type", "" + type);
        el.setAttribute("body", b);
        if (category != null) {
            el.setAttribute("category", category);
        }
        if (imageUrl != null) {
            Element imgEl = new Element("img");
            imgEl.setAttribute("src", imageUrl);
            el.addChild(imgEl);
        }
        return el.toString();
    }
    return sb.toString();
}
Also used : Element(com.codename1.xml.Element)

Example 9 with Category

use of com.codename1.rad.nodes.ActionNode.Category in project CodenameOne by codenameone.

the class AndroidImplementation method appendNotification.

public static void appendNotification(String type, String body, String image, String category, Context a) {
    try {
        String[] fileList = a.fileList();
        byte[] data = null;
        for (int iter = 0; iter < fileList.length; iter++) {
            if (fileList[iter].equals("CN1$AndroidPendingNotifications")) {
                InputStream is = a.openFileInput("CN1$AndroidPendingNotifications");
                if (is != null) {
                    data = readInputStream(is);
                    sCleanup(a);
                    break;
                }
            }
        }
        DataOutputStream os = new DataOutputStream(a.openFileOutput("CN1$AndroidPendingNotifications", 0));
        if (data != null) {
            data[0]++;
            os.write(data);
        } else {
            os.writeByte(1);
        }
        String bodyType = type;
        if (image != null || category != null) {
            type = "99";
        }
        if (type != null) {
            os.writeBoolean(true);
            os.writeUTF(type);
        } else {
            os.writeBoolean(false);
        }
        if ("99".equals(type)) {
            String msg = "body=" + java.net.URLEncoder.encode(body, "UTF-8") + "&type=" + java.net.URLEncoder.encode(bodyType, "UTF-8");
            if (category != null) {
                msg += "&category=" + java.net.URLEncoder.encode(category, "UTF-8");
            }
            if (image != null) {
                image += "&image=" + java.net.URLEncoder.encode(image, "UTF-8");
            }
            os.writeUTF(msg);
        } else {
            os.writeUTF(body);
        }
        os.writeLong(System.currentTimeMillis());
    } catch (IOException err) {
        err.printStackTrace();
    }
}
Also used : BufferedInputStream(com.codename1.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Paint(android.graphics.Paint)

Example 10 with Category

use of com.codename1.rad.nodes.ActionNode.Category in project CodenameOne by codenameone.

the class AndroidImplementation method getPendingPush.

public static String[] getPendingPush(String type, Context a) {
    InputStream i = null;
    try {
        i = a.openFileInput("CN1$AndroidPendingNotifications");
        if (i == null) {
            return null;
        }
        DataInputStream is = new DataInputStream(i);
        int count = is.readByte();
        Vector v = new Vector<String>();
        for (int iter = 0; iter < count; iter++) {
            boolean hasType = is.readBoolean();
            String actualType = null;
            if (hasType) {
                actualType = is.readUTF();
            }
            final String t;
            final String b;
            if ("99".equals(actualType)) {
                // This was a rich push
                Map<String, String> vals = splitQuery(is.readUTF());
                t = vals.get("type");
                b = vals.get("body");
            // category = vals.get("category");
            // image = vals.get("image");
            } else {
                t = actualType;
                b = is.readUTF();
            // category = null;
            // image = null;
            }
            long s = is.readLong();
            if (t != null && ("3".equals(t) || "6".equals(t))) {
                String[] m = b.split(";");
                v.add(m[0]);
            } else if (t != null && "4".equals(t)) {
                String[] m = b.split(";");
                v.add(m[1]);
            } else if (t != null && "2".equals(t)) {
                continue;
            } else if (t != null && "101".equals(t)) {
                v.add(b.substring(b.indexOf(" ") + 1));
            } else {
                v.add(b);
            }
        }
        String[] retVal = new String[v.size()];
        for (int j = 0; j < retVal.length; j++) {
            retVal[j] = (String) v.get(j);
        }
        return retVal;
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (i != null) {
                i.close();
            }
        } catch (IOException ex) {
        }
    }
    return null;
}
Also used : BufferedInputStream(com.codename1.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Vector(java.util.Vector) Paint(android.graphics.Paint) JSONException(org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) MediaException(com.codename1.media.AsyncMedia.MediaException) ParseException(java.text.ParseException) SAXException(org.xml.sax.SAXException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

IOException (java.io.IOException)8 Paint (android.graphics.Paint)5 PushAction (com.codename1.push.PushAction)4 PushActionCategory (com.codename1.push.PushActionCategory)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 RemoteException (android.os.RemoteException)3 BufferedInputStream (com.codename1.io.BufferedInputStream)3 MediaException (com.codename1.media.AsyncMedia.MediaException)3 Result (com.codename1.rad.processing.Result)3 Element (com.codename1.xml.Element)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 URISyntaxException (java.net.URISyntaxException)3 ParseException (java.text.ParseException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 JSONException (org.json.JSONException)3 SAXException (org.xml.sax.SAXException)3 Element (android.renderscript.Element)2 ConnectionRequest (com.codename1.io.ConnectionRequest)2