Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,742,966 Members 41,984 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Using hardware zoom and shutter controls in own application

Tip us?
 
geetarguy86
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: May 2014
Camera [Q] Using hardware zoom and shutter controls in own application

Hi All,

I have recently been trying to port an augmented reality research project to the Galaxy Camera (EK-GC100) and have hit a few stumbling blocks. The main one of these is that whilst I can control the camera using software UI controls and the Android camera API, I would like to use the hardware zoom and shutter controls. My understanding based on trawling this forum is that it hasn't been done, but can anyone confirm whether or not this is the case? And if it is possible, how should I go about it? Any help would be greatly appreciated.

Thanks
 
geetarguy86
Old
#2  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: May 2014
Talking Answered my own question!

It's ok, I've figured out the answer to this! I suspected Samsung may have been using the standard key event constants so wrote a very simple app to read out the key code value for any key down or up events. This app confirmed my thoughts. The constants used are:

Zoom in button pressed: KEYCODE_ZOOM_IN (value 168)
Zoom out button pressed: KEYCODE_ZOOM_OUT (value 169)
Shutter button pressed halfway: KEYCODE_FOCUS (value 80)
Shutter button pressed fully: KEYCODE_CAMERA (value 27)

When I pressed and held any of these buttons, the keycodes were sent repeatedly at a fairly high frequency. To make button handling a bit smoother, I have added some simple checks. If the user holds down a button, the first keycode is registered. The following 5 are ignored, then the 6th would be registered and the 5 event counter resets. If the user lets go of a button, this counter is also reset. The result is that the camera handles the zoom and shutter commands better than if I were just acting on every received keycode. Some example code is below:

Code:
Select Code
@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    switch (keyCode) {
	        case KeyEvent.KEYCODE_ZOOM_IN:	

	            if(hwBtnHeldCounter==0)
	            {
	            	zoomIn();
	            	hwBtnHeldCounter++;
	            }
	            else if(hwBtnHeldCounter==5)
	            {
	            	// reset counter
	            	hwBtnHeldCounter = 0;
	            }
	            else
	            {
	            	// increment counter
	            	hwBtnHeldCounter++;
	            }
	            return true;

	        default:
	            return super.onKeyDown(keyCode, event);
	    }
	}
	
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
	    switch (keyCode) {
	        case KeyEvent.KEYCODE_ZOOM_IN:
	        	
	            // reset counter
	        	hwBtnHeldCounter=0;
	            
	        	return true;

	        default:
	            return super.onKeyUp(keyCode, event);
	    }
	}
Hope this helps some other aspiring Galaxy Camera developers out!
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes