Android Open Source - gym-app-android Main Activity






From Project

Back to project page gym-app-android.

License

The source code is released under:

GNU General Public License

If you think the Android project gym-app-android 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.tabi.motiontest;
/*w  w  w  . jav a2  s .  c o  m*/
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.TextureView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements AccelerometerListener{
 
  TextView txtMotionChange;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         
        // Check onResume Method to start accelerometer listener
    }
    
    public void onAccelerationChanged(float x, float y, float z) {
        // TODO Auto-generated method stub
      txtMotionChange = (TextView) findViewById(R.id.txtMotion);
      txtMotionChange.setText("x = "+x+ " y = " + y+" z ="+z);
//       Toast.makeText(getBaseContext(), "x = "+x+ "y = " + y , 
//                 Toast.LENGTH_SHORT).show();
         
    }
 
    public void onShake(float force) {
         
        // Do your stuff here
         
        // Called when Motion Detected
        Toast.makeText(getBaseContext(), "Motion detected", 
                Toast.LENGTH_SHORT).show();
         
    }
 
    @Override
    public void onResume() {
            super.onResume();
            Toast.makeText(getBaseContext(), "onResume Accelerometer Started", 
                    Toast.LENGTH_SHORT).show();
             
            //Check device supported Accelerometer senssor or not
            if (AccelerometerManager.isSupported(this)) {
                 
                //Start Accelerometer Listening
                AccelerometerManager.startListening(this);
            }
    }
     
    @Override
    public void onStop() {
            super.onStop();
             
            //Check device supported Accelerometer senssor or not
            if (AccelerometerManager.isListening()) {
                 
                //Start Accelerometer Listening
                AccelerometerManager.stopListening();
                 
                Toast.makeText(getBaseContext(), "onStop Accelerometer Stoped", 
                         Toast.LENGTH_SHORT).show();
            }
            
    }
     
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("Sensor", "Service  distroy");
         
        //Check device supported Accelerometer senssor or not
        if (AccelerometerManager.isListening()) {
             
            //Start Accelerometer Listening
            AccelerometerManager.stopListening();
             
            Toast.makeText(getBaseContext(), "onDestroy Accelerometer Stoped", 
                   Toast.LENGTH_SHORT).show();
        }
             
    }
 
}




Java Source Code List

com.tabi.motiontest.AccelerometerListener.java
com.tabi.motiontest.AccelerometerManager.java
com.tabi.motiontest.MainActivity.java