Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_android_sdk_maven_plugin
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Panagiotis Triantafyllou
2023-07-10 14:08:29 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
24b87bc4a56cef03e5aa46bf49fc30acd3d68186
24b87bc4
1 parent
fb0bd4f7
telematics additions
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
warply_android_sdk/src/main/java/ly/warp/sdk/activities/TelematicsActivity.java
warply_android_sdk/src/main/res/layout/activity_telematics.xml
warply_android_sdk/src/main/java/ly/warp/sdk/activities/TelematicsActivity.java
View file @
24b87bc
...
...
@@ -18,6 +18,7 @@ import android.os.Handler;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.WindowManager
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
...
...
@@ -70,13 +71,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private
float
velocity
=
0
;
private
ArrayList
<
JSONObject
>
mAccelerationTimestamps
=
new
ArrayList
<>();
private
float
mAcceleration
=
0
;
private
static
final
float
ALPHA
=
0.8f
;
// Filter factor
private
static
final
float
STOP_THRESHOLD
=
8.0f
;
// Stop threshold in m/s²
private
static
final
int
PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE
=
4000
;
private
static
final
int
PERMISSION_REQUEST_ACCESS_FINE_LOCATION
=
4001
;
private
final
float
ALPHA
=
0.8f
;
// Filter factor
private
final
float
STOP_THRESHOLD
=
8.0f
;
// Stop threshold in m/s²
private
final
int
PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE
=
4000
;
private
final
int
PERMISSION_REQUEST_ACCESS_FINE_LOCATION
=
4001
;
private
JSONArray
jsonArray
=
new
JSONArray
();
private
LocationManager
locationManager
;
private
static
final
int
LOCATION_UPDATE_INTERVAL
=
1000
;
private
final
int
LOCATION_UPDATE_INTERVAL
=
1000
;
private
double
mLatitude
=
0
;
private
double
mLongitude
=
0
;
// Radius of the Earth in meters
...
...
@@ -86,6 +87,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private
int
orientationCount
=
0
,
touchCount
=
0
;
final
long
REFRESH_TIME
=
100
;
// miliseconds
private
String
mStartTimestamp
=
""
,
mStopTimestamp
=
""
;
private
final
int
RECORDS_INTERVAL
=
5000
;
private
EditText
mEtLimit
;
// ===========================================================
...
...
@@ -110,6 +113,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mIvBack
.
setOnClickListener
(
this
);
mTvOrientationCount
=
findViewById
(
R
.
id
.
tv_orientation
);
mTvTouchCount
=
findViewById
(
R
.
id
.
tv_touch
);
mEtLimit
=
findViewById
(
R
.
id
.
et_acceleration
);
locationManager
=
(
LocationManager
)
getSystemService
(
Context
.
LOCATION_SERVICE
);
previousLocation
=
null
;
...
...
@@ -199,6 +203,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mIsTripStarted
=
false
;
mTvTripButton
.
setText
(
R
.
string
.
cos_dlg_start_trip
);
}
else
{
if
(
mEtLimit
.
getText
().
length
()
==
0
)
{
Snackbar
.
make
(
mLlTelematicsMain
,
"Please fill the Cut off field"
,
Snackbar
.
LENGTH_SHORT
).
show
();
return
;
}
mTouchHandler
=
new
Handler
();
mTouchRunnable
=
new
Runnable
()
{
@Override
...
...
@@ -375,6 +383,18 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mLocationHandler
.
removeCallbacks
(
mLocationRunnable
);
}
private
String
getCutOffLimit
()
{
if
(
mEtLimit
.
getText
().
length
()
!=
0
)
{
if
(
Float
.
valueOf
(
mEtLimit
.
getText
().
toString
())
>
mAcceleration
)
{
return
"red"
;
}
else
{
return
"green"
;
}
}
return
""
;
}
private
void
registerSensor
()
{
mStartTimestamp
=
String
.
valueOf
(
System
.
currentTimeMillis
());
mSensorManager
=
(
SensorManager
)
getSystemService
(
Context
.
SENSOR_SERVICE
);
...
...
@@ -382,7 +402,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mSensorManager
.
registerListener
(
this
,
mSensor
,
SensorManager
.
SENSOR_DELAY_NORMAL
);
Snackbar
.
make
(
mLlTelematicsMain
,
"Sensor Registered"
,
Snackbar
.
LENGTH_SHORT
).
show
();
final
int
delay
=
1000
;
final
int
[]
recordsCount
=
{
0
};
mTvRecordsSaved
.
setText
(
String
.
valueOf
(
recordsCount
[
0
]));
mHandler
=
new
Handler
();
...
...
@@ -400,8 +419,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
jobjData
.
putOpt
(
"timestamp"
,
timestamp
);
jobjData
.
putOpt
(
"start_time"
,
mStartTimestamp
);
jobjData
.
putOpt
(
"stop_time"
,
mStopTimestamp
);
jobjData
.
putOpt
(
"latitude"
,
mLatitude
);
jobjData
.
putOpt
(
"latitude"
,
mLatitude
);
jobjData
.
putOpt
(
"longitude"
,
mLongitude
);
jobjData
.
putOpt
(
"limit"
,
getCutOffLimit
());
jobj
.
putOpt
(
timestamp
,
jobjData
);
mAccelerationTimestamps
.
add
(
jobj
);
recordsCount
[
0
]++;
...
...
@@ -410,10 +430,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
e
.
printStackTrace
();
Snackbar
.
make
(
mLlTelematicsMain
,
"Runnable Failed"
,
Snackbar
.
LENGTH_SHORT
).
show
();
}
mHandler
.
postDelayed
(
this
,
delay
);
mHandler
.
postDelayed
(
this
,
RECORDS_INTERVAL
);
}
};
mHandler
.
postDelayed
(
mRunnable
,
delay
);
mHandler
.
postDelayed
(
mRunnable
,
RECORDS_INTERVAL
);
}
private
void
unregisterSensor
()
{
...
...
warply_android_sdk/src/main/res/layout/activity_telematics.xml
View file @
24b87bc
...
...
@@ -189,6 +189,19 @@
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<EditText
android:id=
"@+id/et_acceleration"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
android:inputType=
"phone"
android:layout_marginTop=
"24dp"
android:hint=
"Cut off in km/h"
android:layout_below=
"@+id/tv_records"
/>
<LinearLayout
android:id=
"@+id/ll_activate_button"
android:layout_width=
"match_parent"
...
...
Please
register
or
login
to post a comment