Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Camera Button Half Way Pressed Listener

I am building a custom camera app and have got the basics to work. I have also been able to block the camera button from initializing the real camera app. The only thing that I would like to do is build in autofocus when the camera button is half pressed.

I am comfortable using camera.autofocus, but cannot find a way to listen for the camera button to be halfway pressed (like the default camera app does) to start the autofocus call.

Is there a keycode or another way to listen for the camera button being depressed to its half way point?

like image 659
ControlAltDelete Avatar asked Sep 05 '26 00:09

ControlAltDelete


1 Answers

I got a little creative and just toasted any key down event in android. I ended up finding out that the key code for camera focus is 80 this way. This also matches up with the android documentation once I knew what I was looking for.

http://developer.android.com/reference/android/view/KeyEvent.html

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {


    if(event.getAction()==KeyEvent.ACTION_DOWN){

        Toast.makeText(this, new Integer(keyCode).toString(), Toast.LENGTH_LONG).show();
        return true;
    }

    return false;
}

Hope this helps others.

like image 170
ControlAltDelete Avatar answered Sep 07 '26 12:09

ControlAltDelete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!