Custom Plugin

Unlike an custom module, the plugin allows you to send new content or new message type between users, like basic plugins provided by MQTT chat (smileys, stickers, records ...).

First add plugin class that extends pluginA abstract class to your App

public class samplePlugin extends com.telifoun.mqttchat.plugins.pluginA {
private Context mContext;
private LinearLayout view;
/**
*
* @param ctx
* @param Name
* @param Label
* @param useIcon
* @param idleIconId
* @param pressedIconId
*/
public samplePlugin(android.content.Context ctx, String Name, String Label, boolean useIcon, int idleIconId, int pressedIconId) {
super(ctx, Name, Label, useIcon, idleIconId, pressedIconId);
mContext=ctx;
}
@Override
public void init() {
view = new LinearLayout(mContext);
view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
view.setOrientation(LinearLayout.HORIZONTAL);
TextView iv = new TextView(mContext);
iv.setText("Plugin Gui here");
view.addView(iv);
}
@Override
public View getRootView() {
return view;
}
/**
* function that render plugin item in messages listview
* @param linearLayout
* @param view
* @param message
* @return
*/
@Override
public View render(LinearLayout linearLayout, View view, Message message) {
if(view==null){
LayoutInflater mInflater = (LayoutInflater) linearLayout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = mInflater.inflate(R.layout.render_plugin, linearLayout, false);
}
LinearLayout pluginLayout=(LinearLayout) view.findViewById(R.id.pluginLayout);
TextView txt =(TextView) view.findViewById(R.id.renderItemText) ;
this.setAlignment(pluginLayout,message.getFrom());
txt.setText(message.getMessage().toString());
return view;
}
/**
* function that add text to last message send in contacts listview
* @param i
* @param message
* @return
*/
@Override
public SpannableStringBuilder preview(int i, Message message) {
SpannableStringBuilder builder = new SpannableStringBuilder();
if(message.getFrom()== Mqttchat.getmInstance().getLoggedUser().getUserId()){ //out message
builder.append("Outbox plugin message ");
}else{
builder.append("Inbox plugin message ");
}
return builder;
}
/**
* function called when user select plugin (plugin oppened) and click in send button
*/
@Override
public void onSendMessageButtonCLicked() {
this.sendMessage("plugin text message to Send", new Callback() {
@Override
public void OK(Object o) {
getMessageActivity().requestMessageBtnOff(getName());
}
@Override
public void KO(String s) {
getMessageActivity().requestMessageBtnOff(getName());
onError(s);
}
});
}
}

Then Add plugin to MQTT chat in Application class.

samplePlugin p =new samplePlugin(getApplicationContext(),
"SamplePlugin",
"Sample Plugin",
true,
R.drawable.ic_share_off,
R.drawable.ic_share_on);
Mqttchat.getmInstance().getPlugins().add(p);

If you want a specific plugin that requires advanced coding. Please contact us and specify your needs.