-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added camera switch mode: Front/Back #97
base: 2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
package="com.miguelbcr.ui.rx_paparazzo2.sample"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA"/> | ||
<uses-feature android:name="android.hardware.camera" android:required="false" /> | ||
<uses-feature android:name="android.hardware.camera.front" android:required="false" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice :) |
||
|
||
<application | ||
android:icon="@mipmap/ic_launcher" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.miguelbcr.ui.rx_paparazzo2.entities; | ||
|
||
public enum CameraMode { | ||
|
||
FRONT, | ||
|
||
BACK | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Maybe without spaces?
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,12 @@ | |
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.hardware.Camera; | ||
import android.net.Uri; | ||
import android.provider.MediaStore; | ||
import android.support.v4.content.FileProvider; | ||
|
||
import com.miguelbcr.ui.rx_paparazzo2.entities.CameraMode; | ||
import com.miguelbcr.ui.rx_paparazzo2.entities.Config; | ||
import com.miguelbcr.ui.rx_paparazzo2.entities.FileData; | ||
import com.miguelbcr.ui.rx_paparazzo2.entities.TargetUi; | ||
|
@@ -69,7 +71,7 @@ public FileData apply(Uri uri) throws Exception { | |
|
||
private Function<Intent, Uri> revokeFileReadWritePermissions(final TargetUi targetUi, final Uri uri) { | ||
return new Function<Intent, Uri>() { | ||
@Override public Uri apply(Intent data) throws Exception { | ||
@Override public Uri apply(Intent data) { | ||
PermissionUtil.revokeFileReadWritePermissions(targetUi, uri); | ||
|
||
return uri; | ||
|
@@ -94,6 +96,16 @@ private Intent getIntentCamera(Uri uri) { | |
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | ||
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); | ||
|
||
if (CameraMode.FRONT.equals(config.getCameraMode())) { | ||
intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); | ||
intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1); | ||
intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that Instead, suggests to use I can see that I wonder if you have tested it in several android versions just to make sure it works, for instance, API 18, 21, 22, 27 I'll try it too... |
||
} else { | ||
intent.putExtra("android.intent.extras.CAMERA_FACING", Camera.CameraInfo.CAMERA_FACING_BACK); | ||
intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 0); | ||
intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", false); | ||
} | ||
|
||
return PermissionUtil.requestReadWritePermission(targetUi, intent, uri); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very good with English 😓 , but maybe this sentence is clearer, wdyt?
And what about adding a reminder to put this lines in the manifest?: