mirror of
https://github.com/zxing/zxing.git
synced 2025-01-13 04:07:27 -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
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
switch (keyCode) {
|
||||||
|
case KeyEvent.KEYCODE_BACK:
|
||||||
if (source == IntentSource.NATIVE_APP_INTENT) {
|
if (source == IntentSource.NATIVE_APP_INTENT) {
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
} else if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
|
}
|
||||||
|
if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
|
||||||
restartPreviewAfterDelay(0L);
|
restartPreviewAfterDelay(0L);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_CAMERA) {
|
break;
|
||||||
|
case KeyEvent.KEYCODE_FOCUS:
|
||||||
|
case KeyEvent.KEYCODE_CAMERA:
|
||||||
// Handle these events so they don't launch the Camera app
|
// Handle these events so they don't launch the Camera app
|
||||||
return true;
|
return true;
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
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[]
|
* 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,
|
* in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
|
||||||
|
|
Loading…
Reference in a new issue