use of com.codename1.util.Callback in project CodenameOne by codenameone.
the class IOSImplementation method locationUpdate.
/**
* Callback for native
*/
public static void locationUpdate() {
if (lm != null) {
final LocationListener ls = lm.getActiveLocationListener();
lm.setStatus();
if (ls != null) {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
ls.locationUpdated(lm.getCurrentLocation());
}
});
}
}
}
use of com.codename1.util.Callback in project CodenameOne by codenameone.
the class JavaSEPort method registerPush.
@Override
public void registerPush(Hashtable meta, boolean noFallback) {
Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
String user = p.get("user", null);
Display d = Display.getInstance();
if (user == null) {
JPanel pnl = new JPanel();
JTextField tf = new JTextField(20);
pnl.add(new JLabel("E-Mail For Push"));
pnl.add(tf);
JOptionPane.showMessageDialog(canvas, pnl, "Email For Push", JOptionPane.PLAIN_MESSAGE);
user = tf.getText();
p.put("user", user);
}
d.setProperty("built_by_user", user);
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
mainClass = mainClass.substring(0, mainClass.lastIndexOf('.'));
d.setProperty("package_name", mainClass);
}
super.registerPush(meta, noFallback);
if (pushSimulation != null && pushSimulation.isVisible()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(window, "registerForPush invoked. Use the buttons in the push simulator to send the appropriate callback to your app", "Push Registration", JOptionPane.INFORMATION_MESSAGE);
}
});
}
}
use of com.codename1.util.Callback in project CodenameOne by codenameone.
the class BarCodeScanner method startScaning.
private void startScaning(ScanResult callback) {
this.callback = callback;
try {
// Add the listener for scan and cancel
Container cmdContainer = new Container(new FlowLayout(Component.CENTER));
Button scanButton = new Button(new Command("Scan") {
public void actionPerformed(ActionEvent evt) {
cameraForm.repaint();
if (snapshotThread != null) {
snapshotThread.continueRun();
}
}
});
Button cancelButton = new Button(new Command("Cancel") {
public void actionPerformed(ActionEvent evt) {
if (snapshotThread != null) {
snapshotThread.stop();
cancelScan();
}
}
});
cmdContainer.addComponent(scanButton);
cmdContainer.addComponent(cancelButton);
cameraForm = new Form();
cameraForm.setScrollable(false);
cameraForm.setLayout(new BorderLayout());
cameraForm.addComponent(BorderLayout.CENTER, media.getVideoComponent());
cameraForm.addComponent(BorderLayout.SOUTH, cmdContainer);
} catch (Exception e) {
// throw new AppException("Image/video capture not supported on this phone", e).setCode(97);
e.printStackTrace();
}
startScan();
}
use of com.codename1.util.Callback in project CodenameOne by codenameone.
the class ComponentSelector method fadeOut.
/**
* Fades out components in this set.
* @param duration Duration of animation.
* @param callback Callback to run when animation completes.
* @return Self for chaining.
*/
public ComponentSelector fadeOut(int duration, final SuccessCallback<ComponentSelector> callback) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
final ArrayList<Component> animatingComponents = new ArrayList<Component>();
for (Component c : this) {
Container parent = c.getParent();
if (parent != null) {
AnimationManager cmgr = c.getAnimationManager();
if (cmgr != null) {
mgr = cmgr;
Container placeholder = new Container();
// placeholder.setShowEvenIfBlank(true);
c.putClientProperty(placeholderProperty, placeholder);
Component.setSameHeight(placeholder, c);
Component.setSameWidth(placeholder, c);
$(placeholder).setMargin(c.getStyle().getMarginTop(), c.getStyle().getMarginRight(false), c.getStyle().getMarginBottom(), c.getStyle().getMarginLeft(false)).setPadding(c.getStyle().getPaddingTop(), c.getStyle().getPaddingRight(false), c.getStyle().getPaddingBottom(), c.getStyle().getPaddingLeft(false));
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createFade(duration));
animations.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimation(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])), new Runnable() {
public void run() {
for (final Component c : animatingComponents) {
// c.setHidden(true);
c.setVisible(false);
final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
c.putClientProperty(placeholderProperty, null);
if (placeholder != null) {
Container parent = placeholder.getParent();
/*
if (parent == null) {
System.out.println("Deferring replace back");
$(new Runnable() {
public void run() {
Container parent = placeholder.getParent();
if (parent != null) {
System.out.println("Found parent after deferral");
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
}
});
} else {
*/
if (parent != null) {
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
// }
}
}
if (callback != null) {
callback.onSucess(ComponentSelector.this);
}
}
});
}
return this;
}
use of com.codename1.util.Callback in project CodenameOne by codenameone.
the class CodenameOneImplementation method downloadImageToFileSystem.
/**
* Downloads an image to file system. This will *not* first check to see if the file exists already.
* It will download and overwrite any existing image at the provided location.
*
* <p>Some platforms may override this method to use platform-level caching. E.g. Javascript will use
* the browser cache for downloading the image.</p>
*
* @param url The URL of the image to download.
* @param fileName The storage key to be used to store the image.
* @param onSuccess Callback on success. Will be executed on EDT.
* @param onFail Callback on failure. Will be executed on EDT.
*/
public void downloadImageToFileSystem(String url, String fileName, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail) {
ConnectionRequest cr = new ConnectionRequest();
cr.setPost(false);
cr.setFailSilently(true);
cr.setReadResponseForErrors(false);
cr.setDuplicateSupported(true);
cr.setUrl(url);
cr.downloadImageToFileSystem(fileName, onSuccess, onFail);
}
Aggregations