use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class AndroidImplementation method fixAttachmentPath.
private String fixAttachmentPath(String attachment) {
com.codename1.io.File cn1File = new com.codename1.io.File(attachment);
File mediaStorageDir = new File(new File(getContext().getCacheDir(), "intent_files"), "Attachment");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(Display.getInstance().getProperty("AppName", "CodenameOne"), "failed to create directory");
return null;
}
}
File newFile = new File(mediaStorageDir.getPath() + File.separator + cn1File.getName());
if (newFile.exists()) {
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
newFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + "_" + cn1File.getName());
}
// Uri fileUri = Uri.fromFile(newFile);
newFile.getParentFile().mkdirs();
// Uri imageUri = Uri.fromFile(newFile);
Uri fileUri = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", newFile);
try {
InputStream is = FileSystemStorage.getInstance().openInputStream(attachment);
OutputStream os = new FileOutputStream(newFile);
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) > -1) {
os.write(buf, 0, len);
}
is.close();
os.close();
} catch (IOException ex) {
Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
}
return fileUri.toString();
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class BlackBerryImplementation method init.
public void init(Object m) {
instance = this;
app = (CodenameOneUiApplication) m;
if (askForPermission) {
app.invokeAndWait(new Runnable() {
public void run() {
ApplicationPermissions permRequest = new ApplicationPermissions();
permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
permRequest.addPermission(ApplicationPermissions.PERMISSION_FILE_API);
permRequest.addPermission(ApplicationPermissions.PERMISSION_WIFI);
try {
// ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION
permRequest.addPermission(11);
} catch (Exception e) {
}
try {
// ApplicationPermissions.PERMISSION_MEDIA
permRequest.addPermission(21);
} catch (Exception e) {
}
try {
// ApplicationPermissions.PERMISSION_INPUT_SIMULATION
permRequest.addPermission(6);
} catch (Exception e) {
}
try {
// ApplicationPermissions.PERMISSION_LOCATION_DATA
permRequest.addPermission(14);
} catch (Exception e) {
}
try {
// ApplicationPermissions.PERMISSION_ORGANIZER_DATA
permRequest.addPermission(16);
} catch (Exception e) {
}
try {
// ApplicationPermissions.PERMISSION_INTERNET
permRequest.addPermission(7);
} catch (Exception e) {
}
try {
// ApplicationPermissions.PERMISSION_RECORDING
permRequest.addPermission(17);
} catch (Exception e) {
}
ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
if (!apm.invokePermissionsRequest(permRequest)) {
exitApplication();
return;
}
}
});
}
app.enableKeyUpEvents(true);
if (!app.isHandlingEvents()) {
new Thread() {
public void run() {
app.enterEventDispatcher();
}
}.start();
}
Dialog.setCommandsAsButtons(true);
UIManager.getInstance().addThemeRefreshListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Hashtable themeProps = new Hashtable();
themeProps.put("SoftButton.margin", "0,0,0,0");
themeProps.put("SoftButton.padding", "0,0,0,0");
UIManager.getInstance().addThemeProps(themeProps);
}
});
RecordEnumeration e = null;
RecordStore r = null;
try {
r = RecordStore.openRecordStore("FAT", true);
if (r.getNumRecords() > 0) {
e = r.enumerateRecords(null, null, false);
while (e.hasNextElement()) {
byte[] rec = e.nextRecord();
ByteArrayInputStream bi = new ByteArrayInputStream(rec);
DataInputStream di = new DataInputStream(bi);
String name = di.readUTF();
short key = di.readShort();
di.close();
bi.close();
fat.put(name, new Short(key));
if (key >= currentKey) {
currentKey += key;
}
}
e.destroy();
e = null;
}
r.closeRecordStore();
r = null;
} catch (Exception ex) {
ex.printStackTrace();
cleanup(r);
cleanup(e);
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class PropertyIndex method loadJSON.
/**
* Loads JSON for the object from storage with the given name
* @param name the name of the storage
*/
public void loadJSON(String name) {
try {
InputStream is = Storage.getInstance().createInputStream(name);
JSONParser jp = new JSONParser();
JSONParser.setUseBoolean(true);
JSONParser.setUseLongs(true);
populateFromMap(jp.parseJSON(new InputStreamReader(is, "UTF-8")), parent.getClass());
} catch (IOException err) {
Log.e(err);
throw new RuntimeException(err.toString());
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class CloudObject method unbindProperty.
/**
* Releases the binding for the specific property name
* @param cmp the component
* @param propertyName the name of the property
*/
public void unbindProperty(Component cmp, String propertyName) {
BindTarget t = (BindTarget) cmp.getClientProperty("CN1Bind" + propertyName);
cmp.unbindProperty(propertyName, t);
;
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class CloudObject method bindProperty.
/**
* Binds a property value within the given component to this cloud object, this means that
* when the component changes the cloud object changes unless deferred. If the defer flag is
* false all changes are stored in a temporary location and only "committed" once commitBindings()
* is invoked.
* @param cmp the component to bind
* @param propertyName the name of the property in the bound component
* @param attributeName the key within the cloud object
* @param defer bind settings whether to defer the binding which requires developers to explicitly commit
* the binding to perform the changes
* @param objectLead if set to true the UI property is initialized from values in the CloudObject, if false
* the cloud object property is initialized from the UI
*/
public void bindProperty(Component cmp, final String propertyName, final String attributeName, final int defer, boolean objectLead) {
if (objectLead) {
Object val = values.get(attributeName);
Object cmpVal = cmp.getBoundPropertyValue(propertyName);
if (val == null) {
if (cmpVal != null) {
cmp.setBoundPropertyValue(propertyName, null);
}
} else {
if (cmpVal == null || !(val.equals(cmpVal))) {
cmp.setBoundPropertyValue(propertyName, val);
}
}
} else {
Object val = values.get(attributeName);
Object cmpVal = cmp.getBoundPropertyValue(propertyName);
if (cmpVal == null) {
if (val != null) {
values.remove(attributeName);
status = STATUS_MODIFIED;
}
} else {
if (val == null || !(val.equals(cmpVal))) {
values.put(attributeName, cmpVal);
status = STATUS_MODIFIED;
}
}
}
BindTarget target = new BindTarget() {
public void propertyChanged(Component source, String propertyName, Object oldValue, Object newValue) {
switch(defer) {
case BINDING_DEFERRED:
if (deferedValues == null) {
deferedValues = new Hashtable();
}
deferedValues.put(attributeName, newValue);
break;
case BINDING_IMMEDIATE:
values.put(attributeName, newValue);
status = STATUS_MODIFIED;
break;
case BINDING_AUTO_SAVE:
values.put(attributeName, newValue);
status = STATUS_MODIFIED;
CloudStorage.getInstance().save(CloudObject.this);
break;
}
}
};
cmp.bindProperty(propertyName, target);
cmp.putClientProperty("CN1Bind" + propertyName, target);
}
Aggregations