package dk.cmol.arduinorgb_controller;

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class ArduinoRGBActivity extends FragmentActivity {

	// Setting vars
	public boolean lamp_toggle[] = { false, false, false, false };
	private ArduinoSocket sock = null;
	private LampParser lp;

	// This is were all the grim menu stuff begins
	MenuPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;

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

		// Create the adapter that will return a fragment for each of the three
		// primary sections of the app.
		mSectionsPagerAdapter = new MenuPagerAdapter(
				getSupportFragmentManager());

		// Set up the ViewPager with the sections adapter.
		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);

		// Create the parser and the socket
		lp = new LampParser();
		sock = new ArduinoSocket(this);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	// Toggle lamp sequence
	public void toggleLamp(View v) {
		Button button = (Button) v;
		int pos = Integer.parseInt(button.getText().toString()) - 1;

		if (lamp_toggle[pos]) {
			button.getBackground().setColorFilter(Color.LTGRAY,
					PorterDuff.Mode.MULTIPLY);
		} else {
			button.getBackground().setColorFilter(Color.GREEN,
					PorterDuff.Mode.MULTIPLY);
		}

		// Change value of button
		lamp_toggle[pos] = !lamp_toggle[pos];
	}

	// React to a pressed color
	public void colorPress(View v) {

		// Check to see if any lamps are toggled on
		boolean go = false;
		for (int i = 0; i < lamp_toggle.length; i++) {
			if (lamp_toggle[i]) {
				go = true;
				break;
			}
		}

		if (go) {

			sock.write(lp.set(lamp_toggle, v.getTag().toString()));

		}
	}

}

@@ -356,16 +356,58 @@
 ctivity 
+implements SliderFragment.ToolbarListener 
 %7B%0A%0A%09// S
@@ -2133,16 +2133,18 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%09
 %0A%09%09if (g
@@ -2148,17 +2148,16 @@
  (go) %7B%0A
-%0A
 %09%09%09sock.
@@ -2207,16 +2207,298 @@
 ng()));%0A
+%09%09%7D%0A%09%7D%0A%0A%09public void seekChange(String colors) %7B%0A%09%09// Check to see if any lamps are toggled on%0A%09%09boolean go = false;%0A%09%09for (int i = 0; i %3C lamp_toggle.length; i++) %7B%0A%09%09%09if (lamp_toggle%5Bi%5D) %7B%0A%09%09%09%09go = true;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09if (go) %7B%0A%09%09%09sock.write(lp.set(lamp_toggle, colors));
 %0A%09%09%7D%0A%09%7D%0A

Add interface for sliders, stille needs lots of work