日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 嵌入式 > 嵌入式軟件
[導(dǎo)讀] com.android.camera.Camera.java,主要的實(shí)現(xiàn)Activity,繼承于ActivityBase。ActivityBase在ActivityBase中執(zhí)行流程:onCreate中進(jìn)行判斷是否是平板;onResume中判斷是否鎖

 com.android.camera.Camera.java,主要的實(shí)現(xiàn)Activity,繼承于ActivityBase。

ActivityBase

在ActivityBase中執(zhí)行流程:

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

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

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

onPause中將mOnResumePending置為false;

Camera.java

接下來分析Camera.java,執(zhí)行流程:

1、onCreate

復(fù)制代碼

// 獲得攝像頭的數(shù)量,前置和后置

getPreferredCameraId();

// 獲得對(duì)焦設(shè)置eg:連續(xù)對(duì)焦或者其它

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

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

mFocusManager = new FocusManager(mPreferences, defaultFocusModes);

// 開啟線程來啟動(dòng)攝像頭

mCameraOpenThread.start();

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

mIsImageCaptureIntent = isImageCaptureIntent();

// 設(shè)置UI布局文件

setContentView(R.layout.camera);

if (mIsImageCaptureIntent) {

// 當(dāng)?shù)谌狡渌团恼眨枰@示不同的UI,比如取消鍵盤

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è)能旋轉(zhuǎn)的dialog.比如相機(jī)設(shè)置的dialog,這個(gè)類實(shí)現(xiàn)了旋轉(zhuǎn)的父類

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

// 設(shè)置camera的ID,寫道SharedPreference中

mPreferences.setLocalId(this, mCameraId);

// 更新preference

CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());

// 獲得相機(jī)數(shù)

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

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

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

// 為當(dāng)前的preview重置曝光值

resetExposureCompensation();

// 隱藏系統(tǒng)導(dǎo)航欄等

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語句就是為了保證openCamera的線程執(zhí)行完后,當(dāng)前的線程才開始運(yùn)行。主要是為了確保camera設(shè)備被打開了

mCameraOpenThread.join();

// 線程執(zhí)行完后置為空來讓系統(tǒng)回收資源

mCameraOpenThread = null;

if (mOpenCameraFail) {

// 打開camera失敗,顯示“無法連接到相機(jī)”

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

return;

} else if (mCameraDisabled) {

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

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

return;

}

} catch (InterruptedException ex) {

// ignore

}

//開啟顯示的子線程

mCameraPreviewThread.start();

if (mIsImageCaptureIntent) {

//如果是第三方開啟的 ,setupCaptureParams 設(shè)置拍照的參數(shù)

setupCaptureParams();

} else {

//設(shè)置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;

復(fù)制代碼

2、surfaceCreated

啥都沒做

3、surfaceChanged

復(fù)制代碼

// 確保在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[!--empirenews.page--]

// 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); 對(duì)應(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());

// 初始化屏幕最上方的標(biāo)志,比如開啟了曝光值啊,什么的

initOnScreenIndicator();

// 位置服務(wù)

mLocationManager.recordLocation(recordLocation);

keepMediaProviderInstance();

// 檢查存儲(chǔ)空間和初始化儲(chǔ)存目錄

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

// 初始化一個(gè)圖片的保存線程

mImageSaver = new ImageSaver();

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

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

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

installIntentFilter();

// 初始化縮放UI

initializeZoom();

// 更新屏幕上的閃光燈什么的標(biāo)記

updateOnScreenIndicators();

// 開始面部檢測(cè)

startFaceDetection();

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

// 假如是第一次啟動(dòng),提示用戶“觸摸對(duì)焦”

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)的時(shí)候的動(dòng)畫

mOrientationListener.enable();

// Start location update if needed.[!--empirenews.page--]

boolean recordLocation = RecordLocationPreference.get(

mPreferences, getContentResolver());

mLocationManager.recordLocation(recordLocation);

//設(shè)置SD卡廣播

installIntentFilter();

mImageSaver = new ImageSaver();

//初始化Zoom

initializeZoom();

//mMediaProviderClient=媒體Provider對(duì)象

keepMediaProviderInstance();

//檢查硬盤

checkStorage();

//淡出retake和done的Button

hidePostCaptureAlert();

if (!mIsImageCaptureIntent) {

//如果不是第三方開啟,則更新縮略圖

updateThumbnailButton();

mModePicker.setCurrentMode(ModePicker.MODE_CAMERA);

}

}

復(fù)制代碼

4、surfaceDestroyed

stopPreview();

mSurfaceHolder = null;

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

其他電腦(比如安卓手機(jī)/平板電腦)的屏幕壞了,你可能想在安排維修之前緊急訪問一些東西。你可以使用android的USB OTG功能(是的,幾乎每個(gè)android都支持這個(gè)功能,你可以將鼠標(biāo)和鍵盤連接到它)。

關(guān)鍵字: USB 鼠標(biāo) Android 樹莓派

Google 宣布與中國(guó) AR 科技公司 XREAL 達(dá)成深度戰(zhàn)略合作,聯(lián)合推出全球首款專為 Android XR 平臺(tái)打造的旗艦級(jí) AR 眼鏡 Project Aura。

關(guān)鍵字: Google XREAL Android XR眼鏡 AR

繼停止維護(hù)AOSP開源項(xiàng)目后,谷歌母公司Alphabet近日被曝在其安卓系統(tǒng)(Android)、Pixel手機(jī)以及Chrome瀏覽器等部門裁員數(shù)百人。這一舉措引發(fā)了業(yè)界的廣泛關(guān)注,也引發(fā)了對(duì)谷歌未來業(yè)務(wù)布局的諸多猜測(cè)。

關(guān)鍵字: 谷歌 AOSP Android 裁員

在本教程中,我們將使用Capacitor 6、Angular和TypeScript構(gòu)建一個(gè)Android應(yīng)用程序,該應(yīng)用程序通過串行端口連接到BleuIO USB加密狗。該應(yīng)用程序允許用戶直接從Android設(shè)備發(fā)送和接...

關(guān)鍵字: Android USB 電容器 BLE設(shè)備

早前媒體報(bào)道谷歌將停止維護(hù)Android開源項(xiàng)目(AOSP),將Android開發(fā)全面轉(zhuǎn)向內(nèi)部閉源分支,目前這一消息已經(jīng)得到谷歌官方確認(rèn)。

關(guān)鍵字: 谷歌 Android 開源

本項(xiàng)目演示了如何通過OTG (on - go) USB在Android設(shè)備上使用BleuIO USB加密狗作為串行端口。使用電容器6和@adeunis/電容器-串行插件,我們建立串行連接,發(fā)送AT命令,并實(shí)時(shí)讀取響應(yīng)。該...

關(guān)鍵字: 電容器 Android 傳感器 微控制器 嵌入式系統(tǒng)

在Linux操作系統(tǒng)中,Android Debug Bridge(ADB)是一個(gè)功能強(qiáng)大的命令行工具,它允許開發(fā)者在計(jì)算機(jī)和Android設(shè)備之間建立通信,從而進(jìn)行調(diào)試、管理、安裝應(yīng)用等操作。本文將詳細(xì)介紹在Linux系...

關(guān)鍵字: Linux系統(tǒng) Android Debug ADB

隨著Android操作系統(tǒng)的進(jìn)步,智能手機(jī)的使用日益增加。隨后,有報(bào)道稱,惡意個(gè)人和黑客利用 Android 提供的漏洞來訪問用戶珍視的數(shù)據(jù)。例如,此類威脅包括 2021 年針對(duì) Android 設(shè)備發(fā)布的 Flubot...

關(guān)鍵字: Android 惡意軟件

在本教程中,我們將構(gòu)建超出電子領(lǐng)域的東西。作為一名電子工程師,我們大多數(shù)人都想為我們的物聯(lián)網(wǎng)應(yīng)用程序構(gòu)建一些用戶界面,在大多數(shù)情況下,Android應(yīng)用程序?qū)⑹怯脩襞c我們的物聯(lián)網(wǎng)設(shè)備交互的正確選擇。所以,如果你想為你的物...

關(guān)鍵字: 物聯(lián)網(wǎng) Android
關(guān)閉