Android Open Source - steamchat Steam Service






From Project

Back to project page steamchat.

License

The source code is released under:

Apache License

If you think the Android project steamchat 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 com.kevelbreh.steamchat.steam;
/*w  ww  . j  a v  a2 s  .  c o m*/
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;

import com.kevelbreh.steamchat.SteamChat;
import com.kevelbreh.steamchat.account.SteamAccount;
import com.kevelbreh.steamchat.activity.AuthenticationActivity;

import java.util.ArrayList;

/**
 * Connect to steam network.
 *  -> Hold up the login screen if there is no account found.
 *  -> Ask for account details
 * Log in the user.
 *  -> Show login screen auth or other things if applicable
 *  -> Update account details
 *  Hide screen and go to conversations.
 *
 *  Start service   -> has account -> connect.
 *                  -> no account -> auth activity -> auth-now = start service.
 *
 *  Any failed login will result in the account getting deleted.
 */
public class SteamService extends Service {

    /**
     * Conversation between the service and other things.
     */
    private final Messenger mMessenger = new Messenger(new IncomingHandler());
    private final ArrayList<Messenger> mBoundClients = new ArrayList<Messenger>();

    /**
     * Steam client.
     */
    private SteamClient client;

    @Override
    public void onCreate() {
        client = new SteamClient(this, "72.165.61.174", 27017);

        /*
         * If there is an existing steam account present then connect it to the steam network. If
         * there isn't one then wait for user data to arrive for a connection attempt.
         */
        SteamAccount account = new SteamAccount(this);
        if (account.hasAccount()) {
            client.setAccount(account);
            client.connect();
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        return mMessenger.getBinder();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
    }

    /**
     * Broadcast a message to all connected {@link com.kevelbreh.steamchat.steam.SteamServiceHandler}
     * who are registered to this service.  The receiver can reply back to the service for everyone
     * or can reply directly to the original message source.
     * @param message the {@link android.os.Message} event.
     */
    public void sendBroadcast(Message message) {
        for (Messenger boundClient : mBoundClients) {
            try {
                Message temp = Message.obtain(null, message.what);
                temp.replyTo = message.replyTo;
                temp.setData(message.getData());

                //SteamChat.debug(this, "Broadcasting " + message.what + " from " +
                //        message.replyTo.toString() + " -> " + boundClient.toString());
                boundClient.send(temp);
            }
            catch(final RemoteException e) {
                SteamChat.debug(this, e.toString());
            }
        }
    }

    /**
     * Service handler to communicate the UI interactions with this android service.
     */
    public class IncomingHandler extends SteamServiceHandler {

        @Override
        public void onAddHandler(Message message) {
            mBoundClients.add(message.replyTo);
        }

        @Override
        public void onRemoveHandler(Message message) {
            mBoundClients.remove(message.replyTo);
        }

        @Override
        public void onBroadcast(Message message) {
            sendBroadcast(message);
        }

        @Override
        public void onAuthenticateNow(Message message) {
            client.setAccount(new SteamAccount(SteamService.this, message.getData()));
            client.reconnect();
        }

        @Override
        public void onAuthenticationRequired(Message message) {
            startActivity(new Intent(SteamService.this, AuthenticationActivity.class));
        }
    }
}




Java Source Code List

com.kevelbreh.steamchat.SteamChat.java
com.kevelbreh.steamchat.account.AuthenticatorService.java
com.kevelbreh.steamchat.account.Authenticator.java
com.kevelbreh.steamchat.account.SteamAccount.java
com.kevelbreh.steamchat.activity.AuthenticationActivity.java
com.kevelbreh.steamchat.activity.ConversationActivity.java
com.kevelbreh.steamchat.activity.FriendsActivity.java
com.kevelbreh.steamchat.activity.InteractionsActivity.java
com.kevelbreh.steamchat.activity.LauncherActivity.java
com.kevelbreh.steamchat.activity.SettingsActivity.java
com.kevelbreh.steamchat.fragment.ConversationFragment.java
com.kevelbreh.steamchat.fragment.FriendsFragment.java
com.kevelbreh.steamchat.fragment.InteractionsFragment.java
com.kevelbreh.steamchat.fragment.SettingsFragment.java
com.kevelbreh.steamchat.provider.SteamProviderUtils.java
com.kevelbreh.steamchat.provider.SteamProvider.java
com.kevelbreh.steamchat.provider.content.InteractionContentItem.java
com.kevelbreh.steamchat.provider.content.PersonaContentItem.java
com.kevelbreh.steamchat.provider.content.UserContentItem.java
com.kevelbreh.steamchat.steam2.SteamConnection.java
com.kevelbreh.steamchat.steam2.SteamEventBus.java
com.kevelbreh.steamchat.steam2.SteamService.java
com.kevelbreh.steamchat.steam2.handler.ConnectionHandler.java
com.kevelbreh.steamchat.steam2.handler.FriendHandler.java
com.kevelbreh.steamchat.steam2.handler.MessageHandler.java
com.kevelbreh.steamchat.steam2.handler.UserHandler.java
com.kevelbreh.steamchat.steam2.packet.Packet.java
com.kevelbreh.steamchat.steam2.packet.ProtoPacket.java
com.kevelbreh.steamchat.steam.SteamClient.java
com.kevelbreh.steamchat.steam.SteamID.java
com.kevelbreh.steamchat.steam.SteamServiceHandler.java
com.kevelbreh.steamchat.steam.SteamService.java
com.kevelbreh.steamchat.steam.handler2.ConnectionHandler.java
com.kevelbreh.steamchat.steam.handler2.FriendHandler.java
com.kevelbreh.steamchat.steam.handler2.Handler.java
com.kevelbreh.steamchat.steam.handler2.UserHandler.java
com.kevelbreh.steamchat.steam.handler.AEventHandler.java
com.kevelbreh.steamchat.steam.handler.AuthenticationHandler.java
com.kevelbreh.steamchat.steam.handler.FriendsHandler.java
com.kevelbreh.steamchat.steam.handler.IEventHandler.java
com.kevelbreh.steamchat.steam.handler.IHandler.java
com.kevelbreh.steamchat.steam.handler.MessageDebugHandler.java
com.kevelbreh.steamchat.steam.language.Language.java
com.kevelbreh.steamchat.steam.language.Message.java
com.kevelbreh.steamchat.steam.network.TCPConnection.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptRequest.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptResponse.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptResult.java
com.kevelbreh.steamchat.steam.network.packet.ClientLogOnResponse.java
com.kevelbreh.steamchat.steam.network.packet.ClientLogOn.java
com.kevelbreh.steamchat.steam.network.packet.HeartBeat.java
com.kevelbreh.steamchat.steam.network.packet.MultiPacket.java
com.kevelbreh.steamchat.steam.network.packet.Packet.java
com.kevelbreh.steamchat.steam.network.packet.ProtoPacket.java
com.kevelbreh.steamchat.steam.proto.DescriptorsProto.java
com.kevelbreh.steamchat.steam.proto.EncryptedAppTicketProto.java
com.kevelbreh.steamchat.steam.proto.SteamMessagesBaseProto.java
com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.java
com.kevelbreh.steamchat.steam.security.AsnKeyParser.java
com.kevelbreh.steamchat.steam.security.AsnParser.java
com.kevelbreh.steamchat.steam.security.BerDecodeException.java
com.kevelbreh.steamchat.steam.security.Cryptography.java
com.kevelbreh.steamchat.steam.security.NetEncryption.java
com.kevelbreh.steamchat.steam.security.PublicKey.java
com.kevelbreh.steamchat.steam.security.RSA.java
com.kevelbreh.steamchat.steam.util.BinaryReader.java
com.kevelbreh.steamchat.steam.util.BinaryWriter.java
com.kevelbreh.steamchat.steam.util.BitVector64.java
com.kevelbreh.steamchat.steam.util.JenkinsHash.java
com.kevelbreh.steamchat.util.AServiceActivity.java
com.kevelbreh.steamchat.util.Dump.java
com.kevelbreh.steamchat.util.MiscUtils.java
com.kevelbreh.steamchat.widget.adapter.ChatAdapter.java
com.kevelbreh.steamchat.widget.adapter.ConversationAdapter.java
com.kevelbreh.steamchat.widget.adapter.FriendAdapter.java
com.kevelbreh.steamchat.widget.view.AvatarView.java
com.kevelbreh.steamchat.widget.view.FriendInteractionsView.java