Search in sources :

Example 6 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class Message method sendMessageViaCloudSync.

/**
 * <p>Send an email message using the Codename One cloud to send the message, notice that this API
 * will only work for pro accounts.</p>
 * <script src="https://gist.github.com/codenameone/8229c1d4627ab3a1f17e.js"></script>
 *
 * @param sender the name of the sender, notice all email will arrive from Codename One to avoid spam issues
 * @param recipient the email for the recipient
 * @param recipientName the display name for the recipient
 * @param subject e-mail subject
 * @param plainTextBody when sending an HTML message you should also attach a plain text fallback message,
 * this is redundant if the email is a plain text message to begin with
 * @return true if sending succeeded
 */
public boolean sendMessageViaCloudSync(String sender, String recipient, String recipientName, String subject, String plainTextBody) {
    ConnectionRequest r = createMessage(sender, recipient, recipientName, subject, plainTextBody);
    r.setFailSilently(true);
    NetworkManager.getInstance().addToQueueAndWait(r);
    return r.getResposeCode() == 200;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 7 with Message

use of com.codename1.messaging.Message 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 8 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class FaceBookAccess method postOnWall.

/**
 * Post a message on the users wall
 *
 * @param userId the userId
 * @param message the message to post
 * @param name
 * @param link
 * @param description
 * @param picture
 * @param caption
 */
public void postOnWall(String userId, String message, String name, String link, String description, String picture, String caption, ActionListener callback) throws IOException {
    checkAuthentication();
    FacebookRESTService con = new FacebookRESTService(token, userId, FacebookRESTService.FEED, true);
    if (message != null) {
        con.addArgument("message", message);
    }
    if (name != null) {
        con.addArgument("name", name);
    }
    if (link != null) {
        con.addArgument("link", link);
    }
    if (description != null) {
        con.addArgument("description", description);
    }
    if (picture != null) {
        con.addArgument("picture", picture);
    }
    if (caption != null) {
        con.addArgument("caption", caption);
    }
    con.addResponseListener(new Listener(con, callback));
    if (slider != null) {
        SliderBridge.bindProgress(con, slider);
    }
    for (int i = 0; i < responseCodeListeners.size(); i++) {
        con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
    }
    current = con;
    NetworkManager.getInstance().addToQueueAndWait(con);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener)

Example 9 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class FaceBookAccess method postComment.

/**
 * Post a comment on a given post
 *
 * @param postId the post id
 * @param message the message to post
 */
public void postComment(String postId, String message, ActionListener callback) throws IOException {
    checkAuthentication();
    FacebookRESTService con = new FacebookRESTService(token, postId, FacebookRESTService.COMMENTS, true);
    con.addResponseListener(new Listener(con, callback));
    con.addArgument("message", "" + message);
    if (slider != null) {
        SliderBridge.bindProgress(con, slider);
    }
    for (int i = 0; i < responseCodeListeners.size(); i++) {
        con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
    }
    current = con;
    NetworkManager.getInstance().addToQueueAndWait(con);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener)

Example 10 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class FaceBookAccess method createNote.

/**
 * Post a note onto the users wall
 *
 * @param userId the userId
 * @param message the message to post
 */
public void createNote(String userId, String subject, String message, ActionListener callback) throws IOException {
    checkAuthentication();
    FacebookRESTService con = new FacebookRESTService(token, userId, FacebookRESTService.NOTES, true);
    con.addResponseListener(new Listener(con, callback));
    con.addArgument("subject", "" + subject);
    con.addArgument("message", "" + message);
    if (slider != null) {
        SliderBridge.bindProgress(con, slider);
    }
    for (int i = 0; i < responseCodeListeners.size(); i++) {
        con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
    }
    current = con;
    System.out.println(con.getUrl());
    NetworkManager.getInstance().addToQueueAndWait(con);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener)

Aggregations

ConnectionRequest (com.codename1.io.ConnectionRequest)8 ActionListener (com.codename1.ui.events.ActionListener)6 IOException (java.io.IOException)5 Message (au.com.dius.pact.model.v3.messaging.Message)4 ActionEvent (com.codename1.ui.events.ActionEvent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 MessagePact (au.com.dius.pact.model.v3.messaging.MessagePact)2 BufferedInputStream (com.codename1.io.BufferedInputStream)2 NetworkEvent (com.codename1.io.NetworkEvent)2 Message (com.codename1.messaging.Message)2 Dialog (com.codename1.ui.Dialog)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 DataInputStream (java.io.DataInputStream)2 Method (java.lang.reflect.Method)2 Hashtable (java.util.Hashtable)2 Vector (java.util.Vector)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1