<commit_before>package cz.mendelu.xmarik.train_manager;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;

import cz.mendelu.xmarik.train_manager.events.ReloadEvent;

import static android.preference.PreferenceManager.getDefaultSharedPreferences;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    private final int port = 5880;
    ServerSocket serverSocket;
    Button lButton;
    ArrayList<String> array;
    ArrayList<String> array1;
    ArrayAdapter<String> fAdapter;
    ArrayAdapter<String> lAdapter;
    Context context;
    Object obj;
    SharedPreferences sharedpreferences;
    private ListView lServers;
    private ListView fServers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //tady nacist ulozeny data
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        get();
        obj = this;
        context = this.getApplicationContext();
        lButton = (Button) findViewById(R.id.serverButton);
        fServers = (ListView) findViewById(R.id.farServers);
        lServers = (ListView) findViewById(R.id.localServers);
        EventBus.getDefault().register(this);
        sharedpreferences = getDefaultSharedPreferences(getApplicationContext());
        ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (mWifi.isConnected()) {
            UdpDiscover udp = new UdpDiscover(context, port, this);
            udp.execute();
            this.lButton.setClickable(false);
        } else Toast.makeText(getApplicationContext(),
                R.string.nedostupnaWifi, Toast.LENGTH_LONG)
                .show();
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        array = ServerList.getInstance().getServersString();
        lAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, array);
        array1 = ServerList.getInstance().getStoredServersString();
        fAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, array1);
        lServers.setAdapter(lAdapter);
        fServers.setAdapter(fAdapter);
        registerForContextMenu(fServers);
        // ListView Item Click Listener
        fServers.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // ListView Clicked item value
                String itemValue = (String) fServers.getItemAtPosition(position);
                AuthorizeServer(itemValue);
            }

        });

        lButton.setOnClickListener(
                new View.OnClickListener() {

                    public void onClick(View view) {
                        ServerList.getInstance().clearLocalServers();
                        array = ServerList.getInstance().getServersString();

                        lAdapter = new ArrayAdapter<>(context,
                                android.R.layout.simple_list_item_1, android.R.id.text1, array);
                        lServers.setAdapter(lAdapter);
                        lAdapter.notifyDataSetChanged();

                        ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                        NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                        if (mWifi.isConnected()) {
                            UdpDiscover udp = new UdpDiscover(context, port, (MainActivity) obj);
                            System.out.print("button activated");
                            //udp.run();
                            udp.execute();
                            float deg = lButton.getRotation() + 720F;
                            lButton.animate().rotation(deg).setInterpolator(new AccelerateDecelerateInterpolator());
                        } else Toast.makeText(getApplicationContext(),
                                R.string.nedostupnaWifi, Toast.LENGTH_LONG)
                                .show();
                        float deg = lButton.getRotation() + 360F;
                        lButton.animate().rotation(deg).setInterpolator(new AccelerateDecelerateInterpolator());
                    }
                });
        // ListView Item Click Listener
        lServers.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // ListView Clicked item value
                String itemValue = (String) lServers.getItemAtPosition(position);

                AuthorizeServer(itemValue);
            }


        });<commit_msg>Fix UDP discovery.<commit_after>package cz.mendelu.xmarik.train_manager;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;

import cz.mendelu.xmarik.train_manager.events.ReloadEvent;

import static android.preference.PreferenceManager.getDefaultSharedPreferences;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    private final int port = 5880;
    ServerSocket serverSocket;
    Button lButton;
    ArrayList<String> array;
    ArrayList<String> array1;
    ArrayAdapter<String> fAdapter;
    ArrayAdapter<String> lAdapter;
    Context context;
    Object obj;
    SharedPreferences sharedpreferences;
    private ListView lServers;
    private ListView fServers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //tady nacist ulozeny data
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        get();
        obj = this;
        context = this.getApplicationContext();
        lButton = (Button) findViewById(R.id.serverButton);
        fServers = (ListView) findViewById(R.id.farServers);
        lServers = (ListView) findViewById(R.id.localServers);
        EventBus.getDefault().register(this);
        sharedpreferences = getDefaultSharedPreferences(getApplicationContext());
        ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (mWifi.isConnected()) {
            UdpDiscover udp = new UdpDiscover(context, port, this);
            udp.execute();
            this.lButton.setClickable(false);
        } else Toast.makeText(getApplicationContext(),
                R.string.nedostupnaWifi, Toast.LENGTH_LONG)
                .show();
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        array = ServerList.getInstance().getServersString();
        lAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, array);
        array1 = ServerList.getInstance().getStoredServersString();
        fAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, array1);
        lServers.setAdapter(lAdapter);
        fServers.setAdapter(fAdapter);
        registerForContextMenu(fServers);
        // ListView Item Click Listener
        fServers.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // ListView Clicked item value
                String itemValue = (String) fServers.getItemAtPosition(position);
                AuthorizeServer(itemValue);
            }

        });

        lButton.setOnClickListener(
                new View.OnClickListener() {

                    public void onClick(View view) {
                        ServerList.getInstance().clearLocalServers();
                        array = ServerList.getInstance().getServersString();

                        lAdapter = new ArrayAdapter<>(context,
                                android.R.layout.simple_list_item_1, android.R.id.text1, array);
                        lServers.setAdapter(lAdapter);
                        lAdapter.notifyDataSetChanged();

                        ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                        NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                        if (mWifi.isConnected()) {
                            new UdpDiscover(context, port, (MainActivity) obj).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
                            System.out.print("button activated");
                            float deg = lButton.getRotation() + 720F;
                            lButton.animate().rotation(deg).setInterpolator(new AccelerateDecelerateInterpolator());
                        } else Toast.makeText(getApplicationContext(),
                                R.string.nedostupnaWifi, Toast.LENGTH_LONG)
                                .show();
                        float deg = lButton.getRotation() + 360F;
                        lButton.animate().rotation(deg).setInterpolator(new AccelerateDecelerateInterpolator());
                    }
                });
        // ListView Item Click Listener
        lServers.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // ListView Clicked item value
                String itemValue = (String) lServers.getItemAtPosition(position);

                AuthorizeServer(itemValue);
            }


        });
{'fraction_non_alphanumeric': 0.08764519535374868, 'fraction_numerical': 0.003620455573993061, 'mean_word_length': 2.562332079527136, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6000444', 'n_tokens_mistral': 3473, 'n_tokens_neox': 3359, 'n_words': 613}