Skip to content

Commit

Permalink
Merge pull request #227 from jpush/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KenChoi1992 authored Jan 11, 2018
2 parents ba89d90 + 16b89e4 commit f724952
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 30 deletions.
9 changes: 4 additions & 5 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.2'
compile 'cn.jiguang.imui:chatinput:0.6.3'
```

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

Expand Down Expand Up @@ -73,8 +73,7 @@ chatInputView.setMenuContainerHeight(softInputHeight);

**初始化后一定要设置一下 MenuContainer 的高度,最好设置为软键盘的高度,否则会导致第一次打开菜单时高度不正常(此时打开软键盘会导致界面伸缩)。**

建议在跳转到聊天界面之前使用 onSizeChanged 方法监听软键盘的高度,然后在初始化的时候设置即可,
关于监听软键盘高度的方法可以参考 sample 下的 MessageListActivity 及 ChatView 中的 onSizeChanged 相关方法。
建议在跳转到聊天界面之前使用 onSizeChanged 方法监听软键盘的高度,然后在初始化的时候设置即可。

## 重要接口及事件
ChatInputView 提供了各种按钮及事件的监听回调,所以用户可以灵活地运用监听事件做一些操作,如发送消息等事件。
Expand Down
14 changes: 7 additions & 7 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.2'
compile 'cn.jiguang.imui:chatinput:0.6.3'
```

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

