12-27-2012 01:30 AM
I created custom Button field in my app for Bold 9900 , and its works well, But whenever I keep the focus on the button using trackpad and Touched some where else in the screen the button field change listener is invoked. But the button change listener must be invoked only if I Touch over the button not else where . Please suggest me to fix this issue.
Here is my code:
class LoginButton extends Field {
private Bitmap _currentPicture;
private Bitmap _onPicture;
private Bitmap _offPicture;
private String name;
private int weight,size=35;
LoginButton (String _text){
super(ButtonField.HIGHLIGHT_FOCUS | ButtonField.FOCUSABLE | Field.FIELD_HCENTER);
name = _text;
_offPicture = Bitmap.getBitmapResource("submit_over.png");
_onPicture = Bitmap.getBitmapResource("submit_normal.png");
weight= _offPicture.getWidth();
_currentPicture = _onPicture;
}
public int getPreferredHeight(){
return _currentPicture.getHeight();
}
public int getPreferredWidth(){
return weight;
}
protected void onFocus(int direction){
_currentPicture = _offPicture;
invalidate();
}
protected void onUnfocus(){
_currentPicture = _onPicture;
invalidate();
}
protected void layout(int width, int height) {
setExtent(Math.min( width, getPreferredWidth()), Math.min( height, getPreferredHeight()));
}
protected void drawFocus(Graphics graphics, boolean on)
{
if (on)
{
//Get the field size that is available from its manager.
XYRect rect = this.getManager().getContentRect();
graphics.setGlobalAlpha(50);
}
}
protected void paint(Graphics graphics) {
graphics.setColor(0x04D5B21);
graphics.drawBitmap((getWidth() - _currentPicture.getWidth())/2, (getHeight() - _currentPicture.getHeight())/2, getWidth(), getHeight(), _currentPicture, 0, 0);
FontFamily fontFamily[] = FontFamily.getFontFamilies();
this.setFont(fontFamily[0].getFont(FontFamily.SCAL ABLE_FONT,size).derive(Font.STYLE_BOLD, size,Ui.UNITS_px));
graphics.drawText(name,(_currentPicture.getWidth() - getFont().getAdvance(name)) / 2, (_currentPicture.getHeight() - fontFamily[0].getFont(FontFamily.SCALABLE_FONT,16) .getHeight()) / 3);
}
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);
return true;
}
public boolean trackwheelClick(int status,int time){
fieldChangeNotify(1);
return true;
}
public boolean trackwheelUnclick(int status, int time) {
return false;
}
public boolean keyChar(char key, int status, int time) {
boolean retval = false;
switch (key) {
case Characters.ENTER:
fieldChangeNotify(1);
retval = true;
break;
default:
retval = super.keyChar(key,status,time);
}
return retval;
}
public boolean keyDown(int keycode, int time) {
return false;
}
public boolean keyRepeat(int keycode, int time) {
return false;
}
public boolean keyStatus(int keycode, int time) {
return false;
}
public boolean keyUp(int keycode, int time) {
return false;
}
}
Solved! Go to Solution.
12-27-2012 06:02 AM
I think add your button in the verticalFieldmanager and add that manager in other manager.
Make your verticlefieldmanager focusable.
Regards,
12-27-2012 06:34 AM
Thank you for the suggestion, I did like this.
HomeContentManager MainContent = new MainContent();
HorizontalFieldManager Subtitle_Row = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
Subtitle_Row.add(new EmptyField(1,5));
LoginButton AddProfile=new LoginButton("Add Profile");
AddProfile.setCookie("profile");
AddProfile.setChangeListener(addProfileListener);
Subtitle_Row.add(AddProfile);
LoginButton NewBtn =new LoginButton("Add+");
NewBtn.setCookie("add");
NewBtn.setChangeListener(addProfileListener);
Subtitle_Row.add(new EmptyField(1,5));
Subtitle_Row.add(NewBtn);
MainContent.add(Subtitle_Row);And My MainContent manager is the Common vertical field manager for all classes.
final class HomeContentManager extends VerticalFieldManager {
HomeContentManager() {
super(Field.FIELD_HCENTER | Field.USE_ALL_WIDTH); this.setBackground(BackgroundFactory.createBitmapB ackground(Bitmap.getBitmapResource(Globals.HomeScr eenBackground)));
}
public void paint(Graphics graphics) {
//graphics.setBackgroundColor(Color.BLACK);
super.paint(graphics);
}
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
}Now I made focusable for Subtitle_Row Manager but its not working. Also in all of others screens i face this issue. But its working in Trackpad devices(Since Trackpad devices doesn't have Touch Event)
12-27-2012 06:39 AM
Just try to make "Subtitle_Row" field VerticleFieldmanager.
Then check it.
Regards,
12-27-2012 06:47 AM
I changed like this,
VerticalFieldManager Subtitle_Row=new VerticalFieldManager(VerticalFieldManager.FOCUSABL
But no use whenever i kept focus over the button using Trackpad and Tocuhed the bottom of the screen the Addprofile Button listener is invoked.
12-27-2012 06:59 AM
Hi,
Put this in your maincontent manager.
protected void sublayout(int width, int height) {
setExtent(width, width);
super.sublayout(width, height);
}
12-27-2012 07:30 AM
Hi milanvishal,
I already implemented the sublayout for Maincontent manager with display width and height. Now i replaced as like your suggestion, but no use.
12-27-2012 07:34 AM
ohhhhhhhhh,
So I think now issue is in your CustomButtonField.
Let me check it.
If I got any solution I will reply you back.
Regards,
12-27-2012 07:37 AM
12-27-2012 07:43 AM