Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Text scrolling............

Look back to my previous reply (2 or 3 replies back) where I explain what needs to be done with the code to flip directions etc.

 

Next time, pay more attention to the thread - quite often one or two people post some code while others come with improvement ideas.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
cyndrilla
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: Text scrolling............

can u rply me peter
Please use plain text.
Developer
cyndrilla
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: Text scrolling............

hi peter,

 

i have tried with your code its working but my issue is that i need to scroll the text from right again when it completes the first scroll.can u please say me where to make changes in your code.

 

Thanks



Please use plain text.
Developer
cyndrilla
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: Text scrolling............

i have tried with the code

if (currentChar >= fullText.length()) {
scrollDirection = -1;
currentChar = fullText.length();
}
if (currentChar < 0) {
scrollDirection = 1;
currentChar = 0;
}



but there is no chnge instead of that the scrolling is getting stopped.

so can u plz post me some code

 

Thanks

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Text scrolling............

Not perfect (you wil see why when you try it) but this should get you started.....

 

LabelField testLabel = new LabelField("This is a very long string that will not fit on one line - let us see if we can make it scroll.",
                                      Field.FOCUSABLE) {
    int currentChar = 0;
    String currentText = null;
    Font ourFont;
    private Timer _scrollTimer;
    private TimerTask _scrollTimerTask;
    int characterIncrement = 4;

    public void paint(Graphics graphics) {
        currentText = this.getText();
        if ( currentChar < currentText.length() ) {
            currentText = currentText.substring(currentChar);
        }
        graphics.drawText(currentText, 0, 0, DrawStyle.ELLIPSIS, Display.getWidth());
    }
    public void layout(int width, int height) {
        ourFont = this.getFont();
        setExtent(Display.getWidth(), ourFont.getHeight());
    }
    protected void onDisplay() {
        startScroll();
    }
    protected void onUnfocus() {
        startScroll();
    }
    private void startScroll() {
        // Start scrolling
        final String fullText = this.getText();
        if ( _scrollTimer == null ) {
            _scrollTimer = new Timer();
            _scrollTimerTask = new TimerTask() {
                public void run() {
                    currentChar = currentChar + characterIncrement;
                    if ( currentChar > fullText.length() ) {
                        characterIncrement = 0 - characterIncrement; // reversie direction
                        currentChar = Math.max(fullText.length() + characterIncrement, 0);
                    } else
                    if ( currentChar < 0 ) {
                        characterIncrement = 0 - characterIncrement; // reversie direction
                        currentChar = 0;
                    }
                    invalidate();
                }
            };
            _scrollTimer.scheduleAtFixedRate(_scrollTimerTask, 500, 500);
        }
    }
    protected void onFocus(int direction) {
        if ( _scrollTimer != null ) {
            _scrollTimerTask.cancel();
            _scrollTimer.cancel();
            _scrollTimer = null;
            _scrollTimerTask = null;
        }
    }
    protected boolean navigationMovement(int dx, int dy, int status, int time) {
        currentText = this.getText();
        int oldCurrentChar = currentChar;
        if ( Math.abs(dx) > Math.abs(dy) ) {
            // horizontal scroll
            if ( dx > 0) {
                currentChar = Math.min(currentText.length()-1, currentChar+1);
            } else
            if ( dx < 0 ) {
                currentChar = Math.max(0, currentChar-1);
            }
            if ( oldCurrentChar != currentChar ) {
                this.invalidate();
            }
            return true;
        } else {
            return super.navigationMovement(dx, dy, status, time);
        }
    }
};

 

Please use plain text.