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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
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!
Developer
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

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

can u rply me peter
Developer
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

Developer
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

Highlighted
Developer
Posts: 19,636
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);
        }
    }
};