@Override public void onOrientationChanged(int orientation) { mOrientation = orientation; if (mHorizonIndicatorMarkHorizontal != null) { mHorizonIndicatorMarkHorizontal.setRotation(orientation - 90); } }
private void rotateHorizonIndicator(float sideErrorVertical, float sideErrorHorizontal) { mHorizonIndicatorAim.setOrientation(mOrientation - 90); int colorVert = (255 - Math.abs(((int) Math.toDegrees(sideErrorVertical) - 90) % 90) * 15); int colorHorz = (255 - Math.abs(((int) Math.toDegrees(sideErrorHorizontal) - 90) % 90) * 15); if (mOrientation == 90 || mOrientation == 270) { if (colorVert > 100) { mHorizonIndicatorMarkRotation.setColorFilter( Color.rgb(colorVert, colorVert, 0), Mode.MULTIPLY); } else { mHorizonIndicatorMarkRotation.clearColorFilter(); } } else { if (colorHorz > 100) { mHorizonIndicatorMarkRotation.setColorFilter( Color.rgb(colorHorz, colorHorz, 0), Mode.MULTIPLY); } else { mHorizonIndicatorMarkRotation.clearColorFilter(); } } if (mOrientation == 90) { mHorizonIndicatorMarkRotation.setOrientation( (int) Math.toDegrees(sideErrorVertical) + 180 + mOrientation); } if (mOrientation == 270) { mHorizonIndicatorMarkRotation.setOrientation( -(int) Math.toDegrees(sideErrorVertical) + mOrientation); } if (mOrientation == 180) { mHorizonIndicatorMarkRotation.setOrientation( (int) Math.toDegrees(sideErrorHorizontal) + 180 + mOrientation); } if (mOrientation == 0) { mHorizonIndicatorMarkRotation.setOrientation( -(int) Math.toDegrees(sideErrorHorizontal) + mOrientation); } }
public void updateHorizonIndicator( float verticalError, float horizontalError, final float sideErrorVertical, final float sideErrorHorizontal) { if (mHorizonIndicatorContainer == null || mHorizonIndicatorContainer == null || mHorizonIndicatorMarkTopDown == null || mHorizonIndicatorMarkRotation == null || mHorizonIndicatorMarkHorizontal == null || mHorizonIndicatorAim == null || mHorizonIndicatorAimTopDown == null || mHorizonIndicatorMarkContainer == null) { return; } if (ApplicationScreen.getGUIManager().lockControls) { mHorizonIndicatorContainer.setVisibility(View.GONE); return; } mHorizonIndicatorContainer.setVisibility(View.VISIBLE); if (!horizon_updating.compareAndSet(false, true)) { return; } if (Math.abs(horizontalError) <= 0.01f && Math.abs(verticalError) <= 0.01f) { mHorizonIndicatorMarkContainer.setPadding(0, 0, 0, 0); if (!flat) { rotateHorizonIndicator(sideErrorVertical, sideErrorHorizontal); } int color = 255; mHorizonIndicatorMarkTopDown.setColorFilter(Color.rgb(color, color, 0), Mode.MULTIPLY); mHorizonIndicatorMarkRotation.setColorFilter(Color.rgb(color, color, 0), Mode.MULTIPLY); horizon_updating.set(false); return; } float density = ApplicationScreen.getAppResources().getDisplayMetrics().density; if ((Math.abs(horizontalError) > 1.0f && (mOrientation == 0 || mOrientation == 180 || flat)) || (Math.abs(verticalError) > 1.0f && (mOrientation == 90 || mOrientation == 270 || flat))) { flat = true; mHorizonIndicatorMarkRotation.setVisibility(View.GONE); mHorizonIndicatorMarkHorizontal.setVisibility(View.GONE); mHorizonIndicatorMarkTopDown.setVisibility(View.VISIBLE); mHorizonIndicatorAim.setVisibility(View.GONE); mHorizonIndicatorAimTopDown.setVisibility(View.VISIBLE); if (Math.abs(verticalError) > 0.9f) { if (verticalError > 0.0f) { verticalError = (float) (verticalError - Math.PI / 2); } else { verticalError = (float) (verticalError + Math.PI / 2); } } if (Math.abs(horizontalError) > 0.9f) { if (horizontalError > 0.0f) { horizontalError = (float) (horizontalError - Math.PI / 2); } else { horizontalError = (float) (horizontalError + Math.PI / 2); } } final int marginVerticalValue = (int) (300.0f * Math.abs(verticalError) * density); final int marginHorizontalValue = (int) (300.0f * Math.abs(horizontalError) * density); int color = (255 - (marginVerticalValue + marginHorizontalValue) * 4); if (color > 50) { mHorizonIndicatorMarkTopDown.setColorFilter(Color.rgb(color, color, 0), Mode.MULTIPLY); } else { mHorizonIndicatorMarkTopDown.clearColorFilter(); } if (verticalError < 0.0f) { if (horizontalError < 0.0f) { mHorizonIndicatorMarkContainer.setPadding( 0, marginVerticalValue, marginHorizontalValue, 0); } else { mHorizonIndicatorMarkContainer.setPadding( marginHorizontalValue, marginVerticalValue, 0, 0); } } else { if (horizontalError < 0.0f) { mHorizonIndicatorMarkContainer.setPadding( 0, 0, marginHorizontalValue, marginVerticalValue); } else { mHorizonIndicatorMarkContainer.setPadding( marginHorizontalValue, 0, 0, marginVerticalValue); } } horizon_updating.set(false); } else { flat = false; mHorizonIndicatorMarkRotation.setVisibility(View.VISIBLE); mHorizonIndicatorMarkHorizontal.setVisibility(View.VISIBLE); mHorizonIndicatorMarkTopDown.setVisibility(View.GONE); mHorizonIndicatorAim.setVisibility(View.VISIBLE); mHorizonIndicatorAimTopDown.setVisibility(View.GONE); final int marginVerticalValue = (int) (300.0f * Math.abs(verticalError) * density); final int marginHorizontalValue = (int) (300.0f * Math.abs(horizontalError) * density); rotateHorizonIndicator(sideErrorVertical, sideErrorHorizontal); if (mOrientation == 90 || mOrientation == 270) { if (verticalError < 0.0f) { mHorizonIndicatorMarkContainer.setPadding(0, marginVerticalValue, 0, 0); } else { mHorizonIndicatorMarkContainer.setPadding(0, 0, 0, marginVerticalValue); } } else { if (horizontalError < 0.0f) { mHorizonIndicatorMarkContainer.setPadding(0, 0, marginHorizontalValue, 0); } else { mHorizonIndicatorMarkContainer.setPadding(marginHorizontalValue, 0, 0, 0); } } horizon_updating.set(false); } }