Skip to content

Commit 8591fcb

Browse files
Auto-update
1 parent 4057be3 commit 8591fcb

File tree

7 files changed

+114
-11
lines changed

7 files changed

+114
-11
lines changed

.google/packaging.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
---
66
status: PUBLISHED
77
technologies: [Android]
8-
categories: [Media]
8+
categories: [Media, Camera, Camera2]
99
languages: [Java]
1010
solutions: [Mobile]
1111
github: android-Camera2Basic
12+
level: INTERMEDIATE
13+
icon: screenshots/icon-web.png
14+
apiRefs:
15+
- android:android.hardware.camera2.CameraManager
16+
- android:android.hardware.camera2.CameraDevice
17+
- android:android.hardware.camera2.CameraCharacteristics
18+
- android:android.hardware.camera2.CameraCaptureSession
19+
- android:android.hardware.camera2.CaptureRequest
20+
- android:android.hardware.camera2.CaptureResult
21+
- android:android.view.TextureView
1222
license: apache2

Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ private void process(CaptureResult result) {
266266
int afState = result.get(CaptureResult.CONTROL_AF_STATE);
267267
if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
268268
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
269-
int aeState = result.get(CaptureResult.CONTROL_AE_STATE);
270-
if (aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
269+
// CONTROL_AE_STATE can be null on some devices
270+
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
271+
if (aeState == null ||
272+
aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
271273
mState = STATE_WAITING_NON_PRECAPTURE;
272274
captureStillPicture();
273275
} else {
@@ -277,17 +279,19 @@ private void process(CaptureResult result) {
277279
break;
278280
}
279281
case STATE_WAITING_PRECAPTURE: {
280-
int aeState = result.get(CaptureResult.CONTROL_AE_STATE);
281-
if (CaptureResult.CONTROL_AE_STATE_PRECAPTURE == aeState) {
282-
mState = STATE_WAITING_NON_PRECAPTURE;
283-
} else if (CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED == aeState) {
282+
// CONTROL_AE_STATE can be null on some devices
283+
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
284+
if (aeState == null ||
285+
aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
286+
aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
284287
mState = STATE_WAITING_NON_PRECAPTURE;
285288
}
286289
break;
287290
}
288291
case STATE_WAITING_NON_PRECAPTURE: {
289-
int aeState = result.get(CaptureResult.CONTROL_AE_STATE);
290-
if (CaptureResult.CONTROL_AE_STATE_PRECAPTURE != aeState) {
292+
// CONTROL_AE_STATE can be null on some devices
293+
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
294+
if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
291295
mState = STATE_PICTURE_TAKEN;
292296
captureStillPicture();
293297
}

CONTRIB.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# How to become a contributor and submit your own code
2+
3+
## Contributor License Agreements
4+
5+
We'd love to accept your sample apps and patches! Before we can take them, we
6+
have to jump a couple of legal hurdles.
7+
8+
Please fill out either the individual or corporate Contributor License Agreement (CLA).
9+
10+
* If you are an individual writing original source code and you're sure you
11+
own the intellectual property, then you'll need to sign an [individual CLA]
12+
(https://developers.google.com/open-source/cla/individual).
13+
* If you work for a company that wants to allow you to contribute your work,
14+
then you'll need to sign a [corporate CLA]
15+
(https://developers.google.com/open-source/cla/corporate).
16+
17+
Follow either of the two links above to access the appropriate CLA and
18+
instructions for how to sign and return it. Once we receive it, we'll be able to
19+
accept your pull requests.
20+
21+
## Contributing A Patch
22+
23+
1. Submit an issue describing your proposed change to the repo in question.
24+
1. The repo owner will respond to your issue promptly.
25+
1. If your proposed change is accepted, and you haven't already done so, sign a
26+
Contributor License Agreement (see details above).
27+
1. Fork the desired repo, develop and test your code changes.
28+
1. Ensure that your code adheres to the existing style in the sample to which
29+
you are contributing. Refer to the
30+
[Android Code Style Guide]
31+
(https://source.android.com/source/code-style.html) for the
32+
recommended coding standards for this organization.
33+
1. Ensure that your code has an appropriate set of unit tests which all pass.
34+
1. Submit a pull request.
35+

NOTICE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This sample uses the following software:
2+
3+
Copyright 2014 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
Android Camera2Basic Sample
22
===================================
33

4-
This sample demonstrates the basic use of Camera2 API. Check the source code to see how
5-
you can display camera preview and take pictures.
4+
This sample demonstrates how to use basic functionalities of Camera2
5+
API. You can learn how to iterate through characteristics of all the
6+
cameras attached to the device, display a camera preview, and take
7+
pictures.
8+
9+
Introduction
10+
------------
11+
12+
The [Camera2 API][1] provides an interface to individual camera
13+
devices connected to an Android device. It replaces the deprecated
14+
Camera class.
15+
16+
Use [getCameraIdList][2] to get a list of all the available
17+
cameras. You can then use [getCameraCharacteristics][3] and find the
18+
best camera that suits your need (front/rear facing, resolution etc).
19+
20+
Create an instance of [CameraDevice.StateCallback][4] and open a
21+
camera. It is ready to start camera preview when the camera is opened.
22+
23+
This sample uses TextureView to show the camera preview. Create a
24+
[CameraCaptureSession][5] and set a repeating [CaptureRequest][6] to it.
25+
26+
Still image capture takes several steps. First, you need to lock the
27+
focus of the camera by updating the CaptureRequest for the camera
28+
preview. Then, in a similar way, you need to run a precapture
29+
sequence. After that, it is ready to capture a picture. Create a new
30+
CaptureRequest and call [capture][7]. Don't forget to unlock the focus
31+
when you are done.
32+
33+
[1]: https://developer.android.com/reference/android/hardware/camera2/package-summary.html
34+
[2]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraIdList()
35+
[3]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraCharacteristics(java.lang.String)
36+
[4]: https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html
37+
[5]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html
38+
[6]: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html
39+
[7]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler)
640

741
Pre-requisites
842
--------------
@@ -11,6 +45,11 @@ Pre-requisites
1145
- Android Build Tools v21.1.1
1246
- Android Support Repository
1347

48+
Screenshots
49+
-------------
50+
51+
<img src="screenshots/main.png" height="400" alt="Screenshot"/>
52+
1453
Getting Started
1554
---------------
1655

screenshots/icon-web.png

63.4 KB
Loading

screenshots/main.png

1.16 MB
Loading

0 commit comments

Comments
 (0)