mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Now can turn light on/off with volume buttons
git-svn-id: https://zxing.googlecode.com/svn/trunk@2286 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
8cc93b521b
commit
1b90db519e
|
@ -305,18 +305,29 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (source == IntentSource.NATIVE_APP_INTENT) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
if (source == IntentSource.NATIVE_APP_INTENT) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
|
||||
restartPreviewAfterDelay(0L);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEYCODE_FOCUS:
|
||||
case KeyEvent.KEYCODE_CAMERA:
|
||||
// Handle these events so they don't launch the Camera app
|
||||
return true;
|
||||
} else if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
|
||||
restartPreviewAfterDelay(0L);
|
||||
// Use volume up/down to turn on light
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
cameraManager.setTorch(false);
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
cameraManager.setTorch(true);
|
||||
return true;
|
||||
}
|
||||
} else if (keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_CAMERA) {
|
||||
// Handle these events so they don't launch the Camera app
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
|
|
@ -135,6 +135,21 @@ public final class CameraManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for {@link com.srowen.bs.android.CaptureActivity}
|
||||
*/
|
||||
public synchronized void setTorch(boolean newSetting) {
|
||||
if (camera != null) {
|
||||
if (autoFocusManager != null) {
|
||||
autoFocusManager.stop();
|
||||
}
|
||||
configManager.setTorch(camera, newSetting);
|
||||
if (autoFocusManager != null) {
|
||||
autoFocusManager.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
|
||||
* in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
|
||||
|
|
Loading…
Reference in a new issue