Search in sources :

Example 6 with Display

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

the class AndroidImplementation method getAppArg.

@Override
public String getAppArg() {
    if (super.getAppArg() != null) {
        // behaviour the existed when AppArg was just another Display property.
        return super.getAppArg();
    }
    if (getActivity() == null) {
        return null;
    }
    android.content.Intent intent = getActivity().getIntent();
    if (intent != null) {
        Uri u = intent.getData();
        String scheme = intent.getScheme();
        if (u == null && intent.getExtras() != null) {
            if (intent.getExtras().keySet().contains("android.intent.extra.STREAM")) {
                try {
                    u = (Uri) intent.getParcelableExtra("android.intent.extra.STREAM");
                    scheme = u.getScheme();
                    System.out.println("u=" + u);
                } catch (Exception ex) {
                    Log.d("Codename One", "Failed to load parcelable extra from intent: " + ex.getMessage());
                }
            }
        }
        if (u != null) {
            // String scheme = intent.getScheme();
            intent.setData(null);
            if ("content".equals(scheme)) {
                try {
                    InputStream attachment = getActivity().getContentResolver().openInputStream(u);
                    if (attachment != null) {
                        String name = getContentName(getActivity().getContentResolver(), u);
                        if (name != null) {
                            String filePath = getAppHomePath() + getFileSystemSeparator() + name;
                            File f = new File(filePath);
                            OutputStream tmp = createFileOuputStream(f);
                            byte[] buffer = new byte[1024];
                            int read = -1;
                            while ((read = attachment.read(buffer)) > -1) {
                                tmp.write(buffer, 0, read);
                            }
                            tmp.close();
                            attachment.close();
                            setAppArg(filePath);
                            return filePath;
                        }
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    return null;
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }
            } else {
                /*
                    // Why do we need this special case?  u.toString()
                    // will include the full URL including query string.
                    // This special case causes urls like myscheme://part1/part2
                    // to only return "/part2" which is obviously problematic and
                    // is inconsistent with iOS.  Is this special case necessary
                    // in some versions of Android?
                    String encodedPath = u.getEncodedPath();
                    if (encodedPath != null && encodedPath.length() > 0) {
                        String query = u.getQuery();
                        if(query != null && query.length() > 0){
                            encodedPath += "?" + query;
                        }
                        setAppArg(encodedPath);
                        return encodedPath;
                    }
                    */
                setAppArg(u.toString());
                return u.toString();
            }
        }
    }
    return null;
}
Also used : 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) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) android.content(android.content) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ParseException(java.text.ParseException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Paint(android.graphics.Paint)

Example 7 with Display

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

the class IOSImplementation method paintNow.

public static void paintNow() {
    final Display d = Display.getInstance();
    d.callSeriallyAndWait(new Runnable() {

        @Override
        public void run() {
            Form f = d.getCurrent();
            f.paintComponent(instance.getCodenameOneGraphics(), true);
        }
    }, 50);
}
Also used : Form(com.codename1.ui.Form) Display(com.codename1.ui.Display)

Example 8 with Display

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

the class XYChart 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) {
    if (points.size() > 2) {
        // there are more than one point
        // record the first point's position
        float previousPointX = points.get(0);
        float previousPointY = points.get(1);
        for (int k = 0; k < points.size(); k += 2) {
            if (k == 2) {
                // not
                if (Math.abs(points.get(2) - points.get(0)) > renderer.getDisplayChartValuesDistance() || Math.abs(points.get(3) - points.get(1)) > renderer.getDisplayChartValuesDistance()) {
                    // first point
                    drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex)), points.get(0), points.get(1) - renderer.getChartValuesSpacing(), paint, 0);
                    // second point
                    drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + 1)), points.get(2), points.get(3) - renderer.getChartValuesSpacing(), paint, 0);
                    previousPointX = points.get(2);
                    previousPointY = points.get(3);
                }
            } else if (k > 2) {
                // are not too close, display
                if (Math.abs(points.get(k) - previousPointX) > renderer.getDisplayChartValuesDistance() || Math.abs(points.get(k + 1) - previousPointY) > renderer.getDisplayChartValuesDistance()) {
                    drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0);
                    previousPointX = points.get(k);
                    previousPointY = points.get(k + 1);
                }
            }
        }
    } else {
        // if only one point, display it
        for (int k = 0; k < points.size(); k += 2) {
            drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0);
        }
    }
}
Also used : Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 9 with Display

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

