recognize the hardware shutter button
This commit is contained in:
parent
8f4ec64521
commit
7bf72858be
|
@ -15,6 +15,7 @@ import android.os.Handler;
|
|||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -52,6 +53,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||
private boolean isCameraAvailable;
|
||||
private boolean isImageCaptureIntent;
|
||||
private boolean isVideoCaptureIntent;
|
||||
private boolean isHardwareShutterHandled;
|
||||
private int currVideoRecTimer;
|
||||
private int orientation;
|
||||
private int currCamera;
|
||||
|
@ -65,6 +67,25 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||
tryInitCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_CAMERA && !isHardwareShutterHandled) {
|
||||
isHardwareShutterHandled = true;
|
||||
shutterPressed();
|
||||
return true;
|
||||
} else {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_CAMERA) {
|
||||
isHardwareShutterHandled = false;
|
||||
}
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
private void hideToggleModeAbout() {
|
||||
if (togglePhotoVideoBtn != null)
|
||||
togglePhotoVideoBtn.setVisibility(View.GONE);
|
||||
|
@ -201,7 +222,11 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||
}
|
||||
|
||||
@OnClick(R.id.shutter)
|
||||
public void shutterPressed() {
|
||||
public void handleShutterPressed() {
|
||||
shutterPressed();
|
||||
}
|
||||
|
||||
private void shutterPressed() {
|
||||
if (!checkCameraAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue