public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { if (magnetic != null) { SensorManager.getRotationMatrix(baseR, null, event.values, magnetic); } if (baseR != null) SensorManager.getOrientation(baseR, currR); } else { if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { magnetic = event.values; } } int orientation = display.getOrientation(); if (currR != null) switch (orientation) { case (1): mLayout.setDepth((int) (MAX_DEPTH * (1.7f + currR[2]))); break; default: mLayout.setDepth((int) (MAX_DEPTH * (currR[1] + 1.4f))); break; } }
@Override public void onActivityCreated(android.os.Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); this.getView().findViewById(R.id.editProgram).setOnClickListener(this); this.getView().findViewById(R.id.startProgram).setOnClickListener(this); btnHelpAbout = (Button) this.getView().findViewById(R.id.HelpAbout); btnHelpAbout.setOnClickListener(this); this.getView().findViewById(R.id.prefs).setOnClickListener(this); mLayout = (DepthLinearLayout) getView().findViewById(R.id.main_linear_layout); mLayout.getBackground().setDither(true); Activity activity = getActivity(); mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); };