Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLipan committed Aug 29, 2018
2 parents 913da5b + 6db523d commit 658060a
Show file tree
Hide file tree
Showing 40 changed files with 1,568 additions and 867 deletions.
2 changes: 1 addition & 1 deletion Android/chatinput/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'cn.jiguang.imui'
PUBLISH_ARTIFACT_ID = 'chatinput'
PUBLISH_VERSION = '0.8.2'
PUBLISH_VERSION = '0.8.3'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ public void run() {
mCameraSupport.cancelRecordingVideo();
mSwitchCameraBtn.setBackgroundResource(R.drawable.aurora_preview_switch_camera);
mRecordVideoBtn.setBackgroundResource(R.drawable.aurora_preview_camera);
mRecordVideoBtn.setVisibility(VISIBLE);
showRecordVideoBtn();

mVideoFilePath = null;
mFinishRecordingVideo = false;
mIsRecordVideoMode = true;
Expand Down Expand Up @@ -814,6 +815,7 @@ public void initCamera() {
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
mCameraId = i;
mIsBackCamera = true;
break;
}
}
Expand Down Expand Up @@ -935,7 +937,7 @@ public void run() {
height);
mTextureView.setLayoutParams(params);
mRecordVideoBtn.setBackgroundResource(R.drawable.aurora_preview_record_video);
mRecordVideoBtn.setVisibility(VISIBLE);
showRecordVideoBtn();
mSwitchCameraBtn.setBackgroundResource(R.drawable.aurora_preview_switch_camera);
mSwitchCameraBtn.setVisibility(VISIBLE);
mCaptureBtn.setBackgroundResource(R.drawable.aurora_menuitem_send_pres);
Expand Down Expand Up @@ -1010,6 +1012,16 @@ public void showCameraLayout() {
mCameraFl.setVisibility(VISIBLE);
}

public void showRecordVideoBtn(){
if(mRecordVideoBtn.getTag()!=null && mRecordVideoBtn.getTag() instanceof String && ((String)mRecordVideoBtn.getTag()).equals("GONE")){
mRecordVideoBtn.setVisibility(GONE);
}else {
mRecordVideoBtn.setVisibility(VISIBLE);
}

}


