Search in sources :

Example 11 with Orientation

use of com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation in project CodenameOne by codenameone.

the class List method paintFocus.

private void paintFocus(Graphics g, int width, Rectangle pos, Dimension rendererSize) {
    if (ignoreFocusComponentWhenUnfocused && !hasFocus()) {
        return;
    }
    if (!shouldRenderSelection()) {
        return;
    }
    calculateComponentPosition(getCurrentSelected(), width, pos, rendererSize, getElementSize(true, true), true);
    Dimension size = pos.getSize();
    Component cmp = renderer.getListFocusComponent(this);
    if (cmp != null) {
        cmp.setCellRenderer(true);
        int x = pos.getX();
        int y = pos.getY();
        // prevent focus animation from working during a drag operation
        if (orientation != HORIZONTAL) {
            y -= (animationPosition + fixedDraggedAnimationPosition);
        } else {
            x -= (animationPosition + fixedDraggedAnimationPosition);
        }
        renderComponentBackground(g, cmp, x, y, size.getWidth(), size.getHeight());
        renderComponent(g, cmp, x, y, size.getWidth(), size.getHeight());
    }
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 12 with Orientation

use of com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation in project CodenameOne by codenameone.

the class List method animate.

/**
 * {@inheritDoc}
 */
public boolean animate() {
    // parent is performing the animation we shouldn't do anything in this case
    // this is the scrolling animation which we don't want to interfear with
    boolean parentFinished = super.animate();
    if ((animationPosition != 0) && listMotion != null && !isDragActivated()) {
        if (animationPosition < 0) {
            animationPosition = Math.min(listMotion.getValue() - destination, 0);
        } else {
            animationPosition = Math.max(destination - listMotion.getValue(), 0);
        }
        if (animationPosition == 0) {
            listMotion = null;
            deregisterAnimatedInternal();
        }
        return true;
    }
    if (fixedDraggedMotion != null) {
        int val = -fixedDraggedMotion.getValue();
        fixedDraggedAnimationPosition = fixedDraggedAnimationPosition - (fixedDraggedPosition - val);
        fixedDraggedPosition = val;
        Dimension size = getElementSize(false, true);
        int s;
        if (orientation == VERTICAL) {
            s = size.getHeight();
        } else {
            s = size.getWidth();
        }
        if (fixedDraggedMotion.isFinished()) {
            deregisterAnimatedInternal();
            // is the closest and animate to it.
            if (fixedDraggedAnimationPosition <= -s / 2) {
                fixedDraggedSelection++;
                if (fixedDraggedSelection >= model.getSize()) {
                    fixedDraggedSelection = 0;
                }
            } else if (fixedDraggedAnimationPosition >= s / 2) {
                fixedDraggedSelection--;
                if (fixedDraggedSelection < 0) {
                    fixedDraggedSelection = model.getSize() - 1;
                }
            }
            if (fixedDraggedAnimationPosition != 0) {
                if (fixedDraggedAnimationPosition < 0) {
                    if (fixedDraggedAnimationPosition < -s / 2) {
                        destination = s + fixedDraggedAnimationPosition;
                        animationPosition = destination;
                    } else {
                        destination = -fixedDraggedAnimationPosition;
                        animationPosition = fixedDraggedAnimationPosition;
                    }
                } else {
                    if (fixedDraggedAnimationPosition > s / 2) {
                        destination = (s - fixedDraggedAnimationPosition);
                        animationPosition = -destination;
                    } else {
                        destination = fixedDraggedAnimationPosition;
                        animationPosition = fixedDraggedAnimationPosition;
                    }
                }
                initListMotion();
                fixedDraggedAnimationPosition = 0;
            }
            // this happens when dragging an empty list causing an exception on a negative selection
            if (fixedDraggedSelection >= 0 && fixedDraggedSelection < getModel().getSize()) {
                setSelectedIndex(fixedDraggedSelection, false);
            }
            setDragActivated(false);
            fixedDraggedMotion = null;
            return false;
        } else {
            if (fixedDraggedAnimationPosition <= -s) {
                fixedDraggedSelection++;
                if (fixedDraggedSelection >= model.getSize()) {
                    fixedDraggedSelection = 0;
                }
                fixedDraggedPosition = val;
            } else if (fixedDraggedAnimationPosition >= s) {
                fixedDraggedSelection--;
                if (fixedDraggedSelection < 0) {
                    fixedDraggedSelection = model.getSize() - 1;
                }
                fixedDraggedPosition = val;
            }
            fixedDraggedAnimationPosition = fixedDraggedAnimationPosition % s;
        }
        return true;
    }
    return parentFinished;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 13 with Orientation

use of com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation in project CodenameOne by codenameone.

the class List method calculateComponentPosition.

/**
 * Calculates the desired bounds for the component and returns them within the
 * given rectangle.
 */
private void calculateComponentPosition(int index, int defaultWidth, Rectangle rect, Dimension rendererSize, Dimension selectedSize, boolean beforeSelected) {
    Style style = getStyle();
    int initialY = style.getPaddingTop();
    int initialX = style.getPaddingLeftNoRTL();
    boolean rtl = isRTL();
    if (rtl) {
        initialX += getSideGap();
    }
    int selection = getCurrentSelected();
    Dimension d = rect.getSize();
    int selectedDiff;
    // which will cause the bottom elements to "return" from the top.
    if (orientation != HORIZONTAL) {
        int height = rendererSize.getHeight();
        selectedDiff = selectedSize.getHeight() - height;
        rect.setX(initialX);
        d.setHeight(height);
        d.setWidth(defaultWidth);
        int y = 0;
        int listHeight = getHeight() - style.getVerticalPadding();
        int totalHeight = (height + itemGap) * getModel().getSize() + selectedDiff;
        switch(fixedSelection) {
            case FIXED_CENTER:
                y = listHeight / 2 - (height + itemGap + selectedDiff) / 2 + (index - selection) * (height + itemGap);
                if (!beforeSelected) {
                    y += selectedDiff;
                }
                y = recalcOffset(y, totalHeight, listHeight, height + itemGap);
                break;
            case FIXED_TRAIL:
                y = listHeight - (height + itemGap + selectedDiff);
            case FIXED_LEAD:
                y += (index - selection) * (height + itemGap);
                if (index - selection > 0) {
                    y += selectedDiff;
                }
                y = recalcOffset(y, totalHeight, listHeight, height + itemGap);
                break;
            default:
                y = index * (height + itemGap);
                if (!beforeSelected) {
                    y += selectedDiff;
                }
                break;
        }
        rect.setY(y + initialY);
        if (index == selection) {
            d.setHeight(d.getHeight() + selectedDiff);
        }
    } else {
        int width = rendererSize.getWidth();
        selectedDiff = selectedSize.getWidth() - width;
        rect.setY(initialY);
        d.setHeight(getHeight() - style.getVerticalPadding());
        d.setWidth(width);
        int x = 0;
        int listWidth = getWidth() - style.getHorizontalPadding();
        int totalWidth = (width + itemGap) * getModel().getSize() + selectedDiff;
        switch(fixedSelection) {
            case FIXED_CENTER:
                x = listWidth / 2 - (width + itemGap + selectedDiff) / 2 + (index - selection) * (width + itemGap);
                if (!beforeSelected) {
                    x += selectedDiff;
                }
                if (rtl) {
                    x = listWidth - x - width;
                }
                x = recalcOffset(x, totalWidth, listWidth, width + itemGap);
                break;
            case FIXED_TRAIL:
                x = listWidth - (width + itemGap + selectedDiff);
            case FIXED_LEAD:
                x += (index - selection) * (width + itemGap);
                if (index - selection > 0) {
                    x += selectedDiff;
                }
                if (rtl) {
                    x = listWidth - x - width;
                }
                x = recalcOffset(x, totalWidth, listWidth, width + itemGap);
                break;
            default:
                x = index * (width + itemGap);
                if (!beforeSelected) {
                    x += selectedDiff;
                }
                break;
        }
        int rectX = initialX + x;
        if ((rtl) && (fixedSelection < FIXED_NONE_BOUNDRY)) {
            rectX = initialX + totalWidth - (x - initialX) - (width + itemGap);
            if (index == getCurrentSelected()) {
                rectX -= selectedDiff;
            }
            if (totalWidth < listWidth) {
                rectX += (listWidth - totalWidth);
            }
        }
        rect.setX(rectX);
        if (index == selection) {
            d.setWidth(d.getWidth() + selectedDiff);
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 14 with Orientation

use of com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation in project CodenameOne by codenameone.

the class List method pointerDraggedImpl.

private void pointerDraggedImpl(int x, int y) {
    if (!isEnabled()) {
        return;
    }
    if (isSmoothScrolling()) {
        if (fixedSelection < FIXED_NONE_BOUNDRY) {
            super.pointerDragged(x, y);
        } else {
            if (!isDragActivated()) {
                setDragActivated(true);
            }
            Dimension size = getElementSize(false, true);
            boolean vertical = orientation == List.VERTICAL;
            int pos;
            int s;
            if (vertical) {
                pos = y;
                s = size.getHeight();
            } else {
                pos = x;
                s = size.getWidth();
            }
            fixedDraggedAnimationPosition = fixedDraggedAnimationPosition - (fixedDraggedPosition - pos);
            fixedDraggedPosition = pos;
            if (fixedDraggedAnimationPosition <= -s) {
                fixedDraggedSelection++;
                if (fixedDraggedSelection >= model.getSize()) {
                    fixedDraggedSelection = 0;
                }
            } else if (fixedDraggedAnimationPosition >= s) {
                fixedDraggedSelection--;
                if (fixedDraggedSelection < 0) {
                    fixedDraggedSelection = model.getSize() - 1;
                }
            }
            fixedDraggedAnimationPosition = fixedDraggedAnimationPosition % s;
        }
    } else {
        int sel = pointerSelect(x, y);
        if (sel > -1) {
            model.setSelectedIndex(sel);
        }
    }
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 15 with Orientation

use of com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation in project CodenameOne by codenameone.

the class List method pointerSelect.

private int pointerSelect(int x, int y) {
    int selectedIndex = -1;
    int numOfcomponents = getModel().getSize();
    Style style = getStyle();
    Dimension rendererSize = getElementSize(false, true);
    Dimension selectedSize = getElementSize(true, true);
    Rectangle pos = new Rectangle();
    int width = getWidth() - style.getHorizontalPadding() - getSideGap();
    if (isScrollableX()) {
        width = Math.max(width, getScrollDimension().getWidth() - style.getHorizontalPadding() - getSideGap());
    }
    y = y - getAbsoluteY();
    x = x - getAbsoluteX();
    if (fixedSelection < FIXED_NONE_BOUNDRY) {
        calculateComponentPosition(getSelectedIndex(), width, pos, rendererSize, getElementSize(true, true), true);
        if (orientation != HORIZONTAL) {
            if (y < pos.getY()) {
                selectedIndex = (y - style.getPaddingTop()) / (rendererSize.getHeight() + itemGap);
            } else {
                int current = getSelectedIndex();
                if (y < pos.getY() + selectedSize.getHeight()) {
                    selectedIndex = current;
                } else {
                    selectedIndex = (current + 1) + (y - (pos.getY() + selectedSize.getHeight())) / (rendererSize.getHeight() + itemGap);
                }
            }
        } else {
            if (isRTL()) {
                if (x > pos.getX() + selectedSize.getWidth()) {
                    int delta = x - (pos.getX() + selectedSize.getWidth());
                    delta /= (rendererSize.getWidth() + itemGap);
                    // should have been -1-delta, but works better like this.
                    selectedIndex = getSelectedIndex() - 1 - delta;
                } else {
                    if (x >= pos.getX()) {
                        selectedIndex = getSelectedIndex();
                    } else {
                        int delta = pos.getX() - x;
                        delta /= (rendererSize.getWidth() + itemGap);
                        selectedIndex = getSelectedIndex() + 1 + delta;
                    }
                }
            } else {
                if (x < pos.getX()) {
                    selectedIndex = (x - style.getPaddingLeftNoRTL()) / (rendererSize.getWidth() + itemGap);
                } else {
                    int current = getSelectedIndex();
                    if (x < pos.getX() + selectedSize.getWidth()) {
                        selectedIndex = current;
                    } else {
                        selectedIndex = (current + 1) + (x - (pos.getX() + selectedSize.getWidth())) / (rendererSize.getWidth() + itemGap);
                    }
                }
            }
        }
    } else {
        for (int i = 0; i < numOfcomponents; i++) {
            calculateComponentPosition(i, width, pos, rendererSize, selectedSize, true);
            if (pos.contains(x, y)) {
                selectedIndex = i;
                break;
            }
        }
    }
    if (selectedIndex < 0 || selectedIndex >= size()) {
        return -1;
    }
    return selectedIndex;
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Dimension (com.codename1.ui.geom.Dimension)8 Style (com.codename1.ui.plaf.Style)7 Rectangle (com.codename1.ui.geom.Rectangle)5 Paint (com.codename1.charts.compat.Paint)3 Point (com.codename1.charts.models.Point)3 Component (com.codename1.ui.Component)3 Form (com.codename1.ui.Form)3 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)2 Container (com.codename1.ui.Container)2 Border (com.codename1.ui.plaf.Border)2 UIManager (com.codename1.ui.plaf.UIManager)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 ExifInterface (android.media.ExifInterface)1 Orientation (com.codename1.charts.compat.GradientDrawable.Orientation)1