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
khalidhabib
Posts: 16
Registered: ‎01-22-2013
My Device: Blackberry9800
My Carrier: JAZZ
Accepted Solution

paint method slow down typing speed

Hi,I am using CustomEditField in which i over ride paint method. Every thing is fine, but the problem which i am facing is that my typing in textfield slows down. I debug it many times and found that,it is because of paint method..Please any one give me suggestions for that..

 

 

-----------------------------------------------------------------xxxxxxxxxx------------------------------------------------------------------------

class CustomEditField extends EditField
{
private boolean _focusableFlag;
private String defaultText;

public CustomEditField(String defaultText)
{
super(FIELD_HCENTER);
this.defaultText = defaultText;


public void setFocusable(boolean focusable){
_focusableFlag =focusable;
}

protected void layout(int width, int height)
{
width = Font.getDefault().derive(Font.BOLD, Font.getDefault().getHeight()-2).getAdvance("Transfer to my Linked Account")+40;
height = Font.getDefault().getHeight();
super.layout(width,height);
super.setExtent(width,height);
super.setFilter(MyTextFilter.get(TextFilter.NUMERIC));
}
protected void paint(Graphics g)
{
setBorder(BorderFactory.createRoundedBorder(new XYEdges(5,5,5,5), 0xD0D0D0, Border.STYLE_SOLID));
setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));

if(super.getText().length() == 0)
{
g.setColor(0xD0D0D0);
g.drawText(defaultText, 0, 0);
g.clear();
}

g.setColor(0x484C54);
super.paint(g);

}



}

Please use plain text.
Developer
simon_hain
Posts: 15,791
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: paint method slow down typing speed

call setBorder and setBackground outside of the paint method
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
khalidhabib
Posts: 16
Registered: ‎01-22-2013
My Device: Blackberry9800
My Carrier: JAZZ

Re: paint method slow down typing speed

Thanx simon for your kind help,it works in my CustomEditField.. Now i have another issue,on the same screen there is header which contains 2 Fields i.e Label field and ImageButtonField.. They both have 2 paint methods.. I am confused,b/c i am not able to put my setBackground and setBorder outside the paint methods...Please help me out there...

---------------------------------------------------LockedHeaderHorizontalManager----------------------------------------------

 

public LockedHeaderHorizontalManager(String label)
{
super(Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | USE_ALL_WIDTH | USE_ALL_HEIGHT);


ButtonField bf = new ButtonField(ButtonField.CONSUME_CLICK)
{          //------Start Of Button Field
boolean _inFocus = false;

protected void layout(int width, int height)
{
super.layout(80,50);
super.setExtent(80,50);
}

public void onFocus(int direction)
{
_inFocus = true;
this.invalidate();
}

public void onUnfocus()
{
_inFocus = false;
this.invalidate();
}

protected void paint(Graphics graphics)
{
graphics.setGlobalAlpha(0);
setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
graphics.setGlobalAlpha(255);
super.setBorder(BorderFactory.createSimpleBorder(new XYEdges(0,0,0,0)));

if(_inFocus)
{ graphics.drawBitmap(15,0,getWidth(),getHeight(),Bitmap.getBitmapResource("homeon.png"),0,0);

}
else
{
graphics.drawBitmap(15,0,getWidth(),getHeight(),Bitmap.getBitmapResource("homeoff.png"),0,0);
}
}


protected void drawFocus(Graphics g, boolean on)
{
}

protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(0);

return false;

}

};

bf.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field,int context)
{
// ((ButtonField)field).setEnabled(false);
}
});


add(bf);

LabelField lf = new LabelField(label, DrawStyle.HCENTER | USE_ALL_WIDTH)
{             //------Start Of Label Field
protected void layout(int width, int height)
{
super.layout(Display.getWidth()-160, height);
setExtent(Display.getWidth()-160, height);
}

protected void paint(Graphics g)
{

synchronized (UiApplication.getEventLock()){
g.setGlobalAlpha(0);
setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
g.setColor(0xA7A7A7);
g.setGlobalAlpha(255);

}
super.paint(g);
}
};

lf.setBorder(BorderFactory.createSimpleBorder(new XYEdges(0,1,0,1), new XYEdges(0,0xA7A7A7,0,0xA7A7A7), Border.STYLE_SOLID));
lf.setFont(Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight()-2));
if(lf.getFont().getAdvance(label)>Display.getWidth()-160)
{
lf.setPadding((50-lf.getPreferredHeight()*2)/2,0,0,0);
}
else
{
lf.setPadding((50-lf.getPreferredHeight())/2,0,0,0);
}

add(lf);
}             //-----End Of Label Field

protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout( Display.getWidth(), 50);
setExtent( Display.getWidth(), 50);
}

public void paintBackground(Graphics graphics)
{
graphics.setBackgroundColor(0x353535);
graphics.clear();
graphics.drawBitmap(Display.getWidth()-Bitmap.getBitmapResource("headerlogo.png").getWidth(), 0, Bitmap.getBitmapResource("headerlogo.png").getWidth(),Bitmap.getBitmapResource("headerlogo.png").getHeight(),Bitmap.getBitmapResource("headerlogo.png"),0,0);
super.paintBackground(graphics);
}
}

 

Please use plain text.
Developer
simon_hain
Posts: 15,791
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: paint method slow down typing speed

please keep one thread for one question, it would be better to create a new one for a new question.

without going too much into detail: the paint method basically controls how the component is drawn onto the screen, it is the lowest level.
if you call higher level methods, like setBackground, they could trigger a paint call themselves and lead to an unwanted recursive call.

if you want to do it all yourself, with paintBackground and paint: Do that.
You can also combine it with the higher level methods like setBackground, but don't call them from within the low level methods.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.