<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > Android -- Camera源碼簡(jiǎn)析,啟動(dòng)流程

Android -- Camera源碼簡(jiǎn)析,啟動(dòng)流程

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

com.android.camera.Camera.java,主要的實(shí)現Activity,繼承于A(yíng)ctivityBase。

本文引用地址:http://dyxdggzs.com/article/201609/304303.htm

ActivityBase

在A(yíng)ctivityBase中執行流程:

onCreate中進(jìn)行判斷是否是平板;

onResume中判斷是否鎖屏,鎖屏camera不存在時(shí)候,mOnResumePending置為true,否則置為false并執行doOnResume;

onWindowFocusChanged中判斷是否獲取到焦點(diǎn)mOnResumePending,滿(mǎn)足的話(huà)執行doOnResume;

onPause中將mOnResumePending置為false;

Camera.java

接下來(lái)分析Camera.java,執行流程:

1、onCreate

復制代碼

// 獲得攝像頭的數量,前置和后置

getPreferredCameraId();

// 獲得對焦設置eg:連續對焦或者其它

String[] defaultFocusModes = getResources().getStringArray(R.array.pref_camera_focusmode_default_array);

//實(shí)例化Focus管理對象

mFocusManager = new FocusManager(mPreferences, defaultFocusModes);

// 開(kāi)啟線(xiàn)程來(lái)啟動(dòng)攝像頭

mCameraOpenThread.start();

// 是否是第三方應用啟動(dòng)拍照功能

mIsImageCaptureIntent = isImageCaptureIntent();

// 設置UI布局文件

setContentView(R.layout.camera);

if (mIsImageCaptureIntent) {

// 當第三方其送拍照,需要顯示不同的UI,比如取消鍵盤(pán)

mReviewDoneButton = (Rotatable) findViewById(R.id.btn_done);

mReviewCancelButton = (Rotatable) findViewById(R.id.btn_cancel);

findViewById(R.id.btn_cancel).setVisibility(View.VISIBLE);

} else {

// 反之顯示縮略圖

mThumbnailView = (RotateImageView) findViewById(R.id.thumbnail);

mThumbnailView.enableFilter(false);

mThumbnailView.setVisibility(View.VISIBLE);

}

// 一個(gè)能旋轉的dialog.比如相機設置的dialog,這個(gè)類(lèi)實(shí)現了旋轉的父類(lèi)

mRotateDialog = new RotateDialogController(this, R.layout.rotate_dialog);

// 設置camera的ID,寫(xiě)道SharedPreference中

mPreferences.setLocalId(this, mCameraId);

// 更新preference

CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());

// 獲得相機數

mNumberOfCameras = CameraHolder.instance().getNumberOfCameras();

// 貌似是獲得是否是快速拍照

mQuickCapture = getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false);

// 為當前的preview重置曝光值

resetExposureCompensation();

// 隱藏系統導航欄等

Util.enterLightsOutMode(getWindow());

//SurfaceView

SurfaceView preview = (SurfaceView) findViewById(R.id.camera_preview);

SurfaceHolder holder = preview.getHolder();

holder.addCallback(this);

holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

try {

// 這個(gè)join語(yǔ)句就是為了保證openCamera的線(xiàn)程執行完后,當前的線(xiàn)程才開(kāi)始運行。主要是為了確保camera設備被打開(kāi)了

mCameraOpenThread.join();

// 線(xiàn)程執行完后置為空來(lái)讓系統回收資源

mCameraOpenThread = null;

if (mOpenCameraFail) {

// 打開(kāi)camera失敗,顯示“無(wú)法連接到相機”

Util.showErrorAndFinish(this, R.string.cannot_connect_camera);

return;

} else if (mCameraDisabled) {

// 由于安全政策限制,相機已被停用

Util.showErrorAndFinish(this, R.string.camera_disabled);

return;

}

} catch (InterruptedException ex) {

// ignore

}

//開(kāi)啟顯示的子線(xiàn)程

mCameraPreviewThread.start();

if (mIsImageCaptureIntent) {

//如果是第三方開(kāi)啟的 ,setupCaptureParams 設置拍照的參數

setupCaptureParams();

} else {

//設置ModePicker

mModePicker = (ModePicker) findViewById(R.id.mode_picker);

mModePicker.setVisibility(View.VISIBLE);

mModePicker.setOnModeChangeListener(this);

mModePicker.setCurrentMode(ModePicker.MODE_CAMERA);

}

mZoomControl = (ZoomControl) findViewById(R.id.zoom_control);

mOnScreenIndicators = (Rotatable) findViewById(R.id.on_screen_indicators);

mLocationManager = new LocationManager(this, this);

//攝像頭ID

mBackCameraId = CameraHolder.instance().getBackCameraId();

mFrontCameraId = CameraHolder.instance().getFrontCameraId();

// 在startPreview里面有notify方法

synchronized (mCameraPreviewThread) {

try {

mCameraPreviewThread.wait();

} catch (InterruptedException ex) {

// ignore

}

}

// 初始化各種控制按鈕

initializeIndicatorControl();

//初始化拍照聲音

mCameraSound = new CameraSound();

try {

//確保顯示

mCameraPreviewThread.join();

} catch (InterruptedException ex) {

// ignore

}

mCameraPreviewThread = null;

復制代碼

2、surfaceCreated

啥都沒(méi)做

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


上一頁(yè) 1 2 3 下一頁(yè)

關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>