微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > Android -- Camera源码简析,启动流程

Android -- Camera源码简析,启动流程

时间:09-12 来源:互联网 点击:

catch (InterruptedException ex) {

// ignore

}

mCameraPreviewThread = null;

复制代码

2、surfaceCreated

啥都没做

3、surfaceChanged

复制代码

// 确保在holder中有surface

if (holder.getSurface() == null) {

Log.d(TAG, holder.getSurface() == null);

return;

}

// We need to save the holder for later use, even when the mCameraDevice

// is null. This could happen if onResume() is invoked after this

// function.

mSurfaceHolder = holder;

if (mCameraDevice == null) return;

if (mPausing || isFinishing()) return;

// Set preview display if the surface is being created. Preview was

// already started. Also restart the preview if display rotation has

// changed. Sometimes this happens when the device is held in portrait

// and camera app is opened. Rotation animation takes some time and

// display rotation in onCreate may not be what we want.

if (mCameraState == PREVIEW_STOPPED) {

startPreview();

startFaceDetection();

} else {

if (Util.getDisplayRotation(this) != mDisplayRotation) {

setDisplayOrientation();

}

if (holder.isCreating()) {

// Set preview display if the surface is being created and preview

// was already started. That means preview display was set to null

// and we need to set it now.

setPreviewDisplay(holder);

}

}

// If first time initialization is not finished, send a message to do

// it later. We want to finish surfaceChanged as soon as possible to let

// user see preview first.

if (!mFirstTimeInitialized) {

mHandler.sendEmptyMessage(FIRST_TIME_INIT);

} else {

initializeSecondTime();

}

复制代码

如果是第一次加载,则执行mHandler.sendEmptyMessage(FIRST_TIME_INIT); 对应处理的是initializeFirstTime();

复制代码

/**

* 初始化,第一次初始化

* // Snapshots can only be taken after this is called. It should be called

* // once only. We could have done these things in onCreate() but we want to

* // make preview screen appear as soon as possible.

*/

private void initializeFirstTime() {

if (mFirstTimeInitialized) return;

// Create orientation listenter. This should be done first because it

// takes some time to get first orientation.

mOrientationListener = new MyOrientationEventListener(Camera.this);

mOrientationListener.enable();

// Initialize location sevice.

boolean recordLocation = RecordLocationPreference.get(

mPreferences, getContentResolver());

// 初始化屏幕最上方的标志,比如开启了曝光值啊,什么的

initOnScreenIndicator();

// 位置服务

mLocationManager.recordLocation(recordLocation);

keepMediaProviderInstance();

// 检查存储空间和初始化储存目录

checkStorage();

// Initialize last picture button.

mContentResolver = getContentResolver();

if (!mIsImageCaptureIntent) { // no thumbnail in image capture intent

// 初始化缩略图

initThumbnailButton();

}

// Initialize shutter button.

// 初始化拍照按钮并设置监听事件

mShutterButton = (ShutterButton) findViewById(R.id.shutter_button);

mShutterButton.setOnShutterButtonListener(this);

mShutterButton.setVisibility(View.VISIBLE);

// Initialize focus UI.

mPreviewFrame = findViewById(R.id.camera_preview);

mPreviewFrame.setOnTouchListener(this);

// 聚焦框

mFocusAreaIndicator = (RotateLayout) findViewById(R.id.focus_indicator_rotate_layout);

CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];

boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);

mFocusManager.initialize(mFocusAreaIndicator, mPreviewFrame, mFaceView, this,

mirror, mDisplayOrientation);

// 初始化一个图片的保存线程

mImageSaver = new ImageSaver();

// 设置屏幕亮度

Util.initializeScreenBrightness(getWindow(), getContentResolver());

// 注册SD卡相关的广播,比如拔出存储卡什么的

installIntentFilter();

// 初始化缩放UI

initializeZoom();

// 更新屏幕上的闪光灯什么的标记

updateOnScreenIndicators();

// 开始面

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top