<commit_before>package com.urucas.popcorntimerc.activities;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Toast;

import com.github.nkzawa.emitter.Emitter;
import com.github.nkzawa.socketio.client.IO;
import com.github.nkzawa.socketio.client.Socket;
import com.urucas.popcorntimerc.R;
import com.urucas.popcorntimerc.utils.Utils;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;


public class SplashActivity extends ActionBarActivity {

    private static final String TAG_NAME = "SplashActivity";
    private ImageButton playBtt, pauseBtt;
    private String myip;
    private static String port = "8006";

    private Socket socket;
    private HashMap<Socket, String> socketes = new HashMap<Socket, String>();
    private HashMap<String, Socket> connectedSockets = new HashMap<String, Socket>();
    private HashMap<String, String> connectedSocketsName = new HashMap<String, String>();
    private Spinner socketsSpinner;
    private Button fullscreenBtt;
    private ImageButton muteBtt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        playBtt = (ImageButton) findViewById(R.id.playBtt);
        playBtt.setVisibility(View.INVISIBLE);

        pauseBtt = (ImageButton) findViewById(R.id.pauseBtt);
        pauseBtt.setVisibility(View.INVISIBLE);

        fullscreenBtt = (Button) findViewById(R.id.fullscreenBtt);
        fullscreenBtt.setVisibility(View.INVISIBLE);

        muteBtt = (ImageButton) findViewById(R.id.muteBtt);
        muteBtt.setVisibility(View.INVISIBLE);

        socketsSpinner = (Spinner) findViewById(R.id.socketsSpinner);
        socketsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                selectSocket((String) parent.getItemAtPosition(position));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        refreshSpinner();

        getSupportActionBar().setTitle(getResources().getString(R.string.title));

        // get current IP address
        myip = Utils.getIPAddress(true);

