@@ -90,9 +90,13 @@ public static ClinometerActivity getInstance(){
9090return singleton ;
9191 }
9292
93- ToneGenerator toneGen1 =new ToneGenerator (AudioManager .STREAM_MUSIC ,ToneGenerator .TONE_CDMA_KEYPAD_VOLUME_KEY_LITE );
93+ private ToneGenerator toneGen1 =new ToneGenerator (AudioManager .STREAM_MUSIC ,ToneGenerator .TONE_CDMA_KEYPAD_VOLUME_KEY_LITE );
9494private Vibrator vibrator ;
9595
96+ // RefAxis Animator
97+ private PIDAnimator pid =new PIDAnimator (0.0f ,0.3f ,0.0f ,0.03f ,16 );
98+ private float old_PIDValue =0.0f ;
99+
96100private static final int TOAST_TIME =2500 ;// The time a toast is shown
97101
98102private static final float AUTOLOCK_MIN_TOLERANCE =0.05f ;// The minimum tolerance of the AutoLock
@@ -110,12 +114,12 @@ public static ClinometerActivity getInstance(){
110114private float prefAutoLockTolerance ;
111115private int prefExposureCompensation =0 ;
112116
113- public boolean isFlat =true ;// True if the device is oriented flat (for example on a table)
114- public boolean isLocked =false ;// True if the angles are locked by user
117+ private boolean isFlat =true ;// True if the device is oriented flat (for example on a table)
118+ private boolean isLocked =false ;// True if the angles are locked by user
115119private boolean isLockRequested =false ;
116- public float displayRotation =0 ;// The rotation angle from the natural position of the device
120+ private float displayRotation =0 ;// The rotation angle from the natural position of the device
117121
118- public boolean isInCameraMode =false ;// True if Camera Mode is active
122+ private boolean isInCameraMode =false ;// True if Camera Mode is active
119123private boolean isCameraLivePreviewActive =false ;// True if the Live Preview with Camera is active
120124private Bitmap cameraPreviewBitmap ;// The image saved from Camera Preview (used by Locking and onPause/onResume)
121125
@@ -143,37 +147,81 @@ public static ClinometerActivity getInstance(){
143147private SensorManager mSensorManager ;
144148private Sensor mRotationSensor ;
145149
146- public float []gravity = {0 ,0 ,0 };// The (filtered) current accelerometers values
147- public float []gravity_gain = {0 ,0 ,0 };
148- public float []gravity_offset = {0 ,0 ,0 };
149- public float []gravity_calibrated = {0 ,0 ,0 };// The (filtered) current calibrated accelerometers values
150+ private float []gravity = {0 ,0 ,0 };// The (filtered) current accelerometers values
151+ private float []gravity_gain = {0 ,0 ,0 };
152+ private float []gravity_offset = {0 ,0 ,0 };
153+ private float []gravity_calibrated = {0 ,0 ,0 };// The (filtered) current calibrated accelerometers values
150154
151- public float []angle_calibration = {0 ,0 ,0 };// The angles for calibration: alpha, beta, gamma (in degrees)
152- public float []angle = {0 ,0 ,0 };// The (filtered) current angles (in degrees)
155+ private float []angle_calibration = {0 ,0 ,0 };// The angles for calibration: alpha, beta, gamma (in degrees)
156+ private float []angle = {0 ,0 ,0 };// The (filtered) current angles (in degrees)
153157
154158private final float [][]calibrationMatrix =new float [3 ][3 ];
155159
156- public float gravityXY =0 ;
157- public float gravityXYZ =0 ;
158- public float angleXY =0 ;// The angle on the horizontal plane (in degrees)
159- public float angleXYZ =0 ;// The angle between XY vector and the vertical (in degrees)
160- public float angleTextLabels =0 ;// The rotation angle for the text labels
160+ private float gravityXY =0 ;
161+ private float gravityXYZ =0 ;
162+ private float angleXY =0 ;// The angle on the horizontal plane (in degrees)
163+ private float angleXYZ =0 ;// The angle between XY vector and the vertical (in degrees)
164+ private float angleTextLabels =0 ;// The rotation angle for the text labels
161165
162166private final static int ACCELEROMETER_UPDATE_INTERVAL_MICROS =10000 ;
163167
164- final MeanVariance mvAngle0 =new MeanVariance (SIZE_OF_MEANVARIANCE );
165- final MeanVariance mvAngle1 =new MeanVariance (SIZE_OF_MEANVARIANCE );
166- final MeanVariance mvAngle2 =new MeanVariance (SIZE_OF_MEANVARIANCE );
167- final MeanVariance mvGravity0 =new MeanVariance (16 );
168- final MeanVariance mvGravity1 =new MeanVariance (16 );
169- final MeanVariance mvGravity2 =new MeanVariance (16 );
168+ private final MeanVariance mvAngle0 =new MeanVariance (SIZE_OF_MEANVARIANCE );
169+ private final MeanVariance mvAngle1 =new MeanVariance (SIZE_OF_MEANVARIANCE );
170+ private final MeanVariance mvAngle2 =new MeanVariance (SIZE_OF_MEANVARIANCE );
171+ private final MeanVariance mvGravity0 =new MeanVariance (16 );
172+ private final MeanVariance mvGravity1 =new MeanVariance (16 );
173+ private final MeanVariance mvGravity2 =new MeanVariance (16 );
170174
171- ValueAnimator animationR =new ValueAnimator ();
175+ private ValueAnimator animationR =new ValueAnimator ();
172176
173177private Camera mCamera ;
174178private CameraPreview mPreview ;
175179
176180
181+ // --------------------------------------------------------------------------------------------------------------------------
182+ // --- GETTERS AND SETTERS --------------------------------------------------------------------------------------------------
183+ // --------------------------------------------------------------------------------------------------------------------------
184+
185+
186+ public void setPIDTargetValue (float newValue ) {
187+ pid .setTargetValue (newValue );
188+ }
189+
190+
191+ public float getPIDValue () {
192+ return pid .getValue ();
193+ }
194+
195+
196+ public float getDisplayRotation () {
197+ return displayRotation ;
198+ }
199+
200+ public boolean isFlat () {
201+ return isFlat ;
202+ }
203+
204+
205+ public float []getAngles () {
206+ return angle ;
207+ }
208+
209+
210+ public float getAngleXY () {
211+ return angleXY ;
212+ }
213+
214+
215+ public float getAngleXYZ () {
216+ return angleXYZ ;
217+ }
218+
219+
220+ public float getAngleTextLabels () {
221+ return angleTextLabels ;
222+ }
223+
224+
177225// --------------------------------------------------------------------------------------------------------------------------
178226// --- CLASS METHODS --------------------------------------------------------------------------------------------------------
179227// --------------------------------------------------------------------------------------------------------------------------
@@ -276,6 +324,11 @@ public void onClick(View view) {
276324 }
277325
278326vibrator = (Vibrator )getSystemService (Context .VIBRATOR_SERVICE );
327+
328+ if (!preferences .contains (KEY_PREF_CALIBRATION_ANGLE_0 )) {
329+ // Not Calibrated!
330+ showToast (getString (R .string .toast_calibrate_before_use ));
331+ }
279332 }
280333
281334
@@ -526,15 +579,18 @@ public void onSensorChanged(SensorEvent event) {
526579mTextViewKeepScreenVertical .setVisibility (View .GONE );
527580 }
528581 }
529-
530582// Apply Changes
531-
532583mClinometerView .invalidate ();
584+
585+ // You must put this setText here in order to force the re-layout also during the rotations.
586+ // Without this, if you lock the measure during the rotation animation, the layout doesn't change correctly :(
587+ mTextViewAngles .setText (String .format ("%1.1f° %1.1f° %1.1f°" ,angle [0 ],angle [1 ],angle [2 ]));
533588 }
534589
535- // You must put this setText here in order to force the re-layout also during the rotations.
536- // Without this, if you lock the measure during the rotation animation, the layout doesn't change correctly :(
537- mTextViewAngles .setText (String .format ("%1.1f° %1.1f° %1.1f°" ,angle [0 ],angle [1 ],angle [2 ]));
590+ if (Math .abs (pid .getValue () -old_PIDValue ) >0.001 ) {
591+ old_PIDValue =pid .getValue ();
592+ mClinometerView .invalidate ();
593+ }
538594 }
539595 }
540596
@@ -621,6 +677,9 @@ public void onAnimationUpdate(ValueAnimator updatedAnimation) {
621677mFrameLayoutOverlays .getLayoutParams ().width =newWidth ;
622678mFrameLayoutOverlays .setRotation (rotationAngle );
623679 }
680+ // You must put this setText here in order to force the re-layout also during the rotations.
681+ // Without this, if you lock the measure during the rotation animation, the layout doesn't change correctly :(
682+ mTextViewAngles .setText (String .format ("%1.1f° %1.1f° %1.1f°" ,angle [0 ],angle [1 ],angle [2 ]));
624683 }
625684 });
626685animationR .start ();