Skip to content

Commit a106689

Browse files
committed
fixing warning and updating to version 1.0.1
1 parent c3be56e commit a106689

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

.idea/modules.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hzitoun.camera2secretpicturetaker"
88
minSdkVersion 21
99
targetSdkVersion 25
10-
versionCode 1
11-
versionName "1.0"
10+
versionCode 2
11+
versionName "1.0.1"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
jackOptions {
1414
enabled true

app/src/main/java/com/hzitoun/camera2SecretPictureTaker/activities/MainActivity.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
/**
29-
* App's Main Activity
29+
* App's Main Activity showing a simple usage of the picture taking service.
3030
*
3131
* @author hzitoun ([email protected])
3232
*/
@@ -107,6 +107,9 @@ public void onRequestPermissionsResult(int requestCode,
107107
}
108108
}
109109

110+
/**
111+
* checking permissions at Runtime.
112+
*/
110113
@TargetApi(Build.VERSION_CODES.M)
111114
private void checkPermissions() {
112115
final String[] requiredPermissions = {

app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/APictureCapturingService.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import com.hzitoun.camera2SecretPictureTaker.listeners.PictureCapturingListener;
1010

1111
/**
12-
* Abstract Picture taking service.
12+
* Abstract Picture Taking Service.
1313
*
1414
* @author hzitoun ([email protected])
1515
*/
1616
public abstract class APictureCapturingService {
1717

18-
public static final SparseIntArray ORIENTATIONS = new SparseIntArray();
18+
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
1919

2020
static {
2121
ORIENTATIONS.append(Surface.ROTATION_0, 90);
@@ -25,8 +25,8 @@ public abstract class APictureCapturingService {
2525
}
2626

2727
private final Activity activity;
28-
protected final Context context;
29-
protected final CameraManager manager;
28+
final Context context;
29+
final CameraManager manager;
3030

3131
/***
3232
* constructor.
@@ -40,9 +40,9 @@ public abstract class APictureCapturingService {
4040
}
4141

4242
/***
43-
* get display orientation
44-
* */
45-
protected int getOrientation() {
43+
* @return orientation
44+
*/
45+
int getOrientation() {
4646
final int rotation = this.activity.getWindowManager().getDefaultDisplay().getRotation();
4747
return ORIENTATIONS.get(rotation);
4848
}

app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/PictureCapturingServiceImpl.java

+23-20
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,38 @@
4141

4242
/**
4343
* The aim of this service is to secretly take pictures (without preview or opening device's camera app)
44-
* from all available cameras.
44+
* from all available cameras using Android Camera 2 API
4545
*
4646
* @author hzitoun ([email protected])
4747
*/
4848

49-
@TargetApi(Build.VERSION_CODES.LOLLIPOP) //camera 2 api was added in API level 21
49+
@TargetApi(Build.VERSION_CODES.LOLLIPOP) //NOTE: camera 2 api was added in API level 21
5050
public class PictureCapturingServiceImpl extends APictureCapturingService {
5151

5252
private static final String TAG = PictureCapturingServiceImpl.class.getSimpleName();
5353

54-
private boolean cameraClosed;
5554
private CameraDevice cameraDevice;
5655
private ImageReader imageReader;
56+
/***
57+
* camera ids queue.
58+
*/
59+
private Queue<String> cameraIds;
60+
private String currentCameraId;
61+
private boolean cameraClosed;
62+
/**
63+
* stores a sorted map of (pictureUrlOnDisk, PictureData).
64+
*/
5765
private TreeMap<String, byte[]> picturesTaken;
5866
private PictureCapturingListener capturingListener;
59-
private String currentCameraId;
60-
//camera ids queue;
61-
private Queue<String> cameraIds;
62-
6367

6468
/***
65-
* private constructor, meant to force the use of {@see getInstance} method
69+
* private constructor, meant to force the use of {@link #getInstance} method
6670
*/
6771
private PictureCapturingServiceImpl(final Activity activity) {
6872
super(activity);
6973
}
70-
71-
/**
74+
75+
/**
7276
* @param activity the activity used to get the app's context and the display manager
7377
* @return a new instance
7478
*/
@@ -92,9 +96,10 @@ public void startCapturing(final PictureCapturingListener listener) {
9296
this.currentCameraId = this.cameraIds.poll();
9397
openCamera();
9498
} else {
99+
//No camera detected!
95100
capturingListener.onDoneCapturingAllPhotos(picturesTaken);
96101
}
97-
} catch (CameraAccessException e) {
102+
} catch (final CameraAccessException e) {
98103
Log.e(TAG, "Exception occurred while accessing the list of cameras", e);
99104
}
100105
}
@@ -109,7 +114,7 @@ private void openCamera() {
109114
== PackageManager.PERMISSION_GRANTED) {
110115
manager.openCamera(currentCameraId, stateCallback, null);
111116
}
112-
} catch (CameraAccessException e) {
117+
} catch (final CameraAccessException e) {
113118
Log.e(TAG, " exception occurred while opening camera " + currentCameraId, e);
114119
}
115120
}
@@ -146,13 +151,12 @@ public void onOpened(@NonNull CameraDevice camera) {
146151
Log.i(TAG, "Taking picture from camera " + camera.getId());
147152
//Take the picture after some delay. It may resolve getting a black dark photos.
148153
new Handler().postDelayed(() -> {
149-
try {
150-
takePicture();
151-
} catch (CameraAccessException e) {
152-
Log.e(TAG, " exception occurred while taking picture from " + currentCameraId, e);
153-
}
154-
}
155-
, 500);
154+
try {
155+
takePicture();
156+
} catch (final CameraAccessException e) {
157+
Log.e(TAG, " exception occurred while taking picture from " + currentCameraId, e);
158+
}
159+
}, 500);
156160
}
157161

158162
@Override
@@ -255,5 +259,4 @@ private void closeCamera() {
255259
}
256260

257261

258-
259262
}

0 commit comments

Comments
 (0)