Skip to content

Commit

Permalink
Merge pull request #453 from jpush/dev
Browse files Browse the repository at this point in the history
Add custom menu API
  • Loading branch information
JoshLipan committed Sep 11, 2018
2 parents a18f066 + 0b0db28 commit c8210a5
Show file tree
Hide file tree
Showing 35 changed files with 1,136 additions and 236 deletions.
104 changes: 101 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.8.3'
compile 'cn.jiguang.imui:chatinput:0.9.0'
```

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

Expand Down Expand Up @@ -265,3 +265,101 @@ mChatInput.setCameraControllerListener(new CameraControllerListener() {
mChatInput.setCameraCaptureFile(path, fileName);
```

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

### 获取MenuManager

`MenuManager menuManager = mChatInput.getMenuManager();`


### 添加自定义菜单

1. 添加菜单项布局,根节点为MenuItem(继承自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. 添加对应菜单功能布局,根节点为MenuFeature(继承自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. 通过MenuManager添加自定义菜单,
```java
//第一种:添加view方式,tag唯一
//menuFeature 传 null 即表示此菜单项不需要对应功能
addCustomMenu(String tag, MenuItem menuItem, MenuFeature menuFeature)

//第二种:添加布局资源,tag唯一
//menuFeatureResource 传 -1 即表示此菜单项不需要对应功能
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.
}
}
});
```
### 设置菜单项的位置
`setMenu(Menu menu)`

#### Menu
通过传入菜单项的tag来控制布局,默认可使用的布局tag有:
```Java
Menu.TAG_VOICE
Menu.TAG_EMOJI
Menu.TAG_GALLERY
Menu.TAG_CAMERA
Menu.TAG_SEND
```
设置位置,tag不能重复:

```java
Menu.newBuilder().
customize(boolean customize).//是否自定义位置
setLeft(String ... tag).//输入框左侧菜单项
setRight(String ... tag).//输入框右侧菜单项
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).
build());
```








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());
```


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.3'
PUBLISH_VERSION = '0.9.0'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ChatInputStyle extends Style {

private int inputMarginLeft;
private int inputMarginRight;
private int inputMarginBottom;
private int inputMarginTop;
private int inputMaxLines;

private String inputText;
Expand Down Expand Up @@ -57,6 +59,10 @@ public static ChatInputStyle parse(Context context, AttributeSet attrs) {
style.getDimension(R.dimen.aurora_margin_input_left));
style.inputMarginRight = typedArray.getDimensionPixelSize(R.styleable.ChatInputView_inputMarginRight,
style.getDimension(R.dimen.aurora_margin_input_right));
style.inputMarginBottom = typedArray.getDimensionPixelSize(R.styleable.ChatInputView_inputMarginBottom,
style.getDimension(R.dimen.aurora_margin_input_bottom));
style.inputMarginTop = typedArray.getDimensionPixelSize(R.styleable.ChatInputView_inputMarginTop,
style.getDimension(R.dimen.aurora_margin_input_top));
style.inputMaxLines = typedArray.getInt(R.styleable.ChatInputView_inputMaxLines, DEFAULT_MAX_LINES);
style.inputHint = typedArray.getString(R.styleable.ChatInputView_inputHint);
style.inputText = typedArray.getString(R.styleable.ChatInputView_inputText);
Expand Down Expand Up @@ -116,6 +122,14 @@ public int getInputMarginRight() {
return this.inputMarginRight;
}

public int getInputMarginTop() {
return this.inputMarginTop;
}

public int getInputMarginBottom() {
return this.inputMarginBottom;
}

public int getInputMaxLines() {
return this.inputMaxLines;
}
Expand Down
Loading

0 comments on commit c8210a5

Please sign in to comment.