Android Open Source - SensOSC Sensor Group 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;
//from  ww w  . ja va2s. c o m
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by thomas on 08.10.14.
 */
public class SensorGroupFragment extends Fragment {

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle args = this.getArguments();
    int dimensions = args.getInt("dimensions");
    int sensorType = args.getInt("sensorType");
    String oscPrefix = args.getString("oscPrefix");

    String name = args.getString("name");
    View v = inflater.inflate(R.layout.sensor_group, null);
    TextView groupName = (TextView) v.findViewById(R.id.group_name);
    groupName.setText(name);

    switch (dimensions) {
      case 1:
        Create1DSensor(sensorType, oscPrefix);
        break;
      case 3:
        Create3DSensors(sensorType, oscPrefix);
        break;
    }

    return v;
  }

  private void Create3DSensors(int sensorType, String oscPrefix) {
    for (int i = 0; i < 3; i++) {
      String direction = "";
      switch (i) {
        case 0:
          direction = "X";
          break;
        case 1:
          direction = "Y";
          break;
        case 2:
          direction = "Z";
          break;
      }
      FragmentManager manager = getChildFragmentManager();
      String fragmentTag = oscPrefix + direction;
      SensorFragment sensorFragment = (SensorFragment) manager.findFragmentByTag(fragmentTag);
      if (sensorFragment == null) {
        sensorFragment = CreateSensorFragment(sensorType, oscPrefix, i, direction, manager, fragmentTag);
      }
      StartupActivity activity = (StartupActivity) this.getActivity();
      activity.addSensorFragment(sensorFragment);
    }
  }

  private SensorFragment CreateSensorFragment(int sensorType, String oscPrefix, int i, String direction, FragmentManager manager, String fragmentTag) {
    SensorFragment sensorFragment;
    FragmentTransaction transaction = manager.beginTransaction();
    sensorFragment = new SensorFragment();
    Bundle args = new Bundle();
    args.putInt("sensorType", sensorType);
    args.putString("name", direction);
    args.putString("oscPrefix", oscPrefix + direction);
    args.putInt("index", i);
    sensorFragment.setArguments(args);
    transaction.add(R.id.sensor_list, sensorFragment, fragmentTag);
    transaction.commit();
    return sensorFragment;
  }

  private void Create1DSensor(int sensorType, String oscPrefix) {
    FragmentManager manager = getChildFragmentManager();
    String fragmentTag = oscPrefix;
    SensorFragment sensorFragment = (SensorFragment) manager.findFragmentByTag(fragmentTag);
    if (sensorFragment == null) {
      sensorFragment = CreateSensorFragment(sensorType, oscPrefix, manager);
    }
    StartupActivity activity = (StartupActivity) this.getActivity();
    activity.addSensorFragment(sensorFragment);
  }

  private SensorFragment CreateSensorFragment(int sensorType, String oscPrefix, FragmentManager manager) {
    SensorFragment sensorFragment;FragmentTransaction transaction = manager.beginTransaction();
    sensorFragment = new SensorFragment();
    Bundle args = new Bundle();
    args.putInt("sensorType", sensorType);
    args.putString("oscPrefix", oscPrefix);
    sensorFragment.setArguments(args);
    transaction.add(R.id.sensor_list, sensorFragment, oscPrefix);
    transaction.commit();
    return sensorFragment;
  }
}




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