public void dismissCameraLayout() {
if (mCameraSupport != null) {
mCameraSupport.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private void process(CaptureResult result) {
if (afState == null) {
captureStillPicture();
} else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED == afState ||
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
// CONTROL_AE_STATE can be null on some devices
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
Expand Down Expand Up @@ -352,6 +353,8 @@ public void onError(@NonNull CameraDevice camera, int error) {
}
};

private Surface mSurface;

/**
* Creates a new {@link CameraCaptureSession} for camera preview.
*/
Expand All @@ -364,14 +367,17 @@ private void createCameraPreviewSession() {
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

// This is the output Surface we need to start preview.
Surface surface = new Surface(texture);
if(mSurface != null){
mSurface.release();
}
mSurface = new Surface(texture);

// We set up a CaptureRequest.Builder with the output Surface.
mPreviewRequestBuilder
= mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);
mPreviewRequestBuilder.addTarget(mSurface);
// Here, we create a CameraCaptureSession for camera preview.
mCamera.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
mCamera.createCaptureSession(Arrays.asList(mSurface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {

@Override
Expand Down Expand Up @@ -513,6 +519,10 @@ public void release() {
mImageReader.close();
mImageReader = null;
}
if(mSurface != null){
mSurface.release();
mSurface = null ;
}
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException("Interrupted while trying to lock camera closing.", e);
Expand Down Expand Up @@ -711,8 +721,8 @@ private void captureStillPicture() {
setAutoFlash(captureBuilder);

// Orientation
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
mCameraCharacteristic.get(CameraCharacteristics.SENSOR_ORIENTATION));
// captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
// mCameraCharacteristic.get(CameraCharacteristics.SENSOR_ORIENTATION));

CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
Expand Down Expand Up @@ -789,20 +799,27 @@ public void run() {
new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.getDefault()).format(new Date())
+ ".jpg");
output = new FileOutputStream(mPhoto);

// 前置摄像头水平翻转照片
Matrix matrix = new Matrix();
Bitmap rotateBmp;
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
int w = bmp.getWidth();
int h = bmp.getHeight();
if (!mIsFacingBack) {
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
int w = bmp.getWidth();
int h = bmp.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(-1, 1);
Bitmap convertBmp = Bitmap.createBitmap(bmp, 0, 0, w, h, matrix, true);
convertBmp.compress(Bitmap.CompressFormat.JPEG, 100, output);
matrix.postScale(-1, 1);
matrix.postRotate(90);
rotateBmp = Bitmap.createBitmap(bmp, 0, 0, w, h, matrix, true);
} else {
output.write(bytes);
matrix.postRotate(90);
rotateBmp = Bitmap.createBitmap(bmp, 0, 0, w, h, matrix, true);
}
rotateBmp.compress(Bitmap.CompressFormat.JPEG, 100, output);

if (mOnCameraCallbackListener != null) {
if(mLastPhoto != null && mLastPhoto.getAbsolutePath().equals(mPhoto.getAbsolutePath())) // Forbid repeat
return;
Log.i(TAG,"Saved capture into "+ mPhoto.getAbsolutePath());
mOnCameraCallbackListener.onTakePictureCompleted(mPhoto.getAbsolutePath());
mLastPhoto = mPhoto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void setVoiceFilePath(String path, String fileName) {
}
//录音文件的命名格式
myRecAudioFile = new File(path, fileName + ".m4a");
myRecAudioFile.setReadable(true,false);
Log.i(TAG, "Create file success file path: " + myRecAudioFile.getAbsolutePath());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public boolean switchToCameraMode() {
EasyPermissions.requestPermissions(MessageListActivity.this,
getResources().getString(R.string.rationale_camera),
RC_CAMERA, perms);
return false;
} else {
File rootDir = getFilesDir();
String fileDir = rootDir.getAbsolutePath() + "/photo";
Expand Down
2 changes: 1 addition & 1 deletion ReactNative/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'cn.jiguang.imui:messagelist:0.7.4'
compile 'cn.jiguang.imui:chatinput:0.8.2'
compile 'cn.jiguang.imui:chatinput:0.8.3'
compile 'pub.devrel:easypermissions:1.0.1'
compile 'org.greenrobot:eventbus:3.0.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class ReactChatInputManager extends ViewGroupManager<ChatInputView> imple
private int mSoftKeyboardHeight;
private double mLineExpend = 0;
private int mScreenWidth;
private String mLastPhotoPath = "";
/**
* Initial soft input height, set this value via {@link #setMenuContainerHeight}
*/
Expand Down Expand Up @@ -335,6 +336,7 @@ public boolean switchToCameraMode() {
EasyPermissions.requestPermissions(activity,
activity.getResources().getString(R.string.rationale_camera),
RC_CAMERA, perms);
return false;
}
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(),
SWITCH_TO_CAMERA_EVENT, null);
Expand Down Expand Up @@ -402,6 +404,12 @@ public void run() {
mChatInput.setOnCameraCallbackListener(new OnCameraCallbackListener() {
@Override
public void onTakePictureCompleted(String photoPath) {

if(mLastPhotoPath.equals(photoPath)){
return;
}
mLastPhotoPath = photoPath;

if (mChatInput.isFullScreen()) {
mContext.runOnUiQueueThread(new Runnable() {
@Override
Expand All @@ -422,6 +430,7 @@ public void run() {
event.putDouble("size", file.length());
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(),
TAKE_PICTURE_EVENT, event);
mChatInput.dismissMenuLayout();
}

@Override
Expand Down Expand Up @@ -673,7 +682,13 @@ public void showSelectAlbumBtn(ChatInputView chatInputView, boolean flag) {

@ReactProp(name = "showRecordVideoBtn")
public void showRecordVideoBtn(ChatInputView chatInputView, boolean flag) {
chatInputView.getRecordVideoBtn().setVisibility(flag ? View.VISIBLE : View.GONE);
if(flag){
chatInputView.getRecordVideoBtn().setVisibility(View.VISIBLE);
chatInputView.getRecordVideoBtn().setTag("VISIBLE");
}else{
chatInputView.getRecordVideoBtn().setVisibility(View.GONE);
chatInputView.getRecordVideoBtn().setTag("GONE");
}
}

@ReactProp(name = "inputPadding")
Expand Down
Loading

0 comments on commit 658060a

Please sign in to comment.