use of com.codename1.ui.events.ActionEvent 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.ui.events.ActionEvent in project CodenameOne by codenameone.
the class BlackBerryCanvas method getMenu.
public Menu getMenu(int val) {
if (Display.getInstance().getCommandBehavior() == Display.COMMAND_BEHAVIOR_NATIVE) {
m = new Menu();
if (commands != null) {
for (int iter = 0; iter < commands.size(); iter++) {
final Command cmd = (Command) commands.elementAt(iter);
String txt = UIManager.getInstance().localize(cmd.getCommandName(), cmd.getCommandName());
MenuItem i = new MenuItem(txt, iter, iter) {
public void run() {
Display.getInstance().callSerially(new Runnable() {
public void run() {
impl.getCurrentForm().dispatchCommand(cmd, new ActionEvent(cmd));
}
});
}
};
m.add(i);
}
}
return m;
}
return super.getMenu(val);
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class InnerActive method readResponse.
/**
* {@inheritDoc}
*/
protected void readResponse(InputStream input) throws IOException {
StringBuffer buf = new StringBuffer();
byte[] buffer = new byte[256];
int len;
while ((len = input.read(buffer)) > 0) {
String temp = new String(buffer, 0, len, "UTF-8");
int endOfFile = temp.indexOf("/html>");
if (endOfFile > 0) {
buf.append(temp.toCharArray(), 0, endOfFile + 6);
break;
} else {
buf.append(temp);
}
}
String s = buf.toString();
// if(s.indexOf("ci=") > -1){
// String ci = s.substring(s.indexOf("ci=") + 3, s.length());
// cid = ci.substring(0, ci.indexOf("&"));
// Storage.getInstance().writeObject("cid", cid);
// Storage.getInstance().flushStorageCache();
// addParam(this, "cid", cid);
// }
fireResponseListener(new ActionEvent(s, ActionEvent.Type.Response));
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class IOSImplementation method captureAudio.
public void captureAudio(ActionListener response) {
if (!nativeInstance.checkMicrophoneUsage()) {
throw new RuntimeException("Please add the ios.NSMicrophoneUsageDescription build hint");
}
dropEvents = false;
String p = FileSystemStorage.getInstance().getAppHomePath();
if (!p.endsWith("/")) {
p += "/";
}
try {
final Media media = MediaManager.createMediaRecorder(p + "cn1TempAudioFile", MediaManager.getAvailableRecordingMimeTypes()[0]);
media.play();
boolean b = Dialog.show("Recording", "", "Save", "Cancel");
final Dialog d = new Dialog("Recording");
media.pause();
media.cleanup();
d.dispose();
if (b) {
response.actionPerformed(new ActionEvent(p + "cn1TempAudioFile"));
} else {
FileSystemStorage.getInstance().delete(p + "cn1TempAudioFile");
response.actionPerformed(null);
}
} catch (IOException err) {
err.printStackTrace();
response.actionPerformed(null);
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Ads method initComponent.
/**
* {@inheritDoc}
*/
public void initComponent() {
if (service != null) {
service.initialize(this);
service.addResponseListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String a = (String) evt.getSource();
setAd(a);
}
});
if (refreshAd) {
getComponentForm().registerAnimated(this);
} else {
requestAd();
}
}
}
Aggregations