@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onSensorChanged(SensorEvent event) { boolean initialized = false; int x; double pos; if ((this.CurrentApi >= 11) && (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)) { levelBar.getLocationOnScreen(LevelValues); x = LevelValues[0]; pos = event.values[1]/2.5; int[] posXY = new int[2]; y = (int)Math.pow(pos, 5); if ((pos <= -0.5) || (pos >= 0.5)){ indicator.setImageResource(R.drawable.level_bad); } else { indicator.setImageResource(R.drawable.level_good); } indicator.setTranslationY(-y); indicator.getLocationOnScreen(posXY); int yPos = posXY[1]; float maxTemp = (float)levelH.getTop(); float minTemp = (float)levelH.getBottom(); max = maxTemp + 20.0f; min = minTemp - 20.0f; Log.d("Y COORDINATES", Integer.toString(yPos)); Log.d("MAX", Float.toString(max)); Log.d("MIN", Float.toString(min)); if (yPos >= min){ indicator.setY(min); } else if (yPos <= max){ indicator.setY(max); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)