Android Open Source - android-rotation-sensor-sample Main Activity






From Project

Back to project page android-rotation-sensor-sample.

License

The source code is released under:

Copyright (c) 2013 Keith Platfoot Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Sof...

If you think the Android project android-rotation-sensor-sample 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 com.kviation.android.sample.orientation;
/*from   w  ww  .j av  a2s  .com*/
import android.app.Activity;
import android.hardware.SensorManager;
import android.os.Bundle;

public class MainActivity extends Activity implements Orientation.Listener {

  private Orientation mOrientation;
  private AttitudeIndicator mAttitudeIndicator;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    mOrientation = new Orientation((SensorManager) getSystemService(Activity.SENSOR_SERVICE),
        getWindow().getWindowManager());
    mAttitudeIndicator = (AttitudeIndicator) findViewById(R.id.attitude_indicator);
  }

  @Override
  protected void onResume() {
    super.onResume();
    mOrientation.startListening(this);
  }

  @Override
  protected void onPause() {
    super.onPause();
    mOrientation.stopListening();
  }

  @Override
  public void onOrientationChanged(float pitch, float roll) {
    mAttitudeIndicator.setAttitude(pitch, roll);
  }
}




Java Source Code List

com.kviation.android.sample.orientation.AttitudeIndicator.java
com.kviation.android.sample.orientation.Log.java
com.kviation.android.sample.orientation.MainActivity.java
com.kviation.android.sample.orientation.Orientation.java