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
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Please suggest me making a view

landing-page.jpg9700.png

I do upto this here is my code.

package mypackage;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class SecondClass extends MainScreen{
	
	public SecondClass() {
		
		 Background bg = BackgroundFactory.createSolidBackground(Color.GREEN);

		 MyHeaderLabel header=new MyHeaderLabel();
			header.setText("Landing Page");
			header.setBackground(bg);
			setBanner(header);
			
			VerticalFieldManager headerManager=new VerticalFieldManager();
			 MyHeaderLabel secondHeader=new MyHeaderLabel();
			 secondHeader.setText("Customer Information");
			 secondHeader.setBackground(bg);
			
			headerManager.setMargin(20,20,0,20);
			headerManager.add(secondHeader);
			add(headerManager);


		
	}
	
}

 

package mypackage;


import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.LabelField;

public class MyHeaderLabel extends LabelField {
	
	
	MyHeaderLabel(){
		
		super(null,USE_ALL_WIDTH);
	}
	
	
	protected void paint(Graphics g) {
		// TODO Auto-generated method stub
		
	//	int currentColor = g.getColor();
	     g.setColor(Color.GREEN);
		
		String myText = this.getText();
		
		
		Font myFont = g.getFont();
		int labelWidth = myFont.getAdvance(myText);
		// Now we know how wide we will be painting. 
		// We know how high we want because that is the height of the Font
		int textX = (this.getWidth() - labelWidth) / 2;
		int textY = (this.getHeight() - myFont.getHeight())/2;

		g.setColor(Color.WHITE);
		int currentColor = g.getColor();
		try {
		g.drawText(myText, 10, textY);
		}
		finally {
		g.setColor(currentColor);
		}
		
		 
		
		//super.paint(g);
	}
	protected void layout(int width, int height) {
		// TODO Auto-generated method stub
		super.layout(width, height);
		setExtent(getWidth(),(getHeight() * 3) / 2);
	}

}

 

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

Re: Please suggest me making a view

You have already asked this question here:

http://supportforums.blackberry.com/t5/Java-Development/suggest-me-how-to-make-this-type-of-view/m-p...

 

As I suggested to you after that post, you need to do some of this work yourself.  So rather than asking us how to do it, you need to think about how you would do it, try it and then help us correct your code.  And do things one at a time and in small steps, so don't move on till you have sorted out the issue you are focused on.  Then you can ask us specific problems rather than general 'how do I do this' questions.

 

I gave you loads of links to useful reference material in my previous Thread.  I very much doubt that you have had time between then and now, to look carefully at this material, or even try anything out.  You need to do this. 

 

And I see you still haven't even managed to get a Gradient background sorted out.  You could at least try.  Read the documentation, it is not hard. Give it a try. 

Developer
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Re: Please suggest me making a view

I am not able to make whit block.

i tried like that

1) First i take vertical manager  and paint rectangle .

than take Horizontal manager add Phone number label +value label

than take horizontal manager  adress + value..

so on

 

add all this horizontal manager to vertical manager ,

I think this is the bad practice please suggest good solution..landing-page.jpg

Developer
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Re: Please suggest me making a view

How to move to next line as in Gray header .i tried lot of method but didnot succeed .

 

1)'\n'

Please explain how to go to next line.

