Search in sources :

Example 21 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class ImageDownloadService method postResponse.

/**
 * {@inheritDoc}
 */
protected void postResponse() {
    // trigger an exception in case of an invalid image
    result.getWidth();
    Image image = result;
    if (toScale != null && toScale.getWidth() != image.getWidth() && toScale.getHeight() != image.getHeight()) {
        image = scaleImage(image, toScale, maintainAspectRatio);
    }
    final Image i = image;
    if (parentLabel != null) {
        final Dimension pref = parentLabel.getPreferredSize();
        if (parentLabel.getComponentForm() != null) {
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    if (isDownloadToStyles()) {
                        parentLabel.getUnselectedStyle().setBgImage(i);
                        parentLabel.getSelectedStyle().setBgImage(i);
                        parentLabel.getPressedStyle().setBgImage(i);
                    } else {
                        parentLabel.setIcon(i);
                    }
                    Dimension newPref = parentLabel.getPreferredSize();
                    // sized image in place or has a hardcoded preferred size.
                    if (pref.getWidth() != newPref.getWidth() || pref.getHeight() != newPref.getHeight()) {
                        parentLabel.getComponentForm().revalidate();
                    }
                }
            });
        } else {
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    if (isDownloadToStyles()) {
                        parentLabel.getUnselectedStyle().setBgImage(i);
                        parentLabel.getSelectedStyle().setBgImage(i);
                        parentLabel.getPressedStyle().setBgImage(i);
                    } else {
                        parentLabel.setIcon(i);
                    }
                }
            });
        }
        parentLabel.repaint();
        return;
    } else {
        if (targetList != null) {
            setEntryInListModel(targetOffset, image);
            // revalidate only once to avoid multiple revalidate refreshes during scroll
            if (targetList.getParent() != null) {
                if (alwaysRevalidate) {
                    targetList.getParent().revalidate();
                } else {
                    if (targetList.getClientProperty("$imgDSReval") == null) {
                        targetList.putClientProperty("$imgDSReval", Boolean.TRUE);
                        targetList.getParent().revalidate();
                    } else {
                        targetList.repaint();
                    }
                }
            }
        }
    }
    // if this is a list cell renderer component
    fireResponseListener(new NetworkEvent(this, result));
}
Also used : NetworkEvent(com.codename1.io.NetworkEvent) Dimension(com.codename1.ui.geom.Dimension) EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) FileEncodedImage(com.codename1.components.FileEncodedImage) StorageImage(com.codename1.components.StorageImage)

Example 22 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class FaceBookAccess method getFaceBookObjectItems.

/**
 * Get a list of FaceBook objects for a given id
 *
 * @param faceBookId the id to preform the query upon
 * @param itemsConnection the type of the query
 * @param feed
 * @param params
 * @param callback the callback that should be updated when the data arrives
 */
public void getFaceBookObjectItems(String faceBookId, String itemsConnection, final DefaultListModel feed, Hashtable params, final ActionListener callback) throws IOException {
    checkAuthentication();
    final FacebookRESTService con = new FacebookRESTService(token, faceBookId, itemsConnection, false);
    con.setResponseDestination(feed);
    con.addResponseListener(new Listener(con, callback));
    if (params != null) {
        Enumeration keys = params.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            con.addArgument(key, (String) params.get(key));
        }
    }
    if (slider != null) {
        SliderBridge.bindProgress(con, slider);
    }
    for (int i = 0; i < responseCodeListeners.size(); i++) {
        con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
    }
    current = con;
    NetworkManager.getInstance().addToQueue(con);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) Enumeration(java.util.Enumeration)

Example 23 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class BlackBerryImplementation method sendMessage.

