新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > Android -- Camera源碼簡析,啟動流程

Android -- Camera源碼簡析,啟動流程

作者: 時間:2016-09-12 來源:網(wǎng)絡(luò) 收藏

// 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();

}

復(fù)制代碼

如果是第一次加載,則執(zhí)行mHandler.sendEmptyMessage(FIRST_TIME_INIT); 對應(yīng)處理的是initializeFirstTime();

復(fù)制代碼

/**

* 初始化,第一次初始化

* // 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();

// 位置服務(wù)

mLocationManager.recordLocation(recordLocation);

keepMediaProviderInstance();

// 檢查存儲空間和初始化儲存目錄

checkStorage();

// Initialize last picture button.

mContentResolver = getContentResolver();

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

// 初始化縮略圖

initThumbnailButton();

}

// Initialize shutter button.

// 初始化拍照按鈕并設(shè)置監(jiān)聽事件

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();

// 設(shè)置屏幕亮度

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

// 注冊SD卡相關(guān)的廣播,比如拔出存儲卡什么的

installIntentFilter();

// 初始化縮放UI

initializeZoom();

// 更新屏幕上的閃光燈什么的標記

updateOnScreenIndicators();

// 開始面部檢測

startFaceDetection();

// Show the tap to focus toast if this is the first start.

// 假如是第一次啟動,提示用戶“觸摸對焦”

if (mFocusAreaSupported

mPreferences.getBoolean(CameraSettings.KEY_CAMERA_FIRST_USE_HINT_SHOWN, true)) {

// Delay the toast for one second to wait for orientation.

mHandler.sendEmptyMessageDelayed(SHOW_TAP_TO_FOCUS_TOAST, 1000);

}

mFirstTimeInitialized = true;

addIdleHandler();

}

復(fù)制代碼

如果不是,則執(zhí)行initializeSecondTime();

復(fù)制代碼

/**

* // If the activity is paused and resumed, this method will be called in

* // onResume.

*/

private void initializeSecondTime() {

// Start orientation listener as soon as possible because it takes

// some time to get first orientation.

//方向翻轉(zhuǎn)設(shè)置enable,其中包括翻轉(zhuǎn)的時候的動畫

mOrientationListener.enable();

// Start location update if needed.



關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