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
Contributor
june_misuki
Posts: 27
Registered: ‎06-19-2012
My Device: Developer
My Carrier: None

Re: Vertical Scrolling very slow for Table

Well i paint the whole selected row a different color, so paint has to be overridden. 

 

Can you tell me how i can actually use the context region to figure out visible fields?

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

Re: Vertical Scrolling very slow for Table

Sorry I have never actually done this, I have just looked at the API and thought that is how I would do it.

 

Given this I think I might wait a bit and see of someone else with more experience chips in before I send you off on the wrong direction. 

 

But I don't understand why painting the selected row requires overriding paint().  I would have though that would be something you did in focus processing.  Can you explain this? 

Please use plain text.
Contributor
june_misuki
Posts: 27
Registered: ‎06-19-2012
My Device: Developer
My Carrier: None

Re: Vertical Scrolling very slow for Table

I iterate over all the field in a loop. If the field is in the same row, paint it a certain way or else paint another way.

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

Re: Vertical Scrolling very slow for Table

[ Edited ]

I understand what you are trying to do, the question I am asking is why do you have to do this in paint() for the Manager?

 

Typically my Fields have a number of states, and each Field paints itself according to that state.  Focused and unfocused are obvious states, but 'selected' is another state I commonly use.  So the option here is to have some sort of focus listener and when focus changes, change the state if the Fields and invalidate() them if the state has changed.  Though I have never tested this, I suspect only those Fields that are actually on display will be repainted which makes this much more efficient.  And if you listen for unFocus and focus, then you will only repaint Fields in the two rows that change - and in fact when someone scrolls right or left, you won't do anything. 

 

That said, I am wondering if perhaps it would be better to review the code involved.

 

Have you used the profiler and determined that the at the time the scrolling slows down, the heavy processing is being done in paint()? 

Please use plain text.
Contributor
june_misuki
Posts: 27
Registered: ‎06-19-2012
My Device: Developer
My Carrier: None

Re: Vertical Scrolling very slow for Table

About the profiler, i dont think i will be able to use it anytime soon. My eclipse has never been able to debug. I always get the timeout exception when the debugger tries to attach. So after trying all i could think of, i have given up on that.

 

My requirement wants me to paint the focused field a different color than the defult blue. Setting the state of the field as focused will not give me the option to change the focus color. 

 

The following are the operations for every field i perform inside the loop. Depending on position of the field,

i change the colors.

 

graphics.setColor(Color.BLACK);
graphics.drawRect(f.getContentLeft() - 1,f.getContentTop() - 1, f.getWidth() + 1,f.getContentHeight() + 1);

graphics.setColor(Color.WHITE);
graphics.fillRect(f.getContentLeft(),f.getContentTop(), f.getContentWidth() - 1,f.getContentHeight() - 1);

graphics.setColor(Color.BLACK);

graphics.drawText(f.getText(),f.getContentLeft()+ (f.getContentWidth() / 2)
- Font.getDefault().getAdvance(f.getText()) / 2,
								f.getContentTop() + (f.getContentHeight() / 2),
								Graphics.VCENTER | Graphics.HCENTER);

 So, as you can see iam drawing a rectangle around each field. Also painting this way lets me center the text  dynamically.

 

Basically, what iam saying is doing it like this gives me more options to paint rather than working with just 3 states:

Selected, focused and unfocused.

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

Re: Vertical Scrolling very slow for Table

So this code is in your Manager?

 

Yes if you do this for every paint, you are going to run into problems when the number of rows and columns increases. 

 

Can you please post a class that is similar to the class you use for each Field.  I don't need the detail, I just want to show you how you can show the various states in the Field. 

 

You appear to have a number of states that you wish to indicate.  Focused and unfocused are two obvious ones.  But they only apply to a cell (Field).  You also seem to have a 'Row selected' state, which uses some different indications.  Can you summarize the states and the indications for me.

 

Re

"I always get the timeout exception when the debugger tries to attach"

