widget for tracker initial commit

This commit is contained in:
Dmitriy Ruban 2019-12-23 19:05:13 +02:00
parent 22be792a53
commit b9dcc3a431
3 changed files with 33 additions and 0 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="status_widget_title">OsmAnd Tracker status</string>
<string name="time_zone_descr">Select time zone to show in your location messages.</string>
<string name="time_zone">Time zone</string>
<string name="units_and_formats">Units &amp; formats</string>

View file

@ -154,6 +154,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
if (shouldCleanupResources) {
app.cleanupResources()
}
app().showLocationHelper.updateStatusWidget(-1)
// remove notification
stopForeground(java.lang.Boolean.TRUE)
@ -194,6 +195,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
updateShareInfoHandler?.postDelayed({
if (isUsedByMyLocation(usedBy)) {
app().shareLocationHelper.updateSendLiveMessages()
app().showLocationHelper.updateStatusWidget(app().locationMessages.getBufferedMessagesCount())
startShareInfoUpdates()
}
}, UPDATE_LIVE_MESSAGES_INTERVAL_MS)

View file

@ -43,6 +43,11 @@ class ShowLocationHelper(private val app: TelegramApplication) {
const val GPX_COLORS_COUNT = 10
private const val STATUS_WIDGET_ID = "status_widget"
private const val STATUS_WIDGET_MENU_ICON = "ic_action_speed"
private const val STATUS_WIDGET_DAY_ICON = "widget_speed_day"
private const val STATUS_WIDGET_NIGHT_ICON = "widget_speed_night"
val GPX_COLORS = arrayOf(
"red", "orange", "lightblue", "blue", "purple",
"translucent_red", "translucent_orange", "translucent_lightblue",
@ -198,6 +203,31 @@ class ShowLocationHelper(private val app: TelegramApplication) {
}
}
fun updateStatusWidget(count: Int) {
val text = when {
count > 0 -> count.toString()
count == 0 -> "ON"
else -> "OFF"
}
val bufferText = when {
count > 0 -> count.toString()
else -> ""
}
osmandAidlHelper.addMapWidget(
STATUS_WIDGET_ID,
STATUS_WIDGET_MENU_ICON,
app.getString(R.string.status_widget_title),
STATUS_WIDGET_DAY_ICON,
STATUS_WIDGET_NIGHT_ICON,
text, bufferText, 50, getStatusWidgetIntent())
}
private fun getStatusWidgetIntent(): Intent {
val startIntent = app.packageManager.getLaunchIntentForPackage(app.packageName)
startIntent.addCategory(Intent.CATEGORY_LAUNCHER)
return startIntent
}
private fun getALatLonFromMessage(content: TdApi.MessageContent): ALatLon? {
return when (content) {
is TdApi.MessageLocation -> ALatLon(content.location.latitude, content.location.longitude)