Skip to content

Commit

Permalink
Add MenuManager class.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLipan committed Sep 10, 2018
1 parent a789322 commit 6f9e4d4
Show file tree
Hide file tree
Showing 21 changed files with 813 additions and 140 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -292,6 +300,7 @@ public void onBackKeyClick() {
// return false;
// }
// });

}

EmoticonClickListener emoticonClickListener = new EmoticonClickListener() {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -965,6 +984,7 @@ public void run() {
}

public void dismissMenuLayout() {
mMenuManager.hideCustomMenu();
mMenuContainer.setVisibility(GONE);
if (mCameraSupport != null) {
mCameraSupport.release();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1457,4 +1485,9 @@ public ImageButton getRecordVideoBtn() {
return this.mRecordVideoBtn;
}

public MenuManager getMenuManager(){
return this.mMenuManager;
}


}
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
Loading

0 comments on commit 6f9e4d4

Please sign in to comment.