Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc26dbe5

Browse files
Update to v1.0.0
2 parents34ce88b +62e0dbe commitc26dbe5

File tree

31 files changed

+1663
-267
lines changed

31 files changed

+1663
-267
lines changed

‎apk/Clinometer-1.0.0.apk‎

3.65 MB
Binary file not shown.

‎apk/Clinometer-latest.apk‎

3.65 MB
Binary file not shown.

‎app/src/main/AndroidManifest.xml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
33
package="eu.basicairdata.clinometer">
44

5-
<uses-feature
6-
android:name="android.hardware.sensor.accelerometer"
7-
android:required="true" />
5+
<uses-featureandroid:name="android.hardware.sensor.accelerometer"android:required="true" />
6+
<uses-featureandroid:name="android.hardware.camera"android:required="false" />
7+
<uses-featureandroid:name="android.hardware.camera.autofocus"android:required="false" />
88

99
<uses-permissionandroid:name="android.permission.VIBRATE" />
10+
<uses-permissionandroid:name="android.permission.CAMERA" />
1011

1112
<application
13+
android:name=".ClinometerApplication"
1214
android:allowBackup="true"
1315
android:icon="@mipmap/clinometer"
1416
android:label="@string/app_name"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* BackgroundView - Java Class for Android
3+
* Created by G.Capelli (BasicAirData) on 7/1/2021
4+
*
5+
* This file is part of BasicAirData Clinometer for Android.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
packageeu.basicairdata.clinometer;
22+
23+
importandroid.content.Context;
24+
importandroid.graphics.Canvas;
25+
importandroid.graphics.Paint;
26+
importandroid.graphics.RadialGradient;
27+
importandroid.graphics.Shader;
28+
importandroid.util.AttributeSet;
29+
importandroid.view.View;
30+
31+
publicclassBackgroundViewextendsView {
32+
33+
privatestaticfinalfloatN_CIRCLES_FULLY_VISIBLE =4.5f;
34+
35+
privatePaintpaint_bg;// For Background Gradient
36+
privatePaintpaint_DKGray;// For Background Lines != 30°
37+
privatebooleanisShaderCreated =false;// True if the Background Shader has been created
38+
39+
privateintx;// The Width of Screen
40+
privateinty;// The Height of Screen
41+
privateintmin_xy;// The minimum between Width and Height
42+
privateintmax_xy;// The maximum between Width and Height
43+
privateintxc;// x screen center
44+
privateintyc;// y screen center
45+
privatedoublediag2c;// Screen Diagonal/2 = distance between 0:0 and xc:yc
46+
privateintncircles;// The number of visible circles
47+
privatefloatr1_value;// The scale (to how many degrees corresponds each circle)
48+
privatefloatr1;// The radius of the first circle = 1 deg.
49+
50+
privateintangle;
51+
52+
53+
publicBackgroundView(Contextcontext,AttributeSetattrs) {
54+
super(context,attrs);
55+
createPaints();
56+
57+
}
58+
59+
60+
publicBackgroundView(Contextcontext,AttributeSetattrs,intdefStyle) {
61+
super(context,attrs,defStyle);
62+
createPaints();
63+
64+
}
65+
66+
67+
publicBackgroundView(Contextcontext) {
68+
super(context);
69+
createPaints();
70+
71+
}
72+
73+
74+
privatevoidcreatePaints() {
75+
// create the Paint and set its color
76+
77+
paint_DKGray =newPaint();
78+
paint_DKGray.setColor(getResources().getColor(R.color.line_dark));
79+
paint_DKGray.setStyle(Paint.Style.STROKE);
80+
paint_DKGray.setDither(true);
81+
paint_DKGray.setAntiAlias(true);
82+
83+
paint_bg =newPaint();
84+
paint_bg.setStyle(Paint.Style.FILL);
85+
isShaderCreated =false;
86+
}
87+
88+
89+
@Override
90+
protectedvoidonDraw(Canvascanvas) {
91+
//super.onDraw(canvas);
92+
93+
x =getWidth();
94+
y =getHeight();
95+
min_xy =Math.min(x,y);
96+
max_xy =Math.max(x,y);
97+
xc =x /2;// x screen center
98+
yc =y /2;// y screen center
99+
100+
diag2c =Math.sqrt(xc *xc +yc *yc);// Screen Diagonal/2 = distance between 0:0 and xc:yc
101+
r1_value =2;// The scale (to how many degrees corresponds each circle)
102+
ncircles = (int)Math.ceil(N_CIRCLES_FULLY_VISIBLE *2 *diag2c /min_xy);
103+
// The number of circles to be drawn
104+
r1 = (min_xy /2.0f) /N_CIRCLES_FULLY_VISIBLE;// The radius of the first circle.
105+
106+
if (!isShaderCreated) {
107+
paint_bg.setShader(newRadialGradient(xc,yc, (int) (Math.sqrt(xc *xc +yc *yc) /2),
108+
getResources().getColor(R.color.bgpaint_dark),
109+
getResources().getColor(R.color.bgpaint_light),
110+
Shader.TileMode.MIRROR));
111+
isShaderCreated =true;
112+
}
113+
canvas.drawCircle(xc,yc, (int)Math.sqrt(xc*xc +yc*yc),paint_bg);
114+
115+
for (angle =0;angle <360;angle +=10) {
116+
if (angle %30 !=0)canvas.drawLine(
117+
xc - (int) (diag2c *Math.cos(Math.toRadians(angle))),
118+
yc - (int) (diag2c *Math.sin(Math.toRadians(angle))),
119+
xc - (int) (r1 *Math.cos(Math.toRadians(angle))),
120+
yc - (int) (r1 *Math.sin(Math.toRadians(angle))),
121+
paint_DKGray);
122+
}
123+
}
124+
}

