package com.saife.examples;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import android.util.Log;

import com.saife.examples.saifeecho.R;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class MainActivity extends ActionBarActivity {

  private static String LOG_TAG = MainActivity.class.getSimpleName();
  private SaifeManager saifeManager;
  private ExecutorService executorService = Executors.newCachedThreadPool();

  private static final String PASSWORD = "hhhh";

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

    saifeManager = new SaifeManager(executorService);

    try {
      if (saifeManager.init(PASSWORD, this.getApplicationContext())) {
        Log.i(LOG_TAG, "Successfully keyed. Exiting.");
        finish();
      }
    } catch (Exception e) {
      Log.e(LOG_TAG, "Exception: ", e);
    }

    Button startSessionButton = (Button) findViewById(R.id.startsessionbutton);
    startSessionButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        saifeManager.runSessionClient();
      }
    });

  }

  @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_settings) {
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
}

@@ -234,16 +234,90 @@
 til.Log;
+%0Aimport android.widget.CompoundButton;%0Aimport android.widget.ToggleButton;
 %0A%0Aimport
@@ -1179,37 +1179,37 @@
     
+Toggle
 Button 
-startSessionButton = (
+toggle = (Toggle
 Butt
@@ -1234,21 +1234,22 @@
 .id.
-start
 session
-b
+ToggleB
 utto
@@ -1260,167 +1260,305 @@
     
-startSessionButton.setOnClickListener(new View.OnClickListener() %7B%0A      @Override%0A      public void onClick(View v) %7B%0A        saifeManager.runSessionClient();
+toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() %7B%0A      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) %7B%0A        if (isChecked) %7B%0A          saifeManager.runSessionClient();%0A        %7D else %7B%0A          saifeManager.stopSessions();%0A        %7D
 %0A   
@@ -1570,17 +1570,16 @@
     %7D);%0A
-%0A
   %7D%0A%0A  @

Change main activity to use a toggle instead of a button