I'm working on an android project based on a motion sensor. For various purposes, I'm using an accelerometer, the gyroscope in my project.
Here is a scippet of onCreate() on onResume() method:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*To setup Gravity*/
flickManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Objects.requireNonNull(flickManager).registerListener(mSensorListener, flickManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
mAccel = 10f;
mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH;
/*End Here*/
/*To setup YouTube API*/
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(Config.YOUTUBE_API_KEY, this);
/*---------End-------------------*/
/*Setup the textbox*/
txtView = (TextView) findViewById(R.id.ttview);
txtview2 = (TextView) findViewById(R.id.ttview2);
txtview3 = (TextView) findViewById(R.id.ttview3);
txtview4 = (TextView) findViewById(R.id.ttview4);
final EditText seekToText = (EditText) findViewById(R.id.seek_to_text);
/*-----------------End------------------------------*/
/* Setup seekbar*/
Button seekToButton = (Button) findViewById(R.id.seek_to_button);
seekToButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int skipToSecs = Integer.valueOf(seekToText.getText().toString());
player.seekToMillis(skipToSecs * 1000);
Log.d("dur:"+skipToSecs * 1000,"Second");
}
});
protected void onResume()
{
flickManager.registerListener(mSensorListener, flickManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
super.onResume();
//accelerometer.register();
//gyroscope.register();
}
My approach is to check up some conditions first before activating any motion-based work. Is it possible to set up any condition such as "If-else" here? If not what is the best practice will be to call them from outside of the method to see whether they should activate or not.
Thank you.