package ca.simonho.randomwalk;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;

import java.util.HashMap;

public class MainActivity extends AppCompatActivity {

    ImageButton forwardButton;
    ImageButton backButton;
    ImageButton leftButton;
    ImageButton rightButton;
    ImageButton randomButton;

    HashMap<ImageButton, Boolean> buttonStates;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //Get references to buttons
        forwardButton = (ImageButton) findViewById(R.id.forwardButton);
        backButton = (ImageButton) findViewById(R.id.backButton);
        leftButton = (ImageButton) findViewById(R.id.leftButton);
        rightButton = (ImageButton) findViewById(R.id.rightButton);
        randomButton = (ImageButton) findViewById(R.id.randomButton);

        //Set initial button state
        buttonStates = new HashMap<>();
        buttonStates.put(forwardButton, false);
        buttonStates.put(backButton, false);
        buttonStates.put(leftButton, true);
        buttonStates.put(rightButton, true);

        //Set state based colour of each button
        for (HashMap.Entry<ImageButton, Boolean> entry : buttonStates.entrySet()) {
            setColour(entry.getKey(), entry.getValue());
        }
    }

    public void setColour(ImageButton button, Boolean newState){
        if (newState){
            button.setColorFilter(getResources().getColor(R.color.buttonSelected));
        } else {
            button.setColorFilter(getResources().getColor(R.color.buttonNotSelected));
        }
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_about) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -142,16 +142,41 @@
 oolbar;%0A
+import android.util.Log;%0A
 import a
@@ -223,16 +223,42 @@
 nuItem;%0A
+import android.view.View;%0A
 import a
@@ -364,16 +364,48 @@
 ctivity 
+implements View.OnClickListener 
 %7B%0A%0A    I
@@ -1496,16 +1496,62 @@
 , true);
+%0A        buttonStates.put(randomButton, true);
 %0A%0A      
@@ -1558,16 +1558,24 @@
   //Set 
+initial 
 state ba
@@ -1589,10 +1589,30 @@
 our 
-of
+and click listener for
  eac
@@ -1765,35 +1765,306 @@
 ));%0A
-        %7D%0A    %7D%0A%0A    public
+%0A            entry.getKey().setOnClickListener(this);%0A        %7D%0A    %7D%0A%0A    private void toggleButtonState(ImageButton button)%7B%0A        Boolean newButtonState = !buttonStates.get(button);%0A        buttonStates.put(button, newButtonState);%0A        setColour(button, newButtonState);%0A    %7D%0A%0A    private
  voi
@@ -3066,11 +3066,1204 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void onClick(View v) %7B%0A        switch(v.getId())%7B%0A            case R.id.forwardButton:%0A                //Toggle the existing button state/colour%0A                toggleButtonState(forwardButton);%0A                break;%0A            case R.id.backButton:%0A                //Toggle the existing button state/colour%0A                toggleButtonState(backButton);%0A                break;%0A            case R.id.leftButton:%0A                //Toggle the existing button state/colour%0A                toggleButtonState(leftButton);%0A                break;%0A            case R.id.rightButton:%0A                //Toggle the existing button state/colour%0A                toggleButtonState(rightButton);%0A                break;%0A            case R.id.randomButton:%0A                Log.d(%22click%22, %22random button pushed%22);%0A                break;%0A        %7D%0A%0A        for (HashMap.Entry%3CImageButton, Boolean%3E entry : buttonStates.entrySet()) %7B%0A            Log.d(%22Click: %22, String.valueOf(getResources().getResourceName(entry.getKey().getId())) + %22: %22 + entry%0A                    .getValue%0A                    ());%0A        %7D%0A%0A        Log.d(%22----------------------%22,%22--------------------%22);%0A    %7D
 %0A%7D%0A

Add toggle behaviour for each direction button