Android Open Source - SensOSC Sensor Fragment






From Project

Back to project page SensOSC.

License

The source code is released under:

Author: Thomas Mayer <thomas@residuum.org> Copyright (c) 2014 Thomas Mayer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation ...

If you think the Android project SensOSC listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.residuum.sensosc;
//w  ww . j  a v  a 2s  .c o m
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;

public class SensorFragment extends Fragment {

  private int sensorType;
  private int index;
  private String oscParam;
  private float currentValue;
  private float sensitivity;
  private CompoundButton activeButton;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    View view = inflater.inflate(R.layout.single_sensor, null);
    Bundle args = this.getArguments();
    this.index = args.getInt("index", 0);
    this.sensorType = args.getInt("sensorType");
    this.oscParam = args.getString("oscPrefix");
    String name = args.getString("name", null);

    if (name != null) {
      view.findViewById(R.id.name).setVisibility(View.VISIBLE);
      ((TextView) view.findViewById(R.id.name)).setText(name);
    }

    this.activeButton = (CompoundButton) view.findViewById(R.id.active);
    return view;
  }

  public int getSensorType() {
    return this.sensorType;
  }

  public int getIndex() {
    return this.index;
  }

  public void setSensitivity(float sensitivity) {
    this.sensitivity = sensitivity;
  }

  public void setValue(float value) {
    if (Math.abs(value - this.currentValue) > this.sensitivity && this.activeButton.isChecked()) {
      this.sendValue(value);
      this.currentValue = value;
    }
  }

  private void sendValue(float value) {
    new OscCommunication(OscConfiguration.getInstance()).execute(oscParam, Float.toString(value));
  }
}




Java Source Code List

org.residuum.sensosc.AboutActivity.java
org.residuum.sensosc.ApplicationTest.java
org.residuum.sensosc.ExtendedEditTextPreference.java
org.residuum.sensosc.OscCommunication.java
org.residuum.sensosc.OscConfiguration.java
org.residuum.sensosc.SensorFragment.java
org.residuum.sensosc.SensorGroupFragment.java
org.residuum.sensosc.Sensor.java
org.residuum.sensosc.SettingsActivity.java
org.residuum.sensosc.StartupActivity.java