Fixed back/front camera init

pull/17/head
florent champigny 8 years ago
parent fcf03a4a44
commit a7dc19664f
  1. 6
      app/src/main/AndroidManifest.xml
  2. 3
      app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java
  3. 13
      camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera1Controller.java
  4. 16
      camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera2Controller.java

@ -24,6 +24,12 @@
android:name="com.github.florent37.camerafragment.sample.MainActivityCustoms"
android:screenOrientation="portrait"
android:theme="@style/ThemeFullscreen" >
</activity>
<activity
android:name="com.github.florent37.camerafragment.sample.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/ThemeFullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

@ -146,7 +146,8 @@ public class MainActivity extends AppCompatActivity {
addCameraButton.setVisibility(View.GONE);
cameraLayout.setVisibility(View.VISIBLE);
final CameraFragment cameraFragment = CameraFragment.newInstance(new Configuration.Builder().build());
final CameraFragment cameraFragment = CameraFragment.newInstance(new Configuration.Builder()
.setCamera(Configuration.CAMERA_FACE_FRONT).build());
getSupportFragmentManager().beginTransaction()
.replace(R.id.content, cameraFragment, FRAGMENT_TAG)
.commit();

@ -6,8 +6,6 @@ import android.support.annotation.Nullable;
import android.util.Log;
import android.view.SurfaceHolder;
import java.io.File;
import com.github.florent37.camerafragment.configuration.Configuration;
import com.github.florent37.camerafragment.configuration.ConfigurationProvider;
import com.github.florent37.camerafragment.internal.controller.CameraController;
@ -23,6 +21,8 @@ import com.github.florent37.camerafragment.internal.utils.CameraHelper;
import com.github.florent37.camerafragment.internal.utils.Size;
import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
import java.io.File;
/*
* Created by memfis on 7/7/16.
*/
@ -101,15 +101,16 @@ public class Camera1Controller implements CameraController<Integer>,
public void switchCamera(@Configuration.CameraFace final int cameraFace) {
final Integer backCameraId = cameraManager.getFaceBackCameraId();
final Integer frontCameraId = cameraManager.getFaceFrontCameraId();
final Integer currentCameraId = cameraManager.getCurrentCameraId();
if(cameraManager.getCurrentCameraId().equals(frontCameraId)){
if (cameraFace == Configuration.CAMERA_FACE_REAR && backCameraId != null && !backCameraId.equals(currentCameraId)) {
setCurrentCameraId(backCameraId);
} else {
cameraManager.closeCamera(this);
} else if (frontCameraId != null && !frontCameraId.equals(currentCameraId)) {
setCurrentCameraId(frontCameraId);
}
cameraManager.closeCamera(this);
}
}
@Override
public void setFlashMode(@Configuration.FlashMode int flashMode) {

@ -8,8 +8,6 @@ import android.support.annotation.Nullable;
import android.util.Log;
import android.view.TextureView;
import java.io.File;
import com.github.florent37.camerafragment.configuration.Configuration;
import com.github.florent37.camerafragment.configuration.ConfigurationProvider;
import com.github.florent37.camerafragment.internal.controller.CameraController;
@ -25,6 +23,8 @@ import com.github.florent37.camerafragment.internal.utils.CameraHelper;
import com.github.florent37.camerafragment.internal.utils.Size;
import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
import java.io.File;
/*
* Created by memfis on 7/6/16.
*/
@ -96,10 +96,18 @@ public class Camera2Controller implements CameraController<String>,
@Override
public void switchCamera(final @Configuration.CameraFace int cameraFace) {
setCurrentCameraId(camera2Manager.getCurrentCameraId().equals(camera2Manager.getFaceFrontCameraId()) ?
camera2Manager.getFaceBackCameraId() : camera2Manager.getFaceFrontCameraId());
final String currentCameraId = camera2Manager.getCurrentCameraId();
final String faceFrontCameraId = camera2Manager.getFaceFrontCameraId();
final String faceBackCameraId = camera2Manager.getFaceBackCameraId();
if (cameraFace == Configuration.CAMERA_FACE_REAR && faceBackCameraId != null && !faceBackCameraId.equals(currentCameraId)) {
setCurrentCameraId(faceBackCameraId);
camera2Manager.closeCamera(this);
} else if (faceFrontCameraId != null && !faceFrontCameraId.equals(currentCameraId)) {
setCurrentCameraId(faceFrontCameraId);
camera2Manager.closeCamera(this);
}
}
private void setCurrentCameraId(String currentCameraId){

Loading…
Cancel
Save