Skip to content

Commit

Permalink
Merge pull request #311 from jpush/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KenChoi1992 authored Mar 22, 2018
2 parents e489913 + 2ecd518 commit 1e65cc0
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 43 deletions.
41 changes: 38 additions & 3 deletions Android/chatinput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

- Gradle
```groovy
compile 'cn.jiguang.imui:chatinput:0.6.7'
compile 'cn.jiguang.imui:chatinput:0.7.2'
```

- Maven
```
<dependency>
<groupId>cn.jiguang.imui</groupId>
<artifactId>chatinput</artifactId>
<version>0.6.7</version>
<version>0.7.2</version>
<type>pom</type>
</dependency>
```
Expand All @@ -42,7 +42,7 @@ compile 'cn.jiguang.imui:chatinput:0.6.7'
```groovy
dependencies {
compile 'com.github.jpush:imui:0.7.4'
compile 'com.github.jpush:imui:0.7.5'
}
```

Expand Down Expand Up @@ -201,7 +201,41 @@ mChatInput.setOnCameraCallbackListener(new OnCameraCallbackListener() {
});
```



#### CameraControllerListener

相机控制相关接口,包括全屏、拍照与录制视频切换、关闭相机等事件。

```
mChatInput.setCameraControllerListener(new CameraControllerListener() {
@Override
public void onFullScreenClick() {
}
@Override
public void onRecoverScreenClick() {
}
@Override
public void onCloseCameraClick() {
}
@Override
public void onSwitchCameraModeClick(boolean isRecordVideoMode) {
// 切换拍照与否,通过 isRecordVideoMode 判断
});
```





### 设置拍照后保存的文件(0.4.5 版本后弃用)

`setCameraCaptureFile(String path, String fileName)`

0.4.5 版本后拍照会返回默认路径。
Expand All @@ -211,3 +245,4 @@ mChatInput.setOnCameraCallbackListener(new OnCameraCallbackListener() {
// 0.4.5 后弃用
mChatInput.setCameraCaptureFile(path, fileName);
```

37 changes: 34 additions & 3 deletions Android/chatinput/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Provides several ways to add dependency, you can choose one of them:

- Via Gradle
```groovy
compile 'cn.jiguang.imui:chatinput:0.6.7'
compile 'cn.jiguang.imui:chatinput:0.7.2'
```

- Via Maven
Expand All @@ -20,7 +20,7 @@ compile 'cn.jiguang.imui:chatinput:0.6.7'
<dependency>
<groupId>cn.jiguang.imui</groupId>
<artifactId>chatinput</artifactId>
<version>0.6.7</version>
<version>0.7.2</version>
<type>pom</type>
</dependency>
```
Expand All @@ -41,7 +41,7 @@ allprojects {
```groovy
dependencies {
compile 'com.github.jpush:imui:0.7.4'
compile 'com.github.jpush:imui:0.7.5'
}
```

Expand Down Expand Up @@ -212,7 +212,38 @@ mChatInput.setOnCameraCallbackListener(new OnCameraCallbackListener() {
});
```



#### CameraControllerListener

Control camera interface, include full screen event, switch take picture/ record video event, close camera event, etc.

```
mChatInput.setCameraControllerListener(new CameraControllerListener() {
@Override
public void onFullScreenClick() {
}
@Override
public void onRecoverScreenClick() {
}
@Override
public void onCloseCameraClick() {
}
@Override
public void onSwitchCameraModeClick(boolean isRecordVideoMode) {
// Judge is take picture mode or record video mode by isRecordVideoMode.
});
```


#### Set file path and file name that after taken picture(Deprecated since 0.4.5)

setCameraCaptureFile(String path, String fileName)

Since 0.4.5, take picture will return default path.
Expand Down
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.7.1'
PUBLISH_VERSION = '0.7.2'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ public void onClick(View view) {
} else if (view.getId() == R.id.aurora_ib_camera_record_video) {
// click record video button
// if it is not record video mode
mCameraControllerListener.onSwitchCameraModeClick(!mIsRecordVideoMode);
if (!mIsRecordVideoMode) {
mIsRecordVideoMode = true;
mCaptureBtn.setBackgroundResource(R.drawable.aurora_preview_record_video_start);
Expand Down Expand Up @@ -626,6 +627,7 @@ public void run() {
}
} else if (view.getId() == R.id.aurora_ib_camera_close) {
try {
mCameraControllerListener.onCloseCameraClick();
mMediaPlayer.stop();
mMediaPlayer.release();
mCameraSupport.cancelRecordingVideo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public interface CameraControllerListener {
void onFullScreenClick();
void onRecoverScreenClick();
void onCloseCameraClick();
void onSwitchCameraModeClick();
void onSwitchCameraModeClick(boolean isRecordVideoMode);
}
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.6.7'
compile 'cn.jiguang.imui:chatinput:0.7.1'
compile 'cn.jiguang.imui:chatinput:0.7.2'
compile 'pub.devrel:easypermissions:0.4.0'
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 @@ -84,12 +84,14 @@ public class ReactChatInputManager extends ViewGroupManager<ChatInputView> imple
private static final String SWITCH_TO_CAMERA_EVENT = "onSwitchToCameraMode";
private static final String SWITCH_TO_EMOJI_EVENT = "onSwitchToEmojiMode";
private static final String TAKE_PICTURE_EVENT = "onTakePicture";
private static final String SWITCH_CAMERA_MODE_EVENT = "switchCameraMode";
private static final String START_RECORD_VIDEO_EVENT = "onStartRecordVideo";
private static final String FINISH_RECORD_VIDEO_EVENT = "onFinishRecordVideo";
private static final String CANCEL_RECORD_VIDEO_EVENT = "onCancelRecordVideo";
private static final String START_RECORD_VOICE_EVENT = "onStartRecordVoice";
private static final String FINISH_RECORD_VOICE_EVENT = "onFinishRecordVoice";
private static final String CANCEL_RECORD_VOICE_EVENT = "onCancelRecordVoice";
private static final String CLOSE_CAMERA_EVENT = "closeCamera";
private static final String ON_TOUCH_EDIT_TEXT_EVENT = "onTouchEditText";
private static final String ON_FULL_SCREEN_EVENT = "onFullScreen";
private static final String ON_RECOVER_SCREEN_EVENT = "onRecoverScreen";
Expand Down Expand Up @@ -411,12 +413,12 @@ public void onStartVideoRecord() {
public void onFinishVideoRecord(String videoPath) {
WritableMap event = Arguments.createMap();
event.putString("mediaPath", videoPath);
MediaPlayer mediaPlayer = MediaPlayer.create(reactContext, Uri.parse(videoPath));
int duration = mediaPlayer.getDuration() / 1000; // Millisecond to second.
mediaPlayer.release();
// MediaPlayer mediaPlayer = MediaPlayer.create(reactContext, Uri.parse(videoPath));
// int duration = mediaPlayer.getDuration() / 1000; // Millisecond to second.
// mediaPlayer.release();
File file = new File(videoPath);
event.putDouble("size", file.length());
event.putInt("duration", duration);
// event.putInt("duration", duration);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(),
FINISH_RECORD_VIDEO_EVENT, event);
}
Expand Down Expand Up @@ -465,22 +467,25 @@ public void onFullScreenClick() {

@Override
public void onRecoverScreenClick() {
mShowMenu = false;
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(),
ON_RECOVER_SCREEN_EVENT, null);
WritableMap map = Arguments.createMap();
Log.e(REACT_CHAT_INPUT, "send onSizeChangedEvent to js, height: " + mInitialChatInputHeight + mSoftKeyboardHeight / mDensity);
map.putDouble("height", mInitialChatInputHeight + mSoftKeyboardHeight / mDensity);
Log.e(REACT_CHAT_INPUT, "send onSizeChangedEvent to js, height: " + mInitialChatInputHeight + mLineExpend);
map.putDouble("height", mInitialChatInputHeight + mLineExpend);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, map);
}

@Override
public void onCloseCameraClick() {

reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), CLOSE_CAMERA_EVENT, null);
}

@Override
public void onSwitchCameraModeClick() {

public void onSwitchCameraModeClick(boolean isRecordVideoMode) {
WritableMap map = Arguments.createMap();
map.putBoolean("isRecordVideoMode", isRecordVideoMode);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), SWITCH_CAMERA_MODE_EVENT, map);
}
});
mChatInput.getSelectAlbumBtn().setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -682,6 +687,8 @@ public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
.put(ON_RECOVER_SCREEN_EVENT, MapBuilder.of("registrationName", ON_RECOVER_SCREEN_EVENT))
.put(ON_INPUT_SIZE_CHANGED_EVENT, MapBuilder.of("registrationName", ON_INPUT_SIZE_CHANGED_EVENT))
.put(ON_CLICK_SELECT_ALBUM_EVENT, MapBuilder.of("registrationName", ON_CLICK_SELECT_ALBUM_EVENT))
.put(SWITCH_CAMERA_MODE_EVENT, MapBuilder.of("registrationName", SWITCH_CAMERA_MODE_EVENT))
.put(CLOSE_CAMERA_EVENT, MapBuilder.of("registrationName", CLOSE_CAMERA_EVENT))
.build();
}

Expand Down
20 changes: 20 additions & 0 deletions ReactNative/chatinput.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export default class ChatInput extends Component {
this._onRecoverScreen = this._onRecoverScreen.bind(this);
this._onSizeChange = this._onSizeChange.bind(this);
this._onClickSelectAlbum = this._onClickSelectAlbum.bind(this);
this._closeCamera = this._closeCamera.bind(this);
this._switchCameraMode = this._switchCameraMode.bind(this);
}

_onSendText(event: Event) {
Expand Down Expand Up @@ -170,6 +172,20 @@ export default class ChatInput extends Component {
this.props.onClickSelectAlbum();
}

_closeCamera(event: Event) {
if (!this.props.closeCamera) {
return;
}
this.props.closeCamera();
}

_switchCameraMode(event: Event) {
if (!this.props.switchCameraMode) {
return;
}
this.props.switchCameraMode(event.nativeEvent.isRecordVideoMode);
}

setMenuContainerHeight(height) {
UIManager.dispatchViewManagerCommand(findNodeHandle(this.refs[CHAT_INPUT]), 99, [height]);
}
Expand Down Expand Up @@ -208,6 +224,8 @@ export default class ChatInput extends Component {
onRecoverScreen={this._onRecoverScreen}
onSizeChange={this._onSizeChange}
onClickSelectAlbum={this._onClickSelectAlbum}
closeCamera={this._closeCamera}
switchCameraMode={this._switchCameraMode}
/>
);
}
Expand Down Expand Up @@ -235,6 +253,8 @@ ChatInput.propTypes = {
onFullScreen: PropTypes.func,
onRecoverScreen: PropTypes.func,
onSizeChange: PropTypes.func,
closeCamera: PropTypes.func,
switchCameraMode: PropTypes.func,
inputViewHeight: PropTypes.number,
onClickSelectAlbum: PropTypes.func,
showSelectAlbumBtn: PropTypes.bool,
Expand Down
Loading

0 comments on commit 1e65cc0

Please sign in to comment.