‎app/src/main/java/eu/basicairdata/clinometer/CalibrationActivity.java‎

Lines changed: 124 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
packageeu.basicairdata.clinometer;
2222

2323
importandroid.content.Context;
24+
importandroid.content.DialogInterface;
2425
importandroid.content.SharedPreferences;
2526
importandroid.hardware.Sensor;
2627
importandroid.hardware.SensorEvent;
@@ -31,16 +32,30 @@
3132
importandroid.os.Bundle;
3233
importandroid.os.Vibrator;
3334
importandroid.util.Log;
35+
importandroid.view.MenuItem;
3436
importandroid.view.View;
3537
importandroid.view.WindowManager;
3638
importandroid.widget.ImageView;
3739
importandroid.widget.ProgressBar;
3840
importandroid.widget.TextView;
3941

42+
importandroidx.appcompat.app.AlertDialog;
4043
importandroidx.appcompat.app.AppCompatActivity;
4144
importandroidx.appcompat.widget.AppCompatButton;
4245
importandroidx.preference.PreferenceManager;
4346

47+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_ANGLE_0;
48+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_ANGLE_1;
49+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_ANGLE_2;
50+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_GAIN_0;
51+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_GAIN_1;
52+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_GAIN_2;
53+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_OFFSET_0;
54+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_OFFSET_1;
55+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_OFFSET_2;
56+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_CALIBRATION_TIME;
57+
importstaticeu.basicairdata.clinometer.ClinometerApplication.KEY_PREF_KEEP_SCREEN_ON;
58+
4459

