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

TextFilter performance issue..

Hi, i am using textFielter in my CustomEditField in my login Page of my application. TextFilter.Interger is working well but the problem is that, it slows down the typing speed in my editField.. I am also posting my codes for my customTextFilter,LoginPage and CustomEdit Field.. Kindly give me solution and suggestions for that..

----------------------------------------------LoginPage---------------------------------------------------------

package mypackage;

import java.util.Date;

import net.rim.device.api.lowmemory.LowMemoryListener;
import net.rim.device.api.lowmemory.LowMemoryManager;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.text.TextFilter;

/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public class AgAppLoginPage extends MainScreen implements FieldChangeListener// , LowMemoryListener
{

private CustomEditField txtMobileNumber;
private EditField editField;
private CustomPasswordEditField txtPinNumber;
private CustomButtonField btnLogin;
private static String stxtMobileNumber;
private static String stxtPinNumber;


public AgAppLoginPage()
{

VerticalFieldManager vertMgr = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | USE_ALL_WIDTH | USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight)
{

super.sublayout( Display.getWidth(), Display.getHeight());
setExtent( Display.getWidth(), Display.getHeight());

}

};

LockedHeaderHorizontalManager HorMgr = new LockedHeaderHorizontalManager("LoginPage");

vertMgr.add(HorMgr);

CustomLabelField lblTop = new CustomLabelField("Sign In", Font.getDefault().getHeight()+10, Field.FIELD_HCENTER | DrawStyle.LEFT);
txtMobileNumber = new CustomEditField("Mobile Number");
txtPinNumber = new CustomPasswordEditField("PIN");
editField = new EditField("MyTextFilterEditField","");
btnLogin = new CustomButtonField("Log In", "Large","login.png");

lblTop.setMargin(5,0,0,0);
vertMgr.add(lblTop);

txtMobileNumber.setMargin(5,0,0,0);
vertMgr.add(txtMobileNumber);

txtPinNumber.setMargin(5,0,0,0);
vertMgr.add(txtPinNumber);

vertMgr.add(editField);
btnLogin.setMargin(5,0,0,0);
btnLogin.setChangeListener(this);
vertMgr.add(btnLogin);
add(vertMgr);
//this.add
}

public void close()
{
if(Dialog.ask(4, "Do You Really Want To Leave MCB-Lite") == Dialog.OK)
System.exit(0);
}

public void fieldChanged(Field field, int context)
{
if(field == btnLogin)
{
if (txtMobileNumber.getTextLength() == 0 || txtPinNumber.getTextLength() == 0)
{
Dialog.alert("Please Enter Complete Information!");
}
else
{
stxtMobileNumber= txtMobileNumber.getText();
txtMobileNumber.setFilter(MyTextFilter.get(TextFilter.NUMERIC));
editField.setFilter(MyTextFilter.get(TextFilter.NUMERIC));
stxtPinNumber = txtPinNumber.getText();
processRequestAndWait getResponse = new processRequestAndWait();
AgAppPleaseWaitScreen.showScreenAndWait(getResponse);
// txtPinNumber = null;

}
}

}

static class processRequestAndWait implements Runnable
{

public void run()
{
final String[][] xmlResponse;

if(AgAppHelperMethods.agAppConnection.compareTo("SMS")!=0)
{
//xmlResponse = AgAppHelperMethods.AgAppXMLParser("AG_IT_App/AgMainServlet?messageType=LOG&pin=" + AgAppHelperMethods.getPIN(stxtPinNumber) + "&mobile=" + stxtMobileNumber + "&source=" + stxtMobileNumber + "&channel=INTERNET;deviceside=true");
xmlResponse=AgAppHelperMethods.AgAppXMLResponse(XMLResponse.login());
}
else
{
AgAppHelperMethods.msg = "AGLOG"+stxtMobileNumber+stxtMobileNumber+AgAppHelperMethods.getPIN(stxtPinNumber);
xmlResponse = AgAppHelperMethods.AgAppSMSParser();
}

UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
if(xmlResponse[0][0].compareTo("null")==0)
{
UiApplication.getUiApplication().pushScreen(new AgAppResponseScreen("Login Screen","Host Not Responding",Font.getDefault().getHeight()));
}
if(xmlResponse[1][1].compareTo("00")==0)
{
TimeCalculator.timeStart = new Date();
TimeCalculator.timeEnd = new Date();

AgAppHelperMethods.varName=xmlResponse[3][1];
AgAppHelperMethods.varBalance=xmlResponse[4][1];
AgAppHelperMethods.varMobileNo=stxtMobileNumber;
UiApplication.getUiApplication().pushScreen(new AgAppHomePage());

}
else
{
UiApplication.getUiApplication().pushScreen(new AgAppResponseScreen("Login Screen",AgAppHelperMethods.getStatus(xmlResponse[1][1]),Font.getDefault().getHeight()));
}
}
});
}

}

 

}

 ----------------------------------------------------CustomEditField----------------------------------------------------------

package mypackage;

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.XYEdges;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
import net.rim.device.api.ui.text.TextFilter;

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.setColor(0x484C54);
super.paint(g);

}



}

 ----------------------------------------------------------MyTextFilter---------------------------------------------------

package mypackage;

import net.rim.device.api.ui.text.TextFilter;
import net.rim.device.api.util.CharacterUtilities;

public class MyTextFilter extends TextFilter {

public char convert(char character, int status) {
// TODO Auto-generated method stub
if (!validate(character))
{
return 0;
}
return character;
}

public boolean validate(char character) {
// TODO Auto-generated method stub

if (CharacterUtilities.isDigit(character))
return true;
else if (CharacterUtilities.isLetter(character))
{
if ((character == 'd') || (character == 'D'))
{
return true;
}
}
return false;
}
}

Developer
Posts: 16,679
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: TextFilter performance issue..

its a bit difficult to dig through this wall of code, please use the code tags next time.

i don't think the textfilter slows down your app, i think you execute things on the UI thread that don't belong there.
Move blocking operations to a separate thread, you can use a callback pattern, for example.
see
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865
----------------------------------------------------------
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
Contributor
Posts: 16
Registered: ‎01-22-2013
My Device: Blackberry9800
My Carrier: JAZZ

Re: TextFilter performance issue..

Thans for your reply...Would you like to tell me please that, how to use event dispatcher for multiple screens in blackberry.. I mean that is it posible that in my every new screen i use event Dispatcher for updating my UI.. Please give me a sample code for this...

Thanks..

Developer
Posts: 16,679
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: TextFilter performance issue..

i don't understand your question, maybe you mean something different when you use "event dispatcher" than i do.
Maybe you can use a new thread for your follow up question as this one is resolved.
----------------------------------------------------------
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