use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class AnalyticsService method sendCrashReport.
/**
* In apps mode we can send information about an exception to the analytics server
* @param t the exception
* @param message up to 150 character message,
* @param fatal is the exception fatal
*/
public static void sendCrashReport(Throwable t, String message, boolean fatal) {
// https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#exception
ConnectionRequest req = GetGARequest();
req.addArgument("t", "exception");
System.out.println(message);
req.addArgument("exd", message.substring(0, Math.min(message.length(), 150) - 1));
if (fatal) {
req.addArgument("exf", "1");
} else {
req.addArgument("exf", "0");
}
NetworkManager.getInstance().addToQueue(req);
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class CloudImageProperty method propertyValue.
/**
* {@inheritDoc}
*/
public Object propertyValue(CloudObject obj, String propertyName) {
final String key = (String) obj.getObject(idProperty);
if (key == null) {
return placeholderImage;
}
Image image = (Image) getCache().get(key);
if (image == null) {
ReplaceableImage r = inProgress.get(key);
if (r != null) {
return r;
}
final ReplaceableImage rp = ReplaceableImage.create(placeholderImage);
inProgress.put(key, rp);
ConnectionRequest cr = new ConnectionRequest() {
private EncodedImage e;
protected void readResponse(InputStream input) throws IOException {
e = EncodedImage.create(input);
;
if (e.getWidth() != placeholderImage.getWidth() || e.getHeight() != placeholderImage.getHeight()) {
ImageIO io = ImageIO.getImageIO();
if (io != null) {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
io.save(new ByteArrayInputStream(e.getImageData()), bo, ImageIO.FORMAT_JPEG, placeholderImage.getWidth(), placeholderImage.getHeight(), 0.9f);
e = EncodedImage.create(bo.toByteArray());
}
}
}
protected void postResponse() {
rp.replace(e);
getCache().put(key, e);
inProgress.remove(key);
}
};
cr.setPost(false);
cr.setUrl(CloudStorage.getInstance().getUrlForCloudFileId(key));
NetworkManager.getInstance().addToQueue(cr);
return rp;
}
return image;
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class CloudPersona method createOrLogin.
/**
* Creates a new user if a user isn't occupying the given login already,
* if the user exists performs a login operation.
*
* @param login a user name
* @param password a password
* @return true if the login is successful false otherwise
*/
public static boolean createOrLogin(String login, String password) {
if (instance == null) {
getCurrentPersona();
if (instance.persona != null) {
return true;
}
}
ConnectionRequest loginRequest = new ConnectionRequest();
loginRequest.setPost(true);
loginRequest.setUrl(CloudStorage.SERVER_URL + "/objStoreUser");
loginRequest.addArgument("l", login);
loginRequest.addArgument("p", password);
loginRequest.addArgument("pk", Display.getInstance().getProperty("package_name", null));
loginRequest.addArgument("bb", Display.getInstance().getProperty("built_by_user", null));
NetworkManager.getInstance().addToQueueAndWait(loginRequest);
if (loginRequest.getResposeCode() != 200) {
return false;
}
ByteArrayInputStream bi = new ByteArrayInputStream(loginRequest.getResponseData());
DataInputStream di = new DataInputStream(bi);
try {
if (di.readBoolean()) {
if (instance == null) {
instance = new CloudPersona();
}
instance.persona = di.readUTF();
Preferences.set("CN1Persona", instance.persona);
Util.cleanup(di);
} else {
Util.cleanup(di);
return false;
}
} catch (IOException ex) {
ex.printStackTrace();
}
return true;
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class CloudPersona method createAnonymous.
/**
* Creates an anonymous persona that will be unique in the cloud, NEVER logout an anonymous user!
* @return false in case login failed e.g. due to bad network connection
*/
public static boolean createAnonymous() {
if (instance == null) {
getCurrentPersona();
}
ConnectionRequest login = new ConnectionRequest();
login.setPost(true);
login.setUrl(CloudStorage.SERVER_URL + "/objStoreUser");
login.addArgument("pk", Display.getInstance().getProperty("package_name", null));
login.addArgument("bb", Display.getInstance().getProperty("built_by_user", null));
NetworkManager.getInstance().addToQueueAndWait(login);
if (login.getResposeCode() != 200) {
return false;
}
ByteArrayInputStream bi = new ByteArrayInputStream(login.getResponseData());
DataInputStream di = new DataInputStream(bi);
if (instance == null) {
instance = new CloudPersona();
}
try {
instance.persona = di.readUTF();
} catch (IOException ex) {
ex.printStackTrace();
}
Preferences.set("CN1Persona", instance.persona);
Preferences.set("CN1PersonaAnonymous", true);
Util.cleanup(di);
return true;
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class CloudStorage method deleteAllCloudFilesForUser.
/**
* Deletes all the cloud files under this user, notice that this method
* is asynchronous and a background server process performs the actual deletion
* @deprecated this API is currently deprecated due to Googles cloud storage deprection
*/
public void deleteAllCloudFilesForUser() {
if (CloudPersona.getCurrentPersona().getToken() == null) {
return;
}
ConnectionRequest req = new ConnectionRequest();
req.setPost(false);
req.setFailSilently(true);
req.setUrl(SERVER_URL + "/purgeCloudFiles");
req.addArgument("own", CloudPersona.getCurrentPersona().getToken());
req.addArgument("u", Display.getInstance().getProperty("built_by_user", ""));
NetworkManager.getInstance().addToQueue(req);
}
Aggregations