package mypackage;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class SecondClass extends MainScreen{
	
	public SecondClass() {
		
		 Background bg = BackgroundFactory.createLinearGradientBackground(Color.GREEN,
				 Color.GREEN,Color.GREEN,Color.GREEN);
		 Background grayBackground = BackgroundFactory.createLinearGradientBackground(Color.GRAY,
				 Color.GRAY,Color.GRAY,Color.GRAY);
		 Font headerFont = Font.getDefault().derive(Font.PLAIN,17);


		 MyHeaderLabel header=new MyHeaderLabel();
			header.setText("Landing Page");
			header.setBackground(bg);
			setBanner(header);
			
			VerticalFieldManager headerManager=new VerticalFieldManager();
			 MyHeaderLabel secondHeader=new MyHeaderLabel();
			 secondHeader.setText("Customer Information");
			 secondHeader.setFont(headerFont);

			 secondHeader.setBackground(bg);
			 
			 MyHeaderLabel servicePlanHeader=new MyHeaderLabel();
			 servicePlanHeader.setText("Service Plan");
			 servicePlanHeader.setFont(headerFont);
			 servicePlanHeader.setBackground(bg);
			 
			 MyHeaderLabel servicePlanValue=new MyHeaderLabel();
	            String x=new String("Optik 2HID/1SD"+"\n"+"1 PVR,2 STB");

			 servicePlanValue.setText(x);
			 servicePlanValue.setFont(headerFont);
			 servicePlanValue.setBackground(grayBackground);
			 
			 MyHeaderLabel assigmentInfo=new MyHeaderLabel();
			 assigmentInfo.setText("Assignment Info");
			 assigmentInfo.setFont(headerFont);
			 assigmentInfo.setBackground(bg);
			 
	           

			 MyHeaderLabel assigmentInfoGray=new MyHeaderLabel();
			 assigmentInfoGray.setText("EDTNABDS01-P1-1-1" +System.getProperty("line.separator") +
					    "127.0.0.1 www.bing.com");
			 assigmentInfoGray.setFont(headerFont);
			 assigmentInfoGray.setBackground(grayBackground);
			 
			 MyHeaderLabel serviceQuality=new MyHeaderLabel();
			 serviceQuality.setText("Service Quality");
			 serviceQuality.setFont(headerFont);
			 serviceQuality.setBackground(bg);
			 
			 MyHeaderLabel provisionStatus=new MyHeaderLabel();
			 provisionStatus.setText("Provision Status");
			 provisionStatus.setFont(headerFont);
			 provisionStatus.setBackground(grayBackground);
			 
			 
			 
			 servicePlanHeader.setMargin(2,0,0,0);
			 servicePlanValue.setMargin(2,0,0,0);
			 assigmentInfo.setMargin(2,0,0,0);
			 assigmentInfoGray.setMargin(2,0,0,0);
			 serviceQuality.setMargin(2,0,0,0);
			 provisionStatus.setMargin(2,0,0,0);





			headerManager.setMargin(20,20,0,20);
			headerManager.add(secondHeader);
			headerManager.add(servicePlanHeader);
			headerManager.add(servicePlanValue);
			headerManager.add(assigmentInfo);
			headerManager.add(assigmentInfoGray);
			headerManager.add(serviceQuality);
			headerManager.add(provisionStatus);


			add(headerManager);


		
	}
	
}

 9700.png

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

Re: Please suggest me making a view

Let us look first at the grey Field.

 

Instead of using a LabelField, I suggest you try RichTextField.  In fact for the moment don't even create a special class like you have for your Header labels.  Instead just replace:

MyHeaderLabel servicePlanValue=new MyHeaderLabel();

with

RichTextField servicePlanValue=new RichTextField();

 

Here is a question for you.  in MyLabel, you actually paint the text.  Do you paint multiple lines?

Developer
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Re: Please suggest me making a view

Hello sir thanks ..i got it 

But  i am facing 2 problem.

1) Move text of gray field towards right in below service plan

 2) if user want that focus will not come on RichTextField .what he do..?

