Android Open Source - Android-Chat-App Android Message Handler






From Project

Back to project page Android-Chat-App.

License

The source code is released under:

GNU General Public License

If you think the Android project Android-Chat-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package bb.apps.firstapp;
/*from   w ww.ja v  a  2s .c o m*/
import java.io.IOException;

import bb.chat.enums.Side;
import bb.chat.interfaces.IIOHandler;
import bb.chat.interfaces.IPacket;
import bb.chat.network.handler.BasicMessageHandler;
import bb.chat.network.handler.DefaultPacketHandler;
import bb.chat.network.handler.IOHandler;
import bb.chat.security.StringPermission;
import bb.chat.security.StringUserPermission;
import bb.chat.security.StringUserPermissionGroup;

import android.net.NetworkInfo;

public class AndroidMessageHandler extends BasicMessageHandler<String,StringPermission,StringUserPermissionGroup> {

    private NetworkInfo netinf;

    @SuppressWarnings("unchecked")
    public AndroidMessageHandler() {

        super();

        side = Side.CLIENT;
        localActor = new IIOHandler<String,StringPermission,StringUserPermissionGroup>() {

            StringUserPermission iup = new StringUserPermission();

            private String name = "Client";

            @Override
            public void start() {

            }

            @Override
            public void stop() {

            }

            @Override
            public boolean isDummy() {
                return false;
            }

            @Override
            public String getActorName() {

                return name;
            }

            @Override
            public void setActorName(String s) {

                name = s;
            }

            @Override
            public boolean sendPacket(IPacket p) {
                return false;
            }

            @Override
            public boolean isAlive() {
                return false;
            }

            @Override
            public void receivedHandshake() {

            }

            @Override
            public StringUserPermission getUserPermission() {
                return iup;
            }

            @Override
            public void run() {

            }
        };

        PD.registerPacketHandler(new DefaultPacketHandler(this));


        addCommand(bb.chat.command.Connect.class);
        addCommand(bb.chat.command.Whisper.class);
        addCommand(bb.chat.command.Rename.class);
        addCommand(bb.chat.command.Disconnect.class);
    }

    @Override
    public void sendPackage(IPacket p) {
        IRServer.sendPacket(p);
    }

    @Override
    public void connect(String host, int port) {
        if (IRServer != null) {
            disconnect(IRServer);
            try {
                IRServer.stop();
            } catch (Throwable e) {
                e.printStackTrace();
            }
            IRServer = null;
        }

        socket = new ConnectionEstablisher(host, port, this, netinf).getSocket();

        try {
            IRServer = new IOHandler(socket.getInputStream(), socket.getOutputStream(), this);
            IRServer.start();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public void setNetworkInfo(NetworkInfo networkInfo) {
        netinf = networkInfo;

    }

}




Java Source Code List

bb.apps.firstapp.AndroidMessageHandler.java
bb.apps.firstapp.ConnectionEstablisher.java
bb.apps.firstapp.MainActivity.java