widget for tracker initial commit
This commit is contained in:
parent
22be792a53
commit
b9dcc3a431
3 changed files with 33 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<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_descr">Select time zone to show in your location messages.</string>
|
||||||
<string name="time_zone">Time zone</string>
|
<string name="time_zone">Time zone</string>
|
||||||
<string name="units_and_formats">Units & formats</string>
|
<string name="units_and_formats">Units & formats</string>
|
||||||
|
|
|
@ -154,6 +154,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
||||||
if (shouldCleanupResources) {
|
if (shouldCleanupResources) {
|
||||||
app.cleanupResources()
|
app.cleanupResources()
|
||||||
}
|
}
|
||||||
|
app().showLocationHelper.updateStatusWidget(-1)
|
||||||
|
|
||||||
// remove notification
|
// remove notification
|
||||||
stopForeground(java.lang.Boolean.TRUE)
|
stopForeground(java.lang.Boolean.TRUE)
|
||||||
|
@ -194,6 +195,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
||||||
updateShareInfoHandler?.postDelayed({
|
updateShareInfoHandler?.postDelayed({
|
||||||
if (isUsedByMyLocation(usedBy)) {
|
if (isUsedByMyLocation(usedBy)) {
|
||||||
app().shareLocationHelper.updateSendLiveMessages()
|
app().shareLocationHelper.updateSendLiveMessages()
|
||||||
|
app().showLocationHelper.updateStatusWidget(app().locationMessages.getBufferedMessagesCount())
|
||||||
startShareInfoUpdates()
|
startShareInfoUpdates()
|
||||||
}
|
}
|
||||||
}, UPDATE_LIVE_MESSAGES_INTERVAL_MS)
|
}, UPDATE_LIVE_MESSAGES_INTERVAL_MS)
|
||||||
|
|
|
@ -43,6 +43,11 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
|
|
||||||
const val GPX_COLORS_COUNT = 10
|
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(
|
val GPX_COLORS = arrayOf(
|
||||||
"red", "orange", "lightblue", "blue", "purple",
|
"red", "orange", "lightblue", "blue", "purple",
|
||||||
"translucent_red", "translucent_orange", "translucent_lightblue",
|
"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? {
|
private fun getALatLonFromMessage(content: TdApi.MessageContent): ALatLon? {
|
||||||
return when (content) {
|
return when (content) {
|
||||||
is TdApi.MessageLocation -> ALatLon(content.location.latitude, content.location.longitude)
|
is TdApi.MessageLocation -> ALatLon(content.location.latitude, content.location.longitude)
|
||||||
|
|
Loading…
Reference in a new issue