Expand Down Expand Up @@ -72,16 +72,16 @@ ChatInputView chatInputView = (ChatInputView) findViewById(R.id.chat_input);
chatInputView.setMenuContainerHeight(softInputHeight);
```

Attention please, **MUST** set MenuContainer's height after init ChatInputView. Best suggestion: get
soft keyboard height from other activity(Like login Activity), then set soft keyboard height via:
**Attention please, for perfect display, MUST set MenuContainer's height after init ChatInputView.**

Best suggestion: get soft keyboard height from other activity(Like login Activity, just before chat Activity), then set soft keyboard height via:

```java
ChatInputView chatinput = (ChatInputView) findViewById(R.id.chat_input);
chatinput.setMenuContainerHeight(softKeyboardHeight);
```

As for how to get soft keyboard height, you can listen `onSizeChanged` method.
Please [refer onSizeChanged in sample's MessageListActivity](./../sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/messages/MessageListActivity.java#L340),
and [onSizedChanged in sample's ChatView](./../sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java#L102).


## Import interface and event
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.6.2'
PUBLISH_VERSION = '0.6.3'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class ChatInputView extends LinearLayout
private int mSoftKeyboardHeight;
private int mNowh;
private int mOldh;
public static int sMenuHeight = 800;
public static int sMenuHeight = 831;

private boolean mShowSoftInput = false;

Expand Down Expand Up @@ -1216,8 +1216,10 @@ public void onGlobalLayout() {
mNowh = mHeight - r.bottom;
if (mOldh != -1 && mNowh != mOldh) {
mShowSoftInput = mNowh > 0;
mSoftKeyboardHeight = mShowSoftInput ? mNowh : 0;
sMenuHeight = mSoftKeyboardHeight;
if (mShowSoftInput) {
mSoftKeyboardHeight = mNowh;
sMenuHeight = mSoftKeyboardHeight;
}
}
mOldh = mNowh;
} catch (Exception e) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Build;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.util.LruCache;
import android.view.View;
Expand Down Expand Up @@ -75,10 +76,12 @@ public void onBind(final MESSAGE message) {
mMsgTv.setLayoutParams(params);
}
String text = message.getText();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
mMsgTv.setText(Html.fromHtml(text, new MyImageGetter(), null));
} else {
mMsgTv.setText(Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT, new MyImageGetter(), null));
if (!TextUtils.isEmpty(text)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
mMsgTv.setText(Html.fromHtml(text, new MyImageGetter(), null));
} else {
mMsgTv.setText(Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT, new MyImageGetter(), null));
}
}

if (message.getTimeString() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class ReactChatInputManager extends ViewGroupManager<ChatInputView> {
private static final String ON_FULL_SCREEN_EVENT = "onFullScreen";
private static final String ON_RECOVER_SCREEN_EVENT = "onRecoverScreen";
private static final String ON_INPUT_SIZE_CHANGED_EVENT = "onSizeChange";
private static final String ON_CLICK_SELECT_ALBUM_EVENT = "onClickSelectAlbum";
private final int REQUEST_PERMISSION = 0x0001;
private final int CLOSE_SOFT_INPUT = 100;
private final int GET_INPUT_TEXT = 101;
Expand All @@ -91,8 +92,12 @@ public class ReactChatInputManager extends ViewGroupManager<ChatInputView> {
private boolean mInitState = true;
private boolean mShowMenu = false;
private double mCurrentInputHeight = 48;
private int InitialChatInputHeight = 100;
private int mInitialChatInputHeight = 100;
private int mScreenWidth;
/**
* Initial soft input height, set this value via {@link #setMenuContainerHeight}
*/
private int mMenuContainerHeight = 831;

@Override
public String getName() {
Expand Down Expand Up @@ -163,7 +168,7 @@ public boolean onSendTextMessage(CharSequence input) {
return false;
}
WritableMap map = Arguments.createMap();
map.putDouble("height", InitialChatInputHeight);
map.putDouble("height", mInitialChatInputHeight);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, map);
WritableMap event = Arguments.createMap();
event.putString("text", input.toString());
Expand Down Expand Up @@ -274,7 +279,7 @@ public void onStartRecord() {
@Override
public void onFinishRecord(File voiceFile, int duration) {
WritableMap event = Arguments.createMap();
event.putString("mediaPath", voiceFile.getName());
event.putString("mediaPath", voiceFile.getAbsolutePath());
event.putInt("duration", duration);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(),
FINISH_RECORD_VOICE_EVENT, event);
Expand Down Expand Up @@ -304,7 +309,7 @@ public void onRecoverScreenClick() {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(),
ON_RECOVER_SCREEN_EVENT, null);
WritableMap map = Arguments.createMap();
map.putDouble("height", InitialChatInputHeight + mChatInput.getSoftKeyboardHeight() / density);
map.putDouble("height", mInitialChatInputHeight + mChatInput.getSoftKeyboardHeight() / density);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, map);
}

Expand All @@ -318,6 +323,12 @@ public void onSwitchCameraModeClick() {

}
});
mChatInput.getSelectAlbumBtn().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_CLICK_SELECT_ALBUM_EVENT, null);
}
});
return mChatInput;
}

Expand All @@ -332,12 +343,16 @@ private void initMenu(float density) {
EventBus.getDefault().post(new ScrollEvent(true));
}
WritableMap event = Arguments.createMap();
event.putDouble("height", InitialChatInputHeight + mChatInput.getSoftKeyboardHeight() / density);
if (mChatInput.getSoftKeyboardHeight() == 0) {
event.putDouble("height", mInitialChatInputHeight + mMenuContainerHeight / density);
} else {
event.putDouble("height", mInitialChatInputHeight + mChatInput.getSoftKeyboardHeight() / density);
}
mContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, event);
}

private double calculateMenuHeight(float density) {
double layoutHeight = InitialChatInputHeight;
double layoutHeight = mInitialChatInputHeight;
if (mShowMenu) {
layoutHeight += mChatInput.getSoftKeyboardHeight() / density;
}
Expand Down Expand Up @@ -378,7 +393,7 @@ public void onEvent(StopPlayVoiceEvent event) {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(OnTouchMsgListEvent event) {
WritableMap map = Arguments.createMap();
map.putDouble("height", InitialChatInputHeight);
map.putDouble("height", mInitialChatInputHeight);
mContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, map);
}

Expand All @@ -391,7 +406,8 @@ public void setBackgroundColor(ChatInputView chatInputView, String color) {
@ReactProp(name = "menuContainerHeight")
public void setMenuContainerHeight(ChatInputView chatInputView, int height) {
Log.d("ReactChatInputManager", "Setting menu container height: " + height);
chatInputView.setMenuContainerHeight(height);
mMenuContainerHeight = height;
// chatInputView.setMenuContainerHeight(height);
}

@ReactProp(name = "isDismissMenuContainer")
Expand All @@ -408,6 +424,11 @@ public void setEditTextHeight(ChatInputView chatInputView, int height) {
editText.setLayoutParams(new LinearLayout.LayoutParams(mWidth, height));
}

@ReactProp(name = "showSelectAlbumBtn")
public void showSelectAlbumBtn(ChatInputView chatInputView, boolean flag) {
chatInputView.getSelectAlbumBtn().setVisibility(flag? View.VISIBLE: View.GONE);
}

@Override
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
return MapBuilder.<String, Object>builder()
Expand All @@ -428,6 +449,7 @@ public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
.put(ON_FULL_SCREEN_EVENT, MapBuilder.of("registrationName", ON_FULL_SCREEN_EVENT))
.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))
.build();
}

Expand Down Expand Up @@ -460,7 +482,7 @@ public void receiveCommand(ChatInputView root, int commandId, @Nullable Readable
float dp = mContext.getResources().getDisplayMetrics().density;
mContext.getCurrentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
if (mInitState) {
event.putDouble("height", InitialChatInputHeight);
event.putDouble("height", mInitialChatInputHeight);
} else {
event.putDouble("height", calculateMenuHeight(dp));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurora-imui-react-native",
"version": "0.6.8",
"version": "0.6.9",
"description": "aurora imui plugin for react native application",
"main": "index.js",

Expand Down

0 comments on commit f724952

Please sign in to comment.