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
New Developer
Posts: 7
Registered: ‎10-08-2009
My Device: Not Specified

Focus Issue

I have a vertical field manager and inside this manager I have a table layout that contain bitmap fields.  A bitmap field has focus.  Underneath the vertical field manager I have a horizontal field manager containing buttons.  When a button is touched/clicked, the button gets the focus and the bitmap field loses focus.  Is there something that can be done to avoid the bitmap field from losing focus and just respond to the button click and not give the button focus. 

 

If you look at the media manager in the blackberry storm, when you select a thumbnail and click a button at the bottom, the thumbnail still retains focus.  I want the same behaviour with my app.

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Focus Issue

Only One field will be having focus at a time. Work around you can try like drawing a line around the selected thumbnail Image when the user clicks on the Button.


Use Search. "Accept Solution" If the problem is resolved.
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Focus Issue

anybody knows how to solve this issue?

 

plz reply with some reference code or something....

Swapnil G.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Focus Issue

Can you try using Field.setVisualState(Field.VISUAL_STATE_FOCUS) of your Bitmap in your Button's onFocus() and see if it helps?


----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Focus Issue

public class PackageInfoTabScreen extends MainScreen implements
		FocusChangeListener,FieldChangeListener
{
	private Bitmap _navbar, _background, _searchbar, _searchbarwhite,_pkgtabscreenshipinfo, _pkgtabscreenbg, _pkgtabscreenbtnh,_pkgtabscreenbtnn, _pkgtabscreenmapbtnn,_pkgtabscreenmapbtnh;

private Bitmap ltab_off;
private Bitmap ltab_on;
private Bitmap rtab_off;
private Bitmap rtab_on;
private Bitmap bg, cell;

	private BitmapField _trackingNumber;
	private BitmapField _shiptoInfo;

	private HorizontalFieldManager hfm1;
	private HorizontalFieldManager hfm2;
	private HorizontalFieldManager hfm3;
	private VerticalFieldManager vfm;

	private HorizontalFieldManager hManager;

	private VerticalFieldManager tab1Manager;
	private VerticalFieldManager tab2Manager;
	private VerticalFieldManager tabArea;
	
	private BitmapField _trackShipment;
	private BitmapField _googleMap;

	public PackageInfoTabScreen()
	{
		super(NO_VERTICAL_SCROLL);
		
		LoadImages();

		// code of the forum
		_trackingNumber = new BitmapField(ltab_on, BitmapField.FOCUSABLE
				/*| BitmapField.FIELD_RIGHT | BitmapField.FIELD_VCENTER*/) {
			private boolean hasFocus;

			protected void layout(int maxWidth, int maxHeight)
			{
				super.layout(ltab_on.getWidth() + 2, ltab_on.getHeight());
				setExtent(ltab_on.getWidth() + 2, ltab_on.getHeight());
			}

			public void onFocus(int direction)
			{
				invalidate();
				setBitmap(ltab_on);
				hasFocus = true;
				// super.onFocus(direction);
			}

			public void onUnfocus()
			{
				hasFocus = false;
				invalidate();
				super.onUnfocus();
				setBitmap(ltab_off);
			}

			protected void paint(Graphics g)
			{
				super.paint(g);
				if (hasFocus)
				{
					g.drawText(_heading, x, y1);
				} else
				{
					g.setColor(Color.WHITE);
					g.drawText(_heading, x, y1);
				}
			}
		};

		_shiptoInfo = new BitmapField(rtab_on, BitmapField.FOCUSABLE
				/*| BitmapField.FIELD_RIGHT | BitmapField.FIELD_VCENTER*/) {
			private boolean hasFocus;

			protected void layout(int maxWidth, int maxHeight)
			{
				super.layout(rtab_on.getWidth() + 2, rtab_on.getHeight());
				setExtent(rtab_on.getWidth() + 2, rtab_on.getHeight());
			}

			public void onFocus(int direction)
			{
				invalidate();
				setBitmap(rtab_on);
				hasFocus = true;
				// super.onFocus(direction);
			}

			public void onUnfocus()
			{
				hasFocus = false;
				invalidate();
				super.onUnfocus();
				setBitmap(rtab_off);
			}

			protected void paint(Graphics g)
			{
				super.paint(g);				

				if (hasFocus)
				{
					g.drawText(asdf, x, y1);
				} else
				{
					g.setColor(Color.WHITE);
					g.drawText(asdf, x, y1);
				}
			}

			protected void invalidate()
			{
				super.invalidate();
			}
		};

		_trackingNumber.setFocusListener(this);
		_shiptoInfo.setFocusListener(this);


		hfm2 = new HorizontalFieldManager(NO_VERTICAL_SCROLL);
		hfm3 = new HorizontalFieldManager(NO_VERTICAL_SCROLL);

		vfm = new VerticalFieldManager(NO_VERTICAL_SCROLL) 
		{
			protected void paintBackground(Graphics arg0)
			{
				arg0.drawBitmap(0, 0, _background.getWidth(), _background
						.getHeight(), _background, 0, 0);
				super.paintBackground(arg0);
			}

			public void invalidate()
			{
				super.invalidate();
			}

			public void add(Field field)
			{
				super.add(field);
			}

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

		tab1Manager = new VerticalFieldManager(NO_VERTICAL_SCROLL) 
		{
			protected void paint(Graphics graphics)
			{				
				super.paint(graphics);
			}

			protected void sublayout(int maxWidth, int maxHeight)
			{
				Field field;
				
				int count = getFieldCount();
				
				for (int i = 0; i < count; i++)
				{				
					field = getField(i);
					
					switch (i)
					{
					//	track shipment bitmap field
					case 0:
						layoutChild(_trackShipment, _trackShipment.getWidth(), _trackShipment.getHeight());
						setPositionChild(_trackShipment, 10, 310);
						break;
					
					default:				
						break;
					}			
				}
				setExtent(360, 379);
			}

			public void invalidate()
			{
				super.invalidate();
			}
		};

		tab2Manager = new VerticalFieldManager(NO_VERTICAL_SCROLL) {
			protected void paint(Graphics graphics)
			{
				graphics.drawBitmap(0, 0, _pkgtabscreenshipinfo.getWidth(),
						_pkgtabscreenshipinfo.getHeight(),
						_pkgtabscreenshipinfo, 0, 0);
				super.paint(graphics);
				

				graphics.setFont(getFont().derive(Font.PLAIN, 7, Ui.UNITS_pt));
				graphics.setColor(Color.BLACK);
				
				graphics.drawText("Name", 20, 12);
				graphics.drawText("Address", 20, 38);
				graphics.drawText("City", 20, 64);
				graphics.drawText("State", 20, 90);
				graphics.drawText("Zip", 20, 116);
				
				graphics.setColor(0x003399);
				int y = 12;
				for (int i = 0; i < 5; i++)
				{					
					graphics.drawText(":", 180, y);
					y = y+26;
				}
			}

			protected void sublayout(int maxWidth, int maxHeight)
			{				
				Field field;
				int count = getFieldCount();
				for (int i = 0; i < count; i++)
				{				
					field = getField(i);
					
					switch (i)
					{
					//	track shipment bitmap field
					case 0:
						layoutChild(_googleMap, _googleMap.getWidth(), _googleMap.getHeight());
						setPositionChild(_googleMap, 10, 200);
						break;
					
					default:				
						break;
					}			
				}
				setExtent(360, 450);
			}

			public void invalidate()
			{
				super.invalidate();
			}

			protected void onFocus(int direction)
			{
				super.onFocus(direction);
			}
		};

		//track shipment button
		_trackShipment = new BitmapField(_pkgtabscreenbtnn, BitmapField.FOCUSABLE
				| BitmapField.FIELD_RIGHT | BitmapField.FIELD_VCENTER) 
		{
			private boolean hasFocus;

			protected void layout(int maxWidth, int maxHeight)
			{
				super.layout(_pkgtabscreenbtnh.getWidth() + 2, _pkgtabscreenbtnh.getHeight());
				setExtent(_pkgtabscreenbtnh.getWidth() + 2, _pkgtabscreenbtnh.getHeight());
			}

			public void onFocus(int direction)
			{
				invalidate();
				setBitmap(_pkgtabscreenbtnh);
				hasFocus = true;
				this.setVisualState(VISUAL_STATE_FOCUS);
				// super.onFocus(direction);
			}

			public void onUnfocus()
			{
				hasFocus = false;
				invalidate();
				super.onUnfocus();
				setBitmap(_pkgtabscreenbtnn);
			}

			protected void paint(Graphics g)
			{
				super.paint(g);
				g.setFont(getFont().derive(Font.BOLD));
				g.setColor(0x003399);
				g.drawText("Track Shipment", 80, 25);
				
				if(hasFocus)
					g.drawLine(0, 0, 0, 0);
			}

			protected void invalidate()
			{
				super.invalidate();
			}
		};
		
		
		_trackShipment.setChangeListener(this);
		//Google Map Button
		_googleMap = new BitmapField(_pkgtabscreenmapbtnn, BitmapField.FOCUSABLE
				| BitmapField.FIELD_RIGHT | BitmapField.FIELD_VCENTER) 
		{
			private boolean hasFocus;

			protected void layout(int maxWidth, int maxHeight)
			{
				super.layout(_pkgtabscreenmapbtnh.getWidth() + 2, _pkgtabscreenmapbtnh.getHeight());
				setExtent(_pkgtabscreenmapbtnh.getWidth() + 2, _pkgtabscreenmapbtnh.getHeight());
			}

			public void onFocus(int direction)
			{
				invalidate();
				setBitmap(_pkgtabscreenmapbtnh);
				hasFocus = true;
				// super.onFocus(direction);
			}

			public void onUnfocus()
			{
				hasFocus = false;
				invalidate();
				super.onUnfocus();
				setBitmap(_pkgtabscreenmapbtnn);
			}

			protected void paint(Graphics g)
			{
				super.paint(g);
				g.setFont(getFont().derive(Font.BOLD));
				g.setColor(0x003399);
				if(hasFocus)
					g.setColor(0x003399);
				else
					g.setColor(Color.WHITE);
				
				g.drawText("Google Map", 30, 25);
			}

			protected void invalidate()
			{
				super.invalidate();
			}
		};
		
		tab1Manager.add(_trackShipment);
		tab2Manager.add(_googleMap);
		
		tabArea = displayTab1();
		hManager = new HorizontalFieldManager();

		hManager.add(_trackingNumber);
		hManager.add(_shiptoInfo);

		hfm2.add(hManager);
		hfm3.add(tabArea);

		vfm.add(hfm2);
		vfm.add(hfm3);

		this.add(vfm);
	}

	private VerticalFieldManager displayTab1()
	{
		return tab1Manager;
	}

	private VerticalFieldManager displayTab2()
	{
		return tab2Manager;
	}

	private void LoadImages()
	{
		Loads the bitmaps…..
	}

	public void focusChanged(Field field, int eventType)
	{
		if (tabArea != null)
		{
			if (eventType == FOCUS_GAINED)
			{
				if (field == _trackingNumber)
				{
					System.out.println("Switch to Tab 1");
					hfm3.delete(tabArea);
					tabArea = displayTab1();
					hfm3.add(tabArea);
					vfm.invalidate();
				} else if (field == _shiptoInfo)
				{
					System.out.println("Switch to Tab 2");
					System.out.println("Switch to Tab 1");
					hfm3.delete(tabArea);
					tabArea = displayTab2();
					tabArea.invalidate();
					hfm3.add(tabArea);
					vfm.invalidate();
				} else if (field == _trackShipment)
				{
					Dialog.alert("Focus Changed Track Shipment");					}
			}
		}
	}
}

 

here is my code in simple terms my prolbem is

in "hmanager" i have added two bitmaps like the tab screen.

in tab1manager and tab2manager i change the according values of it.

 

 

when bitmap1 is selected the tab1manager is active and when bitmap2 is selected the tab2manager is active. on tab1manager i have also added one bitmap3 button. when the focus goes on that button the focus goes off from bitmap1. like they both gets the disabled state.

i want is the selected state of bitmap1 should also remain and the selected state of bitmap3 button should also remain.

Swapnil G.
Highlighted
Developer
Posts: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone

Re: Focus Issue

HI swapnil

 

you can do one thing just replace the BitmapField with CustomButton and try that.

 

Thanks

Tita