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
Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

add screen over another screen

[ Edited ]

actually ,my problem is bit lengthy, i have made a code to swipe the screen left and right with slide transition,that is working fine,here is code i hv used. i mean to say that text is looking like it's moving.

public final class MyScreen extends MainScreen
{
    private boolean _pushed;
    LabelField label, labeltwo;
    Preview screen1; 
    int counter,mycounter;
	private InputStream ips;
	private FileConnection fc;
	private URI str;
	private Database db;
	
    public MyScreen()
    {        
        // Set the displayed title of the screen      
    	copyFromResToDeviceMemory();
    	System.out.println("111111111111111111111111111");
        setTitle("MyTitle");
        label = new LabelField(/*"First main screen A class extending the MainScreen class, which provides default standard"*/);
        add(label);
        
        
        
       
        
    }
    protected boolean navigationMovement(int dx,int dy,int status,int time)
    {
        try
        {
            if(dx == -1)
            {
            	UiApplication.getUiApplication().invokeLater(new Runnable() {
					
					public void run() {
						// TODO Auto-generated method stub
						System.out.println("------------MyScreen---------------");
						System.out.println("----CHECK 1111111111111----");
						push();     
					}
				});
            
            }
            if(dx ==  1)
            {
            	UiApplication.getUiApplication().invokeLater(new Runnable() {
					
					public void run() {
						// TODO Auto-generated method stub
						System.out.println("-----------MyScreen-2222222222----------");
						System.out.println("----CHECK 222222222222----");
						pushsecond();
					}
				});

            }
            
            this.invalidate();
        }
        catch(Exception e)
        {
        	System.out.println("WError:"+e.toString());
        }
        return true;
    }
    
    
    public class Preview extends MainScreen{

		public Preview() {
			// TODO Auto-generated constructor stub
			setTitle("MyTitle Preview");
			
			labeltwo = new LabelField();
			this.add(labeltwo);
			
		}
		protected boolean navigationMovement(int dx,int dy,int status,int time)
	    {
	        try
	        {
	            if(dx == -1)
	            {
	            	UiApplication.getUiApplication().invokeLater(new Runnable() {
						
						public void run() {
							// TODO Auto-generated method stub
							try{
								
							counter++;
								
								labeltwo.setText(""+counter);
							
							System.out.println("counter=="+counter);
							System.out.println("-------------Preview---------------");
							System.out.println("----CHECK 3333333333333333----");
							
							UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
							push();
							
							}catch(Exception e){
								System.out.println("navidation error="+e.toString());
							}
						}
					});
	            }
	            if(dx ==  1)
	            {
	            	UiApplication.getUiApplication().invokeLater(new Runnable() {
						
						public void run() {
							// TODO Auto-generated method stub
							try{
								 
							counter--;
							
							UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
							pushsecond();
							
							}catch(Exception e){
								System.out.println("navigation error="+e.toString());
							}
						}
					});
	            }
	           
	            this.invalidate();
	        }
	        catch(Exception e)
	        {
	        	System.out.println("WError:"+e.toString());
	        }
	        return true;
	    }
	}
    
    
	public void pushsecond() {
		// TODO Auto-generated method stub
		System.out.println("-----------pushsecond-----------------");
		try{
        TransitionContext transitionContextIn;
        TransitionContext transitionContextOut;
        
        UiEngineInstance engine = Ui.getUiEngineInstance();    
        
        screen1 = new Preview();  
        
        transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_SLIDE);

        transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
        transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT); 
        
        transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
        transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
        transitionContextOut.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT);
        transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT);    
               
        engine.setTransition(null, screen1, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
                
        engine.setTransition(screen1, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);
            
		}catch(Exception e){
			System.out.println("push second error="+e.toString());
		}
        synchronized(UiApplication.getEventLock())
        {
        	System.out.println("777777----pushsecond-----7777777777777");
        	
           UiApplication.getUiApplication().pushScreen(screen1);
           System.out.println("my counter="+mycounter);
           
          
           
            _pushed = true;                      
        }      
		
	}
	public void push() {
		// TODO Auto-generated method stub
		System.out.println("--------------push--------------");
        try{
		
        TransitionContext transitionContextIn;
        TransitionContext transitionContextOut;
        
        UiEngineInstance engine = Ui.getUiEngineInstance();    
        
        screen1 = new Preview(); 
        
        transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_SLIDE);

        transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
        transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_RIGHT); 
        
        transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
        transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
        transitionContextOut.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_RIGHT);
        transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT);    
                
        engine.setTransition(null, screen1, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
                
        engine.setTransition(screen1, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);
            
        }catch(Exception e){
        	System.out.println("push error="+e.toString());
        }
        synchronized(UiApplication.getEventLock())
        {
        	System.out.println("77777----push------77777777777777");
        	
           UiApplication.getUiApplication().pushScreen(screen1);  
          
           System.out.println(""+mycounter);
         
            _pushed = true;                      
        }      

	}
	
}

 

when ever i run that code ,first i see a screen with label,and when ever i swipe left or right i pushed a another screen with slide transition and the text is looking like ,it's moving working fine,now my problem is explained on the 2nd pic ,

look at the middle part which have label with some text now how can i add another screen over just the middle part i when i swipe to my label left or right.and here is my code to create a layout

public final class MyScreen extends MainScreen
{
	
	private HorizontalFieldManager vfm;
	private int deviceWidth = Display.getWidth();
    private int deviceHeight = Display.getHeight();
	private HorizontalFieldManager hfm;
	private VerticalFieldManager thought;
	private LabelField mytext;
	private HorizontalFieldManager lasthfm;
	private VerticalFieldManager mainManager;
	private VerticalFieldManager subManager;
	private Bitmap _backgroundBitmap = Bitmap.getBitmapResource("a.png");  

