Android Open Source - luminous Background Task






From Project

Back to project page luminous.

License

The source code is released under:

GNU General Public License

If you think the Android project luminous 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 de.denisulmer.luminous.v2;
//from   ww w .ja v  a2s. c o  m
import android.os.AsyncTask;
import android.util.Log;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;

public class BackgroundTask extends AsyncTask<String, Void, String>
{

    @Override
    protected String doInBackground(String... strings)
    {
        String host = strings[0];
        int port = Integer.parseInt(strings[1]);

        try
        {
            Socket socket = new Socket();
            int TIMEOUT = 5000;
            socket.connect(new InetSocketAddress(host, port), TIMEOUT);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());

            dataOutputStream.writeBytes("{\"message\": \"client controller\"}\n");

            if (bufferedReader.readLine().contains("accept"))
            {
                dataOutputStream.writeBytes("{\"message\": \"request config\"}\n");
            }
            String config = bufferedReader.readLine();
            if (config.contains("config"))
            {
                socket.close();
                return config;
            }
        }
        catch (Exception e)
        {
            String TAG = "BackgroundTask";
            Log.d(TAG, "Error connecting to pilight-daemon: " + e.toString());
            return null;
        }
        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Core.refreshUI(s);
    }
}




Java Source Code List

de.denisulmer.luminous.v2.BackgroundTask.java
de.denisulmer.luminous.v2.Core.java
de.denisulmer.luminous.v2.DeviceListAdapter.java
de.denisulmer.luminous.v2.Device.java
de.denisulmer.luminous.v2.LocationFragment.java
de.denisulmer.luminous.v2.LocationPageAdapter.java
de.denisulmer.luminous.v2.MainActivity.java
de.denisulmer.luminous.v2.SetupActivity.java