        // search for possible sockets
        search4sockets();
    }

    private void selectSocket(String localname) {
        if(localname == null) return;

        String socketip = connectedSocketsName.get(localname);
        socket = connectedSockets.get(socketip);
        if(socket == null) return;

        playBtt.setVisibility(View.VISIBLE);
        playBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("play", new Emitter.Listener() {
                    @Override
                    public void call(Object... args) {
                    }
                });
            }
        });

        pauseBtt.setVisibility(View.VISIBLE);
        pauseBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("pause", new Emitter.Listener() {
                    @Override
                    public void call(Object... args) {
                    }
                });
            }
        });

        fullscreenBtt.setVisibility(View.VISIBLE);
        fullscreenBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("fullscreen", new Emitter.Listener(){
                    @Override
                    public void call(Object... args) {

                    }
                });
            }
        });

        muteBtt.setVisibility(View.VISIBLE);
        muteBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("mute");
            }
        });
    }

    private void search4sockets() {

        if(!Utils.isWIFIConnected(SplashActivity.this)){
            Utils.Toast(SplashActivity.this, R.string.noconnection, Toast.LENGTH_SHORT);
            return;
        }

        // set local ip search based on the mobile ip assigned
        String localip = "http://192.168." +
                myip.split("\\.")[2]
                +".";

        for(int i = 0; i<256; i++) {
            String ip = localip + String.valueOf(i);
            String socketip = ip + ":"+port;
            if(ip.equals(myip)) continue;
            if(connectedSockets.get(socket)!=null) continue;

            Socket socket = createPossibleSocket(socketip);
            if(socket != null) socketes.put(socket, socketip);
        }

    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        int action = event.getAction();
        int keyCode = event.getKeyCode();<commit_msg>show/hide media buttons on player view created/close<commit_after>package com.urucas.popcorntimerc.activities;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Toast;

import com.github.nkzawa.emitter.Emitter;
import com.github.nkzawa.socketio.client.IO;
import com.github.nkzawa.socketio.client.Socket;
import com.urucas.popcorntimerc.R;
import com.urucas.popcorntimerc.utils.Utils;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;


public class SplashActivity extends ActionBarActivity {

    private static final String TAG_NAME = "SplashActivity";
    private ImageButton playBtt, pauseBtt;
    private String myip;
    private static String port = "8006";

    private Socket socket;
    private HashMap<Socket, String> socketes = new HashMap<Socket, String>();
    private HashMap<String, Socket> connectedSockets = new HashMap<String, Socket>();
    private HashMap<String, String> connectedSocketsName = new HashMap<String, String>();
    private Spinner socketsSpinner;
    private Button fullscreenBtt;
    private ImageButton muteBtt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        playBtt = (ImageButton) findViewById(R.id.playBtt);
        playBtt.setVisibility(View.INVISIBLE);

        pauseBtt = (ImageButton) findViewById(R.id.pauseBtt);
        pauseBtt.setVisibility(View.INVISIBLE);

        fullscreenBtt = (Button) findViewById(R.id.fullscreenBtt);
        fullscreenBtt.setVisibility(View.INVISIBLE);

        muteBtt = (ImageButton) findViewById(R.id.muteBtt);
        muteBtt.setVisibility(View.INVISIBLE);

        socketsSpinner = (Spinner) findViewById(R.id.socketsSpinner);
        socketsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                selectSocket((String) parent.getItemAtPosition(position));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        refreshSpinner();

        getSupportActionBar().setTitle(getResources().getString(R.string.title));

        // get current IP address
        myip = Utils.getIPAddress(true);

        // search for possible sockets
        search4sockets();
    }

    private void selectSocket(String localname) {
        if(localname == null) return;

        String socketip = connectedSocketsName.get(localname);
        socket = connectedSockets.get(socketip);
        if(socket == null) return;

        playBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("play", new Emitter.Listener() {
                    @Override
                    public void call(Object... args) {
                    }
                });
            }
        });

        pauseBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("pause", new Emitter.Listener() {
                    @Override
                    public void call(Object... args) {
                    }
                });
            }
        });


        fullscreenBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("fullscreen", new Emitter.Listener(){
                    @Override
                    public void call(Object... args) {

                    }
                });
            }
        });

        muteBtt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socket.emit("mute");
            }
        });

        socket.on("player created", new Emitter.Listener() {
            @Override
            public void call(Object... args) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showPlayerButtons();
                    }
                });
            }
        });

        socket.on("player close", new Emitter.Listener() {
            @Override
            public void call(Object... args) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        hidePlayerButtons();
                    }
                });
            }
        });
    }

    private void showPlayerButtons(){
        muteBtt.setVisibility(View.VISIBLE);
        fullscreenBtt.setVisibility(View.VISIBLE);
        pauseBtt.setVisibility(View.VISIBLE);
        playBtt.setVisibility(View.VISIBLE);
    }

    private void hidePlayerButtons() {
        muteBtt.setVisibility(View.INVISIBLE);
        fullscreenBtt.setVisibility(View.INVISIBLE);
        pauseBtt.setVisibility(View.INVISIBLE);
        playBtt.setVisibility(View.INVISIBLE);
    }

    private void search4sockets() {

        if(!Utils.isWIFIConnected(SplashActivity.this)){
            Utils.Toast(SplashActivity.this, R.string.noconnection, Toast.LENGTH_SHORT);
            return;
        }

        // set local ip search based on the mobile ip assigned
        String localip = "http://192.168." +
                myip.split("\\.")[2]
                +".";

        for(int i = 0; i<256; i++) {
            String ip = localip + String.valueOf(i);
            String socketip = ip + ":"+port;
            if(ip.equals(myip)) continue;
            if(connectedSockets.get(socket)!=null) continue;

            Socket socket = createPossibleSocket(socketip);
            if(socket != null) socketes.put(socket, socketip);
        }

    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        int action = event.getAction();
        int keyCode = event.getKeyCode();
{'fraction_non_alphanumeric': 0.10191948360794972, 'fraction_numerical': 0.0030575845082384916, 'mean_word_length': 2.162771958098308, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6441883', 'n_tokens_mistral': 3299, 'n_tokens_neox': 3085, 'n_words': 627}