I do too, with some Simulators,  But not typically with ones I have downloaded.  SO change your configuration to use a downloaded Simulator and you might be able to get away with doing this. 

Please use plain text.
Contributor
june_misuki
Posts: 27
Registered: ‎06-19-2012
My Device: Developer
My Carrier: None

Re: Vertical Scrolling very slow for Table

Yes thats the code in the table paint method. 

 

About the timeout exception, I have tried both with the existing and downloaded simulators and had no luck.

 

The class i use for every field is just a focusable labelfield (a class that extends Labelfield). If the text of the labelfield matches a certain predifined text, then i perform certain operations in navigation click. Otherwise the click is consumed with no action taken. 

 

Suppose, i have 4 rows and 3 col.

 

Then let the table fiels be f11, f12, f13,  f21, f22, f23, f31.................f43.

 

Now suppose f11 has focus, i paint it say a color c1 with text color t1. Additionally, i paint f12 and f13 color c2 and text color t2. All other fields have default white background with black text.

 

Now if f12 gets focus, It is painted with c1 and t1 colors. f11 and f13 are painted c2 and t2.

 

So basically in my table manager paint i iterate through all fields. Find if it is focused or belongs to the same row and paint accordingly.

 

By the way , i have not overridden the paint, onfocus or unfocus methods of the individual fields.


public class ExtendedLabelDynamicListener extends LabelField {

	public boolean focus1 = false;
	public String age_bucket;
	private int row_no;

	public ExtendedLabelDynamicListener() {
		super();
	}

	public ExtendedLabelDynamicListener(String string, String ab,int rw, long style) {

		super(string, style);
		age_bucket = ab;
		row_no=rw;

	}

	public ExtendedLabelDynamicListener(String string) {

		super(string);

	}

	protected boolean navigationClick(int status, int time) {

		this.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field arg0, int arg1) {
				
				try{
				if(!age_bucket.equalsIgnoreCase("NA")&& !getText().equalsIgnoreCase("-"))
					
				{	LoginScreen.sql_details.readInvoiceData(String.valueOf(row_no), age_bucket);
			
				UiApplication.getUiApplication().pushScreen(
						new InvoiceNoList(SQLManager_Details.inv_no));
				}

				}catch(Exception e){Dialog.alert(e.getMessage());}
				

			}
		});

		fieldChangeNotify(0);

		return true;

	}

	protected void fieldChangeNotify(int context) {

		if (context == 0) {

			try {

				this.getChangeListener().fieldChanged(this, context);
				this.setChangeListener(null);

			} catch (Exception e) {
			}

		}

	}

	protected void layout(int width, int height) {
		super.layout(width, Display.getHeight() / 13);
		setExtent(width, Display.getHeight() / 13);
	}
	public void invalidate(){
		super.invalidate();
	}

}

 

 

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

Re: Vertical Scrolling very slow for Table

Good explanation.

 

I think doing the painting in the Fields and only repainting the changed Fields will solve your problem.  And for me it is a better solution. 

 

Creating sample code will take a bit of time however, I expect to have something back to you within 24 hours, and should be quicker.  But can you wait?

 

You could alternatively investigate the Graphics

getAbsoluteClippingRect(), or

getClippingRect()

and see if you can use these to limit the Fields you paint. 

Please use plain text.
Contributor
june_misuki
Posts: 27
Registered: ‎06-19-2012
My Device: Developer
My Carrier: None

Re: Vertical Scrolling very slow for Table

[ Edited ]

:Yes: Yeah that would be swell. Thanks a lot. I will start looking in to getClippingRect right away. But if i know right, getFocusRect is the only method that returns Coordinates in terms of the visible screen. So iam not sure if getClippingRect would work.  Anyways, i will check out.

 

Please use plain text.
Contributor
june_misuki
Posts: 27
Registered: ‎06-19-2012
My Device: Developer
My Carrier: None

Re: Vertical Scrolling very slow for Table

I used GetClippingRect and the scrolling speed improved. But if there is a way, i would like it to be still better.

Please use plain text.