Search in sources :

Example 61 with Data

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

the class AddResourceDialog method addResource.

public String addResource(EditableResources res, ResourceEditorView view) {
    // "Image", "Animation", "Font", "Theme", "Data", "Localization (L10N)"
    String newName = name.getText();
    for (String r : res.getResourceNames()) {
        if (r.equalsIgnoreCase(newName)) {
            JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
            return null;
        }
    }
    switch(type.getSelectedIndex()) {
        case // image
        IMAGE:
            ImageRGBEditor imageEditor = new ImageRGBEditor(res, name.getText(), view);
            imageEditor.selectFile();
            view.setSelectedResource(name.getText());
            break;
        case MULTI_IMAGE:
            ImageMultiEditor multiImageEditor = new ImageMultiEditor(res, name.getText(), view);
            view.setSelectedResource(name.getText());
            break;
        case TIMELINE:
            new TimelineEditor(res, name.getText(), view);
            view.setSelectedResource(name.getText());
            break;
        case // animation
        ANIMATION:
            TimelineEditor.selectFile(view, res, name.getText());
            /*ImageEditor animationEditor = new ImageEditor(res, name.getText());
                animationEditor.setAnimation(true);
                animationEditor.selectFile(view);*/
            break;
        case // font
        FONT:
            new FontEditor(res, new EditorFont(com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_MEDIUM), null, "Arial-plain-12", true, RenderingHints.VALUE_TEXT_ANTIALIAS_ON, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,;:!@/\\*()[]{}|#$%^&<>?'\"+- "), name.getText()).createFont();
            view.setSelectedResource(name.getText());
            break;
        case // theme
        THEME:
            res.setTheme(name.getText(), new Hashtable());
            view.setSelectedResource(name.getText());
            // ResourceEditorView.expandAndSelect(tree, name.getText());
            break;
        case // data
        DATA:
            DataEditor dataEditor = new DataEditor(res, name.getText());
            dataEditor.selectDataFile(view);
            view.setSelectedResource(name.getText());
            break;
        case // localization
        LOCALIZATION:
            Hashtable h = new Hashtable();
            Hashtable local = new Hashtable();
            local.put("cancel", "Cancel");
            local.put("ok", "OK");
            local.put("menu", "Menu");
            local.put("select", "Select");
            local.put("edit", "Edit");
            h.put("en", local);
            res.setL10N(name.getText(), h);
            view.setSelectedResource(name.getText());
            // ResourceEditorView.expandAndSelect(tree, name.getText());
            break;
        case UI:
            UserInterfaceEditor uiEditor = new UserInterfaceEditor(name.getText(), res, view.getProjectGeneratorSettings(), view);
            view.setSelectedResource(name.getText());
            break;
    }
    return name.getText();
}
Also used : Hashtable(java.util.Hashtable) EditorFont(com.codename1.ui.EditorFont)

Example 62 with Data

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

the class AddThemeResource method addResource.

// GEN-LAST:event_templateActionPerformed
public String addResource(EditableResources res, ResourceEditorView view) {
    String newName = name.getText();
    for (String r : res.getResourceNames()) {
        if (r.equalsIgnoreCase(newName)) {
            JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
            return null;
        }
    }
    Hashtable theme = new Hashtable();
    InputStream is = getClass().getResourceAsStream("/templates/" + template.getSelectedItem().toString() + ".res");
    if (is != null) {
        try {
            EditableResources r = new EditableResources();
            r.openFile(is);
            is.close();
            theme = r.getTheme(r.getThemeResourceNames()[0]);
            view.checkDuplicateResourcesLoop(r, res.getImageResourceNames(), r.getImageResourceNames(), "Rename Image", "Image ", true);
            view.checkDuplicateResourcesLoop(r, res.getL10NResourceNames(), r.getL10NResourceNames(), "Rename Localization", "Localization ", true);
            view.checkDuplicateResourcesLoop(r, res.getDataResourceNames(), r.getDataResourceNames(), "Rename Data", "Data ", true);
            view.checkDuplicateResourcesLoop(r, res.getUIResourceNames(), r.getUIResourceNames(), "Rename GUI", "GUI ", true);
            view.checkDuplicateResourcesLoop(r, res.getFontResourceNames(), r.getFontResourceNames(), "Rename Font", "Font ", true);
            for (String s : r.getImageResourceNames()) {
                if (r.isMultiImage(s)) {
                    res.setMultiImage(s, (EditableResources.MultiImage) r.getResourceObject(s));
                } else {
                    res.setImage(s, r.getImage(s));
                }
            }
            for (String s : r.getL10NResourceNames()) {
                res.setL10N(s, (Hashtable) r.getResourceObject(s));
            }
            for (String s : r.getDataResourceNames()) {
                res.setData(s, (byte[]) r.getResourceObject(s));
            }
            for (String s : r.getUIResourceNames()) {
                res.setUi(s, (byte[]) r.getResourceObject(s));
            }
            for (String s : r.getFontResourceNames()) {
                res.setFont(s, r.getFont(s));
            }
        } catch (IOException err) {
            err.printStackTrace();
        }
    }
    res.setTheme(name.getText(), theme);
    view.setSelectedResource(name.getText());
    return name.getText();
}
Also used : Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) IOException(java.io.IOException) EditableResources(com.codename1.ui.util.EditableResources)

Example 63 with Data

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

the class GameCanvasImplementation method playNativeBuiltinSound.

/**
 * @inheritDoc
 */
protected void playNativeBuiltinSound(Object data) {
    try {
        try {
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
            m.play();
        } catch (Exception err) {
            // some simulators take issue with the audio/mpeg string but the mp3 string
            // works fine
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
            m.play();
        }
    } catch (IOException ex) {
        // not likely since the stream is a byte array input stream
        ex.printStackTrace();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Media(com.codename1.media.Media) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Example 64 with Data

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

the class BlackBerryImplementation method playNativeBuiltinSound.

/**
 * @inheritDoc
 */
protected void playNativeBuiltinSound(Object data) {
    try {
        try {
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
            m.play();
        } catch (Exception err) {
            // some simulators take issue with the audio/mpeg string but the mp3 string
            // works fine
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
            m.play();
        }
    } catch (IOException ex) {
        // not likely since the stream is a byte array input stream
        ex.printStackTrace();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Media(com.codename1.media.Media) IOException(java.io.IOException) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Example 65 with Data

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

the class Security method verify.

/**
 * Verifies that the signature from the server matches the computed
 * signature on the data.  Returns true if the data is correctly signed.
 *
 * @param publicKey public key associated with the developer account
 * @param signedData signed data from server
 * @param signature server signature
 * @return true if the data and signature match
 */
public static boolean verify(PublicKey publicKey, String signedData, String signature) {
    Signature sig;
    try {
        sig = Signature.getInstance(SIGNATURE_ALGORITHM);
        sig.initVerify(publicKey);
        sig.update(signedData.getBytes());
        if (!sig.verify(Base64.decode(signature))) {
            Log.e(TAG, "Signature verification failed.");
            return false;
        }
        return true;
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "NoSuchAlgorithmException.");
    } catch (InvalidKeyException e) {
        Log.e(TAG, "Invalid key specification.");
    } catch (SignatureException e) {
        Log.e(TAG, "Signature exception.");
    } catch (Base64DecoderException e) {
        Log.e(TAG, "Base64 decoding failed.");
    }
    return false;
}
Also used : Base64DecoderException(com.codename1.impl.android.util.Base64DecoderException) Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

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