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
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0
Accepted Solution

how to handle the event of "alt + trackpaddown " event key char method

hello 

i want to do some task ob clicking the "alt + trackpad down".is this possible ? 

if yes how can i handle this task.?

 

 

Thanks

Naveen

Highlighted
Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Re: how to handle the event of "alt + trackpaddown " event key char method

[ Edited ]

Override navigationMovement(dx, dy, status, time) in the screen/manager/field you want the task done in.

dy should be greater than zero for a downwards scroll

status will have the KeypadListener.STATUS_FOUR_WAY bit set if the scroll event was generated by the trackpad, and the KeypadListener.STATUS_ALT bit set if the alt key is pressed

so basically

 

protected boolean navigationMovement(int dx, int dy, int status, int time)
	{
		if(dy > 0 && (status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY && (status & KeypadListener.STATUS_ALT) == KeypadListener.STATUS_ALT)
		{
			// do stuff
			return true; // if you want the field to consume this event
		}
		return super.navigationMovement(dx, dy, status, time);
	}

 

EDIT - I re-read your post and I'm not sure, it looks like you want to handle alt+trackpad click? anyway, it's pretty much the same as above, except you override navigationUnclick(status, time) instead of navigationMovement(dx, dy, status, time), and there's no dy so no need to check for that.

 

protected boolean navigationUnclick(int status, int time)
	{
		if((status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY && (status & KeypadListener.STATUS_ALT) == KeypadListener.STATUS_ALT)
		{
			// do stuff
			return true; // if you want the field to consume this event
		}
		return super.navigationUnclick(status, time);
	}

 



I've got 99 problems and eclipse is all of them


Twitter

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: how to handle the event of "alt + trackpaddown " event key char method

Hello sir thanks for replay ..actually i have two listfield in my screen .i want to toggle between two listfield using" alt+ trackup and trackdown". my this is not working..Smiley Sad i am using this code...

package com.black.applicationloader;

import java.util.Vector;

import net.rim.device.api.system.Display;
import net.rim.device.api.system.KeypadListener;
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.Keypad;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.container.VerticalFieldManager;

import com.black.blackinterface.BlackInterface;
import com.black.common.BaseScreen;
import com.black.components.CustomEditField;
import com.black.utility.Utilities;

public class BlackSecondScreen extends BaseScreen implements BlackInterface,ListFieldCallback {
	 private VerticalFieldManager listFieldManager;
	 private VerticalFieldManager listFieldManager_2;
	 private static final String[] _elements = {"First element", "Second element", "Third element", "Fourth element", "Fifth element"};
	 private Vector _listElements = new Vector(_elements.length, 1);
	 int columnWidth  = Display.getWidth()/4;
	 private boolean hasFocus; // =false
	private CustomEditField userEditField;
	ListField colourList_1;
	ListField colourList_2;
	
	BlackSecondScreen(){
		
		
		
		colourList_1 = new ListField(){
			
			protected boolean keyChar(char key, int status, int time) {
				if(colourList_1 == getLeafFieldWithFocus()){
				if(key=='t'||key=='T'){
					
					colourList_2.setFocus();
					
				}
				return true;
				}
				else{
					return super.keyChar(key,status,time);
					
				}
			};
			
			protected void drawFocus(Graphics graphics, boolean on) {
				
				hasFocus = on;
				super.drawFocus(graphics, on);
				hasFocus = false;
//				XYRect rect = new XYRect();
//			     graphics.setGlobalAlpha(200);
//				getFocusRect(rect);
//				drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,rect.x,rect.y,rect.width,rect.height);
			}
			
			protected boolean navigationMovement(int dx, int dy, int status, int time) {
			
				if(dy > 0 && (status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY && (status & KeypadListener.STATUS_ALT) == KeypadListener.STATUS_ALT)
				{
					// do stuff
					colourList_2.setFocus();
					return true; // if you want the field to consume this event
				}
				return super.navigationMovement(dx, dy, status, time);
				
				
			};
			
			
			
		};
		
		colourList_1.setCallback(this);
		  int elementLength = _elements.length;
		 for(int count = 0; count < elementLength; ++count)
	        {
			 colourList_1.insert(count);
	            this.insert(_elements[count], count);
	        }
		 
		 
		 
		 
		 
		 colourList_2 = new ListField(){
				
				
				protected void drawFocus(Graphics graphics, boolean on) {
					hasFocus = on;
					super.drawFocus(graphics, on);
					hasFocus = false;

				}
				
				protected boolean keyChar(char key, int status, int time) {
					if(colourList_2 == getLeafFieldWithFocus()){
					//if(key=='t'||key=='T'){
						if(key=='t'){
						colourList_1.setFocus();
						colourList_1.setSelectedIndex(0);
					
						
					}
					return true;
					}
					else{
						return super.keyChar(key,status,time);
						
					}
				}
				
			
				
				
			};
			
			colourList_2.setCallback(this);
			  
			 for(int count = 0; count < elementLength; ++count)
		        {
				 colourList_2.insert(count);
		            this.insert(_elements[count], count);
		        }
		 
		 //add(colourList);
		 createComponents();
		 layoutComponents();
		
	}

	public void createComponents() {
		
		listFieldManager= new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.HORIZONTAL_SCROLL){
			protected void sublayout(int maxWidth, int maxHeight) {
				 super.sublayout( maxWidth, 2*colourList_1.getRowHeight());
				    setExtent(maxWidth,2*colourList_1.getRowHeight()); 
				
			};
			
		};
		
		
		listFieldManager_2= new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.HORIZONTAL_SCROLL){
			protected void sublayout(int maxWidth, int maxHeight) {
				 super.sublayout( maxWidth, 2*colourList_2.getRowHeight());
				    setExtent(maxWidth,2*colourList_2.getRowHeight()); 
				
			};
			
		};
		
		
		
//		userEditField=new CustomEditField(Utilities.getAdjustedWidth(150),
//				Utilities.getAdjustWidth(2), Manager.NO_HORIZONTAL_SCROLL
//				| Manager.VERTICAL_SCROLL, true);
		
	}

	public void layoutComponents() {
		// TODO Auto-generated method stub
		listFieldManager.add(colourList_1);
		
		
		listFieldManager_2.add(colourList_2);
		
		
		listFieldManager.setMargin(0,0,40,0);
		add(listFieldManager);
		add(listFieldManager_2);
		
		
	}

	public void initializeListeners() {
		// TODO Auto-generated method stub
		
	}

	public void setComponentsXYMargins() {
		// TODO Auto-generated method stub
		
	}

	public void drawListRow(ListField listField, Graphics graphics, int index,
			int y, int width) {
		int curSelected;
		    if(!hasFocus){
		    if(index%2  == 0){
			
			graphics.setColor(Color.RED); 
			graphics.fillRect(0, y, width, listField.getRowHeight());
			graphics.setColor(Color.WHITE); 
			
			}else{
			graphics.setColor(Color.BLACK); 
			graphics.fillRect(0, y, width, listField.getRowHeight());
			}
		    }
			//graphics.fillRect(0,0,width,y);
			 
			int xpos = 0;int ypos = 0;
			graphics.setFont(Font.getDefault());// please set a font value
			// this is first column text
			graphics.setColor(Color.PINK); 
			graphics.drawText("column1"+index,xpos,y);
			xpos +=  columnWidth;
			 
			//graphics.setColor(Color.RED); 
			graphics.drawText("column2",xpos,y);
			 
			xpos +=  columnWidth;
			graphics.drawText("column3",xpos,y);
			 
			xpos +=  columnWidth;
			 
			graphics.drawText("column4",xpos,y);
		
	}

	public Object get(ListField listField, int index) {
		// TODO Auto-generated method stub
		 return _listElements.elementAt(index);
	}

	public int getPreferredWidth(ListField listField) {
		// TODO Auto-generated method stub
		return Graphics.getScreenWidth();
	}

	public int indexOfList(ListField listField, String prefix, int start) {
		// TODO Auto-generated method stub
		return _listElements.indexOf(prefix, start);
	}
	
	public void insert(String toInsert, int index) 
    {
        _listElements.insertElementAt(toInsert, index);
    }
	
	 public void erase() 
	    {
	        _listElements.removeAllElements();
	    }
	

}

 

 

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to handle the event of "alt + trackpaddown " event key char method

Can we please have a better problem description that "is not working".  Have you debugged this?  Which lines get executed? etc. etc..

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: how to handle the event of "alt + trackpaddown " event key char method

Thanks sir it working..Thanks a lot....!!!
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: how to handle the event of "alt + trackpaddown " event key char method

Need to ask one more question ...actually if i have more column i want to scroll list horizontally can it is possible ..actually my list is scrolling vertically ...can it possible to scroll horizontal..?
Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to handle the event of "alt + trackpaddown " event key char method

Been here already,  New Question, new Thread.  OK? 

Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Re: how to handle the event of "alt + trackpaddown " event key char method

Yeah, check for dx being greater than zero and implement the horizontal scrolling logic.



I've got 99 problems and eclipse is all of them


Twitter