	public MyScreen(){
		 super(NO_VERTICAL_SCROLL);
				// TODO Auto-generated method stub
		    	 vfm = new HorizontalFieldManager()
			    	{
			            protected void sublayout(int maxWidth, int maxHeight)  {
			            	
			              super.sublayout(maxWidth,60);  
			              setExtent(maxWidth,60);
			            
			              }
			            public void paint(Graphics g){
			            	//Variables for drawing the gradient  
						     int[] X_PTS_MAIN = { 0, deviceWidth, deviceWidth, 0};   
						     int[] Y_PTS_MAIN = { 0, 0, deviceHeight, deviceHeight };   
						     int[] drawColors_MAIN = { Color.RED, Color.RED, Color.DARKBLUE, Color.DARKBLUE}; 
						     
						     try {  
						         //Draw the gradients     
						         g.drawShadedFilledPath(X_PTS_MAIN, Y_PTS_MAIN, null, drawColors_MAIN, null);  
						             
						        } catch (IllegalArgumentException iae) { 
						        	
						           }  
						         
						        //Call super to paint the graphics on the inherited window   
						        super.paint(g);  
			            	
			            }
			      };
			           
			           //vfm.add(new BitmapField(complete));
			            vfm.setPadding(0, 0, 5, 0);
			           
			            
		            //this manager is used for second image over background image        
		            hfm = new HorizontalFieldManager(/*Manager.VERTICAL_SCROLL| Manager.FOCUSABLE*/)
		            {
		         	   protected void sublayout(int maxWidth, int maxHeight)  
		         	   {
		                    super.sublayout(maxWidth,226);  
		                    setExtent(maxWidth,226);
		                }
		         	  public void paint(Graphics g){
		              	//Variables for drawing the gradient  
		  			     int[] X_PTS_MAIN = { 0, deviceWidth, deviceWidth,0};   
		  			     int[] Y_PTS_MAIN = { 0, 0 ,deviceHeight, deviceHeight };   
		  			     int[] drawColors_MAIN = { Color.RED, Color.RED, Color.DARKBLUE, Color.DARKBLUE}; 
		  			     
		  			     try {  
		  			         //Draw the gradients     
		  			         g.drawShadedFilledPath(X_PTS_MAIN, Y_PTS_MAIN, null, drawColors_MAIN, null); 
		  			             
		  			        } catch (IllegalArgumentException iae) {  
		  			        	
		  			           }  
		  			        //Call super to paint the graphics on the inherited window   
		  			        super.paint(g);  
		              	
		              }
		         	
		            };
		           
		            thought = new VerticalFieldManager(Manager.VERTICAL_SCROLL/*| Manager.FOCUSABLE*/);
		           
		            mytext = new LabelField("A BlackBerry device.",Field.FOCUSABLE){
		            	boolean myfocus = false;
		            	protected void drawFocus(Graphics g, boolean on) 
			         	{
			         	    g.setColor(Color.RED);
					    }
		            	protected void onFocus(int direction) {
							// TODO Auto-generated method stub
							myfocus = true;
							
							super.onFocus(direction);
						}
						
						protected void onUnfocus() {
							// TODO Auto-generated method stub
							myfocus = false;
							super.onUnfocus();
						}
						protected boolean navigationMovement(int dx,int dy,int status,int time)
					    {
							if(myfocus){
								try
						        {
						            if(dx > 0)
						            {
						            	try {
						            		
						            		//SwipeForPreviousdata();
						            		
						    			} catch (Exception e) {
						    				// TODO Auto-generated catch block
						    				System.out.println("previous ??????????" + e.getMessage());
						    			}
						            	//previous
						            	//counter++;
						            	//text.setText(""+counter);
						            }
						            if(dx < 0)
						            {
						            	try {
						            		//swipeFornextdata();
						            		
						    				
						    			} catch (Exception enext) {
						    				// TODO Auto-generated catch block
						    				System.out.println("?????????" + enext.getMessage());
						    			}
						            	//next
						            	//counter--;
						            	//text.setText(""+counter);left
						            }
						            if(dy < 0)
						            {
						            	myfocus = false;
						                 System.out.println("UP : ");
						                // Dialog.alert("UP : ");
						            }
						            if(dy > 0)
						            {
						            	myfocus = false;
						                 System.out.println("DOWN : ");
						                 //Dialog.alert("DOWN");
						            }
						            this.invalidate();
						        }
						        catch(Exception e)
						        {
						        	System.out.println(""+e.getMessage());
						        }
							}if(!myfocus){
								//System.out.println("==============");
								return false;
							}
					        
					        return true;
					    }
						
						
		            };
		           
		            hfm.setPadding(8, 0, 0, 0); 
		            mytext.setPadding(5, 5, 5, 5);
		            thought.add(mytext);
		           
		            hfm.add(thought);
		            
		          //this manager is used for third image over background image
		            lasthfm = new HorizontalFieldManager()
		            {
		         	   protected void sublayout(int maxWidth, int maxHeight)  
		         	   {
		                    super.sublayout(maxWidth,50);  
		                    setExtent(maxWidth,50);
		                }
		         	  public void paint(Graphics g){
		              	//Variables for drawing the gradient  
		  			     int[] X_PTS_MAIN = { 0, deviceWidth, deviceWidth, 0};   
		  			     int[] Y_PTS_MAIN = { 0, 0, deviceHeight, deviceHeight }; 
		  			     int[] drawColors_MAIN = { Color.RED, Color.RED, Color.DARKBLUE, Color.DARKBLUE}; 
		  			     
		  			     try {  
		  			         //Draw the gradients     
		  			         g.drawShadedFilledPath(X_PTS_MAIN, Y_PTS_MAIN, null, drawColors_MAIN, null);  
		  			             
		  			        } catch (IllegalArgumentException iae) {  
		  			           }  
		  			         
		  			        //Call super to paint the graphics on the inherited window   
		  			        super.paint(g);  
		              	
		              }
		            };  
		           //  
		            lasthfm.setPadding(11, 0, 0, 0);
		           
		        //this manager is used for the static background image
		        mainManager = new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL |  Manager.NO_VERTICAL_SCROLLBAR )
		        {            
		            public void paint(Graphics graphics)
		            {
		                graphics.clear();
		                graphics.drawBitmap(0, 0, deviceWidth,  deviceHeight, _backgroundBitmap, 0, 0);                 
		                super.paint(graphics);
		            }         
		            protected void sublayout(int maxWidth, int maxHeight) 
					{               
						super.sublayout(Display.getWidth(),Display.getHeight());
						setExtent(Display.getWidth(),Display.getHeight());
					}
		        };
		        