the class OnOffSwitch method fireActionEvent.

private void fireActionEvent() {
    dispatcher.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed));
    Display d = Display.getInstance();
    if (d.isBuiltinSoundsEnabled()) {
        d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Display(com.codename1.ui.Display)

Example 10 with Display

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

the class AbstractChart method drawLabel.

/**
 * Draws a text label.
 *
 * @param canvas the canvas
 * @param labelText the label text
 * @param renderer the renderer
 * @param prevLabelsBounds the previous rendered label bounds
 * @param centerX the round chart center on X axis
 * @param centerY the round chart center on Y axis
 * @param shortRadius the short radius for the round chart
 * @param longRadius the long radius for the round chart
 * @param currentAngle the current angle
 * @param angle the label extra angle
 * @param left the left side
 * @param right the right side
 * @param color the label color
 * @param paint the paint
 * @param line if a line to the label should be drawn
 * @param display display the label anyway
 */
protected void drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<Rectangle2D> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display) {
    if (renderer.isShowLabels() || display) {
        paint.setColor(color);
        double rAngle = Math.toRadians(90 - (currentAngle + angle / 2));
        double sinValue = Math.sin(rAngle);
        double cosValue = Math.cos(rAngle);
        int x1 = Math.round(centerX + (float) (shortRadius * sinValue));
        int y1 = Math.round(centerY + (float) (shortRadius * cosValue));
        int x2 = Math.round(centerX + (float) (longRadius * sinValue));
        int y2 = Math.round(centerY + (float) (longRadius * cosValue));
        float size = renderer.getLabelsTextSize();
        float extra = Math.max(size / 2, 10);
        paint.setTextAlign(Component.LEFT);
        if (x1 > x2) {
            extra = -extra;
            paint.setTextAlign(Component.RIGHT);
        }
        float xLabel = x2 + extra;
        float yLabel = y2;
        float width = right - xLabel;
        if (x1 > x2) {
            width = xLabel - left;
        }
        labelText = getFitText(labelText, width, paint);
        float widthLabel = paint.measureText(labelText);
        boolean okBounds = false;
        while (!okBounds && line) {
            boolean intersects = false;
            int length = prevLabelsBounds.size();
            for (int j = 0; j < length && !intersects; j++) {
                Rectangle2D prevLabelBounds = prevLabelsBounds.get(j);
                if (prevLabelBounds.intersects(xLabel, yLabel, widthLabel, size)) {
                    intersects = true;
                    yLabel = (float) Math.max(yLabel, prevLabelBounds.getY() + prevLabelBounds.getHeight());
                }
            }
            okBounds = !intersects;
        }
        if (line) {
            y2 = (int) (yLabel - size / 2);
            canvas.drawLine(x1, y1, x2, y2, paint);
            canvas.drawLine(x2, y2, x2 + extra, y2, paint);
        } else {
            paint.setTextAlign(Component.CENTER);
        }
        canvas.drawText(labelText, xLabel, yLabel, paint);
        if (line) {
            prevLabelsBounds.add(PkgUtils.makeRect(xLabel, yLabel, xLabel + widthLabel, yLabel + size));
        }
    }
}
Also used : Rectangle2D(com.codename1.ui.geom.Rectangle2D) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Aggregations

Display (com.codename1.ui.Display)10 Component (com.codename1.ui.Component)7 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Container (com.codename1.ui.Container)4 Dialog (com.codename1.ui.Dialog)4 Form (com.codename1.ui.Form)4 IOException (java.io.IOException)4 RGBImage (com.codename1.ui.RGBImage)3 InputStream (java.io.InputStream)3 ParseException (java.text.ParseException)3 Hashtable (java.util.Hashtable)3 Cursor (android.database.Cursor)2 Paint (android.graphics.Paint)2 Paint (com.codename1.charts.compat.Paint)2 Point (com.codename1.charts.models.Point)2 SpanButton (com.codename1.components.SpanButton)2 Address (com.codename1.contacts.Address)2 Contact (com.codename1.contacts.Contact)2 Button (com.codename1.ui.Button)2 Font (com.codename1.ui.Font)2