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-11 15:22:59 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
50376aa3b9a7dd0acd39b270765ea19a35e9557d
50376aa3
1 parent
2d4dfb2d
telematics changes
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
205 additions
and
180 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 @
50376aa
...
...
@@ -15,6 +15,7 @@ import android.location.LocationManager;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.text.TextUtils
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.WindowManager
;
...
...
@@ -88,7 +89,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
final
long
REFRESH_TIME
=
100
;
// miliseconds
private
String
mStartTimestamp
=
""
,
mStopTimestamp
=
""
;
private
final
int
RECORDS_INTERVAL
=
5000
;
private
EditText
mEtLimit
;
private
EditText
mEtLimit
,
mEtSampleTime
;
// ===========================================================
...
...
@@ -114,6 +115,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mTvOrientationCount
=
findViewById
(
R
.
id
.
tv_orientation
);
mTvTouchCount
=
findViewById
(
R
.
id
.
tv_touch
);
mEtLimit
=
findViewById
(
R
.
id
.
et_acceleration
);
mEtSampleTime
=
findViewById
(
R
.
id
.
et_save
);
locationManager
=
(
LocationManager
)
getSystemService
(
Context
.
LOCATION_SERVICE
);
previousLocation
=
null
;
...
...
@@ -176,8 +178,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
velocity
=
acceleration
*
time
;
}
// Convert velocity to km/h
mAcceleration
=
velocity
*
3.6f
;
// Convert to km/h
mTvVelocity
.
setText
(
String
.
format
(
"%.1f"
,
mAcceleration
)
+
" km/h"
);
// mAcceleration = velocity * 3.6f; // Convert to km/h
mAcceleration
=
velocity
;
// Convert to km/h
mTvVelocity
.
setText
(
String
.
format
(
"%.1f"
,
velocity
)
+
" m/s^2"
);
// Update last values
lastX
=
filteredX
;
lastY
=
filteredY
;
...
...
@@ -253,7 +256,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
//TODO: comment the first block and uncomment the second block if needs revert to handler implementation
if
(
mLatitude
!=
0
&&
mLongitude
!=
0
)
{
mSpeed
=
calculateSpeed
(
mLatitude
,
mLongitude
,
location
.
getLatitude
(),
location
.
getLongitude
(),
(
LOCATION_UPDATE_INTERVAL
/
1000
));
mTvAvgVelocity
.
setText
(
String
.
format
(
"%.1f"
,
Math
.
floor
(
mSpeed
))
+
"
km/h
"
);
mTvAvgVelocity
.
setText
(
String
.
format
(
"%.1f"
,
Math
.
floor
(
mSpeed
))
+
"
m/s^2
"
);
}
...
...
@@ -317,8 +320,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
// ===========================================================
private
void
initViews
()
{
mTvVelocity
.
setText
(
"0.0
km/h
"
);
mTvAvgVelocity
.
setText
(
"0.0
km/h
"
);
mTvVelocity
.
setText
(
"0.0
m/s^2
"
);
mTvAvgVelocity
.
setText
(
"0.0
m/s^2
"
);
}
private
void
requestLocationUpdates
()
{
...
...
@@ -349,7 +352,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
@Override
public
void
run
()
{
double
speed
=
calculateSpeed
(
mLatitude
,
mLongitude
,
location
.
getLatitude
(),
location
.
getLongitude
(),
(
LOCATION_UPDATE_INTERVAL
/
1000
));
mTvAvgVelocity
.
setText
(
String
.
format
(
"%.1f"
,
Math
.
floor
(
speed
))
+
"
km/h
"
);
mTvAvgVelocity
.
setText
(
String
.
format
(
"%.1f"
,
Math
.
floor
(
speed
))
+
"
m/s^2
"
);
mLocationHandler
.
postDelayed
(
this
,
LOCATION_UPDATE_INTERVAL
);
}
};
...
...
@@ -365,7 +368,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
// Function to calculate speed in meters per second
private
double
calculateSpeed
(
double
lat1
,
double
lon1
,
double
lat2
,
double
lon2
,
double
timeDifferenceInSeconds
)
{
double
distance
=
calculateDistance
(
lat1
,
lon1
,
lat2
,
lon2
);
return
(
distance
/
timeDifferenceInSeconds
)
*
3.6f
;
// Convert to km/h;
// return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h;
return
(
distance
/
timeDifferenceInSeconds
);
// Convert to km/h;
}
private
void
requestSingleLocationUpdate
()
{
...
...
@@ -430,10 +434,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
e
.
printStackTrace
();
Snackbar
.
make
(
mLlTelematicsMain
,
"Runnable Failed"
,
Snackbar
.
LENGTH_SHORT
).
show
();
}
mHandler
.
postDelayed
(
this
,
RECORDS_INTERVAL
);
mHandler
.
postDelayed
(
this
,
TextUtils
.
isEmpty
(
mEtSampleTime
.
getText
())
?
RECORDS_INTERVAL
:
Integer
.
valueOf
(
mEtSampleTime
.
getText
().
toString
())
);
}
};
mHandler
.
postDelayed
(
mRunnable
,
RECORDS_INTERVAL
);
mHandler
.
postDelayed
(
mRunnable
,
TextUtils
.
isEmpty
(
mEtSampleTime
.
getText
())
?
RECORDS_INTERVAL
:
Integer
.
valueOf
(
mEtSampleTime
.
getText
().
toString
())
);
}
private
void
unregisterSensor
()
{
...
...
@@ -441,8 +445,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
orientationCount
=
0
;
touchCount
=
0
;
mSensorManager
.
unregisterListener
(
this
);
mTvVelocity
.
setText
(
"0.0
km/h
"
);
mTvAvgVelocity
.
setText
(
"0.0
km/h
"
);
mTvVelocity
.
setText
(
"0.0
m/s^2
"
);
mTvAvgVelocity
.
setText
(
"0.0
m/s^2
"
);
Snackbar
.
make
(
mLlTelematicsMain
,
"Sensor Unregistered"
,
Snackbar
.
LENGTH_SHORT
).
show
();
if
(
mHandler
!=
null
)
mHandler
.
removeCallbacks
(
mRunnable
);
...
...
warply_android_sdk/src/main/res/layout/activity_telematics.xml
View file @
50376aa
...
...
@@ -39,190 +39,211 @@
app:layout_constraintTop_toTopOf=
"parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/cos_light_grey3"
android:gravity=
"center_horizontal"
>
<ScrollView
android:fillViewport=
"true"
android:layout_width=
"wrap_content"
android:layout_height=
"match_parent"
>
<TextView
android:id=
"@+id/tv_sensor_data_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:text=
"Sensor Data"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/cos_light_grey3"
android:gravity=
"center_horizontal"
>
<TextView
android:id=
"@+id/tv_sensor_data
"
fontPath=
"fonts/PeridotPE-Bold
.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_sensor_data_label
"
android:layout_centerHorizontal=
"true
"
android:layout_marginTop=
"24dp
"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_sensor_data_label
"
fontPath=
"fonts/PeridotPE-Regular
.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true
"
android:layout_marginTop=
"24dp
"
android:text=
"Sensor Data
"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_velocity_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:text=
"Acceleration"
android:layout_below=
"@+id/tv_sensor_data"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_sensor_data"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_sensor_data_label"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_velocity"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_velocity_label"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_velocity_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_sensor_data"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:text=
"Acceleration"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_avg_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:text=
"Velocity"
android:layout_below=
"@+id/tv_velocity"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_velocity"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_velocity_label"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:textColor=
"@color/blue_dark"
android:textSize=
"20sp"
/>
<TextView
android:id=
"@+id/tv_avg"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_avg_label"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_avg_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_velocity"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:text=
"Velocity"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_orientation_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentStart=
"true"
android:layout_marginTop=
"24dp"
android:layout_marginStart=
"24dp"
android:text=
"Orientation Count"
android:layout_below=
"@+id/tv_avg"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_avg"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_avg_label"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:textColor=
"@color/blue_dark"
android:textSize=
"20sp"
/>
<TextView
android:id=
"@+id/tv_orientation
"
fontPath=
"fonts/PeridotPE-Bold
.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_orientation_label
"
android:layout_alignStart=
"@+id/tv_orientation_label
"
android:layout_alignEnd=
"@+id/tv_orientation_label
"
android:layout_marginTop=
"24dp"
android:gravity=
"center
"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_orientation_label
"
fontPath=
"fonts/PeridotPE-Regular
.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_avg
"
android:layout_alignParentStart=
"true
"
android:layout_marginStart=
"24dp
"
android:layout_marginTop=
"24dp"
android:text=
"Orientation Count
"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_touch_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"24dp"
android:layout_marginEnd=
"24dp"
android:layout_alignParentEnd=
"true"
android:text=
"Touch Count"
android:layout_below=
"@+id/tv_avg"
android:layout_alignEnd=
"@+id/tv_orientation_label"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_orientation"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_orientation_label"
android:layout_alignStart=
"@+id/tv_orientation_label"
android:layout_alignEnd=
"@+id/tv_orientation_label"
android:layout_marginTop=
"24dp"
android:gravity=
"center"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_touch"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_touch_label"
android:layout_alignStart=
"@+id/tv_touch_label"
android:layout_alignEnd=
"@+id/tv_touch_label"
android:layout_marginTop=
"24dp"
android:gravity=
"center"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_touch_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_avg"
android:layout_alignParentEnd=
"true"
android:layout_marginTop=
"24dp"
android:paddingEnd=
"24dp"
android:layout_marginEnd=
"24dp"
android:text=
"Touch Count"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_records_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:text=
"Records Saved"
android:layout_below=
"@+id/tv_orientation"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_touch"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_touch_label"
android:layout_alignStart=
"@+id/tv_touch_label"
android:layout_alignEnd=
"@+id/tv_touch_label"
android:layout_marginTop=
"24dp"
android:gravity=
"center"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_records"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_records_label"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
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"
android:layout_height=
"55dp"
android:layout_alignParentBottom=
"true"
android:layout_marginHorizontal=
"24dp"
android:layout_marginBottom=
"56dp"
android:background=
"@drawable/selector_button_green_border"
android:gravity=
"center"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/tv_records_label"
fontPath=
"fonts/PeridotPE-Regular.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_orientation"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
android:text=
"Records Saved"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/tv_
trip_button
"
fontPath=
"fonts/PeridotPE-
Semi
Bold.ttf"
android:id=
"@+id/tv_
records
"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"center"
android:includeFontPadding=
"false"
android:text=
"@string/cos_dlg_start_trip"
android:layout_below=
"@+id/tv_records_label"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"24dp"
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_below=
"@+id/tv_records"
android:layout_alignParentStart=
"true"
android:layout_marginTop=
"24dp"
android:layout_marginStart=
"24dp"
android:hint=
"Cut off in m/s^2"
android:inputType=
"phone"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
</LinearLayout>
</RelativeLayout>
<EditText
android:id=
"@+id/et_save"
fontPath=
"fonts/PeridotPE-Bold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_records"
android:layout_alignParentEnd=
"true"
android:paddingEnd=
"24dp"
android:layout_marginTop=
"24dp"
android:hint=
"Sample Interval in ms"
android:inputType=
"phone"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
<LinearLayout
android:id=
"@+id/ll_activate_button"
android:layout_width=
"match_parent"
android:layout_height=
"55dp"
android:layout_below=
"@+id/et_acceleration"
android:layout_marginHorizontal=
"24dp"
android:layout_marginVertical=
"56dp"
android:background=
"@drawable/selector_button_green_border"
android:gravity=
"center"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/tv_trip_button"
fontPath=
"fonts/PeridotPE-SemiBold.ttf"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"center"
android:includeFontPadding=
"false"
android:text=
"@string/cos_dlg_start_trip"
android:textColor=
"@color/blue_dark"
android:textSize=
"16sp"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
\ No newline at end of file
...
...
Please
register
or
login
to post a comment