Android Open Source - SensOSC Sensor Fragment

From Project

Back to project page SensOSC.


The source code is released under:

Author: Thomas Mayer <> 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.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;

  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) {
      ((TextView) view.findViewById(;

    this.activeButton = (CompoundButton) view.findViewById(;
    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.currentValue = value;

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

Java Source Code List