From 6f9e4d4d725a30bec11f590b6ca499a2588cce4a Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Mon, 10 Sep 2018 17:07:53 +0800 Subject: [PATCH 01/15] Add MenuManager class. --- .../imui/chatinput/ChatInputStyle.java | 14 + .../jiguang/imui/chatinput/ChatInputView.java | 45 ++- .../listener/CustomMenuEventListener.java | 21 ++ .../cn/jiguang/imui/chatinput/menu/Menu.java | 76 +++++ .../imui/chatinput/menu/MenuManager.java | 186 +++++++++++++ .../menu/collection/MenuCollection.java | 51 ++++ .../collection/MenuFeatureCollection.java | 32 +++ .../menu/collection/MenuItemCollection.java | 55 ++++ .../imui/chatinput/menu/view/MenuFeature.java | 21 ++ .../imui/chatinput/menu/view/MenuItem.java | 22 ++ .../chatinput/utils/SimpleCommonUtils.java | 4 + .../imui/chatinput/utils/ViewUtil.java | 10 + .../main/res/layout/layout_chatinput_menu.xml | 262 +++++++++--------- .../src/main/res/layout/menu_item_camera.xml | 25 ++ .../src/main/res/layout/menu_item_emoji.xml | 25 ++ .../src/main/res/layout/menu_item_photo.xml | 25 ++ .../src/main/res/layout/menu_item_send.xml | 42 +++ .../src/main/res/layout/menu_item_voice.xml | 25 ++ .../src/main/res/layout/view_chatinput.xml | 8 +- .../chatinput/src/main/res/values/attrs.xml | 2 + .../chatinput/src/main/res/values/dimens.xml | 2 + 21 files changed, 813 insertions(+), 140 deletions(-) create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/listener/CustomMenuEventListener.java create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/Menu.java create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuItemCollection.java create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuFeature.java create mode 100644 Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuItem.java create mode 100644 Android/chatinput/src/main/res/layout/menu_item_camera.xml create mode 100644 Android/chatinput/src/main/res/layout/menu_item_emoji.xml create mode 100644 Android/chatinput/src/main/res/layout/menu_item_photo.xml create mode 100644 Android/chatinput/src/main/res/layout/menu_item_send.xml create mode 100644 Android/chatinput/src/main/res/layout/menu_item_voice.xml diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputStyle.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputStyle.java index 1588edb0..b330cc9e 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputStyle.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputStyle.java @@ -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; @@ -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); @@ -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; } diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputView.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputView.java index fc619d39..2d97d8bb 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputView.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputView.java @@ -7,7 +7,6 @@ import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; -import android.content.res.Resources; import android.graphics.Rect; import android.graphics.SurfaceTexture; import android.graphics.drawable.Drawable; @@ -29,7 +28,6 @@ import android.util.TypedValue; import android.view.Display; import android.view.Gravity; -import android.view.MotionEvent; import android.view.Surface; import android.view.TextureView; import android.view.View; @@ -70,9 +68,11 @@ import cn.jiguang.imui.chatinput.listener.CameraEventListener; import cn.jiguang.imui.chatinput.listener.OnCameraCallbackListener; import cn.jiguang.imui.chatinput.listener.OnClickEditTextListener; +import cn.jiguang.imui.chatinput.listener.CustomMenuEventListener; import cn.jiguang.imui.chatinput.listener.OnFileSelectedListener; import cn.jiguang.imui.chatinput.listener.OnMenuClickListener; import cn.jiguang.imui.chatinput.listener.RecordVoiceListener; +import cn.jiguang.imui.chatinput.menu.MenuManager; import cn.jiguang.imui.chatinput.model.FileItem; import cn.jiguang.imui.chatinput.model.VideoItem; import cn.jiguang.imui.chatinput.photo.SelectPhotoView; @@ -178,6 +178,9 @@ public class ChatInputView extends LinearLayout private View mPhotoBtnContainer; private View mEmojiBtnContainer; + + private MenuManager mMenuManager; + public ChatInputView(Context context) { super(context); init(context); @@ -197,6 +200,12 @@ private void init(Context context) { mContext = context; inflate(context, R.layout.view_chatinput, this); + mChatInputContainer = (LinearLayout) findViewById(R.id.aurora_ll_input_container); + mMenuItemContainer = (LinearLayout) findViewById(R.id.aurora_ll_menuitem_container); + mMenuContainer = (FrameLayout) findViewById(R.id.aurora_fl_menu_container); + + mMenuManager = new MenuManager(this,mChatInputContainer,mMenuItemContainer,mMenuContainer); + // menu buttons mChatInput = (EmoticonsEditText) findViewById(R.id.aurora_et_chat_input); mVoiceBtn = (ImageButton) findViewById(R.id.aurora_menuitem_ib_voice); @@ -218,9 +227,8 @@ private void init(Context context) { mSendCountTv = (TextView) findViewById(R.id.aurora_menuitem_tv_send_count); mInputMarginLeft = (Space) findViewById(R.id.aurora_input_margin_left); mInputMarginRight = (Space) findViewById(R.id.aurora_input_margin_right); - mChatInputContainer = (LinearLayout) findViewById(R.id.aurora_ll_input_container); - mMenuItemContainer = (LinearLayout) findViewById(R.id.aurora_ll_menuitem_container); - mMenuContainer = (FrameLayout) findViewById(R.id.aurora_fl_menu_container); + + mRecordVoiceRl = (RelativeLayout) findViewById(R.id.aurora_rl_recordvoice_container); mPreviewPlayLl = (LinearLayout) findViewById(R.id.aurora_ll_recordvoice_preview_container); mPreviewPlayBtn = (ProgressButton) findViewById(R.id.aurora_pb_recordvoice_play_audio); @@ -292,6 +300,7 @@ public void onBackKeyClick() { // return false; // } // }); + } EmoticonClickListener emoticonClickListener = new EmoticonClickListener() { @@ -330,7 +339,6 @@ public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) { private void init(Context context, AttributeSet attrs) { init(context); mStyle = ChatInputStyle.parse(context, attrs); - mChatInput.setMaxLines(mStyle.getInputMaxLines()); mChatInput.setHint(mStyle.getInputHint()); mChatInput.setText(mStyle.getInputText()); @@ -340,6 +348,7 @@ private void init(Context context, AttributeSet attrs) { mChatInput.setBackgroundResource(mStyle.getInputEditTextBg()); mChatInput.setPadding(mStyle.getInputPaddingLeft(), mStyle.getInputPaddingTop(), mStyle.getInputPaddingRight(), mStyle.getInputPaddingBottom()); + mInputMarginLeft.getLayoutParams().width = mStyle.getInputMarginLeft(); mInputMarginRight.getLayoutParams().width = mStyle.getInputMarginRight(); mVoiceBtn.setImageResource(mStyle.getVoiceBtnIcon()); @@ -353,6 +362,10 @@ private void init(Context context, AttributeSet attrs) { mSendCountTv.setBackground(mStyle.getSendCountBg()); mSelectAlbumIb.setVisibility(mStyle.getShowSelectAlbum() ? VISIBLE : INVISIBLE); + LinearLayout.LayoutParams lp =(LayoutParams) mChatInputContainer.getLayoutParams(); + lp.setMargins(0,mStyle.getInputMarginTop(),0,mStyle.getInputMarginBottom()); + mChatInputContainer.setLayoutParams(lp); + mMediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override @@ -378,6 +391,11 @@ public void setMenuClickListener(OnMenuClickListener listener) { mListener = listener; } + public void setCustomMenuClickListener(CustomMenuEventListener listener){ + mMenuManager.setCustomMenuClickListener(listener); + } + + public void setRecordVoiceListener(RecordVoiceListener listener) { this.mRecordVoiceBtn.setRecordVoiceListener(listener); this.mRecordVoiceListener = listener; @@ -446,6 +464,7 @@ public void onClick(View view) { } } else { + mMenuManager.hideCustomMenu(); mChatInput.clearFocus(); if (view.getId() == R.id.aurora_ll_menuitem_voice_container) { if (mListener != null && mListener.switchToMicrophoneMode()) { @@ -965,6 +984,7 @@ public void run() { } public void dismissMenuLayout() { + mMenuManager.hideCustomMenu(); mMenuContainer.setVisibility(GONE); if (mCameraSupport != null) { mCameraSupport.release(); @@ -1039,6 +1059,14 @@ public void showEmojiLayout() { mEmojiRl.setVisibility(VISIBLE); } + public void hideDefaultMenuLayout(){ + mRecordVoiceRl.setVisibility(GONE); + mSelectPhotoView.setVisibility(GONE); + mCameraFl.setVisibility(GONE); + mEmojiRl.setVisibility(GONE); + } + + public void dismissEmojiLayout() { mEmojiRl.setVisibility(GONE); } @@ -1457,4 +1485,9 @@ public ImageButton getRecordVideoBtn() { return this.mRecordVideoBtn; } + public MenuManager getMenuManager(){ + return this.mMenuManager; + } + + } diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/listener/CustomMenuEventListener.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/listener/CustomMenuEventListener.java new file mode 100644 index 00000000..ae94f5b6 --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/listener/CustomMenuEventListener.java @@ -0,0 +1,21 @@ +package cn.jiguang.imui.chatinput.listener; + + +import android.view.View; + +import java.util.List; + +import cn.jiguang.imui.chatinput.menu.view.MenuFeature; +import cn.jiguang.imui.chatinput.menu.view.MenuItem; +import cn.jiguang.imui.chatinput.model.FileItem; + +/** + * Custom Menu' callbacks + */ +public interface CustomMenuEventListener { + + boolean onMenuItemClick(String tag, MenuItem menuItem); + + void onMenuFeatureVisibilityChanged(int visibility,String tag,MenuFeature menuFeature); + +} \ No newline at end of file diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/Menu.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/Menu.java new file mode 100644 index 00000000..ae6195a9 --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/Menu.java @@ -0,0 +1,76 @@ +package cn.jiguang.imui.chatinput.menu; + + +public class Menu { + + public static final String TAG_VOICE = "voice"; + public static final String TAG_GALLERY = "gallery"; + public static final String TAG_CAMERA = "camera"; + public static final String TAG_EMOJI = "emoji"; + public static final String TAG_SEND = "send"; + + private final boolean customize; + private final String[] left; + private final String[] right; + private final String[] bottom; + + private Menu(Builder builder) { + this.customize = builder.customize; + this.left = builder.left; + this.right = builder.right; + this.bottom = builder.bottom; + } + + public boolean isCustomize() { + return customize; + } + + public String[] getLeft() { + return left; + } + + public String[] getRight() { + return right; + } + + public String[] getBottom() { + return bottom; + } + + public static Builder newBuilder(){ + return new Builder(); + } + + public static class Builder{ + private boolean customize; + private String[] left; + private String[] right; + private String[] bottom; + + public Builder customize(boolean customize){ + this.customize = customize; + return this; + } + + + public Builder setLeft(String ... tags){ + this.left =tags; + return this; + } + + public Builder setRight(String ... tags){ + this.right =tags; + return this; + } + + public Builder setBottom(String ... tags){ + this.bottom =tags; + return this; + } + + public Menu build(){ + return new Menu(this); + } + + } +} diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java new file mode 100644 index 00000000..f1e09ef0 --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java @@ -0,0 +1,186 @@ +package cn.jiguang.imui.chatinput.menu; + +import android.content.Context; +import android.util.Log; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.LinearLayout; + +import cn.jiguang.imui.chatinput.ChatInputView; +import cn.jiguang.imui.chatinput.emoji.EmoticonsKeyboardUtils; +import cn.jiguang.imui.chatinput.listener.CustomMenuEventListener; +import cn.jiguang.imui.chatinput.menu.collection.MenuCollection; +import cn.jiguang.imui.chatinput.menu.collection.MenuFeatureCollection; +import cn.jiguang.imui.chatinput.menu.collection.MenuItemCollection; +import cn.jiguang.imui.chatinput.menu.view.MenuFeature; +import cn.jiguang.imui.chatinput.menu.view.MenuItem; +import cn.jiguang.imui.chatinput.utils.SimpleCommonUtils; + +import static android.view.View.GONE; +import static android.view.View.VISIBLE; + + +public class MenuManager { + public static final String TAG = SimpleCommonUtils.formatTag(MenuManager.class.getSimpleName()); + + private ChatInputView mChatInputView; + private LinearLayout mChatInputContainer; + private LinearLayout mMenuItemContainer; + private FrameLayout mMenuContainer; + private Context mContext; + private MenuItemCollection mMenuItemCollection; + private MenuFeatureCollection mMenuFeatureCollection; + private CustomMenuEventListener mCustomMenuEventListener; + + public MenuManager(ChatInputView chatInputView, LinearLayout chatInputContainer, LinearLayout menuItemContainer, FrameLayout menuContainer) { + mChatInputView = chatInputView; + mContext = chatInputView.getContext(); + mChatInputContainer = chatInputContainer; + mMenuItemContainer = menuItemContainer; + mMenuContainer = menuContainer; + initCollection(); + + initDefaultMenu(); + } + + private void initCollection() { + mMenuItemCollection = new MenuItemCollection(mContext); + + mMenuItemCollection.setMenuCollectionChangedListener(new MenuCollection.MenuCollectionChangedListener() { + @Override + public void addMenu(String menuTag, View menu) { + menu.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mChatInputView.getInputView().clearFocus(); + String tag = (String) v.getTag(); + if (mCustomMenuEventListener != null && mCustomMenuEventListener.onMenuItemClick(tag, (MenuItem) v)) { + showMenuFeatureByTag(tag); + } + } + }); + } + }); + + mMenuFeatureCollection = new MenuFeatureCollection(mContext); + mMenuFeatureCollection.setMenuCollectionChangedListener(new MenuCollection.MenuCollectionChangedListener() { + @Override + public void addMenu(String menuTag, View menu) { + menu.setVisibility(View.GONE); + mMenuContainer.addView(menu); + } + }); + + } + + + private void showMenuFeatureByTag(String tag) { + + + View menuFeature = mMenuFeatureCollection.get(tag); + if (menuFeature == null) { + Log.i(TAG, "Can't find MenuFeature to show by tag:" + tag); + return; + } + + if (menuFeature.getVisibility() == VISIBLE && mMenuContainer.getVisibility() == VISIBLE) { + mChatInputView.dismissMenuLayout(); + return; + } + + if (mChatInputView.isKeyboardVisible()) { + mChatInputView.setPendingShowMenu(true); + EmoticonsKeyboardUtils.closeSoftKeyboard(mChatInputView.getInputView()); + + } else { + mChatInputView.showMenuLayout(); + + } + + mChatInputView.hideDefaultMenuLayout(); + hideCustomMenu(); + menuFeature.setVisibility(VISIBLE); + if (mCustomMenuEventListener != null) + mCustomMenuEventListener.onMenuFeatureVisibilityChanged(VISIBLE, tag, (MenuFeature) menuFeature); + lastMenuFeature = menuFeature; + + } + + private View lastMenuFeature; + + public void hideCustomMenu() { + if (lastMenuFeature != null && lastMenuFeature.getVisibility() != GONE) { + lastMenuFeature.setVisibility(View.GONE); + if (mCustomMenuEventListener != null) + mCustomMenuEventListener.onMenuFeatureVisibilityChanged(GONE, (String) lastMenuFeature.getTag(), (MenuFeature) lastMenuFeature); + } + + } + + + private void initDefaultMenu() { + addBottomByTag(Menu.TAG_VOICE, + Menu.TAG_GALLERY, + Menu.TAG_CAMERA, + Menu.TAG_EMOJI, + Menu.TAG_SEND); + } + + public void setMenu(Menu menu) { + if (menu.isCustomize()) { + mMenuItemContainer.removeAllViews(); + addViews(mChatInputContainer, 1, menu.getLeft()); + addViews(mChatInputContainer, mChatInputContainer.getChildCount() - 1, menu.getRight()); + addBottomByTag(menu.getBottom()); + } + } + + private void addBottomByTag(String... tags) { + if (tags == null || tags.length == 0) { + mMenuItemContainer.setVisibility(View.GONE); + } + addViews(mMenuItemContainer, -1, tags); + } + + + private void addViews(LinearLayout parent, int index, String... tags) { + if (parent == null || tags == null) + return; + for (String tag : tags) { + View child = mMenuItemCollection.get(tag); + if (child == null) { + Log.e(TAG, "Can't find view by tag " + tag + "."); + continue; + } + + parent.addView(child, index); + } + } + +// public MenuItemCollection getMenuItemCollection() { +// return mMenuItemCollection; +// } +// +// public MenuFeatureCollection getMenuFeatureCollection() { +// return mMenuFeatureCollection; +// } + + public void addCustomMenu(String tag, MenuItem menuItem, MenuFeature menuFeature) { + + mMenuItemCollection.addCustomMenuItem(tag, menuItem); + mMenuFeatureCollection.addMenuFeature(tag, menuFeature); + } + + public void addCustomMenu(String tag, int menuItemResource, int menuFeatureResource) { + + mMenuItemCollection.addCustomMenuItem(tag, menuItemResource); + mMenuFeatureCollection.addMenuFeature(tag, menuFeatureResource); + } + + + public void setCustomMenuClickListener(CustomMenuEventListener listener) { + this.mCustomMenuEventListener = listener; + } + + +} diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java new file mode 100644 index 00000000..276238d4 --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java @@ -0,0 +1,51 @@ +package cn.jiguang.imui.chatinput.menu.collection; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; + +import java.util.HashMap; + +import cn.jiguang.imui.chatinput.utils.SimpleCommonUtils; + + +public class MenuCollection extends HashMap { + + public static final String TAG = SimpleCommonUtils.formatTag(MenuCollection.class.getSimpleName()); + protected Context mContext; + protected LayoutInflater mInflater; + + + public MenuCollection(Context context) { + mContext = context; + mInflater = LayoutInflater.from(mContext); + } + + + protected void addMenu(String menuTag, View menu) { + + if (containsKey(menuTag)) { + Log.e(TAG, "Tag " + menuTag + " has been used already!"); + } + menu.setTag(menuTag); + if (mMenuCollectionChangedListener != null) { + mMenuCollectionChangedListener.addMenu(menuTag, menu); + } + + this.put(menuTag, menu); + + } + + private MenuCollectionChangedListener mMenuCollectionChangedListener; + + public void setMenuCollectionChangedListener(MenuCollectionChangedListener menuCollectionChangedListener) { + this.mMenuCollectionChangedListener = menuCollectionChangedListener; + } + + public interface MenuCollectionChangedListener { + void addMenu(String menuTag, View menu); + } + + +} diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java new file mode 100644 index 00000000..f3be4751 --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java @@ -0,0 +1,32 @@ +package cn.jiguang.imui.chatinput.menu.collection; + +import android.content.Context; +import android.util.Log; +import android.view.View; + +import cn.jiguang.imui.chatinput.menu.view.MenuFeature; + + +public class MenuFeatureCollection extends MenuCollection { + + + public MenuFeatureCollection(Context context) { + super(context); + } + + public void addMenuFeature(String tag, int resource) { + View view = mInflater.inflate(resource, null); + addMenuFeature(tag, view); + } + + public void addMenuFeature(String tag, View menuFeature) { + + if (menuFeature instanceof MenuFeature) { + menuFeature.setVisibility(View.GONE); + addMenu(tag, menuFeature); + } else { + Log.e(TAG, "Collection menu feature failed exception!"); + } + } + +} diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuItemCollection.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuItemCollection.java new file mode 100644 index 00000000..4524f0b3 --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuItemCollection.java @@ -0,0 +1,55 @@ +package cn.jiguang.imui.chatinput.menu.collection; + +import android.content.Context; +import android.util.Log; +import android.view.View; + + +import cn.jiguang.imui.chatinput.R; +import cn.jiguang.imui.chatinput.menu.Menu; +import cn.jiguang.imui.chatinput.menu.view.MenuItem; +import cn.jiguang.imui.chatinput.utils.ViewUtil; + + +public class MenuItemCollection extends MenuCollection { + + + public MenuItemCollection(Context context) { + super(context); + initDefaultMenu(); + } + + private void initDefaultMenu() { + this.put(Menu.TAG_VOICE, inflaterMenu(R.layout.menu_item_voice)); + this.put(Menu.TAG_GALLERY, inflaterMenu(R.layout.menu_item_photo)); + this.put(Menu.TAG_CAMERA, inflaterMenu(R.layout.menu_item_camera)); + this.put(Menu.TAG_EMOJI, inflaterMenu(R.layout.menu_item_emoji)); + this.put(Menu.TAG_SEND, inflaterMenu(R.layout.menu_item_send)); + + } + + private View inflaterMenu(int resource) { + View view = mInflater.inflate(resource, null); + view = ViewUtil.formatViewWeight(view, 1); + return view; + + } + + public void addCustomMenuItem(String tag, int resource) { + View view = mInflater.inflate(resource, null); + addCustomMenuItem(tag, view); + } + + + public void addCustomMenuItem(String tag, View menu) { + if (menu instanceof MenuItem) { + menu.setClickable(true); + menu = ViewUtil.formatViewWeight(menu, 1); + addMenu(tag, menu); + } else { + Log.e(TAG, "Collection menu item failed !"); + } + } + + +} diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuFeature.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuFeature.java new file mode 100644 index 00000000..f6b26715 --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuFeature.java @@ -0,0 +1,21 @@ +package cn.jiguang.imui.chatinput.menu.view; + +import android.content.Context; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.widget.LinearLayout; + + +public class MenuFeature extends LinearLayout { + public MenuFeature(Context context) { + super(context); + } + + public MenuFeature(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public MenuFeature(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } +} diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuItem.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuItem.java new file mode 100644 index 00000000..daf731cb --- /dev/null +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/view/MenuItem.java @@ -0,0 +1,22 @@ +package cn.jiguang.imui.chatinput.menu.view; + +import android.content.Context; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.widget.LinearLayout; + + +public class MenuItem extends LinearLayout { + public MenuItem(Context context) { + super(context); + } + + public MenuItem(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public MenuItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + +} diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/SimpleCommonUtils.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/SimpleCommonUtils.java index 7f5f3a5e..9539b937 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/SimpleCommonUtils.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/SimpleCommonUtils.java @@ -224,4 +224,8 @@ public static void delClick(EditText editText) { // // tv_content.setText(spannable); // } + public static String formatTag(String tag){ + return "IMUI-"+tag; + } + } diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/ViewUtil.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/ViewUtil.java index 1a998cde..999b92e6 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/ViewUtil.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/ViewUtil.java @@ -1,6 +1,8 @@ package cn.jiguang.imui.chatinput.utils; import android.content.res.Resources; +import android.view.View; +import android.widget.LinearLayout; public final class ViewUtil { @@ -15,5 +17,13 @@ public static int dpToPx(int dp) { return Math.round(dp * density); } + public static View formatViewWeight(View view,float weight) { + if(view != null){ + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,weight); + view.setLayoutParams(lp); + } + return view; + } + } diff --git a/Android/chatinput/src/main/res/layout/layout_chatinput_menu.xml b/Android/chatinput/src/main/res/layout/layout_chatinput_menu.xml index aafc0963..9f31245c 100644 --- a/Android/chatinput/src/main/res/layout/layout_chatinput_menu.xml +++ b/Android/chatinput/src/main/res/layout/layout_chatinput_menu.xml @@ -6,135 +6,135 @@ android:baselineAligned="false" android:orientation="horizontal"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/chatinput/src/main/res/layout/menu_item_camera.xml b/Android/chatinput/src/main/res/layout/menu_item_camera.xml new file mode 100644 index 00000000..4f46278f --- /dev/null +++ b/Android/chatinput/src/main/res/layout/menu_item_camera.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/Android/chatinput/src/main/res/layout/menu_item_emoji.xml b/Android/chatinput/src/main/res/layout/menu_item_emoji.xml new file mode 100644 index 00000000..6a46af09 --- /dev/null +++ b/Android/chatinput/src/main/res/layout/menu_item_emoji.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/Android/chatinput/src/main/res/layout/menu_item_photo.xml b/Android/chatinput/src/main/res/layout/menu_item_photo.xml new file mode 100644 index 00000000..17fb0e84 --- /dev/null +++ b/Android/chatinput/src/main/res/layout/menu_item_photo.xml @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/Android/chatinput/src/main/res/layout/menu_item_send.xml b/Android/chatinput/src/main/res/layout/menu_item_send.xml new file mode 100644 index 00000000..cfe6eab8 --- /dev/null +++ b/Android/chatinput/src/main/res/layout/menu_item_send.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + diff --git a/Android/chatinput/src/main/res/layout/menu_item_voice.xml b/Android/chatinput/src/main/res/layout/menu_item_voice.xml new file mode 100644 index 00000000..ae819e54 --- /dev/null +++ b/Android/chatinput/src/main/res/layout/menu_item_voice.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/Android/chatinput/src/main/res/layout/view_chatinput.xml b/Android/chatinput/src/main/res/layout/view_chatinput.xml index 5add0011..8858e651 100644 --- a/Android/chatinput/src/main/res/layout/view_chatinput.xml +++ b/Android/chatinput/src/main/res/layout/view_chatinput.xml @@ -13,14 +13,14 @@ diff --git a/Android/chatinput/src/main/res/values/attrs.xml b/Android/chatinput/src/main/res/values/attrs.xml index ef68dcb0..00ec976e 100644 --- a/Android/chatinput/src/main/res/values/attrs.xml +++ b/Android/chatinput/src/main/res/values/attrs.xml @@ -6,6 +6,8 @@ + + diff --git a/Android/chatinput/src/main/res/values/dimens.xml b/Android/chatinput/src/main/res/values/dimens.xml index 36272c36..2aebe953 100644 --- a/Android/chatinput/src/main/res/values/dimens.xml +++ b/Android/chatinput/src/main/res/values/dimens.xml @@ -8,6 +8,8 @@ 20dp 20dp + 8dp + 0dp 17sp From 65683f880bbc3294036d255229ffa13cce362150 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Mon, 10 Sep 2018 17:09:06 +0800 Subject: [PATCH 02/15] Update sample --- .../jiguang/cn/imuisample/views/ChatView.java | 36 ++++++++++++++++++- .../src/main/res/layout/activity_chat.xml | 2 ++ .../src/main/res/layout/menu_text.xml | 12 +++++++ .../src/main/res/layout/menu_text_feature.xml | 14 ++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Android/sample/exampleui/src/main/res/layout/menu_text.xml create mode 100644 Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml diff --git a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java index 5f078c53..f2dd20dd 100644 --- a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java +++ b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java @@ -1,19 +1,25 @@ package imui.jiguang.cn.imuisample.views; import android.content.Context; -import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; +import android.util.Log; +import android.view.View; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; import cn.jiguang.imui.chatinput.ChatInputView; import cn.jiguang.imui.chatinput.listener.OnCameraCallbackListener; import cn.jiguang.imui.chatinput.listener.OnClickEditTextListener; +import cn.jiguang.imui.chatinput.listener.CustomMenuEventListener; import cn.jiguang.imui.chatinput.listener.OnMenuClickListener; import cn.jiguang.imui.chatinput.listener.RecordVoiceListener; +import cn.jiguang.imui.chatinput.menu.Menu; +import cn.jiguang.imui.chatinput.menu.view.MenuFeature; +import cn.jiguang.imui.chatinput.menu.view.MenuItem; import cn.jiguang.imui.chatinput.record.RecordVoiceButton; import cn.jiguang.imui.messages.MessageList; import cn.jiguang.imui.messages.MsgListAdapter; @@ -81,6 +87,34 @@ public void initModule() { // set show display name or not // mMsgList.setShowReceiverDisplayName(true); // mMsgList.setShowSenderDisplayName(false); + + + // add Custom Menu View + mChatInput.getMenuManager().addCustomMenu("MY_CUSTOM",R.layout.menu_text,R.layout.menu_text_feature); + + // Custom menu order + mChatInput.getMenuManager().setMenu(Menu.newBuilder(). + customize(true). + setRight(Menu.TAG_SEND). + setBottom(Menu.TAG_VOICE,Menu.TAG_EMOJI,Menu.TAG_GALLERY,Menu.TAG_CAMERA,"MY_CUSTOM"). + build()); + mChatInput.setCustomMenuClickListener(new CustomMenuEventListener() { + @Override + public boolean onMenuItemClick(String tag, MenuItem menuItem) { + //Menu feature will not be show 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. + } + } + }); + } public PullToRefreshLayout getPtrLayout() { diff --git a/Android/sample/exampleui/src/main/res/layout/activity_chat.xml b/Android/sample/exampleui/src/main/res/layout/activity_chat.xml index 051e83af..bd1654af 100644 --- a/Android/sample/exampleui/src/main/res/layout/activity_chat.xml +++ b/Android/sample/exampleui/src/main/res/layout/activity_chat.xml @@ -64,6 +64,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" + app:inputMarginLeft="3dp" + app:inputMarginRight="3dp" app:showSelectAlbum="true"/> diff --git a/Android/sample/exampleui/src/main/res/layout/menu_text.xml b/Android/sample/exampleui/src/main/res/layout/menu_text.xml new file mode 100644 index 00000000..cf85988e --- /dev/null +++ b/Android/sample/exampleui/src/main/res/layout/menu_text.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml b/Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml new file mode 100644 index 00000000..25ed1b5b --- /dev/null +++ b/Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file From 735c7299d357841e252ebbb4cac808a1948b988b Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Mon, 10 Sep 2018 17:50:37 +0800 Subject: [PATCH 03/15] =?UTF-8?q?Update=20menu=20API=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menu/collection/MenuCollection.java | 8 +++++- .../collection/MenuFeatureCollection.java | 27 ++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java index 276238d4..bf6bc60b 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuCollection.java @@ -1,6 +1,7 @@ package cn.jiguang.imui.chatinput.menu.collection; import android.content.Context; +import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -24,9 +25,14 @@ public MenuCollection(Context context) { protected void addMenu(String menuTag, View menu) { + if(TextUtils.isEmpty(menuTag)){ + Log.e(TAG, "Collection custom menu failed,tag is empty."); + return; + } if (containsKey(menuTag)) { - Log.e(TAG, "Tag " + menuTag + " has been used already!"); + Log.e(TAG, "Collection custom menu failed,Tag " + menuTag + " has been used already!"); + return; } menu.setTag(menuTag); if (mMenuCollectionChangedListener != null) { diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java index f3be4751..282e0ada 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/collection/MenuFeatureCollection.java @@ -7,25 +7,34 @@ import cn.jiguang.imui.chatinput.menu.view.MenuFeature; -public class MenuFeatureCollection extends MenuCollection { +public class MenuFeatureCollection extends MenuCollection{ - public MenuFeatureCollection(Context context) { + + public MenuFeatureCollection(Context context){ super(context); } - public void addMenuFeature(String tag, int resource) { + public void addMenuFeature(String tag,int resource){ + if(resource == -1){ + Log.i(TAG,"Menu feature with tag"+tag+" will not be added."); + return; + } View view = mInflater.inflate(resource, null); - addMenuFeature(tag, view); + addMenuFeature(tag,view); } - public void addMenuFeature(String tag, View menuFeature) { + public void addMenuFeature(String tag,View menuFeature){ + if(menuFeature == null){ + Log.i(TAG,"Menu feature with tag"+tag+" will not be added."); + return; + } - if (menuFeature instanceof MenuFeature) { + if(menuFeature instanceof MenuFeature){ menuFeature.setVisibility(View.GONE); - addMenu(tag, menuFeature); - } else { - Log.e(TAG, "Collection menu feature failed exception!"); + addMenu(tag,menuFeature); + }else { + Log.e(TAG,"Collection menu feature failed exception!"); } } From 83d0b1c961ef7b5999033edad52d26146316f3a1 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Mon, 10 Sep 2018 17:52:22 +0800 Subject: [PATCH 04/15] Explode menu collection class --- .../jiguang/imui/chatinput/menu/MenuManager.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java index f1e09ef0..89c466cf 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/menu/MenuManager.java @@ -157,13 +157,13 @@ private void addViews(LinearLayout parent, int index, String... tags) { } } -// public MenuItemCollection getMenuItemCollection() { -// return mMenuItemCollection; -// } -// -// public MenuFeatureCollection getMenuFeatureCollection() { -// return mMenuFeatureCollection; -// } + public MenuItemCollection getMenuItemCollection() { + return mMenuItemCollection; + } + + public MenuFeatureCollection getMenuFeatureCollection() { + return mMenuFeatureCollection; + } public void addCustomMenu(String tag, MenuItem menuItem, MenuFeature menuFeature) { From 62eadcd8945d25c404261e4ac3e1362d3bef71aa Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Mon, 10 Sep 2018 19:57:37 +0800 Subject: [PATCH 05/15] Update sample --- .../main/java/imui/jiguang/cn/imuisample/views/ChatView.java | 4 +--- .../exampleui/src/main/res/layout/menu_text_feature.xml | 4 ++-- .../src/main/res/layout/{menu_text.xml => menu_text_item.xml} | 0 3 files changed, 3 insertions(+), 5 deletions(-) rename Android/sample/exampleui/src/main/res/layout/{menu_text.xml => menu_text_item.xml} (100%) diff --git a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java index f2dd20dd..a4179632 100644 --- a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java +++ b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java @@ -3,13 +3,11 @@ import android.content.Context; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; -import android.util.Log; import android.view.View; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toast; import cn.jiguang.imui.chatinput.ChatInputView; import cn.jiguang.imui.chatinput.listener.OnCameraCallbackListener; @@ -90,7 +88,7 @@ public void initModule() { // add Custom Menu View - mChatInput.getMenuManager().addCustomMenu("MY_CUSTOM",R.layout.menu_text,R.layout.menu_text_feature); + mChatInput.getMenuManager().addCustomMenu("MY_CUSTOM",R.layout.menu_text_item,R.layout.menu_text_feature); // Custom menu order mChatInput.getMenuManager().setMenu(Menu.newBuilder(). diff --git a/Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml b/Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml index 25ed1b5b..3a1079b3 100644 --- a/Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml +++ b/Android/sample/exampleui/src/main/res/layout/menu_text_feature.xml @@ -7,8 +7,8 @@ + android:text="CUSTOM MENU"/> \ No newline at end of file diff --git a/Android/sample/exampleui/src/main/res/layout/menu_text.xml b/Android/sample/exampleui/src/main/res/layout/menu_text_item.xml similarity index 100% rename from Android/sample/exampleui/src/main/res/layout/menu_text.xml rename to Android/sample/exampleui/src/main/res/layout/menu_text_item.xml From 322942c2d6c3075695e59b7d1b3b9d710becba19 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Mon, 10 Sep 2018 19:58:08 +0800 Subject: [PATCH 06/15] Update chatinput version to v0.9.0 --- Android/chatinput/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Android/chatinput/build.gradle b/Android/chatinput/build.gradle index 8cf28efe..d9e71ddc 100644 --- a/Android/chatinput/build.gradle +++ b/Android/chatinput/build.gradle @@ -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 { From 199ae6849c65ebfb46380a0e5480436b32df8e1f Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Tue, 11 Sep 2018 11:28:47 +0800 Subject: [PATCH 07/15] Update sample --- .../java/imui/jiguang/cn/imuisample/views/ChatView.java | 8 +++++--- .../exampleui/src/main/res/layout/menu_text_item.xml | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java index a4179632..b1ed5da1 100644 --- a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java +++ b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/views/ChatView.java @@ -16,6 +16,7 @@ import cn.jiguang.imui.chatinput.listener.OnMenuClickListener; import cn.jiguang.imui.chatinput.listener.RecordVoiceListener; import cn.jiguang.imui.chatinput.menu.Menu; +import cn.jiguang.imui.chatinput.menu.MenuManager; import cn.jiguang.imui.chatinput.menu.view.MenuFeature; import cn.jiguang.imui.chatinput.menu.view.MenuItem; import cn.jiguang.imui.chatinput.record.RecordVoiceButton; @@ -88,15 +89,16 @@ public void initModule() { // add Custom Menu View - mChatInput.getMenuManager().addCustomMenu("MY_CUSTOM",R.layout.menu_text_item,R.layout.menu_text_feature); + MenuManager menuManager = mChatInput.getMenuManager(); + menuManager.addCustomMenu("MY_CUSTOM",R.layout.menu_text_item,R.layout.menu_text_feature); // Custom menu order - mChatInput.getMenuManager().setMenu(Menu.newBuilder(). + 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"). build()); - mChatInput.setCustomMenuClickListener(new CustomMenuEventListener() { + menuManager.setCustomMenuClickListener(new CustomMenuEventListener() { @Override public boolean onMenuItemClick(String tag, MenuItem menuItem) { //Menu feature will not be show shown if return false; diff --git a/Android/sample/exampleui/src/main/res/layout/menu_text_item.xml b/Android/sample/exampleui/src/main/res/layout/menu_text_item.xml index cf85988e..35fac49a 100644 --- a/Android/sample/exampleui/src/main/res/layout/menu_text_item.xml +++ b/Android/sample/exampleui/src/main/res/layout/menu_text_item.xml @@ -1,7 +1,8 @@ Date: Tue, 11 Sep 2018 11:29:07 +0800 Subject: [PATCH 08/15] Update doc --- Android/chatinput/README.md | 106 +++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/Android/chatinput/README.md b/Android/chatinput/README.md index 0dffc077..64378015 100644 --- a/Android/chatinput/README.md +++ b/Android/chatinput/README.md @@ -12,7 +12,7 @@ - Gradle ```groovy -compile 'cn.jiguang.imui:chatinput:0.8.3' +compile 'cn.jiguang.imui:chatinput:0.9.0' ``` - Maven @@ -20,7 +20,7 @@ compile 'cn.jiguang.imui:chatinput:0.8.3' cn.jiguang.imui chatinput - 0.8.3 + 0.9.0 pom ``` @@ -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' } ``` @@ -265,3 +265,103 @@ mChatInput.setCameraControllerListener(new CameraControllerListener() { mChatInput.setCameraCaptureFile(path, fileName); ``` +## MenuManager(从0.9.0版本开始支持) +菜单功能管理类,用于添加自定义菜单,自由设置菜单项的位置,包括输入框的左边/右边/下边位置。 + +### 获取MenuManager + +`MenuManager menuManager = mChatInput.getMenuManager();` + + +### 添加自定义菜单 + +` + +1. 添加菜单项布局,根节点为MenuItem(继承自LinearLayout) +```xml + + + ... + + +``` + +2. 添加对应菜单功能布局,根节点为MenuFeature(继承自LinearLayout) +```xml + + + ... + + +``` +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,"MY_CUSTOM"). + build()); +``` + + + + + + + + From d408210f4ecf732ad96129a9f2cddd6747a33ea2 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Tue, 11 Sep 2018 13:33:57 +0800 Subject: [PATCH 09/15] Update doc --- Android/chatinput/README.md | 14 +++-- Android/chatinput/README_EN.md | 93 ++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 8 deletions(-) diff --git a/Android/chatinput/README.md b/Android/chatinput/README.md index 64378015..7892a5ae 100644 --- a/Android/chatinput/README.md +++ b/Android/chatinput/README.md @@ -266,7 +266,7 @@ mChatInput.setCameraCaptureFile(path, fileName); ``` ## MenuManager(从0.9.0版本开始支持) -菜单功能管理类,用于添加自定义菜单,自由设置菜单项的位置,包括输入框的左边/右边/下边位置。 +菜单功能管理类,用于添加自定义菜单,自由设置菜单项的位置,包括输入框的左边/右边/下边位置。 ### 获取MenuManager @@ -275,9 +275,7 @@ mChatInput.setCameraCaptureFile(path, fileName); ### 添加自定义菜单 -` - -1. 添加菜单项布局,根节点为MenuItem(继承自LinearLayout) +1. 添加菜单项布局,根节点为MenuItem(继承自LinearLayout) ```xml ``` -2. 添加对应菜单功能布局,根节点为MenuFeature(继承自LinearLayout) +2. 添加对应菜单功能布局,根节点为MenuFeature(继承自LinearLayout) ```xml + + ... + + +``` + +2. Add custom menu feature layout,the root node has to be MenuFeature(Extends LinearLayout) +```xml + + + ... + + +``` +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()); +``` From aeb0e2a55dca8ef8b5e622ffee4b51784f6fce6e Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Tue, 11 Sep 2018 15:01:08 +0800 Subject: [PATCH 10/15] Add customLayoutItems for android --- ReactNative/android/build.gradle | 2 +- .../viewmanager/ReactChatInputManager.java | 40 +++++++++++++++++++ ReactNative/chatinput.android.js | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ReactNative/android/build.gradle b/ReactNative/android/build.gradle index e97a3ef2..9d891a27 100644 --- a/ReactNative/android/build.gradle +++ b/ReactNative/android/build.gradle @@ -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.3' + compile 'cn.jiguang.imui:chatinput:0.9.0' compile 'pub.devrel:easypermissions:1.0.1' compile 'org.greenrobot:eventbus:3.0.0' implementation 'com.android.support:appcompat-v7:27.1.0' diff --git a/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java b/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java index ad77a98b..0ed4b165 100644 --- a/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java +++ b/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java @@ -56,6 +56,7 @@ import cn.jiguang.imui.chatinput.listener.OnCameraCallbackListener; import cn.jiguang.imui.chatinput.listener.OnMenuClickListener; import cn.jiguang.imui.chatinput.listener.RecordVoiceListener; +import cn.jiguang.imui.chatinput.menu.Menu; import cn.jiguang.imui.chatinput.model.FileItem; import cn.jiguang.imui.chatinput.model.VideoItem; import cn.jiguang.imui.messagelist.AuroraIMUIModule; @@ -554,6 +555,7 @@ public void onPageScrollStateChanged(int state) { } }); + return mChatInput; } @@ -742,6 +744,44 @@ public void hidePhotoButton(ChatInputView chatInputView, boolean hide) { chatInputView.getPhotoBtnContainer().setVisibility(hide ? View.GONE : View.VISIBLE); } + @ReactProp(name = "customLayoutItems") + public void setCustomItems(ChatInputView chatInputView, ReadableMap map) { + ReadableArray left = map.hasKey("left")?map.getArray("left"):null; + ReadableArray right = map.hasKey("right")?map.getArray("right"):null; + ReadableArray bottom = map.hasKey("bottom")?map.getArray("bottom"):null; + String[] bottomTags = new String[0]; + if(bottom!=null){ + bottomTags = new String[bottom.size()]; + for(int i =0;i getExportedCustomDirectEventTypeConstants() { return MapBuilder.builder() diff --git a/ReactNative/chatinput.android.js b/ReactNative/chatinput.android.js index 8f5a34e5..0958eef5 100644 --- a/ReactNative/chatinput.android.js +++ b/ReactNative/chatinput.android.js @@ -267,6 +267,7 @@ ChatInput.propTypes = { hideVoiceButton: PropTypes.bool, hideEmojiButton: PropTypes.bool, hidePhotoButton: PropTypes.bool, + customLayoutItems: PropTypes.object, ...ViewPropTypes }; From a634a5f5b731f85f25227936c4732768f6e3fc1f Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Tue, 11 Sep 2018 15:01:50 +0800 Subject: [PATCH 11/15] Update RN sample --- ReactNative/sample/App.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ReactNative/sample/App.js b/ReactNative/sample/App.js index 5c72fd28..2c8f5be4 100644 --- a/ReactNative/sample/App.js +++ b/ReactNative/sample/App.js @@ -549,7 +549,6 @@ export default class TestRNIMUI extends Component { inputPadding={{ left: 30, top: 10, right: 10, bottom: 10 }} galleryScale={0.6}//default = 0.5 compressionQuality={0.6} - hideCameraButton={false} customLayoutItems={{ left: [], right: [], From 4aab2d8d31bca1f99246dede870cbb6c2d1f46dd Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Tue, 11 Sep 2018 15:04:22 +0800 Subject: [PATCH 12/15] Update RN docs --- ReactNative/docs/APIs.md | 39 +------------------------------------ ReactNative/docs/APIs_zh.md | 39 +------------------------------------ 2 files changed, 2 insertions(+), 76 deletions(-) diff --git a/ReactNative/docs/APIs.md b/ReactNative/docs/APIs.md index 71f55b04..372f451b 100644 --- a/ReactNative/docs/APIs.md +++ b/ReactNative/docs/APIs.md @@ -578,7 +578,7 @@ Example: ```isAllowPullToRefresh={ture}```。 *** -#### customLayoutItems(iOS Only) +#### customLayoutItems **PropTypes.string:** @@ -628,43 +628,6 @@ Set the visibility of the record video button. Example: ```showRecordVideoBtn={true}``` ------- - -#### hideCameraButton(Android Only) -**PropTypes.bool:** - -Set the visibility of the camera button. - -Example: ```hideCameraButton={true}``` - - ------- - -#### hideVoiceButton(Android Only) -**PropTypes.bool:** - -Set the visibility of the voice button. - -Example: ```hideVoiceButton={true}``` - ------- - -#### hideEmojiButton(Android Only) -**PropTypes.bool:** - -Set the visibility of the Emoji button. - -Example: ```hideEmojiButton={true}``` - ------- - -#### hidePhotoButton(Android Only) -**PropTypes.bool:** - -Set the visibility of the photo button. - -Example: ```hidePhotoButton={true}``` - ------ ### inputPadding diff --git a/ReactNative/docs/APIs_zh.md b/ReactNative/docs/APIs_zh.md index 0f926e24..1918a224 100644 --- a/ReactNative/docs/APIs_zh.md +++ b/ReactNative/docs/APIs_zh.md @@ -577,7 +577,7 @@ Example: `messageTextLineHeight={5}` ### Props customizable style ------ -#### customLayoutItems(iOS Only) +#### customLayoutItems **PropTypes.string:** @@ -627,43 +627,6 @@ Example: ```showSelectAlbumBtn={true}``` Example: ```showRecordVideoBtn={true}``` - ------- - -#### hideCameraButton(Android Only) -**PropTypes.bool:** - -设置菜单栏相机按钮可见性。 - -Example: ```hideCameraButton={true}``` - ------- - -#### hideVoiceButton(Android Only) -**PropTypes.bool:** - -设置菜单栏录音按钮可见性。 - -Example: ```hideVoiceButton={true}``` - ------- - -#### hideEmojiButton(Android Only) -**PropTypes.bool:** - -设置菜单栏Emoji表情按钮可见性。 - -Example: ```hideEmojiButton={true}``` - ------- - -#### hidePhotoButton(Android Only) -**PropTypes.bool:** - -设置菜单栏相册按钮可见性。 - -Example: ```hidePhotoButton={true}``` - ------ ### inputPadding From dda08bb51349f0f719704ae7a4d5d026db2b4489 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Tue, 11 Sep 2018 15:08:45 +0800 Subject: [PATCH 13/15] Update version to v0.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b003489..e1ce69a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurora-imui-react-native", - "version": "0.10.12", + "version": "0.11.0", "description": "aurora imui plugin for react native application", "main": "index.js", From 97b2543815309027d3abf8900dd6f40b99bcb700 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Tue, 11 Sep 2018 15:11:48 +0800 Subject: [PATCH 14/15] Update RN chatinput --- .../viewmanager/ReactChatInputManager.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java b/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java index 0ed4b165..d3074f25 100644 --- a/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java +++ b/ReactNative/android/src/main/java/cn/jiguang/imui/messagelist/viewmanager/ReactChatInputManager.java @@ -65,7 +65,6 @@ import cn.jiguang.imui.messagelist.event.OnTouchMsgListEvent; import cn.jiguang.imui.messagelist.event.ScrollEvent; import cn.jiguang.imui.messagelist.event.StopPlayVoiceEvent; -import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.AppSettingsDialog; import pub.devrel.easypermissions.EasyPermissions; @@ -406,7 +405,7 @@ public void run() { @Override public void onTakePictureCompleted(String photoPath) { - if(mLastPhotoPath.equals(photoPath)){ + if (mLastPhotoPath.equals(photoPath)) { return; } mLastPhotoPath = photoPath; @@ -684,10 +683,10 @@ public void showSelectAlbumBtn(ChatInputView chatInputView, boolean flag) { @ReactProp(name = "showRecordVideoBtn") public void showRecordVideoBtn(ChatInputView chatInputView, boolean flag) { - if(flag){ + if (flag) { chatInputView.getRecordVideoBtn().setVisibility(View.VISIBLE); chatInputView.getRecordVideoBtn().setTag("VISIBLE"); - }else{ + } else { chatInputView.getRecordVideoBtn().setVisibility(View.GONE); chatInputView.getRecordVideoBtn().setTag("GONE"); } @@ -746,39 +745,40 @@ public void hidePhotoButton(ChatInputView chatInputView, boolean hide) { @ReactProp(name = "customLayoutItems") public void setCustomItems(ChatInputView chatInputView, ReadableMap map) { - ReadableArray left = map.hasKey("left")?map.getArray("left"):null; - ReadableArray right = map.hasKey("right")?map.getArray("right"):null; - ReadableArray bottom = map.hasKey("bottom")?map.getArray("bottom"):null; - String[] bottomTags = new String[0]; - if(bottom!=null){ - bottomTags = new String[bottom.size()]; - for(int i =0;i Date: Tue, 11 Sep 2018 15:18:33 +0800 Subject: [PATCH 15/15] Update RN docs --- ReactNative/docs/APIs.md | 4 ---- ReactNative/docs/APIs_zh.md | 4 ---- 2 files changed, 8 deletions(-) diff --git a/ReactNative/docs/APIs.md b/ReactNative/docs/APIs.md index 372f451b..0683d60a 100644 --- a/ReactNative/docs/APIs.md +++ b/ReactNative/docs/APIs.md @@ -82,10 +82,6 @@ Refer to iOS,Android example - [chatInputBackgroupColor](#chatInputbackgroupcolor) - [showSelectAlbumBtn](#showselectalbumbtnandroid-only) - [showRecordVideoBtn](#showRecordVideoBtnandroid-only) - - [hideCameraButton](#hideCameraButtonandroid-only) - - [hideVoiceButton](#hideVoiceButtonandroid-only) - - [hideEmojiButton](#hideEmojiButtonandroid-only) - - [hidePhotoButton](#hidePhotoButtonandroid-only) - [inputPadding](#inputPadding) - [inputTextColor](#inputTextColor) - [inputTextSize](#inputTextSize) diff --git a/ReactNative/docs/APIs_zh.md b/ReactNative/docs/APIs_zh.md index 1918a224..6e73ddc2 100644 --- a/ReactNative/docs/APIs_zh.md +++ b/ReactNative/docs/APIs_zh.md @@ -81,10 +81,6 @@ const AuroraIMUIController = IMUI.AuroraIMUIController; // the IMUI controller, - [chatInputBackgroupColor](#chatInputbackgroupcolor) - [showSelectAlbumBtn](#showselectalbumbtnandroid-only) - [showRecordVideoBtn](#showRecordVideoBtnandroid-only) - - [hideCameraButton](#hideCameraButtonandroid-only) - - [hideVoiceButton](#hideVoiceButtonandroid-only) - - [hideEmojiButton](#hideEmojiButtonandroid-only) - - [hidePhotoButton](#hidePhotoButtonandroid-only) - [inputPadding](#inputPadding) - [inputTextColor](#inputTextColor) - [inputTextSize](#inputTextSize)