Android Open Source - deskflix Main Activity






From Project

Back to project page deskflix.

License

The source code is released under:

Apache License

If you think the Android project deskflix 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.urucas.deskflix.activities;
//from  w  ww.ja v a2 s .co  m
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

import com.urucas.deskflix.R;
import com.urucas.deskflix.interfaces.RemoteControlCallback;
import com.urucas.deskflix.sockets.RemoteControl;

import java.util.ArrayList;


public class MainActivity extends ActionBarActivity {

    private RemoteControl remote;
    private Spinner socketsSpinner;
    private Button fullscreenToggle;
    private Button playToggle;

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

        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) {

            }
        });

        remote = new RemoteControl(MainActivity.this, new RemoteControlCallback() {
            @Override
            public void onSocketFound(ArrayList<String> socketsName) {
                refreshSpinner(socketsName);
            }
            @Override
            public void onSocketDisconected(ArrayList<String> socketsName) {

            }
        });
        refreshSpinner(new ArrayList<String>());

        remote.search4Sockets();

        fullscreenToggle = (Button) findViewById(R.id.fullscreenToggle);
        fullscreenToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                remote.fullscreen();
            }
        });

        playToggle = (Button) findViewById(R.id.playToggle);
        playToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                remote.toggle();
            }
        });

    }

    private void selectSocket(String localname) {
        remote.selectSocket(localname);
    }

    public void refreshSpinner(ArrayList<String> socketsList) {

        if(socketsList.size() == 0){
            socketsList.add(getResources().getString(R.string.nosockets));
        }

        ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
                MainActivity.this,
                R.layout.spinner_item,
                socketsList
        );

        spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        socketsSpinner.setAdapter(spinnerArrayAdapter);
    }

}




Java Source Code List

com.urucas.deskflix.ApplicationTest.java
com.urucas.deskflix.DeskflixApp.java
com.urucas.deskflix.activities.MainActivity.java
com.urucas.deskflix.interfaces.RemoteControlCallback.java
com.urucas.deskflix.interfaces.VolumeKeysCallback.java
com.urucas.deskflix.sockets.RemoteControl.java
com.urucas.deskflix.utils.Utils.java