Search in sources :

Example 71 with com.codename1.rad.ui

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

the class ComponentSelector method setPadding.

/**
 * Sets padding to all components in found set.
 * @param top Top padding in pixels.
 * @param right Right padding in pixels
 * @param bottom Bottom padding in pixels.
 * @param left Left padding in pixels.
 * @return
 * @see #getStyle(com.codename1.ui.Component)
 */
public ComponentSelector setPadding(int top, int right, int bottom, int left) {
    Style s = currentStyle();
    s.setPaddingUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
    s.setPadding(top, bottom, left, right);
    return this;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 72 with com.codename1.rad.ui

use of com.codename1.rad.ui 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;
}
Also used : ComponentAnimation(com.codename1.ui.animations.ComponentAnimation) ArrayList(java.util.ArrayList)

Example 73 with com.codename1.rad.ui

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

the class AndroidImplementation method createIntentForURL.

private Intent createIntentForURL(String url) {
    Intent intent;
    Uri uri;
    try {
        if (url.startsWith("intent")) {
            intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
        } else {
            if (url.startsWith("/") || url.startsWith("file:")) {
                if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to open the file")) {
                    return null;
                }
            }
            intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            if (url.startsWith("/")) {
                File f = new File(url);
                Uri furi = null;
                try {
                    furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
                } catch (Exception ex) {
                    f = makeTempCacheCopy(f);
                    furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
                }
                if (Build.VERSION.SDK_INT < 21) {
                    List<ResolveInfo> resInfoList = getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
                    for (ResolveInfo resolveInfo : resInfoList) {
                        String packageName = resolveInfo.activityInfo.packageName;
                        getContext().grantUriPermission(packageName, furi, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    }
                }
                uri = furi;
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {
                if (url.startsWith("file:")) {
                    File f = new File(removeFilePrefix(url));
                    System.out.println("File size: " + f.length());
                    Uri furi = null;
                    try {
                        furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
                    } catch (Exception ex) {
                        f = makeTempCacheCopy(f);
                        furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
                    }
                    if (Build.VERSION.SDK_INT < 21) {
                        List<ResolveInfo> resInfoList = getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
                        for (ResolveInfo resolveInfo : resInfoList) {
                            String packageName = resolveInfo.activityInfo.packageName;
                            getContext().grantUriPermission(packageName, furi, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        }
                    }
                    uri = furi;
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else {
                    uri = Uri.parse(url);
                }
            }
            String mimeType = getMimeType(url);
            if (mimeType != null) {
                intent.setDataAndType(uri, mimeType);
            } else {
                intent.setData(uri);
            }
        }
        return intent;
    } catch (Exception err) {
        com.codename1.io.Log.e(err);
        return null;
    }
}
Also used : Uri(android.net.Uri) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) JSONException(org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) MediaException(com.codename1.media.AsyncMedia.MediaException) ParseException(java.text.ParseException) SAXException(org.xml.sax.SAXException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 74 with com.codename1.rad.ui

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

the class AndroidImplementation method drawShape.

@Override
public void drawShape(Object graphics, com.codename1.ui.geom.Shape shape, com.codename1.ui.Stroke stroke) {
    AndroidGraphics ag = (AndroidGraphics) graphics;
    Path p = cn1ShapeToAndroidPath(shape);
    ag.drawPath(p, stroke);
}
Also used : Path(android.graphics.Path) GeneralPath(com.codename1.ui.geom.GeneralPath)

Example 75 with com.codename1.rad.ui

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

the class AndroidImplementation method fixAttachmentPath.

private String fixAttachmentPath(String attachment) {
    com.codename1.io.File cn1File = new com.codename1.io.File(attachment);
    File mediaStorageDir = new File(new File(getContext().getCacheDir(), "intent_files"), "Attachment");
    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d(Display.getInstance().getProperty("AppName", "CodenameOne"), "failed to create directory");
            return null;
        }
    }
    File newFile = new File(mediaStorageDir.getPath() + File.separator + cn1File.getName());
    if (newFile.exists()) {
        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        newFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + "_" + cn1File.getName());
    }
    // Uri fileUri = Uri.fromFile(newFile);
    newFile.getParentFile().mkdirs();
    // Uri imageUri = Uri.fromFile(newFile);
    Uri fileUri = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", newFile);
    try {
        InputStream is = FileSystemStorage.getInstance().openInputStream(attachment);
        OutputStream os = new FileOutputStream(newFile);
        byte[] buf = new byte[1024];
        int len;
        while ((len = is.read(buf)) > -1) {
            os.write(buf, 0, len);
        }
        is.close();
        os.close();
    } catch (IOException ex) {
        Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
    }
    return fileUri.toString();
}
Also used : Audio(com.codename1.media.Audio) java.io(java.io) com.codename1.io(com.codename1.io) BufferedInputStream(com.codename1.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedOutputStream(com.codename1.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Uri(android.net.Uri) Date(java.util.Date) Paint(android.graphics.Paint) FileOutputStream(java.io.FileOutputStream) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

IOException (java.io.IOException)34 EncodedImage (com.codename1.ui.EncodedImage)28 ArrayList (java.util.ArrayList)27 Point (java.awt.Point)25 File (java.io.File)24 AnimationObject (com.codename1.ui.animations.AnimationObject)22 BufferedImage (java.awt.image.BufferedImage)22 Hashtable (java.util.Hashtable)19 Component (com.codename1.ui.Component)18 Form (com.codename1.ui.Form)18 Image (com.codename1.ui.Image)16 EditableResources (com.codename1.ui.util.EditableResources)16 FileInputStream (java.io.FileInputStream)16 Timeline (com.codename1.ui.animations.Timeline)15 BorderLayout (com.codename1.ui.layouts.BorderLayout)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)11 FileOutputStream (java.io.FileOutputStream)10 AttributedString (java.text.AttributedString)10 EditorFont (com.codename1.ui.EditorFont)9