예제 #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // the alarm is the thing that triggers monitor execution
    createMonitorAlarm();

    // bind to monitoring service
    monitoringServiceConnector = new MonitoringServiceConnector(this);
    monitoringServiceConnector.bind(
        new MonitoringServiceConnector.RunPostBind() {
          @Override
          public void onPostBind(MonitoringService monitoringService) {
            onCreateAfterServiceBind(monitoringService);
          }
        });

    // create inflater and UI handler
    mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    uiHandler = new Handler();

    Button clearButton = (Button) findViewById(R.id.clearButton);
    clearButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            monitoringService.clearData();
          }
        });
    clearButton.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            monitoringService.toggleTestMode();
            return true;
          }
        });

    Switch killSwitch = (Switch) findViewById(R.id.monitorsEnabled);
    killSwitch.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            monitoringService.setMonitorsEnabled(isChecked);
          }
        });
  }
예제 #2
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   monitoringServiceConnector.unbind();
 }