		        //this manger is used for adding the componentes
		        subManager = new VerticalFieldManager(/* Manager.VERTICAL_SCROLL |   Manager.VERTICAL_SCROLLBAR */)
		        {
		            protected void sublayout(int maxWidth, int maxHeight)
		            {
		                int displayWidth = deviceWidth;
		                int displayHeight = deviceHeight;
		 
		                super.sublayout( displayWidth, displayHeight);
		                setExtent( displayWidth, displayHeight);
		            }
		        };
		        
		       
		        
		        // add your component to this subManager       
		        subManager.add(vfm);
		        subManager.add(hfm);
		        subManager.add(lasthfm);
		        
		        //add subManager over the mainManager
		        mainManager.add(subManager);
		        
		        //finally add the mainManager over the screen
		        this.add(mainManager);
		     
	 }
	 
 }

 

8530.png 

Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2

Re: add screen over another screen

maybe you could try make a 3 field on the screen...
on the center of it would be verticalfieldmanager.
when you do a swipe you could use replace function on the field
Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: add screen over another screen

i'm new to BB, so plz can you give some example of replace function
i have searched through the forum , but did not able to find any example
Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: add screen over another screen

<Manager>.replace(....).

 

See Managet API documentation.

Developer
Posts: 57
Registered: ‎10-29-2010
My Device: Z10 LE, PlayBook

Re: add screen over another screen

I'm only seeing one picture, so maybe I'm not completely understanding what you are looking for. What I think you are wanting is the top and bottom areas to not move, while having the text area in the middle scroll left and right.

 

What I am seeing in my mind is a horizontal field manager in the middle with text fields using the entire screen width, scrolling left and right between objects.

 

Is that what you are trying to accomplish? In essence, a scrollable horizontal field manager.

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: add screen over another screen

I have been through the process of a scrolling HFM with this poster on a previous Thread.  He does not want this because it does not give a slide transition, it is a push transition.  Also there are issues getting the scrolling to stop at the correct place. 

 

replace does not do this, either, I only answered that question to clarify the previous post. 

 

In this case, one approach that I think works the way the OP wants is to have a screen with transparent top and bottom parts, this can then slide over the top.  This will not work correctly if the top and bottom parts contain focusable Fields.

 

Alternatively it is possible to paint the screen directly and simulate the moving text by animating a movement.  Unfortunately my experience suggests that getting this working is well beyond the OPs understanding. 

Developer
Posts: 57
Registered: ‎10-29-2010
My Device: Z10 LE, PlayBook

Re: add screen over another screen

Almost sounds like screens would need to be added in backwards, with the top layer having a transparent center with navigation controls at the bottom, and the sliding page underneath. It would then be a matter of controlling the sliding page from touching the top layer and managing content independant from the sliding layer.

 

Tricky? Sure. Resource intensive? More than likely. Definitely not the optimal way to do things.

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: add screen over another screen

"need to be added in backwards...."

If you do it that way you are assuming there is no interaction with the underlying 'content' screen, because, for example, swipe scrolling becomes problematic!

 

Yes, if given this specification, I would have gone back to the designer and asked for something more BlackBerry friendly..... 

Developer
Posts: 57
Registered: ‎10-29-2010
My Device: Z10 LE, PlayBook

Re: add screen over another screen

I absolutely and totally agree.