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
silwar
Posts: 53
Registered: ‎01-12-2011
My Device: BOLD 9780
My Carrier: Bharti Airtel
Accepted Solution

animation effect for horizontal field manager

Hi
I have three fieldManagers arranged horizontally in which contents of

middle fieldmanager will change on button click

 

is it possible to apply slide in - slide out effect to these contents?

i dont want to redraw whole screen again n again?

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

Re: animation effect for horizontal field manager

You can achieve a transition effect for a HFM by just having a Thread that changes the horizontalScrollPosition every, say 100 milliseconds,  Say where you want to go is position 500 and you are currently at 100, then if you do 4 100 pixel movements, it looks like it is sliding.  I don't have any useful code that does this, it is just an idea.  But give it a try if you don't find any other way. 

Please use plain text.
Developer
silwar
Posts: 53
Registered: ‎01-12-2011
My Device: BOLD 9780
My Carrier: Bharti Airtel

Re: animation effect for horizontal field manager

Hi peter_strange

I tried with your suggestion and partly succeeded in slide-in / out effect

but manager can only be slide in from left side of screen only.

I want manager to slide in from right side of the screen.

 

what could be the possible solution for this ??

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: animation effect for horizontal field manager

Wrap the middle manager in a HorizontalFieldManager(HORIZONTAL_SCROLL). When you want to slide out the old content and slide in the new one, do the following:

1) add the new content to the HFM;

2) make an animation sliding from the left boundary of the old content (probably 0) to the left boundary of the new one (getLeft() returns the value). Use the method suggested by Peter;

3) Once the animation has finished, delete the old content and setHorizontalScroll on the enveloping HFM to 0 (since the new content now starts there).

----------------------------------------------------------
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
silwar
Posts: 53
Registered: ‎01-12-2011
My Device: BOLD 9780
My Carrier: Bharti Airtel

Re: animation effect for horizontal field manager

Hi arkadyz and peter

Thanx for useful suggestions:Yes:

 

As peter suggested, i am succeeded to implement Transition effect for HFM from Left To Right

is it possible to apply reverse effect (Right to Left) for the same

so that HFM will seems to be sliding in from right side of the screen?

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: animation effect for horizontal field manager

But that's exactly what I suggested - see my previous reply to make your manager "slide" from right to left...

----------------------------------------------------------
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.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: animation effect for horizontal field manager

Hi peter,

 As u have explained i have created a class that does the sliding effect for the field.. and here is the class.

class CentricHManager extends HorizontalFieldManager {
        int focusedFieldIndex = 0;
        private int[] xPositions;   
        int scroll;
        int scrollpos = 0;
        boolean isKeepGoing = true;
        int middlePoint;
        int position;
        int focusedFieldIndexNew;
        
        CentricHManager(){
            super(Manager.HORIZONTAL_SCROLL);
        }
        protected void sublayout(int maxWidth, int maxHeight) {
            int x = 0;
            xPositions = new int[getFieldCount()];
            for (int i = 0; i < getFieldCount(); i++) {
                layoutChild(getField(i), 0, maxHeight);
                setPositionChild(getField(i), x , 0);
                xPositions[i] = x;
                //System.out.println("Xposition of "+i+" is "+xPositions[i]);
                x = x + getField(i).getWidth();
            }
            setExtent(getPreferredWidth(),getPreferredHeight());         
        }

        public void focusChangeNotify(int arg0) {
            super.focusChangeNotify(arg0);
            focusedFieldIndexNew = getFieldWithFocusIndex();
            if (focusedFieldIndexNew != focusedFieldIndex && focusedFieldIndexNew < getFieldCount()) {
                scrollpos = this.getHorizontalScroll();
                position  = xPositions[focusedFieldIndexNew];
                isKeepGoing = true;
                System.out.println("scrollpos  is "+ scrollpos);
                System.out.println("position  is "+ position);
                if (focusedFieldIndexNew - focusedFieldIndex > 0){
                    if(focusedFieldIndexNew == getFieldCount() - 1){
                        middlePoint = Display.getWidth() - getField(focusedFieldIndexNew).getWidth();
                        scroll = position - middlePoint;
                    }else {
                        middlePoint = (Display.getWidth() - getField(focusedFieldIndexNew).getWidth())/2;
                        scroll = position - middlePoint;
                    }
                    System.out.println("middlePoint  is "+ middlePoint);
                    System.out.println("scroll  is "+ scroll);
                    if(focusedFieldIndexNew != 0  && !(scroll < 0)){
                         new Thread(){
                            public void run(){
                                while(isKeepGoing){
                                    try{
                                    scrollpos = scrollpos + 1;
                                    System.out.println("scrollpos  is "+ scrollpos);
                                    if(scrollpos < scroll){
                                        isKeepGoing = true;
                                        CentricHManager.this.setHorizontalScroll(scrollpos);
                                    }else {
                                        isKeepGoing = false;
                                        CentricHManager.this.setHorizontalScroll(scroll);
                                    }
                                        sleep(1);
                                    }catch(Exception e){
                                        System.out.println("Exception Thrown here :"+ e);
                                    }
                                }
                            }
                        }.start();
                    }
                } else {
                    if(focusedFieldIndexNew == 0){
                        scroll = 0;
                    }else {
                        middlePoint = (Display.getWidth() - getField(focusedFieldIndexNew).getWidth())/2;
                        scroll = position - middlePoint;
                    }
                    System.out.println("middlePoint  is "+ middlePoint);
                    System.out.println("scroll  is "+ scroll);
                    if(focusedFieldIndexNew != getFieldCount()-1  && !(scroll < 0)){
                         new Thread(){
                            public void run(){
                                while(isKeepGoing){
                                    try{
                                    scrollpos = scrollpos - 1;
                                    System.out.println("scrollpos  is "+ scrollpos);
                                    if(scrollpos > scroll){
                                        isKeepGoing = true;
                                        CentricHManager.this.setHorizontalScroll(scrollpos);
                                    }else {
                                        isKeepGoing = false;
                                        CentricHManager.this.setHorizontalScroll(scroll);
                                    }
                                        sleep(1);
                                    }catch(Exception e){
                                        System.out.println("Exception Thrown here :"+ e);
                                    }
                                }
                            }
                        }.start();
                    }
                }
                focusedFieldIndex = focusedFieldIndexNew;
            }
        }
        
        public void add(Field field) {
            super.add(field);
        }
    }

 this works fine for 5.0 device. for for below that... 4.5 device throw exception --  java.lang.IllegalStateException: UI engine accessed without holding the event lock. it will work but no sliding effect. can you please help me for this.

This question is related to this thread, thats why i am asking here itself.

 

Thanks & Regards

               pp

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: animation effect for horizontal field manager

Hi,

  sorry peter. it was my mistake.

 i was trying to make a UI change without holding the UI event lock. and now i solved it.

 

Thanks & Regards

              pp  

Please use plain text.
New Developer
harinadh
Posts: 77
Registered: ‎09-02-2010
My Device: torch
My Carrier: blackberry developer

Re: animation effect for horizontal field manager

Hi

 

I have added four Bitmapfields to this CentricHManager and they were not even visible on the device screen. Can you please let me know to add the fields to this and make it slide.

Please use plain text.
Contributor
cyberlinks
Posts: 17
Registered: ‎01-13-2012
My Device: i dont have blackberry
My Carrier: nokia

Re: animation effect for horizontal field manager

 i have created 7 Bitmap field and add to this class but my bitmap images are not visible can u help me to sought out this problem.

Please use plain text.