Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
fix(android): Fix Objects.equals that is only available after API 19 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoccazinsp authored and sibelius committed Dec 10, 2019
1 parent 047bbea commit 8c6a26f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.atomic.AtomicBoolean;

import org.reactnative.camera.utils.ObjectUtils;


@SuppressWarnings("deprecation")
class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
Expand Down Expand Up @@ -342,13 +343,13 @@ int getFacing() {
@Override
void setCameraId(String id) {

if(!Objects.equals(_mCameraId, id)){
if(!ObjectUtils.equals(_mCameraId, id)){
_mCameraId = id;

// only update if our camera ID actually changes
// from what we currently have.
// Passing null will always yield true
if(!Objects.equals(_mCameraId, String.valueOf(mCameraId))){
if(!ObjectUtils.equals(_mCameraId, String.valueOf(mCameraId))){
// this will call chooseCamera
mBgHandler.post(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;

import org.reactnative.camera.utils.ObjectUtils;



@SuppressWarnings("MissingPermission")
@TargetApi(21)
class Camera2 extends CameraViewImpl implements MediaRecorder.OnInfoListener, MediaRecorder.OnErrorListener {
Expand Down Expand Up @@ -366,13 +369,13 @@ int getFacing() {

@Override
void setCameraId(String id) {
if(!Objects.equals(_mCameraId, id)){
if(!ObjectUtils.equals(_mCameraId, id)){
_mCameraId = id;

// only update if our camera ID actually changes
// from what we currently have.
// Passing null will always yield true
if(!Objects.equals(_mCameraId, mCameraId)){
if(!ObjectUtils.equals(_mCameraId, mCameraId)){
// this will call chooseCameraIdByFacing
if (isCameraOpened()) {
stop();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.reactnative.camera.utils;


public class ObjectUtils {

/*
* Replacement for Objects.equals that is only available after Android API 19
*/
public static boolean equals(Object o1, Object o2) {
if (o1 == null && o2 == null) return true;
if (o1 == null) return false;
return o1.equals(o2);
}

}

0 comments on commit 8c6a26f

Please sign in to comment.