Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom menu API #453

Merged
merged 16 commits into from
Sep 11, 2018
Prev Previous commit
Next Next commit
Update doc
  • Loading branch information
JoshLipan committed Sep 11, 2018
commit d408210f4ecf732ad96129a9f2cddd6747a33ea2
14 changes: 6 additions & 8 deletions Android/chatinput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ mChatInput.setCameraCaptureFile(path, fileName);
```

## MenuManager(从0.9.0版本开始支持)
菜单功能管理类,用于添加自定义菜单,自由设置菜单项的位置,包括输入框的左边/右边/下边位置
菜单功能管理类,用于添加自定义菜单,自由设置菜单项的位置,包括输入框的左边/右边/下边位置

### 获取MenuManager

Expand All @@ -275,9 +275,7 @@ mChatInput.setCameraCaptureFile(path, fileName);

### 添加自定义菜单

`

1. 添加菜单项布局,根节点为MenuItem(继承自LinearLayout)
1. 添加菜单项布局,根节点为MenuItem(继承自LinearLayout)
```xml
<cn.jiguang.imui.chatinput.menu.view.MenuItem
android:layout_width="match_parent"
Expand All @@ -288,7 +286,7 @@ mChatInput.setCameraCaptureFile(path, fileName);
</cn.jiguang.imui.chatinput.menu.view.MenuItem>
```

2. 添加对应菜单功能布局,根节点为MenuFeature(继承自LinearLayout
2. 添加对应菜单功能布局,根节点为MenuFeature(继承自LinearLayout
```xml
<cn.jiguang.imui.chatinput.menu.view.MenuFeature
android:layout_width="match_parent"
Expand Down Expand Up @@ -331,7 +329,7 @@ menuManager.setCustomMenuClickListener(new CustomMenuEventListener() {
`setMenu(Menu menu)`

#### Menu
通过传入菜单项的tag来控制布局,默认可使用的布局tag有
通过传入菜单项的tag来控制布局,默认可使用的布局tag有
```Java
Menu.TAG_VOICE
Menu.TAG_EMOJI
Expand All @@ -349,12 +347,12 @@ Menu.newBuilder().
setBottom(String ... tag).//输入框下侧菜单项
build()
```
#### 示例
#### 示例
```java
menuManager.setMenu(Menu.newBuilder().
customize(true).
setRight(Menu.TAG_SEND).
setBottom(Menu.TAG_VOICE,Menu.TAG_EMOJI,Menu.TAG_GALLERY,Menu.TAG_CAMERA,"MY_CUSTOM").
setBottom(Menu.TAG_VOICE,Menu.TAG_EMOJI,Menu.TAG_GALLERY,Menu.TAG_CAMERA).
build());
```

Expand Down
93 changes: 93 additions & 0 deletions Android/chatinput/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,98 @@ Since 0.4.5, take picture will return default path.
mChatInput.setCameraCaptureFile(path, fileName);
```

## MenuManager(Support since 0.9.0)

Menu management class, used to add a custom menu, freely set the position of the menu item, including the left/right/lower position of the chatinput.

### Get MenuManager

`MenuManager menuManager = mChatInput.getMenuManager();`


### Add custom menu

1. Add custom menu item layout,the root node has to be MenuItem(Extends LinearLayout)
```xml
<cn.jiguang.imui.chatinput.menu.view.MenuItem
android:layout_width="match_parent"
android:layout_height="match_parent">

...

</cn.jiguang.imui.chatinput.menu.view.MenuItem>
```

2. Add custom menu feature layout,the root node has to be MenuFeature(Extends LinearLayout)
```xml
<cn.jiguang.imui.chatinput.menu.view.MenuFeature
android:layout_width="match_parent"
android:layout_height="match_parent">

...

</cn.jiguang.imui.chatinput.menu.view.MenuFeature>
```
3. Add custom menu by MenuManager
```java
//First:add view mode, tag must be unique
//If set menuFeature as null means that this menu item does not require a corresponding function.
addCustomMenu(String tag, MenuItem menuItem, MenuFeature menuFeature)

//Second: add layout resources, tag must be unique
//If set menuFeatureResource as -1 means that this menu item does not require a corresponding function.
addCustomMenu(String tag, int menuItemResource, int menuFeatureResource)
```
4. CustomMenuEventListener
```java
menuManager.setCustomMenuClickListener(new CustomMenuEventListener() {
@Override
public boolean onMenuItemClick(String tag, MenuItem menuItem) {
//Menu feature will not be shown if return false;
return true;
}

@Override
public void onMenuFeatureVisibilityChanged(int visibility, String tag, MenuFeature menuFeature) {
if(visibility == View.VISIBLE){
// Menu feature is visible.
}else {
// Menu feature is gone.
}
}
});
```
### Set the position of the menu item
`setMenu(Menu menu)`

#### Menu

The position is controlled by passing in the tag of the menu item. The default layout tags are:

```Java
Menu.TAG_VOICE
Menu.TAG_EMOJI
Menu.TAG_GALLERY
Menu.TAG_CAMERA
Menu.TAG_SEND
```
Set position,tag cannot be repeated:

```java
Menu.newBuilder().
customize(boolean customize).// Whether to customize the position
setLeft(String ... tag).// Set left menu items
setRight(String ... tag).// Set right menu items
setBottom(String ... tag).//Set bottom menu items
build()
```
#### Sample
```java
menuManager.setMenu(Menu.newBuilder().
customize(true).
setRight(Menu.TAG_SEND).
setBottom(Menu.TAG_VOICE,Menu.TAG_EMOJI,Menu.TAG_GALLERY,Menu.TAG_CAMERA).
build());
```