Search in sources :

Example 46 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class IOSImplementation method capturePhoto.

/**
 * Captures a photo and notifies with the image data when available
 * @param response callback for the resulting image
 */
public void capturePhoto(ActionListener response) {
    if (!nativeInstance.checkCameraUsage()) {
        throw new RuntimeException("Please add the ios.NSCameraUsageDescription build hint");
    }
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    nativeInstance.captureCamera(false);
    dropEvents = true;
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 47 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class IOSImplementation method showNativePicker.

@Override
public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) {
    datePickerResult = -2;
    int x = 0, y = 0, w = 20, h = 20, preferredHeight = 0, preferredWidth = 0;
    if (source != null) {
        x = source.getAbsoluteX();
        y = source.getAbsoluteY();
        w = source.getWidth();
        h = source.getHeight();
    }
    if (source instanceof Picker) {
        Picker p = (Picker) source;
        preferredHeight = p.getPreferredPopupHeight();
        preferredWidth = p.getPreferredPopupWidth();
    }
    if (type == Display.PICKER_TYPE_STRINGS) {
        String[] strs = (String[]) data;
        int offset = -1;
        if (currentValue != null) {
            int slen = strs.length;
            for (int iter = 0; iter < slen; iter++) {
                if (strs[iter].equals(currentValue)) {
                    offset = iter;
                    break;
                }
            }
        }
        nativeInstance.openStringPicker(strs, offset, x, y, w, h, preferredWidth, preferredHeight);
    } else if (type == Display.PICKER_TYPE_DURATION) {
        long time;
        if (currentValue instanceof Long) {
            time = (Long) currentValue;
        } else {
            time = 0l;
        }
        int minuteStep = 5;
        if (data instanceof String) {
            String strData = (String) data;
            String[] parts = Util.split(strData, "\n");
            for (String part : parts) {
                if (part.indexOf("minuteStep=") != -1) {
                    minuteStep = Integer.parseInt(part.substring(part.indexOf("=") + 1));
                }
            }
        }
        nativeInstance.openDatePicker(type, time, x, y, w, h, preferredWidth, preferredHeight, minuteStep);
    } else {
        long time;
        if (currentValue instanceof Integer) {
            java.util.Calendar c = java.util.Calendar.getInstance();
            c.set(java.util.Calendar.HOUR_OF_DAY, ((Integer) currentValue).intValue() / 60);
            c.set(java.util.Calendar.MINUTE, ((Integer) currentValue).intValue() % 60);
            time = c.getTime().getTime();
        } else if (currentValue != null) {
            time = ((java.util.Date) currentValue).getTime();
        } else {
            time = new java.util.Date().getTime();
        }
        nativeInstance.openDatePicker(type, time, x, y, w, h, preferredWidth, preferredHeight, 5);
    }
    // wait for the native code to complete
    Display.getInstance().invokeAndBlock(new Runnable() {

        public void run() {
            while (datePickerResult == -2) {
                synchronized (PICKER_LOCK) {
                    try {
                        PICKER_LOCK.wait(100);
                    } catch (InterruptedException err) {
                    }
                }
            }
        }
    }, true);
    if (datePickerResult == -1) {
        // }
        return null;
    }
    if (type == Display.PICKER_TYPE_STRINGS) {
        if (datePickerResult < 0) {
            return null;
        }
        return ((String[]) data)[(int) datePickerResult];
    }
    Object result;
    if (type == Display.PICKER_TYPE_DURATION || type == Display.PICKER_TYPE_DURATION_HOURS || type == Display.PICKER_TYPE_DURATION_MINUTES) {
        if (datePickerResult < 0) {
            return null;
        }
        return new Long(datePickerResult);
    }
    if (type == Display.PICKER_TYPE_TIME) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(new Date(datePickerResult));
        result = new Integer(c.get(java.util.Calendar.HOUR_OF_DAY) * 60 + c.get(java.util.Calendar.MINUTE));
    } else {
        result = new Date(datePickerResult);
    }
    return result;
}
Also used : Date(java.util.Date) Picker(com.codename1.ui.spinner.Picker)

Example 48 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class IOSImplementation method captureVideo.

/**
 * Captures a video and notifies with the data when available
 * @param response callback for the resulting video
 */
public void captureVideo(ActionListener response) {
    if (!nativeInstance.checkCameraUsage() || !nativeInstance.checkMicrophoneUsage()) {
        throw new RuntimeException("Please add the ios.NSCameraUsageDescription and ios.NSMicrophoneUsageDescription build hints");
    }
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    nativeInstance.captureCamera(true);
    dropEvents = true;
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 49 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class CachedDataService method readResponse.

/**
 * {@inheritDoc}
 */
protected void readResponse(InputStream input) throws IOException {
    data.setData(Util.readInputStream(input));
    fireResponseListener(new NetworkEvent(this, data));
    data.setFetching(false);
}
Also used : NetworkEvent(com.codename1.io.NetworkEvent)

Example 50 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class ImageDownloadService method createImageToFileSystem.

/**
 * Constructs an image request that will automatically populate the given Label
 * when the response arrives, it will cache the file locally.
 *
 * @param url the image URL
 * @param callback the callback that should be updated when the data arrives
 * @param destFile local file to store the data into the given path
 */
public static void createImageToFileSystem(String url, ActionListener callback, String destFile) {
    Image im = cacheImage(null, false, destFile, null, null, defaultMaintainAspectRatio);
    if (im != null) {
        callback.actionPerformed(new NetworkEvent(null, im));
        return;
    }
    // image not found on cache go and download from the url
    ImageDownloadService i = new ImageDownloadService(url, callback);
    i.cacheImages = true;
    i.destinationFile = destFile;
    i.setFailSilently(true);
    NetworkManager.getInstance().addToQueue(i);
}
Also used : NetworkEvent(com.codename1.io.NetworkEvent) EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) FileEncodedImage(com.codename1.components.FileEncodedImage) StorageImage(com.codename1.components.StorageImage)

Aggregations

IOException (java.io.IOException)18 EncodedImage (com.codename1.ui.EncodedImage)12 Hashtable (java.util.Hashtable)12 Image (com.codename1.ui.Image)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)9 FileInputStream (java.io.FileInputStream)8 ActionEvent (com.codename1.ui.events.ActionEvent)7 ActionListener (com.codename1.ui.events.ActionListener)7 FileEncodedImage (com.codename1.components.FileEncodedImage)6 ConnectionRequest (com.codename1.io.ConnectionRequest)6 File (java.io.File)6 Intent (android.content.Intent)5 StorageImage (com.codename1.components.StorageImage)5 IntentResultListener (com.codename1.impl.android.IntentResultListener)5 EditableResources (com.codename1.ui.util.EditableResources)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 DataInputStream (java.io.DataInputStream)5 Vector (java.util.Vector)5 CodenameOneActivity (com.codename1.impl.android.CodenameOneActivity)4