Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RoomView
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOISIL Paul
RoomView
Commits
16b55ed3
Commit
16b55ed3
authored
2 years ago
by
FurWaz
Browse files
Options
Downloads
Patches
Plain Diff
Added compass hint to camera view
parent
0104e97b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java
+35
-7
35 additions, 7 deletions
.../app/src/main/java/com/furwaz/roomview/PhotoActivity.java
with
35 additions
and
7 deletions
Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java
+
35
−
7
View file @
16b55ed3
...
...
@@ -27,6 +27,7 @@ import android.widget.ImageButton;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
java.io.File
;
...
...
@@ -54,7 +55,10 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe
SensorManager
sm
=
null
;
Sensor
accelerometer
=
null
;
Sensor
magnet
=
null
;
LevelCanvas
levelView
=
null
;
float
[]
accelValues
=
new
float
[]{
0
f
,
0
f
,
0
f
};
float
[]
magnetValues
=
new
float
[]{
0
f
,
0
f
,
0
f
};
BuildingInfo
building
=
null
;
RoomInfo
room
=
null
;
...
...
@@ -143,6 +147,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe
sm
=
(
SensorManager
)
getSystemService
(
SENSOR_SERVICE
);
if
(
sm
!=
null
)
{
accelerometer
=
sm
.
getDefaultSensor
(
Sensor
.
TYPE_ACCELEROMETER
);
magnet
=
sm
.
getDefaultSensor
(
Sensor
.
TYPE_MAGNETIC_FIELD
);
register
();
}
}
...
...
@@ -220,13 +225,21 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe
}
protected
void
register
()
{
if
(
sm
!=
null
&&
accelerometer
!=
null
)
sm
.
registerListener
(
this
,
accelerometer
,
SensorManager
.
SENSOR_DELAY_GAME
);
if
(
sm
!=
null
)
{
if
(
accelerometer
!=
null
)
sm
.
registerListener
(
this
,
accelerometer
,
SensorManager
.
SENSOR_DELAY_UI
);
if
(
magnet
!=
null
)
sm
.
registerListener
(
this
,
magnet
,
SensorManager
.
SENSOR_DELAY_UI
);
}
}
protected
void
unregister
()
{
if
(
sm
!=
null
&&
accelerometer
!=
null
)
sm
.
unregisterListener
(
this
,
accelerometer
);
if
(
sm
!=
null
)
{
if
(
accelerometer
!=
null
)
sm
.
unregisterListener
(
this
,
accelerometer
);
if
(
magnet
!=
null
)
sm
.
unregisterListener
(
this
,
magnet
);
}
}
@Override
...
...
@@ -235,14 +248,29 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe
@Override
public
void
onSensorChanged
(
SensorEvent
sensorEvent
)
{
if
(
sensorEvent
.
sensor
==
accelerometer
)
{
accelValues
=
sensorEvent
.
values
;
float
x_val
=
sensorEvent
.
values
[
0
];
float
y_val
=
sensorEvent
.
values
[
1
];
float
orient
=
(
float
)
Math
.
atan2
(
y_val
,
x_val
);
if
(
levelView
!=
null
)
levelView
.
askForDraw
(
orient
);
if
(
orient
<
1
)
displayOrientation
(
Orientation
.
NORTH
);
else
displayOrientation
(
Orientation
.
EST
);
}
if
(
sensorEvent
.
sensor
==
magnet
)
{
magnetValues
=
sensorEvent
.
values
;
float
res
[]
=
new
float
[
9
];
SensorManager
.
getRotationMatrix
(
res
,
null
,
accelValues
,
magnetValues
);
float
values
[]
=
new
float
[
3
];
SensorManager
.
getOrientation
(
res
,
values
);
int
angle
=
((
int
)(
values
[
0
]
*
180
/
Math
.
PI
)
+
135
)
%
360
;
if
(
angle
<
0
)
angle
=
360
+
angle
;
Orientation
orient
=
Orientation
.
NORTH
;
if
(
angle
>=
0
&&
angle
<
90
)
orient
=
Orientation
.
WEST
;
if
(
angle
>=
90
&&
angle
<
180
)
orient
=
Orientation
.
NORTH
;
if
(
angle
>=
180
&&
angle
<
270
)
orient
=
Orientation
.
EST
;
if
(
angle
>=
270
&&
angle
<
360
)
orient
=
Orientation
.
SOUTH
;
displayOrientation
(
orient
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment