5

does anyone knows how to use the blackberry JDE API to create a screen slide animation similar to Featured Items screen in the Blackberry App World? I am aware that in blackberry 5.0, there are some transition apis to perform that. But I am looking to do it for version 4.6 OS. It has the nice scrolling effect using the scrolling ball in blackberry bold.

Thanks.

dickyj
  • 1,672
  • 1
  • 19
  • 35

2 Answers2

4

As an alternative to the screenshot/Bitmap approach...

In the paint method of your screen you can use Graphics.pushContext(..) to push a clipping region and drawing offset. For best results, you'll want to do the transition in a runnable, and synchronize on the event lock. This will ensure that your screen can be dismissed in the middle of a transition.

Rough example:

class TransitionScreen extends Screen {
    private int transitionOffset;
    private boolean isTransitionHorizontal;
    private ScreenTransition currentTransition;

    public TransitionScreen(boolean isTransitionHorizontal) {
        this.isTransitionHorizontal = isTransitionHorizontal;

        transitionOffset = getTransitionMaximum(); // So the screen starts offset
    }

    protected void paint(Graphics graphics) {
        // use transitionOffset as x or y depending on isTransitionHorizontal
        graphics.pushContext(...);
    }

    protected void onExposed() {
        transitionToOffset(0);
    }

    protected void onObscured() {
        int target = getTransitionMaximum();

        transitionToOffset(target);
    }

    private int getTransitionMaximum() {
        return isTransitionHorizontal ? Display.getWidth() : Display.getHeight();
    }

    private void transitionToOffset(int target) {
        if (currentTransition != null) {
            currentTransition.stop();
        }

        currentTransition = new ScreenTransition(target);

        getApplication().invokeLater(currentTransition);
    }
}

class ScreenTransition implements Runnable {
    private boolean animating;
    private int target;

    public ScreenTransitionUpdater(int target) {
        this.target = target;
    }

    public void stop() {
        animating = false;
    }

    public void run() {
        while(animating) {
            Object eventLock = getApplication().getEventLock();

            synchronized(eventLock) {
                // Interpolate myOffset to target

                // Set animating = false if myOffset = target

                invalidate();
            }
        }
    }
}

No need to mark animating as volatile as it is ignored on this platform.

Doug Moscrop
  • 4,368
  • 2
  • 23
  • 45
0

Maybe use a timer to change the coordinate position of the images in the paint method

Michael Donohue
  • 11,606
  • 5
  • 29
  • 44
Bohemian
  • 5,777
  • 11
  • 36
  • 47
  • Yes, I am thinking I need to do something like that, I saw bits and pieces of code doing that on other sites, but so far there is none that is doing anything exactly like the App World app, I'll need to experiment then...thanks. – dickyj Dec 23 '09 at 05:00