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
Highlighted
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon
Accepted Solution

Clickable Manager

I ended up needing to work on an odd-ball Manager. Basically, I want a Manager that can take Fields and Managers (as it already can), lay them out, and pain them.

 

But, I don't want any of the fields to get focus, be clickable, and for the manager itself to be the one to get focus and to be highlighted.

 

Currently I have a basic extended HorizontalFieldManager with a slightly modified paint function and with some overridden interaction functions that hopefully will allow me to make the class "clickable".

 

Unfortunately focus always goes into the fields contained by the manager. I am not very good at any GUI work and have yet to figure out what functions I should override to keep focus on the Manager and not the Fields within it.

 

Any ideas?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Clickable Manager

There is a nice little gadget which should help you - NullField. It is invisible, takes no room on the screen,  but can be focusable (and is focusable by default). Add such field to your Manager, listen on the focus on it and react accordingly.

 

I've done it many times with great success.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Clickable Manager

I think there is a further trick -  make all the Fields in the Manager non focusable.  Except the NullField that will get focus.  Have your Manager listen for focusEvents on that NullField, and have it 'paint' appropriately.  .

Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Clickable Manager

Sounds perfect. Simulator starting up...

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Clickable Manager

[ Edited ]

Focus now works perfectly.

 

But my click functions are, non-functional. Any ideas? Or any other comments for that manner.

 

I posted the code I have:

private static class SelectField extends HorizontalFieldManager implements FocusChangeListener
{
	private boolean click;
	
	public SelectField()
	{
		this(0);
	}
	
	public SelectField(long style)
	{
		super(style);
		
		NullField field = new NullField();
		field.setFocusListener(this);
		add(field);
	}
	
	protected void paint(Graphics graphics)
	{
		if(this.getField(0).isFocus())
		{
			int tc = graphics.getColor();
			graphics.setColor(Color.RED);
			graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
			graphics.setColor(tc);
		}
		super.paint(graphics);
	}
	
	public void focusChanged(Field field, int eventType)
	{
		if(eventType == FocusChangeListener.FOCUS_LOST)
		{
			click = false;
		}
		invalidate();
	}
	
	protected boolean navigationClick(int status, int time)
	{
		if(this.getField(0).isFocus())
		{
			click = true;
			return true;
		}
		return super.navigationClick(status, time);
	}
	
	protected boolean navigationUnclick(int status, int time)
	{
		if(this.getField(0).isFocus() && click)
		{
			click = false;
			invokeAction(0);
			return true;
		}
		return super.navigationUnclick(status, time);
	}
	
	protected boolean trackwheelClick(int status, int time)
	{
		if(this.getField(0).isFocus())
		{
			click = true;
			return true;
		}
		return super.trackwheelClick(status, time);
	}
	
	protected boolean trackwheelUnclick(int status, int time)
	{
		if(this.getField(0).isFocus() && click)
		{
			click = false;
			invokeAction(0);
			return true;
		}
		return super.trackwheelUnclick(status, time);
	}
	
	protected boolean touchEvent(TouchEvent message)
	{
		switch(message.getEvent())
		{
			case TouchEvent.CLICK:
				invokeAction(0);
				break;
		}
		return super.touchEvent(message);
	}
}

 Note: The red color is solely for debugging purposes. I'll replace with a better color later.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Clickable Manager

I ended up creating a different field and not really using this (I used it in a different manner then what I was planning). So I don't need the input stuff to make it clickable.

Thanks @arkadyz and @peter
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.