Repository: hzitoun/android-camera2-secret-picture-taker
Branch: master
Commit: 885408d834f2
Files: 29
Total size: 43.2 KB
Directory structure:
gitextract_b0o9xqpx/
├── .gitignore
├── .idea/
│ ├── gradle.xml
│ └── runConfigurations.xml
├── .travis.yml
├── LICENSE
├── README.md
├── app/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── hzitoun/
│ │ └── camera2SecretPictureTaker/
│ │ └── ExampleInstrumentedTest.java
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── hzitoun/
│ │ │ └── camera2SecretPictureTaker/
│ │ │ ├── activities/
│ │ │ │ └── MainActivity.java
│ │ │ ├── listeners/
│ │ │ │ └── PictureCapturingListener.java
│ │ │ └── services/
│ │ │ ├── APictureCapturingService.java
│ │ │ └── PictureCapturingServiceImpl.java
│ │ └── res/
│ │ ├── layout/
│ │ │ └── activity_main.xml
│ │ ├── values/
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── values-w820dp/
│ │ └── dimens.xml
│ └── test/
│ └── java/
│ └── com/
│ └── hzitoun/
│ └── camera2SecretPictureTaker/
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
# User-specific configurations
.idea/libraries/
.idea/workspace.xml
.idea/tasks.xml
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
.idea/datasources.xml
.idea/dataSources.ids
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
================================================
FILE: .idea/gradle.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
================================================
FILE: .idea/runConfigurations.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
================================================
FILE: .travis.yml
================================================
language: android
jdk: oraclejdk8
env:
android:
components:
- tools
- build-tools-25.0.2
- android-25
- platform-tools
- extra-android-m2repository
before_install:
- chmod +x gradlew
install:
- echo y | android update sdk -u -a -t tools
- echo y | android update sdk -u -a -t platform-tools
- echo y | android update sdk -u -a -t build-tools-25.0.2
- echo y | android update sdk -u -a -t android-25
- echo y | android update sdk -u -a -t extra-google-m2repository
- echo y | android update sdk -u -a -t extra-android-m2repository
script:
- ./gradlew assembleRelease
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2019 Hamed ZITOUN <zitoun.hamed@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
<img align="right" width="200" height="200" src="https://user-images.githubusercontent.com/34313493/44617202-8d051180-a880-11e8-8788-b52580aea56e.jpg">
[](https://travis-ci.org/hzitoun/android-camera2-secret-picture-taker)
# 📸 Android Camera2 Secret Picture Taker (AC2SPT)
Take pictures secretly (without preview or launching device's camera app) from all available cameras using Android CAMERA2 API.
The <a href="https://developer.android.com/reference/android/hardware/camera2/package-summary.html">Camera2 API</a> replaces the deprecated Camera class.
___
## How can I support this project?
- If you have enjoyed the project and it helped you creating a project, building an app, starting a business. You could encourage and support me on patreon https://www.patreon.com/hzitoun 🤗 !
- Star this GitHub repo :star:
- Create pull requests, submit bugs, suggest new features or documentation updates :wrench:
## Usage
1. Implement the interface <a href="https://github.com/hzitoun/android-camera2-secret-picture-taker/blob/master/app/src/main/java/com/hzitoun/camera2SecretPictureTaker/listeners/PictureCapturingListener.java">```PictureCapturingListener```</a> (your capture listener) and override the following methods:
- **void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken)** which is called when we've done taking pictures from ALL available cameras OR when NO camera was detected on the device;
- **void onCaptureDone(String pictureUrl, byte[] pictureData)** to get a couple (picture Url, picture Data). Use this method if you don't want to wait for ALL pictures to be ready;
2. Create a new instance of <a href="https://github.com/hzitoun/android-camera2-secret-picture-taker/blob/master/app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/APictureCapturingService.java">```APictureCapturingService``` </a> using <a href="https://github.com/hzitoun/android-camera2-secret-picture-taker/blob/master/app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/PictureCapturingServiceImpl.java">```PictureCapturingServiceImpl#getInstance()```</a> method;
3. **Start capture** by calling the method ```APictureCapturingService#startCapturing(PictureCapturingListener listener) ``` and pass the listener you've just implemented (**step 1**)
## Sample
Here, I've chosen to just display the two pictures taken within a vertical linear layout. Here is a code snippet of how to use the service:
```java
public class MainActivity extends AppCompatActivity implements PictureCapturingListener, ActivityCompat.OnRequestPermissionsResultCallback {
private APictureCapturingService pictureService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//check for camera and external storage permissions
checkPermissions();
final Button btn = (Button) findViewById(R.id.startCaptureBtn);
pictureService = PictureCapturingServiceImpl.getInstance(this);
//start capturing when clicking on the button
btn.setOnClickListener(v ->
pictureService.startCapturing(this)
);
}
@Override
public void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken) {
if (picturesTaken != null && !picturesTaken.isEmpty()) {
picturesTaken.forEach((pictureUrl, pictureData) -> {
//convert the byte array 'pictureData' to a bitmap (no need to read the file from the external storage) but in case you
//You can also use 'pictureUrl' which stores the picture's location on the device
final Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0, pictureData.length);
});
showToast("Done capturing all photos!");
return;
}
showToast("No camera detected!");
}
@Override
public void onCaptureDone(String pictureUrl, byte[] pictureData) {
if (pictureData != null && pictureUrl != null) {
runOnUiThread(() -> {
//convert byte array 'pictureData' to a bitmap (no need to read the file from the external storage)
final Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0, pictureData.length);
//scale image to avoid POTENTIAL "Bitmap too large to be uploaded into a texture" when displaying into an ImageView
final int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
final Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 512, nh, true);
//do whatever you want with the bitmap or the scaled one...
});
showToast("Picture saved to " + pictureUrl);
}
}
private void showToast(final String text) {
runOnUiThread(() ->
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show()
);
}
}
```
Thanks to [maaudrana](https://github.com/maaudrana) for the logo :)
## Contributors
Hamed ZITOUN <zitoun.hamed@gmail.com>
## Help
If you run into issues, please don't hesitate to find help on the GitHub project.
## License
The android-camera2-secret-picture-taker is covered by the MIT License.
The MIT License (MIT)
Copyright (c) 2022 Hamed ZITOUN and contributors to the android-camera2-secret-picture-taker project.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.hzitoun.camera2secretpicturetaker"
minSdkVersion 21
targetSdkVersion 25
versionCode 2
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\hamed\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: app/src/androidTest/java/com/hzitoun/camera2SecretPictureTaker/ExampleInstrumentedTest.java
================================================
package com.hzitoun.camera2SecretPictureTaker;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.hzitoun.camera2secretpicturetaker", appContext.getPackageName());
}
}
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hzitoun.camera2SecretPictureTaker">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.hzitoun.camera2SecretPictureTaker.activities.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
================================================
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/activities/MainActivity.java
================================================
package com.hzitoun.camera2SecretPictureTaker.activities;
import android.Manifest;
import android.annotation.TargetApi;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.hzitoun.camera2SecretPictureTaker.R;
import com.hzitoun.camera2SecretPictureTaker.listeners.PictureCapturingListener;
import com.hzitoun.camera2SecretPictureTaker.services.APictureCapturingService;
import com.hzitoun.camera2SecretPictureTaker.services.PictureCapturingServiceImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
/**
* App's Main Activity showing a simple usage of the picture taking service.
* @author hzitoun (zitoun.hamed@gmail.com)
*/
public class MainActivity extends AppCompatActivity implements PictureCapturingListener, ActivityCompat.OnRequestPermissionsResultCallback {
private static final String[] requiredPermissions = {
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
};
private static final int MY_PERMISSIONS_REQUEST_ACCESS_CODE = 1;
private ImageView uploadBackPhoto;
private ImageView uploadFrontPhoto;
//The capture service
private APictureCapturingService pictureService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkPermissions();
uploadBackPhoto = (ImageView) findViewById(R.id.backIV);
uploadFrontPhoto = (ImageView) findViewById(R.id.frontIV);
final Button btn = (Button) findViewById(R.id.startCaptureBtn);
// getting instance of the Service from PictureCapturingServiceImpl
pictureService = PictureCapturingServiceImpl.getInstance(this);
btn.setOnClickListener(v -> {
showToast("Starting capture!");
pictureService.startCapturing(this);
});
}
private void showToast(final String text) {
runOnUiThread(() ->
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show()
);
}
/**
* We've finished taking pictures from all phone's cameras
*/
@Override
public void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken) {
if (picturesTaken != null && !picturesTaken.isEmpty()) {
showToast("Done capturing all photos!");
return;
}
showToast("No camera detected!");
}
/**
* Displaying the pictures taken.
*/
@Override
public void onCaptureDone(String pictureUrl, byte[] pictureData) {
if (pictureData != null && pictureUrl != null) {
runOnUiThread(() -> {
final Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0, pictureData.length);
final int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
final Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 512, nh, true);
if (pictureUrl.contains("0_pic.jpg")) {
uploadBackPhoto.setImageBitmap(scaled);
} else if (pictureUrl.contains("1_pic.jpg")) {
uploadFrontPhoto.setImageBitmap(scaled);
}
});
showToast("Picture saved to " + pictureUrl);
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_ACCESS_CODE: {
if (!(grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
checkPermissions();
}
}
}
}
/**
* checking permissions at Runtime.
*/
@TargetApi(Build.VERSION_CODES.M)
private void checkPermissions() {
final List<String> neededPermissions = new ArrayList<>();
for (final String permission : requiredPermissions) {
if (ContextCompat.checkSelfPermission(getApplicationContext(),
permission) != PackageManager.PERMISSION_GRANTED) {
neededPermissions.add(permission);
}
}
if (!neededPermissions.isEmpty()) {
requestPermissions(neededPermissions.toArray(new String[]{}),
MY_PERMISSIONS_REQUEST_ACCESS_CODE);
}
}
}
================================================
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/listeners/PictureCapturingListener.java
================================================
package com.hzitoun.camera2SecretPictureTaker.listeners;
import java.util.TreeMap;
/**
* Picture capturing listener
*
* @author hzitoun (zitoun.hamed@gmail.com)
*/
public interface PictureCapturingListener {
/**
* a callback called when we've done taking a picture from a single camera
* (use this method if you don't want to wait for ALL taken pictures to be ready @see onDoneCapturingAllPhotos)
*
* @param pictureUrl taken picture's location on the device
* @param pictureData taken picture's data as a byte array
*/
void onCaptureDone(String pictureUrl, byte[] pictureData);
/**
* a callback called when we've done taking pictures from ALL AVAILABLE cameras
* OR when NO camera was detected on the device
*
* @param picturesTaken : a Map<PictureUrl, PictureData>
*/
void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken);
}
================================================
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/APictureCapturingService.java
================================================
package com.hzitoun.camera2SecretPictureTaker.services;
import android.app.Activity;
import android.content.Context;
import android.hardware.camera2.CameraManager;
import android.util.SparseIntArray;
import android.view.Surface;
import com.hzitoun.camera2SecretPictureTaker.listeners.PictureCapturingListener;
/**
* Abstract Picture Taking Service.
*
* @author hzitoun (zitoun.hamed@gmail.com)
*/
public abstract class APictureCapturingService {
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
ORIENTATIONS.append(Surface.ROTATION_0, 90);
ORIENTATIONS.append(Surface.ROTATION_90, 0);
ORIENTATIONS.append(Surface.ROTATION_180, 270);
ORIENTATIONS.append(Surface.ROTATION_270, 180);
}
private final Activity activity;
final Context context;
final CameraManager manager;
/***
* constructor.
*
* @param activity the activity used to get display manager and the application context
*/
APictureCapturingService(final Activity activity) {
this.activity = activity;
this.context = activity.getApplicationContext();
this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
}
/***
* @return orientation
*/
int getOrientation() {
final int rotation = this.activity.getWindowManager().getDefaultDisplay().getRotation();
return ORIENTATIONS.get(rotation);
}
/**
* starts pictures capturing process.
*
* @param listener picture capturing listener
*/
public abstract void startCapturing(final PictureCapturingListener listener);
}
================================================
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/PictureCapturingServiceImpl.java
================================================
package com.hzitoun.camera2SecretPictureTaker.services;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.graphics.ImageFormat;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.Image;
import android.media.ImageReader;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.util.Size;
import android.view.Surface;
import com.hzitoun.camera2SecretPictureTaker.listeners.PictureCapturingListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.TreeMap;
import java.util.UUID;
/**
* The aim of this service is to secretly take pictures (without preview or opening device's camera app)
* from all available cameras using Android Camera 2 API
*
* @author hzitoun (zitoun.hamed@gmail.com)
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP) //NOTE: camera 2 api was added in API level 21
public class PictureCapturingServiceImpl extends APictureCapturingService {
private static final String TAG = PictureCapturingServiceImpl.class.getSimpleName();
private CameraDevice cameraDevice;
private ImageReader imageReader;
/***
* camera ids queue.
*/
private Queue<String> cameraIds;
private String currentCameraId;
private boolean cameraClosed;
/**
* stores a sorted map of (pictureUrlOnDisk, PictureData).
*/
private TreeMap<String, byte[]> picturesTaken;
private PictureCapturingListener capturingListener;
/***
* private constructor, meant to force the use of {@link #getInstance} method
*/
private PictureCapturingServiceImpl(final Activity activity) {
super(activity);
}
/**
* @param activity the activity used to get the app's context and the display manager
* @return a new instance
*/
public static APictureCapturingService getInstance(final Activity activity) {
return new PictureCapturingServiceImpl(activity);
}
/**
* Starts pictures capturing treatment.
*
* @param listener picture capturing listener
*/
@Override
public void startCapturing(final PictureCapturingListener listener) {
this.picturesTaken = new TreeMap<>();
this.capturingListener = listener;
this.cameraIds = new LinkedList<>();
try {
final String[] cameraIds = manager.getCameraIdList();
if (cameraIds.length > 0) {
this.cameraIds.addAll(Arrays.asList(cameraIds));
this.currentCameraId = this.cameraIds.poll();
openCamera();
} else {
//No camera detected!
capturingListener.onDoneCapturingAllPhotos(picturesTaken);
}
} catch (final CameraAccessException e) {
Log.e(TAG, "Exception occurred while accessing the list of cameras", e);
}
}
private void openCamera() {
Log.d(TAG, "opening camera " + currentCameraId);
try {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
manager.openCamera(currentCameraId, stateCallback, null);
}
} catch (final CameraAccessException e) {
Log.e(TAG, " exception occurred while opening camera " + currentCameraId, e);
}
}
private final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
if (picturesTaken.lastEntry() != null) {
capturingListener.onCaptureDone(picturesTaken.lastEntry().getKey(), picturesTaken.lastEntry().getValue());
Log.i(TAG, "done taking picture from camera " + cameraDevice.getId());
}
closeCamera();
}
};
private final ImageReader.OnImageAvailableListener onImageAvailableListener = (ImageReader imReader) -> {
final Image image = imReader.acquireLatestImage();
final ByteBuffer buffer = image.getPlanes()[0].getBuffer();
final byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
saveImageToDisk(bytes);
image.close();
};
private final CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
@Override
public void onOpened(@NonNull CameraDevice camera) {
cameraClosed = false;
Log.d(TAG, "camera " + camera.getId() + " opened");
cameraDevice = camera;
Log.i(TAG, "Taking picture from camera " + camera.getId());
//Take the picture after some delay. It may resolve getting a black dark photos.
new Handler().postDelayed(() -> {
try {
takePicture();
} catch (final CameraAccessException e) {
Log.e(TAG, " exception occurred while taking picture from " + currentCameraId, e);
}
}, 500);
}
@Override
public void onDisconnected(@NonNull CameraDevice camera) {
Log.d(TAG, " camera " + camera.getId() + " disconnected");
if (cameraDevice != null && !cameraClosed) {
cameraClosed = true;
cameraDevice.close();
}
}
@Override
public void onClosed(@NonNull CameraDevice camera) {
cameraClosed = true;
Log.d(TAG, "camera " + camera.getId() + " closed");
//once the current camera has been closed, start taking another picture
if (!cameraIds.isEmpty()) {
takeAnotherPicture();
} else {
capturingListener.onDoneCapturingAllPhotos(picturesTaken);
}
}
@Override
public void onError(@NonNull CameraDevice camera, int error) {
Log.e(TAG, "camera in error, int code " + error);
if (cameraDevice != null && !cameraClosed) {
cameraDevice.close();
}
}
};
private void takePicture() throws CameraAccessException {
if (null == cameraDevice) {
Log.e(TAG, "cameraDevice is null");
return;
}
final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraDevice.getId());
Size[] jpegSizes = null;
StreamConfigurationMap streamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (streamConfigurationMap != null) {
jpegSizes = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG);
}
final boolean jpegSizesNotEmpty = jpegSizes != null && 0 < jpegSizes.length;
int width = jpegSizesNotEmpty ? jpegSizes[0].getWidth() : 640;
int height = jpegSizesNotEmpty ? jpegSizes[0].getHeight() : 480;
final ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
final List<Surface> outputSurfaces = new ArrayList<>();
outputSurfaces.add(reader.getSurface());
final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(reader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation());
reader.setOnImageAvailableListener(onImageAvailableListener, null);
cameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
try {
session.capture(captureBuilder.build(), captureListener, null);
} catch (final CameraAccessException e) {
Log.e(TAG, " exception occurred while accessing " + currentCameraId, e);
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession session) {
}
}
, null);
}
private void saveImageToDisk(final byte[] bytes) {
final String cameraId = this.cameraDevice == null ? UUID.randomUUID().toString() : this.cameraDevice.getId();
final File file = new File(Environment.getExternalStorageDirectory() + "/" + cameraId + "_pic.jpg");
try (final OutputStream output = new FileOutputStream(file)) {
output.write(bytes);
this.picturesTaken.put(file.getPath(), bytes);
} catch (final IOException e) {
Log.e(TAG, "Exception occurred while saving picture to external storage ", e);
}
}
private void takeAnotherPicture() {
this.currentCameraId = this.cameraIds.poll();
openCamera();
}
private void closeCamera() {
Log.d(TAG, "closing camera " + cameraDevice.getId());
if (null != cameraDevice && !cameraClosed) {
cameraDevice.close();
cameraDevice = null;
}
if (null != imageReader) {
imageReader.close();
imageReader = null;
}
}
}
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hzitoun.camera2SecretPictureTaker.activities.MainActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_shadow">
<ImageView
android:id="@+id/backIV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/back_picture" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_shadow">
<ImageView
android:id="@+id/frontIV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/front_picture" />
</RelativeLayout>
<Button
android:id="@+id/startCaptureBtn"
android:background="@drawable/bg_shadow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/take_pic_btn_label" />
</LinearLayout>
</ScrollView>
================================================
FILE: app/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
================================================
FILE: app/src/main/res/values/dimens.xml
================================================
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
================================================
FILE: app/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">Camera 2 Secret Picture Taker</string>
<string name="take_pic_btn_label">Take photos</string>
<string name="front_picture">Front Camera Picture</string>
<string name="back_picture">Back Camera Picture</string>
</resources>
================================================
FILE: app/src/main/res/values/styles.xml
================================================
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
================================================
FILE: app/src/main/res/values-w820dp/dimens.xml
================================================
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
================================================
FILE: app/src/test/java/com/hzitoun/camera2SecretPictureTaker/ExampleUnitTest.java
================================================
package com.hzitoun.camera2SecretPictureTaker;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
include ':app'
gitextract_b0o9xqpx/ ├── .gitignore ├── .idea/ │ ├── gradle.xml │ └── runConfigurations.xml ├── .travis.yml ├── LICENSE ├── README.md ├── app/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── hzitoun/ │ │ └── camera2SecretPictureTaker/ │ │ └── ExampleInstrumentedTest.java │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── hzitoun/ │ │ │ └── camera2SecretPictureTaker/ │ │ │ ├── activities/ │ │ │ │ └── MainActivity.java │ │ │ ├── listeners/ │ │ │ │ └── PictureCapturingListener.java │ │ │ └── services/ │ │ │ ├── APictureCapturingService.java │ │ │ └── PictureCapturingServiceImpl.java │ │ └── res/ │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ ├── values/ │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── values-w820dp/ │ │ └── dimens.xml │ └── test/ │ └── java/ │ └── com/ │ └── hzitoun/ │ └── camera2SecretPictureTaker/ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle
SYMBOL INDEX (32 symbols across 6 files)
FILE: app/src/androidTest/java/com/hzitoun/camera2SecretPictureTaker/ExampleInstrumentedTest.java
class ExampleInstrumentedTest (line 17) | @RunWith(AndroidJUnit4.class)
method useAppContext (line 19) | @Test
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/activities/MainActivity.java
class MainActivity (line 32) | public class MainActivity extends AppCompatActivity implements PictureCa...
method onCreate (line 46) | @Override
method showToast (line 62) | private void showToast(final String text) {
method onDoneCapturingAllPhotos (line 71) | @Override
method onCaptureDone (line 83) | @Override
method onRequestPermissionsResult (line 100) | @Override
method checkPermissions (line 116) | @TargetApi(Build.VERSION_CODES.M)
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/listeners/PictureCapturingListener.java
type PictureCapturingListener (line 10) | public interface PictureCapturingListener {
method onCaptureDone (line 19) | void onCaptureDone(String pictureUrl, byte[] pictureData);
method onDoneCapturingAllPhotos (line 27) | void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken);
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/APictureCapturingService.java
class APictureCapturingService (line 16) | public abstract class APictureCapturingService {
method APictureCapturingService (line 36) | APictureCapturingService(final Activity activity) {
method getOrientation (line 45) | int getOrientation() {
method startCapturing (line 56) | public abstract void startCapturing(final PictureCapturingListener lis...
FILE: app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/PictureCapturingServiceImpl.java
class PictureCapturingServiceImpl (line 50) | @TargetApi(Build.VERSION_CODES.LOLLIPOP) //NOTE: camera 2 api was added ...
method PictureCapturingServiceImpl (line 73) | private PictureCapturingServiceImpl(final Activity activity) {
method getInstance (line 81) | public static APictureCapturingService getInstance(final Activity acti...
method startCapturing (line 90) | @Override
method openCamera (line 110) | private void openCamera() {
method onCaptureCompleted (line 126) | @Override
method onOpened (line 149) | @Override
method onDisconnected (line 165) | @Override
method onClosed (line 174) | @Override
method onError (line 187) | @Override
method takePicture (line 197) | private void takePicture() throws CameraAccessException {
method saveImageToDisk (line 237) | private void saveImageToDisk(final byte[] bytes) {
method takeAnotherPicture (line 248) | private void takeAnotherPicture() {
method closeCamera (line 253) | private void closeCamera() {
FILE: app/src/test/java/com/hzitoun/camera2SecretPictureTaker/ExampleUnitTest.java
class ExampleUnitTest (line 12) | public class ExampleUnitTest {
method addition_isCorrect (line 13) | @Test
Condensed preview — 29 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (48K chars).
[
{
"path": ".gitignore",
"chars": 525,
"preview": "*.iml\n.gradle\n/local.properties\n/.idea/workspace.xml\n/.idea/libraries\n.DS_Store\n/build\n/captures\n.externalNativeBuild\n# "
},
{
"path": ".idea/gradle.xml",
"chars": 626,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"GradleSettings\">\n <option name=\"linke"
},
{
"path": ".idea/runConfigurations.xml",
"chars": 564,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"RunConfigurationProducerService\">\n <o"
},
{
"path": ".travis.yml",
"chars": 594,
"preview": "language: android\njdk: oraclejdk8\nenv:\nandroid:\n components:\n - tools\n - build-tools-25.0.2\n - android-25\n - platfo"
},
{
"path": "LICENSE",
"chars": 1094,
"preview": "MIT License\n\nCopyright (c) 2019 Hamed ZITOUN <zitoun.hamed@gmail.com>\n\nPermission is hereby granted, free of charge, to "
},
{
"path": "README.md",
"chars": 6539,
"preview": "<img align=\"right\" width=\"200\" height=\"200\" src=\"https://user-images.githubusercontent.com/34313493/44617202-8d051180-a8"
},
{
"path": "app/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "app/build.gradle",
"chars": 1075,
"preview": "apply plugin: 'com.android.application'\n\nandroid {\n compileSdkVersion 25\n buildToolsVersion \"25.0.2\"\n defaultCo"
},
{
"path": "app/proguard-rules.pro",
"chars": 671,
"preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in C:"
},
{
"path": "app/src/androidTest/java/com/hzitoun/camera2SecretPictureTaker/ExampleInstrumentedTest.java",
"chars": 778,
"preview": "package com.hzitoun.camera2SecretPictureTaker;\n\nimport android.content.Context;\nimport android.support.test.Instrumentat"
},
{
"path": "app/src/main/AndroidManifest.xml",
"chars": 1018,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package="
},
{
"path": "app/src/main/java/com/hzitoun/camera2SecretPictureTaker/activities/MainActivity.java",
"chars": 4914,
"preview": "package com.hzitoun.camera2SecretPictureTaker.activities;\n\nimport android.Manifest;\nimport android.annotation.TargetApi;"
},
{
"path": "app/src/main/java/com/hzitoun/camera2SecretPictureTaker/listeners/PictureCapturingListener.java",
"chars": 923,
"preview": "package com.hzitoun.camera2SecretPictureTaker.listeners;\n\nimport java.util.TreeMap;\n\n/**\n * Picture capturing listener\n "
},
{
"path": "app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/APictureCapturingService.java",
"chars": 1666,
"preview": "package com.hzitoun.camera2SecretPictureTaker.services;\n\nimport android.app.Activity;\nimport android.content.Context;\nim"
},
{
"path": "app/src/main/java/com/hzitoun/camera2SecretPictureTaker/services/PictureCapturingServiceImpl.java",
"chars": 10534,
"preview": "package com.hzitoun.camera2SecretPictureTaker.services;\n\nimport android.Manifest;\nimport android.annotation.TargetApi;\ni"
},
{
"path": "app/src/main/res/layout/activity_main.xml",
"chars": 2218,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScrollView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n androi"
},
{
"path": "app/src/main/res/values/colors.xml",
"chars": 208,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"colorPrimary\">#3F51B5</color>\n <color name=\"color"
},
{
"path": "app/src/main/res/values/dimens.xml",
"chars": 211,
"preview": "<resources>\n <!-- Default screen margins, per the Android Design guidelines. -->\n <dimen name=\"activity_horizontal"
},
{
"path": "app/src/main/res/values/strings.xml",
"chars": 275,
"preview": "<resources>\n <string name=\"app_name\">Camera 2 Secret Picture Taker</string>\n <string name=\"take_pic_btn_label\">Tak"
},
{
"path": "app/src/main/res/values/styles.xml",
"chars": 300,
"preview": "<resources>\n <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\">\n <item name=\"colorPrimary\">@"
},
{
"path": "app/src/main/res/values-w820dp/dimens.xml",
"chars": 358,
"preview": "<resources>\n <!-- Example customization of dimensions originally defined in res/values/dimens.xml\n (such as s"
},
{
"path": "app/src/test/java/com/hzitoun/camera2SecretPictureTaker/ExampleUnitTest.java",
"chars": 415,
"preview": "package com.hzitoun.camera2SecretPictureTaker;\n\nimport org.junit.Test;\n\nimport static org.junit.Assert.*;\n\n/**\n * Exampl"
},
{
"path": "build.gradle",
"chars": 498,
"preview": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n r"
},
{
"path": "gradle/wrapper/gradle-wrapper.properties",
"chars": 233,
"preview": "#Mon Dec 28 10:00:20 PST 2015\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_"
},
{
"path": "gradle.properties",
"chars": 730,
"preview": "# Project-wide Gradle settings.\n\n# IDE (e.g. Android Studio) users:\n# Gradle settings configured through the IDE *will o"
},
{
"path": "gradlew",
"chars": 4971,
"preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n## Gradle start "
},
{
"path": "gradlew.bat",
"chars": 2314,
"preview": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem "
},
{
"path": "settings.gradle",
"chars": 15,
"preview": "include ':app'\n"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the hzitoun/android-camera2-secret-picture-taker GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 29 files (43.2 KB), approximately 11.1k tokens, and a symbol index with 32 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.