4560
publicclassCalibrationActivityextendsAppCompatActivityimplementsSensorEventListener {
4661

@@ -64,6 +79,7 @@ public class CalibrationActivity extends AppCompatActivity implements SensorEven
6479
privateAppCompatButtonbuttonNext;
6580
privateProgressBarprogressBar;
6681
privateImageViewimageViewMain;
82+
privateImageViewimageViewCalibrationIcon;
6783
privateTextViewtextViewStepDescription;
6884
privateTextViewtextViewLastCalibration;
6985
privateTextViewtextViewProgress;
@@ -84,7 +100,7 @@ public class CalibrationActivity extends AppCompatActivity implements SensorEven
84100
privatestaticfinalintSTEP_6_CAL =11;// Calibrating... Don't move the device
85101
privatestaticfinalintSTEP_7 =12;// Step 7 of 7 Press next and lay face down
86102
privatestaticfinalintSTEP_7_CAL =13;// Calibrating... Don't move the device
87-
privatestaticfinalintSTEP_COMPLETED =14;// Calibration completed (Message Box)
103+
privatestaticfinalintSTEP_COMPLETED =14;// Calibration completed, performs calculations and shows results
88104

89105
privatestaticfinalfloatSTANDARD_GRAVITY =9.807f;
90106

@@ -110,12 +126,16 @@ protected void onCreate(Bundle savedInstanceState) {
110126
textViewLastCalibration =findViewById(R.id.id_textview_last_calibration);
111127
textViewProgress =findViewById(R.id.id_textview_progress);
112128
imageViewMain =findViewById(R.id.id_imageViewMain);
129+
imageViewCalibrationIcon =findViewById(R.id.id_imageViewCalibrationIcon);
113130

114131
buttonNext.setOnClickListener(newView.OnClickListener() {
115132
@Override
116133
publicvoidonClick(Viewview) {
117-
currentStep++;
118-
startStep();
134+
if (currentStep ==STEP_COMPLETED)finish();
135+
else {
136+
currentStep++;
137+
startStep();
138+
}
119139
}
120140
});
121141

@@ -125,16 +145,16 @@ public void onClick(View view) {
125145

126146
SharedPreferencespreferences =PreferenceManager.getDefaultSharedPreferences(this);
127147

128-
if (preferences.contains("prefCalibrationAngle0")) {
148+
if (preferences.contains(KEY_PREF_CALIBRATION_ANGLE_0)) {
129149
textViewLastCalibration.setText(getString(R.string.calibration_active_calibration) +"\n"
130150
+getString(R.string.calibration_active_calibration_gains)
131-
+String.format(" = %1.3f; %1.3f; %1.3f",preferences.getFloat("prefCalibrationGain0",0),preferences.getFloat("prefCalibrationGain1",0),preferences.getFloat("prefCalibrationGain2",0))
151+
+String.format(" = %1.3f; %1.3f; %1.3f",preferences.getFloat(KEY_PREF_CALIBRATION_GAIN_0,0),preferences.getFloat(KEY_PREF_CALIBRATION_GAIN_1,0),preferences.getFloat(KEY_PREF_CALIBRATION_GAIN_2,0))
132152
+"\n"
133153
+getString(R.string.calibration_active_calibration_offsets)
134-
+String.format(" = %1.3f; %1.3f; %1.3f",preferences.getFloat("prefCalibrationOffset0",0),preferences.getFloat("prefCalibrationOffset1",0),preferences.getFloat("prefCalibrationOffset2",0))
154+
+String.format(" = %1.3f; %1.3f; %1.3f",preferences.getFloat(KEY_PREF_CALIBRATION_OFFSET_0,0),preferences.getFloat(KEY_PREF_CALIBRATION_OFFSET_1,0),preferences.getFloat(KEY_PREF_CALIBRATION_OFFSET_2,0))
135155
+"\n"
136156
+getString(R.string.calibration_active_calibration_angles)
137-
+String.format(" = %1.2f°; %1.2f°; %1.2f°",preferences.getFloat("prefCalibrationAngle0",0),preferences.getFloat("prefCalibrationAngle1",0),preferences.getFloat("prefCalibrationAngle2",0))
157+
+String.format(" = %1.2f°; %1.2f°; %1.2f°",preferences.getFloat(KEY_PREF_CALIBRATION_ANGLE_2,0),preferences.getFloat(KEY_PREF_CALIBRATION_ANGLE_1,0),preferences.getFloat(KEY_PREF_CALIBRATION_ANGLE_0,0))
138158
);
139159
}
140160

@@ -143,16 +163,62 @@ public void onClick(View view) {
143163

144164

145165
@Override
146-
protectedvoidonResume() {
147-
super.onResume();
148-
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
166+
publicbooleanonOptionsItemSelected(MenuItemitem)
167+
{
168+
// Handle action bar item clicks here. The action bar will
169+
// automatically handle clicks on the Home/Up button, so long
170+
// as you specify a parent activity in AndroidManifest.xml.
171+
switch (item.getItemId()) {
172+
caseandroid.R.id.home:
173+
onBackPressed();
174+
returntrue;
175+
default:
176+
returnsuper.onOptionsItemSelected(item);
177+
}
178+
}
149179

150-
if ((int) (currentStep /2) *2 !=currentStep)currentStep--;
151-
Log.d("CalibrationActivity","CurrentStep = " +currentStep);
152180

153-
startStep();
181+
@Override
182+
publicvoidonBackPressed()
183+
{
184+
Log.d("CalibrationActivity","onBackPressed on Step " +currentStep);
185+
if ((currentStep !=STEP_1) && (currentStep <STEP_COMPLETED)) {
186+
AlertDialog.Builderbuilder =newAlertDialog.Builder(this);
187+
builder.setMessage(getResources().getString(R.string.calibration_abort));
188+
//builder.setIcon(android.R.drawable.ic_menu_info_details);
189+
builder.setPositiveButton(R.string.yes,newDialogInterface.OnClickListener() {
190+
publicvoidonClick(DialogInterfacedialog,intid) {
191+
dialog.dismiss();
192+
finish();
193+
}
194+
});
195+
builder.setNegativeButton(R.string.no,newDialogInterface.OnClickListener() {
196+
publicvoidonClick(DialogInterfacedialog,intid) {
197+
dialog.dismiss();
198+
}
199+
});
200+
AlertDialogdialog =builder.create();
201+
dialog.show();
202+
}else {
203+
finish();
204+
//super.onBackPressed(); // optional depending on your needs
205+
}
206+
}
154207

155-
//mSensorManager.registerListener(this, mRotationSensor, ACCELEROMETER_UPDATE_INTERVAL_MICROS);
208+
209+
@Override
210+
protectedvoidonResume() {
211+
super.onResume();
212+
213+
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(KEY_PREF_KEEP_SCREEN_ON,true))getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
214+
elsegetWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
215+
216+
if (currentStep <STEP_COMPLETED) {
217+
// If the app was calibrating when the onPause is called, the app goes back 1 step (the previous screen)
218+
if ((int) (currentStep /2) *2 !=currentStep)currentStep--;
219+
Log.d("CalibrationActivity","CurrentStep = " +currentStep);
220+
startStep();
221+
}
156222
}
157223

158224

@@ -238,7 +304,20 @@ private void startStep() {
238304
mSensorManager.registerListener(this,mRotationSensor,ACCELEROMETER_UPDATE_INTERVAL_MICROS);
239305
break;
240306
caseSTEP_COMPLETED:
307+
308+
// Write raw step Values into Preferences
309+
310+
SharedPreferencespreferences =PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
311+
SharedPreferences.EditoreditorRaw =preferences.edit();
312+
for (inti =0;i <7;i++) {
313+
editorRaw.putFloat("prefCalibrationRawMean_0_" +i ,mean[0][i]);
314+
editorRaw.putFloat("prefCalibrationRawMean_1_" +i ,mean[1][i]);
315+
editorRaw.putFloat("prefCalibrationRawMean_2_" +i ,mean[2][i]);
316+
}
317+
editorRaw.commit();
318+
241319
// Calculations
320+
242321
Log.d("Clinometer","-- MEAN NOT CORRECTED ------------------------------------------------------");
243322
for (inti =0;i <7;i++) {
244323
Log.d("Clinometer",String.format("mean[ ][" +i +"] = %+1.4f %+1.4f %+1.4f",mean[0][i],mean[1][i],mean[2][i]));
@@ -292,29 +371,45 @@ private void startStep() {
292371

293372
calibrationAngle[2] = (angle[0][0] +angle[0][1])/2;// angle 0 = X axis
294373
calibrationAngle[1] = -(angle[1][0] +angle[1][1])/2;// angle 1 = Y axis
295-
calibrationAngle[0] = -(angle[1][3]+angle[1][2])/2;// angle 2 = Z axis
374+
calibrationAngle[0] = -(angle[1][3]-angle[1][2])/2;// angle 2 = Z axis
296375

297376
Log.d("Clinometer","-- CALIBRATION ANGLES ------------------------------------------------------");
298-
Log.d("Clinometer",String.format("Cal.Angles = %+1.4f° %+1.4f° %+1.4f°",calibrationAngle[0],calibrationAngle[1],calibrationAngle[2]));
299-
377+
Log.d("Clinometer",String.format("Cal.Angles = %+1.4f° %+1.4f° %+1.4f°",calibrationAngle[2],calibrationAngle[1],calibrationAngle[0]));
300378
Log.d("Clinometer","----------------------------------------------------------------------------");
301379

302380
// Write Calibration Angles into Preferences
303-
SharedPreferencespreferences =PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
381+
304382
SharedPreferences.Editoreditor =preferences.edit();
305-
editor.putFloat("prefCalibrationAngle0",calibrationAngle[0]);
306-
editor.putFloat("prefCalibrationAngle1",calibrationAngle[1]);
307-
editor.putFloat("prefCalibrationAngle2",calibrationAngle[2]);
308-
editor.putFloat("prefCalibrationGain0",calibrationGain[0]);
309-
editor.putFloat("prefCalibrationGain1",calibrationGain[1]);
310-
editor.putFloat("prefCalibrationGain2",calibrationGain[2]);
311-
editor.putFloat("prefCalibrationOffset0",calibrationOffset[0]);
312-
editor.putFloat("prefCalibrationOffset1",calibrationOffset[1]);
313-
editor.putFloat("prefCalibrationOffset2",calibrationOffset[2]);
314-
editor.putLong("prefCalibrationTime",System.currentTimeMillis());
383+
editor.putFloat(KEY_PREF_CALIBRATION_ANGLE_0,calibrationAngle[0]);
384+
editor.putFloat(KEY_PREF_CALIBRATION_ANGLE_1,calibrationAngle[1]);
385+
editor.putFloat(KEY_PREF_CALIBRATION_ANGLE_2,calibrationAngle[2]);
386+
editor.putFloat(KEY_PREF_CALIBRATION_GAIN_0,calibrationGain[0]);
387+
editor.putFloat(KEY_PREF_CALIBRATION_GAIN_1,calibrationGain[1]);
388+
editor.putFloat(KEY_PREF_CALIBRATION_GAIN_2,calibrationGain[2]);
389+
editor.putFloat(KEY_PREF_CALIBRATION_OFFSET_0,calibrationOffset[0]);
390+
editor.putFloat(KEY_PREF_CALIBRATION_OFFSET_1,calibrationOffset[1]);
391+
editor.putFloat(KEY_PREF_CALIBRATION_OFFSET_2,calibrationOffset[2]);
392+
editor.putLong(KEY_PREF_CALIBRATION_TIME,System.currentTimeMillis());
315393
editor.commit();
316394

317-
finish();
395+
progressBar.setVisibility(View.INVISIBLE);
396+
textViewProgress.setVisibility(View.INVISIBLE);
397+
imageViewMain.setImageBitmap(null);
398+
textViewStepDescription.setText(R.string.dialog_calibration_completed);
399+
textViewLastCalibration.setText(getString(R.string.calibration_active_calibration) +"\n"
400+
+getString(R.string.calibration_active_calibration_gains)
401+
+String.format(" = %1.3f; %1.3f; %1.3f",preferences.getFloat(KEY_PREF_CALIBRATION_GAIN_0,0),preferences.getFloat(KEY_PREF_CALIBRATION_GAIN_1,0),preferences.getFloat(KEY_PREF_CALIBRATION_GAIN_2,0))
402+
+"\n"
403+
+getString(R.string.calibration_active_calibration_offsets)
404+
+String.format(" = %1.3f; %1.3f; %1.3f",preferences.getFloat(KEY_PREF_CALIBRATION_OFFSET_0,0),preferences.getFloat(KEY_PREF_CALIBRATION_OFFSET_1,0),preferences.getFloat(KEY_PREF_CALIBRATION_OFFSET_2,0))
405+
+"\n"
406+
+getString(R.string.calibration_active_calibration_angles)
407+
+String.format(" = %1.2f°; %1.2f°; %1.2f°",preferences.getFloat(KEY_PREF_CALIBRATION_ANGLE_2,0),preferences.getFloat(KEY_PREF_CALIBRATION_ANGLE_1,0),preferences.getFloat(KEY_PREF_CALIBRATION_ANGLE_0,0))
408+
);
409+
textViewLastCalibration.setVisibility(View.VISIBLE);
410+
buttonNext.setVisibility(View.VISIBLE);
411+
buttonNext.setText(R.string.close);
412+
imageViewCalibrationIcon.setVisibility(View.VISIBLE);
318413
}
319414
}
320415

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp