Android Example

Here is an example of an Activity that can respond to SymGym events:

package fit.symgym.example;

import android.app.Activity;
import android.os.Bundle;
import fit.symgym.android.api.SgStub;
import fit.symgym.android.api.SgState;

public class ExampleActivity extends Activity {
  private SgStub sgStub = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    sgStub = new SgStub(this, "api_key_string_here");
    new Thread(new Runnable() {
      @Override public void run() {
        while(true) {
          try {
              Thread.sleep(100);
              SgState state = sgStub.getState();
              if(state.isLeftTrigger()) {
                  // do something about left trigger
              }
              if(state.getLeftArmVelocity() > 24) {
                  // increase resistance if moving too fast
                  sgStub.setResistanceArms(state.getLeftArmResistance()+10);
              }
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
        }
      }
    }).start();
  }
}

In this example, the ExampleActivity starts a new thread when created and the thread communicates with SymGym.