我在这个Android领域的新事物我有Android事件操作系统图像FLASHED for pico IMX7并成功启动,一切都很好......直到我运行Github(https://github.com/dozingcat/CamTimer)程序来验证相机。
1)当我运行程序时我能够拍摄第一张照片,但当我尝试拍摄第二张照片时出现以下错误 ==>
01-01 05:36:36.395 3399-3399/com.dozingcatsoftware.cameratimer V/MediaPlayer: resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
01-01 05:36:36.395 3399-3399/com.dozingcatsoftware.cameratimer V/MediaPlayer: cleanDrmObj: mDrmObj=null mDrmSessionId=null
01-01 05:36:37.415 3399-3399/com.dozingcatsoftware.cameratimer V/MediaPlayer: resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
01-01 05:36:37.415 3399-3399/com.dozingcatsoftware.cameratimer V/MediaPlayer: cleanDrmObj: mDrmObj=null mDrmSessionId=null
01-01 05:36:38.410 3399-3399/com.dozingcatsoftware.cameratimer V/MediaPlayer: resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
01-01 05:36:38.410 3399-3399/com.dozingcatsoftware.cameratimer V/MediaPlayer: cleanDrmObj: mDrmObj=null mDrmSessionId=null
01-01 05:36:48.175 3399-3399/com.dozingcatsoftware.cameratimer E/Camera: Error 1
然后应用程序崩溃时出现此错误==>
05:41:23.712 5793-6317/com.dozingcatsoftware.cameratimer W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
01-01 05:41:23.712 5793-6317/com.dozingcatsoftware.cameratimer D/OpenGLRenderer: Swap behavior 0
01-01 05:41:23.712 5793-6317/com.dozingcatsoftware.cameratimer A/OpenGLRenderer: Failed to choose config, error = EGL_SUCCESS
01-01 05:41:23.713 5793-6317/com.dozingcatsoftware.cameratimer A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 6317 (RenderThread)
这里是相机错误痕迹(1):== ----- pid 187 at 2009-01-01 05:36:48 ----- Cmd行:/ system / bin / cameraserver
"cameraserver" sysTid=187
#00 pc 00047e55 /system/lib/libbinder.so (_ZN7android14IPCThreadState14talkWithDriverEb+168)
#01 pc 00047f4d /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+8)
#02 pc 000484a3 /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+38)
#03 pc 00000c6d /system/bin/cameraserver
#04 pc 00017d35 /system/lib/libc.so (__libc_init+48)
#05 pc 00000b34 /system/bin/cameraserver
"HwBinder:187_1" sysTid=265
#00 pc 00049400 /system/lib/libc.so (__ioctl+8)
#01 pc 0001de4f /system/lib/libc.so (ioctl+38)
#02 pc 00010015 /system/lib/libhwbinder.so (_ZN7android8hardware14IPCThreadState14talkWithDriverEb+168)
#03 pc 0001010d /system/lib/libhwbinder.so (_ZN7android8hardware14IPCThreadState20getAndExecuteCommandEv+8)
#04 pc 00010713 /system/lib/libhwbinder.so (_ZN7android8hardware14IPCThreadState14joinThreadPoolEb+38)
#05 pc 00016e3d /system/lib/libhwbinder.so
#06 pc 0000d38d /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+140)
#07 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#08 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"HwBinder:187_2" sysTid=268
#00 pc 00049400 /system/lib/libc.so (__ioctl+8)
#01 pc 0001de4f /system/lib/libc.so (ioctl+38)
#02 pc 00010015 /system/lib/libhwbinder.so (_ZN7android8hardware14IPCThreadState14talkWithDriverEb+168)
#03 pc 0001010d /system/lib/libhwbinder.so (_ZN7android8hardware14IPCThreadState20getAndExecuteCommandEv+8)
#04 pc 00010713 /system/lib/libhwbinder.so (_ZN7android8hardware14IPCThreadState14joinThreadPoolEb+38)
#05 pc 00016e3d /system/lib/libhwbinder.so
#06 pc 0000d38d /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+140)
#07 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#08 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"HotplugThread" sysTid=275
#00 pc 0004949c /system/lib/libc.so (__ppoll+20)
#01 pc 000201c1 /system/lib/libc.so (poll+48)
#02 pc 00000e4b /system/lib/libhardware_legacy.so (uevent_next_event+54)
#03 pc 00003457 /system/lib/hw/camera.imx7d.so
#04 pc 000039df /system/lib/hw/camera.imx7d.so
#05 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#06 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#07 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"cameraserver" sysTid=277
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"cameraserver" sysTid=278
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"cameraserver" sysTid=279
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"Binder:187_1" sysTid=280
#00 pc 00049400 /system/lib/libc.so (__ioctl+8)
#01 pc 0001de4f /system/lib/libc.so (ioctl+38)
#02 pc 00047e55 /system/lib/libbinder.so (_ZN7android14IPCThreadState14talkWithDriverEb+168)
#03 pc 00047f4d /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+8)
#04 pc 000484a3 /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+38)
#05 pc 0005e5ad /system/lib/libbinder.so
#06 pc 0000d38d /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+140)
#07 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#08 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"Binder:187_2" sysTid=1410
#00 pc 00049400 /system/lib/libc.so (__ioctl+8)
#01 pc 0001de4f /system/lib/libc.so (ioctl+38)
#02 pc 00047e55 /system/lib/libbinder.so (_ZN7android14IPCThreadState14talkWithDriverEb+168)
#03 pc 00047f4d /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+8)
#04 pc 000484a3 /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+38)
#05 pc 0005e5ad /system/lib/libbinder.so
#06 pc 0000d38d /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+140)
#07 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#08 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C3Dev-0-ReqQueu" sysTid=1426
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C3Dev-0-ReqQueu" sysTid=1427
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C3Dev-0-ReqQueu" sysTid=1899
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"Binder:187_1" sysTid=3646
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"Binder:187_1" sysTid=3647
#00 pc 00018d98 /system/lib/libc.so (syscall+28)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0004bf0d /system/lib/libc++.so (_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE+8)
#03 pc 000175bb /system/lib/libhidlbase.so (_ZN7android8hardware7details17SynchronizedQueueINSt3__18functionIFvvEEEE8wait_popEv+42)
#04 pc 00017511 /system/lib/libhidlbase.so
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C3Dev-0-Status" sysTid=3648
#00 pc 00018d9c /system/lib/libc.so (syscall+32)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 000c0935 /system/lib/libcameraservice.so (_ZN7android7camera313StatusTracker10threadLoopEv+200)
#03 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#04 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#05 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C3Dev-0-ReqQueu" sysTid=3649
#00 pc 00018d9c /system/lib/libc.so (syscall+32)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 000b622b /system/lib/libcameraservice.so (_ZN7android13Camera3Device13RequestThread12waitIfPausedEv+202)
#03 pc 000b5fbb /system/lib/libcameraservice.so (_ZN7android13Camera3Device13RequestThread10threadLoopEv+58)
#04 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C2-0-FrameProc" sysTid=3650
#00 pc 00018d9c /system/lib/libc.so (syscall+32)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 000b0ec1 /system/lib/libcameraservice.so (_ZN7android13Camera3Device16waitForNextFrameEx+212)
#03 pc 00086c4f /system/lib/libcameraservice.so (_ZN7android7camera218FrameProcessorBase10threadLoopEv+86)
#04 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C2-0-CaptureSeq" sysTid=3651
#00 pc 00009a51 /system/lib/libutils.so (_ZN7android9CallStack6updateEii+52)
#01 pc 00011595 /system/lib/libutils.so (_ZN7android16ProcessCallStack6updateEv+264)
#02 pc 000c64a7 /system/lib/libcameraservice.so (_ZN7android7camera312CameraTraces9saveTraceEv+106)
#03 pc 000b2e67 /system/lib/libcameraservice.so (_ZN7android13Camera3Device20setErrorStateLockedVEPKcSt9__va_list+198)
#04 pc 000ab6cf /system/lib/libcameraservice.so (_ZN7android13Camera3Device19setErrorStateLockedEPKcz+30)
#05 pc 000b0b91 /system/lib/libcameraservice.so (_ZN7android13Camera3Device22waitUntilDrainedLockedEv+64)
#06 pc 000b0ae7 /system/lib/libcameraservice.so (_ZN7android13Camera3Device16waitUntilDrainedEv+62)
#07 pc 0009d9c7 /system/lib/libcameraservice.so (_ZN7android7camera216CaptureSequencer10manageDoneERNS_2spINS_13Camera2ClientEEE+186)
#08 pc 0009dc5b /system/lib/libcameraservice.so (_ZN7android7camera216CaptureSequencer10threadLoopEv+90)
#09 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#10 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#11 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C2-0-JpegProc" sysTid=3652
#00 pc 00018d9c /system/lib/libc.so (syscall+32)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 00099d19 /system/lib/libcameraservice.so (_ZN7android7camera213JpegProcessor10threadLoopEv+192)
#03 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#04 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#05 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C2-0-ZslProc" sysTid=3653
#00 pc 00018d9c /system/lib/libc.so (syscall+32)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 000a01ef /system/lib/libcameraservice.so (_ZN7android7camera212ZslProcessor10threadLoopEv+186)
#03 pc 000a0243 /system/lib/libcameraservice.so (_ZTv0_n32_N7android7camera212ZslProcessor10threadLoopEv+10)
#04 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#05 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#06 pc 0001afbd /system/lib/libc.so (__start_thread+32)
"C2-0-CallbkProc" sysTid=3654
#00 pc 00018d9c /system/lib/libc.so (syscall+32)
#01 pc 000476af /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)
#02 pc 0009ad51 /system/lib/libcameraservice.so (_ZN7android7camera217CallbackProcessor10threadLoopEv+192)
#03 pc 0000d40f /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
#04 pc 00047c9f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#05 pc 0001afbd /system/lib/libc.so (__start_thread+32)
----- end 187 -----
这是MainActivity类代码,我做了很少的改动。
public class MainActivity extends Activity implements Camera.PictureCallback, Camera.AutoFocusCallback, OnShutterButtonListener {
static final List<Integer> DELAY_DURATIONS = Arrays.asList(0, 5, 15, 30);
static final int DEFAULT_DELAY = 5;
static final String DELAY_PREFERENCES_KEY = "delay";
int pictureDelay = DEFAULT_DELAY;
private static final int MY_CAMERA_REQUEST_CODE = 100;
static final String FLASH_MODE_AUTO = "auto";
static final String FLASH_MODE_ON = "on";
static final String FLASH_MODE_OFF = "off";
Map<String, String> flashButtonLabels = new HashMap<String, String>();
ARManager arManager;
SurfaceView cameraView;
int[] maxCameraViewSize;
Camera camera;
ShutterButton shutterButton;
Button pictureDelayButton;
Button cancelPictureButton;
Button switchCameraButton;
Button flashButton;
Button numberOfPicturesButton;
TextView statusTextField;
// only one beep type for now
//int beepType;
//int numBeepTypes = 3;
//Random RAND = new Random();
// assign ID when we start a timed picture, used in makeDecrementTimerFunction callback. If the ID changes, the countdown will stop.
int currentPictureID = 0;
// PictureView works, but for timed pictures it makes more sense to always go to ViewImageActivity
// since the user may not be by the camera when it takes the picture
//PictureView pictureView;
Uri pictureURI;
Handler handler = new Handler();
int pictureTimer = 0;
boolean hasMultipleCameras;
List<String> flashModes = new ArrayList<String>();
int selectedFlashMode;
boolean flashButtonConfigured = false;
int picturesToTake = 1;
List<Uri> pictureURIs;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
if (checkSelfPermission(Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA},
MY_CAMERA_REQUEST_CODE);
}
flashButtonLabels.put(FLASH_MODE_AUTO, getString(R.string.flashButtonAutoLabel));
flashButtonLabels.put(FLASH_MODE_ON, getString(R.string.flashButtonOnLabel));
flashButtonLabels.put(FLASH_MODE_OFF, getString(R.string.flashButtonOffLabel));
try {
cameraView = (SurfaceView)findViewById(R.id.cameraView);
arManager = ARManager.createAndSetupCameraView(this, cameraView, null);
arManager.setCameraOpenedCallback(new Runnable() {public void run() {cameraOpened();}});
arManager.setCameraStartedCallback(new Runnable() {public void run() {cameraPreviewStarted();}});
} catch (RuntimeException e) {
Log.e("CameraTest", "Camera Open filed");
return;
}
// flashButtonLabels.put(FLASH_MODE_AUTO, getString(R.string.flashButtonAutoLabel));
// flashButtonLabels.put(FLASH_MODE_ON, getString(R.string.flashButtonOnLabel));
// flashButtonLabels.put(FLASH_MODE_OFF, getString(R.string.flashButtonOffLabel));
// cameraView = (SurfaceView)findViewById(R.id.cameraView);
// arManager = ARManager.createAndSetupCameraView(this, cameraView, null);
// arManager.setCameraOpenedCallback(new Runnable() {public void run() {cameraOpened();}});
// arManager.setCameraStartedCallback(new Runnable() {public void run() {cameraPreviewStarted();}});
shutterButton = (ShutterButton)findViewById(R.id.shutterButton);
shutterButton.setOnShutterButtonListener(this);
pictureDelayButton = (Button)findViewById(R.id.pictureDelayButton);
cancelPictureButton = (Button)findViewById(R.id.cancelPictureButton);
flashButton = (Button)findViewById(R.id.flashButton);
numberOfPicturesButton = (Button)findViewById(R.id.numberOfPicturesButton);
switchCameraButton = (Button)findViewById(R.id.switchCameraButton);
hasMultipleCameras = (CameraUtils.numberOfCameras() > 1);
switchCameraButton.setVisibility(hasMultipleCameras ? View.VISIBLE : View.GONE);
statusTextField = (TextView)findViewById(R.id.statusText);
AndroidUtils.bindOnClickListener(this, pictureDelayButton, "cycleDelay");
AndroidUtils.bindOnClickListener(this, cancelPictureButton, "cancelSavePicture");
AndroidUtils.bindOnClickListener(this, switchCameraButton, "switchCamera");
AndroidUtils.bindOnClickListener(this, flashButton, "cycleFlashMode");
AndroidUtils.bindOnClickListener(this, numberOfPicturesButton, "toggleNumberOfPictures");
AndroidUtils.bindOnClickListener(this, findViewById(R.id.helpButton), "doHelp");
AndroidUtils.bindOnClickListener(this, findViewById(R.id.libraryButton), "openLibrary");
// this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
this.readDelayPreference();
if (camera!=null) {
camera.setPreviewCallback(null);
camera.stopPreview();
camera.release();
camera = null;
}
}
@Override
public void onPause() {
if (pictureTimer > 0) {
this.cancelSavePicture();
}
arManager.stopCamera();
super.onPause();
}
@Override
public void onResume() {
super.onResume();
arManager.startCameraIfVisible();
AndroidUtils.setSystemUiLowProfile(cameraView);
}
// callback from ARManager
public void cameraOpened() {
if (maxCameraViewSize==null) {
maxCameraViewSize = new int[] {cameraView.getWidth(), cameraView.getHeight()};
}
arManager.setPreferredPreviewSize(maxCameraViewSize[0], maxCameraViewSize[1]);
CameraUtils.setLargestCameraSize(arManager.getCamera());
//statusTextField.setText(arManager.getCamera().getParameters().getPictureSize().width+"");
if (!flashButtonConfigured) {
configureFlashButton();
flashButtonConfigured = true;
}
}
public void cameraPreviewStarted() {
// resize camera view to scaled size of preview image
Camera.Size size = arManager.getCamera().getParameters().getPreviewSize();
int[] scaledWH = AndroidUtils.scaledWidthAndHeightToMaximum(
size.width, size.height, maxCameraViewSize[0], maxCameraViewSize[1]);
cameraView.setLayoutParams(new FrameLayout.LayoutParams(scaledWH[0], scaledWH[1], Gravity.CENTER));
}
void updateButtons(boolean allowSave) {
this.findViewById(R.id.miscButtonBar).setVisibility(allowSave ? View.VISIBLE : View.GONE);
this.findViewById(R.id.optionsButtonBar).setVisibility(allowSave ? View.VISIBLE : View.GONE);
shutterButton.setVisibility(allowSave ? View.VISIBLE : View.GONE);
cancelPictureButton.setVisibility(allowSave ? View.GONE : View.VISIBLE);
}
public void cancelSavePicture() {
pictureTimer = 0;
++currentPictureID;
statusTextField.setText("");
Toast.makeText(this, getString(R.string.canceledPictureMessage), Toast.LENGTH_SHORT).show();
updateButtons(true);
}
void updateTimerMessage() {
String messageFormat = getString(R.string.timerCountdownMessageFormat);
statusTextField.setText(String.format(messageFormat, pictureTimer));
}
Runnable makeDecrementTimerFunction(final int pictureID) {
return new Runnable() {
public void run() {decrementTimer(pictureID);}
};
}
MediaPlayer.OnCompletionListener releaseMediaPlayerFunction = new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.release();
}
};
void playTimerBeep() {
int soundResource = R.raw.beep_sound0;
MediaPlayer mp = MediaPlayer.create(this, soundResource);
mp.start();
mp.setOnCompletionListener(releaseMediaPlayerFunction);
}
public void decrementTimer(final int pictureID) {
if (pictureID!=this.currentPictureID) {
return;
}
boolean takePicture = (pictureTimer==1);
--pictureTimer;
if (takePicture) {
savePictureNow();
playTimerBeep();
}
else if (pictureTimer>0) {
updateTimerMessage();
handler.postDelayed(makeDecrementTimerFunction(pictureID), 1000);
if (pictureTimer<3) playTimerBeep();
}
}
public void savePicture() {
if (this.pictureDelay==0) {
savePictureNow();
}
else {
savePictureAfterDelay(this.pictureDelay);
}
}
void savePictureAfterDelay(int delay) {
pictureTimer = delay;
updateTimerMessage();
currentPictureID++;
handler.postDelayed(makeDecrementTimerFunction(currentPictureID), 1000);
//beepType = RAND.nextInt(numBeepTypes);
updateButtons(false);
}
public void savePictureNow() {
pictureURIs = new ArrayList<Uri>();
statusTextField.setText("Taking picture...");
arManager.getCamera().autoFocus(this);
}
public void switchCamera() {
flashButtonConfigured = false;
arManager.switchToNextCamera();
}