public class MainActivity extends AppCompatActivity { ImageView img = null; private SensorManager mSensorManager; private Sensor mSensor; float buttonX; float buttonY; float viewWidth; float viewHeight; EditText webin; TextView TextX; TextView TextY; TextView TextZ; float x; float y; float z;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
/* Display display = getWindowManager().getDefaultDisplay();
int imageSize = img.getWidth();
Point size = new Point();
display.getSize(size);
viewWidth = size.x;
viewHeight = size.y; */
}
private float mAccel; // acceleration apart from gravity
private float mAccelCurrent; // current acceleration including gravity
private float mAccelLast; // last acceleration including gravity
private final SensorEventListener mSensorListener = new SensorEventListener() {
public void onSensorChanged(SensorEvent se) {
float x = se.values[0];
TextView TextX = (TextView) findViewById(R.id.TextX);
TextX.setText(String.valueOf(x));
float y = se.values[1];
TextView TextY = (TextView) findViewById(R.id.TextY);
TextY.setText(String.valueOf(y));
float z = se.values[2];
TextView TextZ = (TextView) findViewById(R.id.TextZ);
TextZ.setText(String.valueOf(z));
ImageView img = (ImageView) findViewById(R.id.imageView);
// TextX.setText(String.valueOf(x)); //ekran sallayınca x koordinatı değişecek.
// float y = se.values[1];
// TextY.setText(String.valueOf(y)); //ekranı sallayınca y koordinati değişecek.
// float z = se.values[2];
// TextZ.setText(String.valueOf(z)); //ekranı sallayınca z koordinatı değişecek.
mAccelLast = mAccelCurrent;
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
float delta = mAccelCurrent - mAccelLast;
mAccel = mAccel * 0.9f + delta; // perform low-cut filter
//img.setZ(z);
/* if (buttonX < viewWidth) { */
// buttonX -= x;
/* } */
/* if (buttonY < viewHeight) { */
// buttonY += y;
/* } */
// img.setX(buttonX);
// img.setY(buttonY);
}
Kod hata vermiyor ama nesne hareket etmiyor neden?