Android Open Source - dcchat Dc Chat Async Task






From Project

Back to project page dcchat.

License

The source code is released under:

Apache License

If you think the Android project dcchat 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 net.kaleidos.dcchat.async;
//from   w w  w .j  av a  2 s.  c  o  m
import java.io.IOException;

import net.kaleidos.dcchat.Base32;
import net.kaleidos.dcchat.DCChat;
import net.kaleidos.dcchat.listener.DccNotificationListener;
import net.kaleidos.dcchat.listener.Messageable;
import android.os.AsyncTask;
import android.util.Log;

public class DcChatAsyncTask extends AsyncTask<String, Void, String> {
  
  private static final String ADCS="adcs";
  



  DCChat dcchat;
  DccNotificationListener listener;
  Messageable messageable;
  String pid;
  String host;
  int port = 2783;
  String protocol="adcs";
  String userName;

    public DcChatAsyncTask(Messageable messageable, String pid, String server, String userName) {
    super();
    this.messageable = messageable;
    this.pid = pid;
    this.userName = userName;
    
    String[] s0 = server.split("://");
    String s1;
    
    if (s0.length == 2){
      protocol = s0[0];
      s1 = s0[1];
    } else {
      s1 = s0[0];
    }
    
    String[] s = s1.split(":");
    
    
    this.host = s[0];
    
    if (s.length == 2){
      this.port = Integer.parseInt(s[1]);
    }
  }
    
    public DCChat getDcchat() {
    return dcchat;
  }

  @Override
    protected String doInBackground(String... params) {
      try {
        listener = new DccNotificationListener();
        listener.addMessageable(messageable);
        
        
        Log.d("Connection host", host);
        Log.d("Connection port", ""+port);
        Log.d("Connection ssl", ""+ADCS.equals(protocol));
        
                
      this.dcchat = new DCChat(userName, host, port, ADCS.equals(protocol), Base32.decode(pid), listener);
      this.dcchat.connect();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      messageable.receiveError(e.getMessage());
    }
        return "Executed";
    }

    @Override
    protected void onPostExecute(String result) {
       
    }

    @Override
    protected void onPreExecute() {}

    @Override
    protected void onProgressUpdate(Void... values) {}
    
    public void disconnect() {
      try {
        Log.d ("DcChatAsyncTask", "disconnect");
      dcchat.disconnect();
      
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
      
    }
       


}




Java Source Code List

interfaces.NotificationListener.java
net.kaleidos.dcchat.Base32.java
net.kaleidos.dcchat.ChatActivity.java
net.kaleidos.dcchat.DCChat.java
net.kaleidos.dcchat.Data.java
net.kaleidos.dcchat.Main.java
net.kaleidos.dcchat.Message.java
net.kaleidos.dcchat.NaiveTrustManager.java
net.kaleidos.dcchat.NaiveTrustProvider.java
net.kaleidos.dcchat.NotificationListenerImp.java
net.kaleidos.dcchat.ServersActivity.java
net.kaleidos.dcchat.async.DcChatAsyncTask.java
net.kaleidos.dcchat.async.SendMessageAsyncTask.java
net.kaleidos.dcchat.listener.DccNotificationListener.java
net.kaleidos.dcchat.listener.Messageable.java