Android Open Source - ArduinoRGB-Controller Gyro Fragment






From Project

Back to project page ArduinoRGB-Controller.

License

The source code is released under:

MIT License

If you think the Android project ArduinoRGB-Controller 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 dk.cmol.arduinorgb_controller;
/*from  w  w  w. j ava  2 s . c  om*/
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class GyroFragment extends Fragment implements OnClickListener {
  // a TextView
  private ToggleButton btn;
  // the Sensor Manager
  private SensorManager sManager;
  boolean sensor = false;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_gyro, container,
        false);

    sManager = (SensorManager) getActivity().getSystemService(getActivity().SENSOR_SERVICE);
    
    btn = (ToggleButton) rootView.findViewById(R.id.gyroButton);
    btn.setOnClickListener((OnClickListener) this);
    
    return rootView;
  }

  @Override
  public void onClick(View v) {
    if (sensor) {
      sManager.unregisterListener((SensorEventListener)getActivity());
    } else {
      sManager.registerListener((SensorEventListener)getActivity(),
          sManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
          SensorManager.SENSOR_DELAY_FASTEST);
    }
    sensor = !sensor;
  }

}




Java Source Code List

dk.cmol.arduinorgb_controller.ArduinoRGBActivity.java
dk.cmol.arduinorgb_controller.ArduinoSocket.java
dk.cmol.arduinorgb_controller.ColorDotsFragment.java
dk.cmol.arduinorgb_controller.FaderFragment.java
dk.cmol.arduinorgb_controller.GyroFragment.java
dk.cmol.arduinorgb_controller.LampParser.java
dk.cmol.arduinorgb_controller.MenuPagerAdapter.java
dk.cmol.arduinorgb_controller.SettingsActivity.java
dk.cmol.arduinorgb_controller.SettingsFragment.java
dk.cmol.arduinorgb_controller.SliderFragment.java