package mypackage;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class SecondClass extends MainScreen{
	
	public SecondClass() {
		
		 Background bg = BackgroundFactory.createLinearGradientBackground(Color.GREEN,
				 Color.GREEN,Color.GREEN,Color.GREEN);
		 Background grayBackground = BackgroundFactory.createLinearGradientBackground(Color.GRAY,
				 Color.GRAY,Color.GRAY,Color.GRAY);
		 Font headerFont = Font.getDefault().derive(Font.PLAIN,17);


		 MyHeaderLabel header=new MyHeaderLabel();
			header.setText("Landing Page");
			header.setBackground(bg);
			setBanner(header);
			
			VerticalFieldManager headerManager=new VerticalFieldManager();
			 MyHeaderLabel secondHeader=new MyHeaderLabel();
			 secondHeader.setText("Customer Information");
			 secondHeader.setFont(headerFont);

			 secondHeader.setBackground(bg);
			 
			 MyHeaderLabel servicePlanHeader=new MyHeaderLabel();
			 servicePlanHeader.setText("Service Plan");
			 servicePlanHeader.setFont(headerFont);
			 servicePlanHeader.setBackground(bg);
			 
			 
			 
			 RichTextField servicePlanValue=new RichTextField(){
				 
				 public synchronized void getFocusRect(XYRect rect) {
		                rect.x=0;
		                rect.y=0;
		                super.getFocusRect(rect);
						}
			 };
			 String x=new String("Optik 2HID/1SD"+"\n"+"1 PVR,2 STB");

			 servicePlanValue.setText(x);
			 servicePlanValue.setFont(headerFont);
			 servicePlanValue.setBackground(grayBackground);
			 
			 MyHeaderLabel assigmentInfo=new MyHeaderLabel();
			 assigmentInfo.setText("Assignment Info");
			 assigmentInfo.setFont(headerFont);
			 assigmentInfo.setBackground(bg);
			 
	           
			 RichTextField assigmentInfoGray=new RichTextField(){
				 public synchronized void getFocusRect(XYRect rect) {
                rect.x=0;
                rect.y=0;
                super.getFocusRect(rect);
				}
			 };
			 String str=new String("EDTNABDS01-P1-1-1"+"\n"+"pairs 1:1,24,45:8"+"\n"+"Modem model,version"+"\n"+"#STB 3 Link:STB Info");

			 assigmentInfoGray.setText(str);
			 assigmentInfoGray.setFont(headerFont);
			 assigmentInfoGray.setBackground(grayBackground);
			 
			 MyHeaderLabel serviceQuality=new MyHeaderLabel();
			 serviceQuality.setText("Service Quality");
			 serviceQuality.setFont(headerFont);
			 serviceQuality.setBackground(bg);
			 
			 MyHeaderLabel provisionStatus=new MyHeaderLabel();
			 provisionStatus.setText("Provision Status");
			 provisionStatus.setFont(headerFont);
			 provisionStatus.setBackground(grayBackground);
			 
			 
			 
			 servicePlanHeader.setMargin(2,0,0,0);
			 servicePlanValue.setMargin(2,0,0,0);
			 assigmentInfo.setMargin(2,0,0,0);
			 assigmentInfoGray.setMargin(2,0,0,0);
			 serviceQuality.setMargin(2,0,0,0);
			 provisionStatus.setMargin(2,0,0,0);





			headerManager.setMargin(20,20,0,20);
			headerManager.add(secondHeader);
			headerManager.add(servicePlanHeader);
			headerManager.add(servicePlanValue);
			headerManager.add(assigmentInfo);
			headerManager.add(assigmentInfoGray);
			headerManager.add(serviceQuality);
			headerManager.add(provisionStatus);


			add(headerManager);


		
	}
	
}

 9700.png

Developer
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Re: Please suggest me making a view

Field.NON_FOCUSABLE

 

i got it  second solution..

first is still there

Developer
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Re: Please suggest me making a view

Please me in doing customer  information as i said how to do that.

 

Thanks

 

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

Re: Please suggest me making a view

You haven't answered my question:

"in MyLabel, you actually paint the text.  Do you paint multiple lines?"

 

One possible solution for you would be to create a Field like your headerLabel, that accepts multiple Lines.

 

Or you can stick with RichTextField and put line breaks in.  Personally that is the option I would choose.

 

So the issue is moving  the text away from the edge.  Look at setPadding to do that.  It is a bit like setMargin. 

 

In addition, I think you want to paint that text in white.  To do that, you just have to override paint().  In your replacement paint() method, set the graphics color to white and then call super.paint().  Then the RichTextField will paint the text for you in the right place in white.  Remember to use try/finally to reset the color back.  You do not want any side effects.  . 

Developer
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Re: Please suggest me making a view

Hello

i got it using padding ..I

And i am only print text not multiple line in My label.

 

You want to say that first i want to take 

a )RichTextField  field in label of phone number + its value(as a text).

again take richfield for address + its value.

again TV customer and its value.?

 

but problem is that in all case it label colour is different that of its value color .so i think it is difficult to implement that.