public void sendMessage(String[] recipients, String subject, Message msg) {
    Folder[] folders = Session.getDefaultInstance().getStore().list(Folder.SENT);
    net.rim.blackberry.api.mail.Message message = new net.rim.blackberry.api.mail.Message(folders[0]);
    try {
        Address[] toAdds = new Address[recipients.length];
        for (int i = 0; i < recipients.length; i++) {
            Address address = new Address(recipients[i], "");
            toAdds[i] = address;
        }
        message.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, toAdds);
        message.setSubject(subject);
    } catch (Exception e) {
        EventLog.getInstance().logErrorEvent("err " + e.getMessage());
    }
    try {
        if (msg.getAttachment() != null && msg.getAttachment().length() > 0) {
            Multipart content = new Multipart();
            TextBodyPart tbp = new TextBodyPart(content, msg.getContent());
            content.addBodyPart(tbp);
            InputStream stream = com.codename1.io.FileSystemStorage.getInstance().openInputStream(msg.getAttachment());
            byte[] buf;
            buf = IOUtilities.streamToBytes(stream);
            stream.close();
            String name = msg.getAttachment();
            name = name.substring(name.lastIndexOf(getFileSystemSeparator()) + 1, name.length());
            SupportedAttachmentPart sap = new SupportedAttachmentPart(content, msg.getAttachmentMimeType(), name, buf);
            content.addBodyPart(sap);
            message.setContent(content);
        } else {
            message.setContent(msg.getContent());
        }
        app.setWaitingForReply(true);
        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
    } catch (Exception ex) {
        EventLog.getInstance().logErrorEvent("err " + ex.getMessage());
    }
}
Also used : Multipart(net.rim.blackberry.api.mail.Multipart) TextMessage(javax.wireless.messaging.TextMessage) Message(com.codename1.messaging.Message) Address(net.rim.blackberry.api.mail.Address) BufferedInputStream(com.codename1.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) TextBodyPart(net.rim.blackberry.api.mail.TextBodyPart) Folder(net.rim.blackberry.api.mail.Folder) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) MessageArguments(net.rim.blackberry.api.invoke.MessageArguments) SupportedAttachmentPart(net.rim.blackberry.api.mail.SupportedAttachmentPart)

Example 24 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class GoogleImpl method onConnected.

public void onConnected(Bundle bundle) {
    List<SuccessCallback<GoogleApiClient>> callbacks;
    synchronized (onConnectedCallbacks) {
        if (!onConnectedCallbacks.isEmpty()) {
            callbacks = new ArrayList<SuccessCallback<GoogleApiClient>>(onConnectedCallbacks);
            onConnectedCallbacks.clear();
        } else {
            callbacks = new ArrayList<SuccessCallback<GoogleApiClient>>();
        }
    }
    GoogleApiClient client = mGoogleApiClient;
    for (SuccessCallback<GoogleApiClient> cb : callbacks) {
        cb.onSucess(client);
    }
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) SuccessCallback(com.codename1.util.SuccessCallback)

Example 25 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class RangeBarChart method drawChartValuesText.

/**
 * The graphical representation of the series values as text.
 *
 * @param canvas the canvas to paint to
 * @param series the series to be painted
 * @param renderer the series renderer
 * @param paint the paint to be used for drawing
 * @param points the array of points to be used for drawing the series
 * @param seriesIndex the index of the series currently being drawn
 * @param startIndex the start index of the rendering points
 */
protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRenderer renderer, Paint paint, List<Float> points, int seriesIndex, int startIndex) {
    int seriesNr = mDataset.getSeriesCount();
    float halfDiffX = getHalfDiffX(points, points.size(), seriesNr);
    int start = 0;
    if (startIndex > 0) {
        start = 2;
    }
    for (int i = start; i < points.size(); i += 4) {
        int index = startIndex + i / 2;
        float x = points.get(i);
        if (mType == Type.DEFAULT) {
            x += seriesIndex * 2 * halfDiffX - (seriesNr - 1.5f) * halfDiffX;
        }
        if (!isNullValue(series.getY(index + 1)) && points.size() > i + 3) {
            // draw the maximum value
            drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(index + 1)), x, points.get(i + 3) - renderer.getChartValuesSpacing(), paint, 0);
        }
        if (!isNullValue(series.getY(index)) && points.size() > i + 1) {
            // draw the minimum value
            drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(index)), x, points.get(i + 1) + renderer.getChartValuesTextSize() + renderer.getChartValuesSpacing() - 3, paint, 0);
        }
    }
}
Also used : Paint(com.codename1.charts.compat.Paint)

Aggregations

Paint (com.codename1.charts.compat.Paint)26 ArrayList (java.util.ArrayList)24 Component (com.codename1.ui.Component)16 List (com.codename1.ui.List)13 Point (com.codename1.charts.models.Point)11 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 Hashtable (java.util.Hashtable)11 Container (com.codename1.ui.Container)9 ContainerList (com.codename1.ui.list.ContainerList)9 Button (com.codename1.ui.Button)8 List (java.util.List)8 TextArea (com.codename1.ui.TextArea)7 Dimension (com.codename1.ui.geom.Dimension)7 EncodedImage (com.codename1.ui.EncodedImage)6 Label (com.codename1.ui.Label)6 RadioButton (com.codename1.ui.RadioButton)5 ActionListener (com.codename1.ui.events.ActionListener)5 JList (javax.swing.JList)4 FileEncodedImage (com.codename1.components.FileEncodedImage)3 StorageImage (com.codename1.components.StorageImage)3