From 867e2aa5d2f53cc936dd773dac79b1cccf472d4e Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 2 Mar 2019 15:56:59 +0100 Subject: [PATCH 01/13] add an experimental feature for high image compression --- res/values/arrays.xml | 10 ++++++++++ res/xml/preferences_advanced.xml | 15 +++++++++++++++ .../preferences/AdvancedPreferenceFragment.java | 4 ++++ .../thoughtcrime/securesms/util/BitmapUtil.java | 10 ++++++++-- src/org/thoughtcrime/securesms/util/Prefs.java | 9 +++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 1affdd1ab..e27e472cd 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -165,6 +165,16 @@ 2 + + Balanced + Worse quality, small size + + + + 0 + 1 + + diff --git a/res/xml/preferences_advanced.xml b/res/xml/preferences_advanced.xml index 19dee460f..8ab7d4c6b 100644 --- a/res/xml/preferences_advanced.xml +++ b/res/xml/preferences_advanced.xml @@ -52,6 +52,21 @@ + + + + + + + + + Date: Tue, 5 Mar 2019 21:12:55 +0100 Subject: [PATCH 02/13] updates gradle syntax, integrates map dependency and removes gradleWitness until 'implementation' is supported --- build.gradle | 131 +++++------------- libs/gradle-witness.jar | Bin 16693 -> 0 bytes .../securesms/ApplicationContext.java | 2 + 3 files changed, 39 insertions(+), 94 deletions(-) delete mode 100644 libs/gradle-witness.jar diff --git a/build.gradle b/build.gradle index 4c031e834..207ff3683 100644 --- a/build.gradle +++ b/build.gradle @@ -11,12 +11,10 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' - classpath files('libs/gradle-witness.jar') } } apply plugin: 'com.android.application' -apply plugin: 'witness' // for dependencyVerification repositories { google() @@ -30,116 +28,60 @@ repositories { } dependencies { - compile 'com.android.support:appcompat-v7:27.0.2' // one use in SearchToolbar. - compile 'com.android.support:design:27.0.2' // used in various locations for a lot of components - compile 'com.android.support:support-v13:27.0.2' // used to prevent a 25... version to be loaded (from where ever) - compile 'com.android.support:preference-v7:27.0.2' // actually a dependency of -v14 - compile 'com.android.support:preference-v14:27.0.2' // used to manage the users preferences - compile 'com.android.support:exifinterface:27.0.2' // Used to edit the Exif in BitmapUtil - compile 'com.android.support.constraint:constraint-layout:1.1.2' // Used in several places - compile 'android.arch.lifecycle:extensions:1.1.1' // Used in situations where data changes should be displayed directly (e.G. Search) - compile 'android.arch.lifecycle:common-java8:1.1.1' // Used in situations where data changes should be displayed directly (e.G. Search) + implementation 'com.android.support:appcompat-v7:27.1.1' // one use in SearchToolbar. + implementation 'com.android.support:design:27.1.1' // used in various locations for a lot of components + implementation 'com.android.support:support-v13:27.1.1' // used to prevent a 25... version to be loaded (from where ever) + implementation 'com.android.support:preference-v7:27.1.1' // actually a dependency of -v14 + implementation 'com.android.support:preference-v14:27.1.1' // used to manage the users preferences + implementation 'com.android.support:exifinterface:27.1.1' // Used to edit the Exif in BitmapUtil + implementation 'com.android.support.constraint:constraint-layout:1.1.2' // Used in several places + implementation 'android.arch.lifecycle:extensions:1.1.1' // Used in situations where data changes should be displayed directly (e.G. Search) + implementation 'android.arch.lifecycle:common-java8:1.1.1' // Used in situations where data changes should be displayed directly (e.G. Search) - compile 'com.google.android.exoplayer:exoplayer:r2.3.1' // plays video. + implementation 'com.google.android.exoplayer:exoplayer:r2.3.1' // plays video. - compile 'com.fasterxml.jackson.core:jackson-databind:2.9.5' // used as JSON library TODO: check if java builtin would work as well + implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.5' // used as JSON library TODO: check if java builtin would work as well - compile 'com.journeyapps:zxing-android-embedded:3.4.0' // QR Code scanner + implementation 'com.journeyapps:zxing-android-embedded:3.4.0' // QR Code scanner - compile "me.leolin:ShortcutBadger:1.1.16" // display messagecount on the home screen icon. - compile 'com.jpardogo.materialtabstrip:library:1.0.9' // used in the emoji selector for the tab selection. - compile 'com.github.chrisbanes:PhotoView:2.1.3' // does the zooming on photos / media - compile 'com.github.bumptech.glide:glide:4.5.0' + implementation "me.leolin:ShortcutBadger:1.1.16" // display messagecount on the home screen icon. + implementation 'com.jpardogo.materialtabstrip:library:1.0.9' // used in the emoji selector for the tab selection. + implementation 'com.github.chrisbanes:PhotoView:2.1.3' // does the zooming on photos / media + implementation 'com.github.bumptech.glide:glide:4.5.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0' - compile 'com.makeramen:roundedimageview:2.1.0' // crops the avatars to circles - compile 'com.pnikosis:materialish-progress:1.5' // used only in the "Progress Wheel" in Share Activity. - compile 'com.soundcloud.android:android-crop:0.9.10@aar' // used in Group Select Avatar, should be unified with profie - compile 'com.nineoldandroids:library:2.4.0' // DEPRECATED! Used to slide in the half-camera. - compile 'mobi.upod:time-duration-picker:1.1.3' // Used to pick the time for inactivity. - compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' // number of unread messages, + implementation 'com.makeramen:roundedimageview:2.1.0' // crops the avatars to circles + implementation 'com.pnikosis:materialish-progress:1.5' // used only in the "Progress Wheel" in Share Activity. + implementation 'com.soundcloud.android:android-crop:0.9.10@aar' // used in Group Select Avatar, should be unified with profie + implementation 'com.nineoldandroids:library:2.4.0' // DEPRECATED! Used to slide in the half-camera. + implementation 'mobi.upod:time-duration-picker:1.1.3' // Used to pick the time for inactivity. + implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' // number of unread messages, // the one-letter circle for the contacts (when there is not avatar) and a white background. - compile 'com.google.zxing:core:3.2.1' // QR Code scanner - compile ('com.davemorrissey.labs:subsampling-scale-image-view:3.6.0') { // for the zooming on photos / media + implementation 'com.google.zxing:core:3.2.1' // QR Code scanner + implementation ('com.davemorrissey.labs:subsampling-scale-image-view:3.6.0') { // for the zooming on photos / media exclude group: 'com.android.support', module: 'support-annotations' } - compile 'com.annimon:stream:1.1.8' // brings future java streams api to SDK Version < 24 - compile 'com.codewaves.stickyheadergrid:stickyheadergrid:0.9.4' // glues the current time segment text in the gallery to the top. + implementation 'com.annimon:stream:1.1.8' // brings future java streams api to SDK Version < 24 + implementation 'com.codewaves.stickyheadergrid:stickyheadergrid:0.9.4' // glues the current time segment text in the gallery to the top. + implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.2.0' - testCompile 'junit:junit:4.12' - testCompile 'org.assertj:assertj-core:1.7.1' - testCompile 'org.mockito:mockito-core:1.9.5' - testCompile 'org.powermock:powermock-api-mockito:1.6.1' - testCompile 'org.powermock:powermock-module-junit4:1.6.1' - testCompile 'org.powermock:powermock-module-junit4-rule:1.6.1' - testCompile 'org.powermock:powermock-classloading-xstream:1.6.1' + testImplementation 'junit:junit:4.12' + testImplementation 'org.assertj:assertj-core:1.7.1' + testImplementation 'org.mockito:mockito-core:1.9.5' + testImplementation 'org.powermock:powermock-api-mockito:1.6.1' + testImplementation 'org.powermock:powermock-module-junit4:1.6.1' + testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.1' + testImplementation 'org.powermock:powermock-classloading-xstream:1.6.1' - androidTestCompile ('org.assertj:assertj-core:1.7.1') { + androidTestImplementation ('org.assertj:assertj-core:1.7.1') { exclude group: 'org.hamcrest', module: 'hamcrest-core' } } -dependencyVerification { - // used by the witness plugin to verifiy dependencies. - // to update the list, call `./gradlew -q calculateChecksums` and paste the result here. - verify = [ - 'com.android.support:design:fa5c27a705310e95a8f4099c98777132ed901a0d69178942306bb34cd76f0d57', - 'com.android.support:preference-v14:1fcf40bd560dc21ce55b6a292d1326d28f52dc5e4f2a64eef2f38dd95777b645', - 'com.android.support:preference-v7:d9f32ddc92f8d6a0bd86a18f4fcaff805fa021245e395b6e7dd382907443ee53', - 'com.pnikosis:materialish-progress:d71d80e00717a096784482aee21001a9d299fec3833e4ebd87739ed36cf77c54', - 'mobi.upod:time-duration-picker:db469ce0f48dd96b892eac424ed76870e54bf00fe0a28cdcddfbe5f2a226a0e1', - 'com.codewaves.stickyheadergrid:stickyheadergrid:5b4aa6a52a957cfd55f60f4220c11c0c371385a3cb9786cae03c260dcdef5794', - 'com.android.support:appcompat-v7:b2825e8b47f665d3362d8481c8d147d1af9230d16f23a2b94f6ccbc53c68cec1', - 'com.android.support:support-v13:6f2848811ceef2e32cc98da02a045d65f7e7447a6bd7198b9ec10aa14d7ad55c', - 'com.android.support:exifinterface:0e7cd526c4468895cd8549def46b3d33c8bcfb1ae4830569898d8c7326b15bb2', - 'com.android.support.constraint:constraint-layout:839a7e16fc50adfabaa8cb753e675ed63f94e1e91ba9115ce43b0d6a37fe8aa6', - 'android.arch.lifecycle:extensions:429426b2feec2245ffc5e75b3b5309bedb36159cf06dc71843ae43526ac289b6', - 'android.arch.lifecycle:common-java8:7078b5c8ccb94203df9cc2a463c69cf0021596e6cf966d78fbfd697aaafe0630', - 'com.google.android.exoplayer:exoplayer:955085aa611a8f7cf6c61b88ae03d1a392f4ad94c9bfbc153f3dedb9ffb14718', - 'com.fasterxml.jackson.core:jackson-databind:0fb4e079c118e752cc94c15ad22e6782b0dfc5dc09145f4813fb39d82e686047', - 'com.journeyapps:zxing-android-embedded:2422d83c2c09a7b645f516c8458ececba6a7da47b94e40778d876facf495c660', - 'me.leolin:ShortcutBadger:e3cb3e7625892129b0c92dd5e4bc649faffdd526d5af26d9c45ee31ff8851774', - 'com.jpardogo.materialtabstrip:library:c6ef812fba4f74be7dc4a905faa4c2908cba261a94c13d4f96d5e67e4aad4aaa', - 'com.github.chrisbanes:PhotoView:7f12b0a9f24b132fc743861ab8f045625faa95c8357887a5fac58fa34a3759e4', - 'com.github.bumptech.glide:glide:997de7ac95be6c944d3b8cbe13de11307736ea45451c1b09a6cec7c328ead59f', - 'com.makeramen:roundedimageview:1f5a1865796b308c6cdd114acc6e78408b110f0a62fc63553278fbeacd489cd1', - 'com.soundcloud.android:android-crop:ffd4b973cf6e97f7d64118a0dc088df50e9066fd5634fe6911dd0c0c5d346177', - 'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a', - 'com.amulyakhare:com.amulyakhare.textdrawable:54c92b5fba38cfd316a07e5a30528068f45ce8515a6890f1297df4c401af5dcb', - 'com.google.zxing:core:b4d82452e7a6bf6ec2698904b332431717ed8f9a850224f295aec89de80f2259', - 'com.davemorrissey.labs:subsampling-scale-image-view:550c5baa07e0bb4ff0a18b705e96d34436d22619248bd8c08c08c730b1f55cfe', - 'com.annimon:stream:5da6e2e3e0551d61a3ea7014f04312276549e3dd739cf637996e4cf43c5535b9', - 'com.android.support:transition:1a7db0453c1467fc8fd815e6d50ca6bb475a7a9ba6b5f3b307329688a7c62a68', - 'android.arch.lifecycle:livedata:50ab0490c1ff1a7cfb4e554032998b080888946d0dd424f39900efc4a1bcd750', - 'android.arch.lifecycle:livedata-core:d6fdd8b985d6178d7ea2f16986a24e83f1bee936b74d43167c69e08d3cc12c50', - 'android.arch.core:runtime:c3215aa5873311b3f88a6f4e4a3c25ad89971bc127de8c3e1291c57f93a05c39', - 'com.android.support:support-v4:1b2b37169fcccfef5e563d273749e3792decdce9818bc17932403a2363f537b4', - 'com.android.support:support-fragment:e4358388022a2205777575a7251fe357334658e4123d5d6e3b082f5899d9b011', - 'com.android.support:animated-vector-drawable:5b117a2c13a898c2a3c84c480d64edcfac2ef720aa9b742c29249fac774ffc48', - 'com.android.support:recyclerview-v7:3eb953930f10941f2b0447ec123a9b03d2746a42a99c523e82c3ece3308ca70b', - 'com.android.support:support-core-ui:2284072511a95d504c074de80c82cd33724c6d2754117833b98ba3a09994163e', - 'com.android.support:support-media-compat:6dd9327ee9aa467cab479aad97df375072b2b6ba61eadffdaa5a88de3843c457', - 'com.android.support:support-core-utils:b69c6e1e7731b876b910fc7100bcadf40a57f27b32ca26b91400995542112c96', - 'com.android.support:support-vector-drawable:bf4f4fcbf58b1380616581224e6487c230bfdb3434ec353d4adaa4b1f4865cfa', - 'com.android.support:support-compat:ed4d25d91a0b13d8b9def1c0de69ed03d7fb89d50fb37eb0e9b63b0cf7a42357', - 'android.arch.lifecycle:runtime:c4e4be66c1b2f0abec593571454e1de14013f7e0f96bf2a9f212931a48cae550', - 'android.arch.core:common:3a616a32f433e9e23f556b38575c31b013613d3ae85206263b7625fe1f4c151a', - 'android.arch.lifecycle:common:8d378e88ebd5189e09eef623414812c868fd90aa519d6160e2311fb8b81cff56', - 'android.arch.lifecycle:viewmodel:7de29cfaba77d6b5d5be234c57f6812d0150d087e63941af22ba1d1f8e2bc96a', - 'com.github.bumptech.glide:gifdecoder:59ccf3bb0cec11dab4b857382cbe0b171111b6fc62bf141adce4e1180889af15', - 'com.android.support:support-annotations:af05330d997eb92a066534dbe0a3ea24347d26d7001221092113ae02a8f233da', - 'com.android.support.constraint:constraint-layout-solver:55f82d93e188b5183b71f4f3bace5725c900b737c3514c841114e225627ff88f', - 'com.fasterxml.jackson.core:jackson-annotations:45d32ac61ef8a744b464c54c2b3414be571016dd46bfc2bec226761cf7ae457a', - 'com.fasterxml.jackson.core:jackson-core:a2bebaa325ad25455b02149c67e6052367a7d7fc1ce77de000eed284a5214eac', - 'com.github.bumptech.glide:disklrucache:c1b1b6f5bbd01e2fcdc9d7f60913c8d338bdb65ed4a93bfa02b56f19daaade4b', - 'com.github.bumptech.glide:annotations:bede99ef9f71517a4274bac18fd3e483e9f2b6108d7d6fe8f4949be4aa4d9512', - ] -} - android { flavorDimensions "none" compileSdkVersion 27 - buildToolsVersion '27.0.1' + buildToolsVersion '27.0.3' useLibrary 'org.apache.http.legacy' defaultConfig { @@ -157,6 +99,7 @@ android { project.ext.set("archivesBaseName", "deltachat"); buildConfigField "boolean", "DEV_BUILD", "false" + buildConfigField "String", "MAP_ACCESS_TOKEN", '"pk.eyJ1IjoiZGVsdGFjaGF0IiwiYSI6ImNqc3c1aWczMzBjejY0M28wZmU0a3cwMzMifQ.ZPTH9dFJaav06RAu4rTYHw"' ndk { abiFilters "armeabi", "armeabi-v7a", "x86" diff --git a/libs/gradle-witness.jar b/libs/gradle-witness.jar deleted file mode 100644 index 6ab83e596258e069a075bcee5d353177160aae2c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16693 zcm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q@cTY26a1HyBlf6b zi)?44+8xaxY$tI{R<;kFb1+S8U+m$pO2iDM_7^$hh!w73fO)CE#Nj-2Yzw!8p_C@1(&c_Q4Wsf@s3NxE zG1B@_@^B7hu1`UidG9GTXH8VT^0=%re&<)z`JxA<<$zT95F*`J?xJx&NRBtExGZMk zX&y!w&^$oG3;GqgyF}6>YY<@OApHw9GU+lgFXEW3ffES23koQzXL$Y`Me5O54}Te$C~B5Kp4eY|Re-o555$(O-|QwyJ>+*$?C2FiSsq((81V1tfll3Bnb z_pHc;a2{7`Jy`jVXu-yL}M_D1Ns^AE}_ ziZ6ChM{j+Ay!h|ioQzHzUs;2q+p2c@KGgbnU>#9m>P|71oRf#40X9Ij5~h@{1HLQd zlc0V1mM-F1dH*v^EpV>u;|syxPp9AcshIEC%)jwdO&#=&tc+>x{x1vjpZT1B$aNF??k!3 zqi(&2y8mJMzoGtfgUz2l(eGHllQ;g3)%;#y{oi8!M&VL_-{Jx{#gMz=Kg0lQKsQ>gi{3S&AN34Hk;{U|@ z!%F6G{)4&u&EWs8<#&Vs*A*A|E&m5C|I_@-NkY5_Lw{Il#18}SpT6cFr^tu@0}e{S Az5oCK diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 490b79296..eb277987d 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -26,6 +26,7 @@ import android.support.annotation.NonNull; import com.b44t.messenger.DcContext; import com.b44t.messenger.DcEventCenter; +import com.mapbox.mapboxsdk.Mapbox; import org.thoughtcrime.securesms.connect.ApplicationDcContext; import org.thoughtcrime.securesms.crypto.PRNGFixes; @@ -71,6 +72,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO initializeJobManager(); initializeIncomingMessageNotifier(); ProcessLifecycleOwner.get().getLifecycle().addObserver(this); + Mapbox.getInstance(getApplicationContext(), BuildConfig.MAP_ACCESS_TOKEN); } @Override From b0534c44f6dd4ff8ef694acfa16ef7908ca60950 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 6 Mar 2019 12:16:52 +0100 Subject: [PATCH 03/13] initial location service implementation, adds a map activity --- AndroidManifest.xml | 24 ++- res/layout/activity_map.xml | 16 ++ res/menu/conversation.xml | 9 +- res/values/attrs.xml | 1 + res/values/strings.xml | 3 + res/values/themes.xml | 2 + .../messenger/geolocation/DcLocation.java | 43 ++++ .../geolocation/DcLocationManager.java | 85 ++++++++ .../LocationBackgroundService.java | 193 ++++++++++++++++++ src/com/b44t/messenger/map/MapActivity.java | 150 ++++++++++++++ .../securesms/ApplicationContext.java | 9 +- .../securesms/ConversationActivity.java | 7 + 12 files changed, 527 insertions(+), 15 deletions(-) create mode 100644 res/layout/activity_map.xml create mode 100644 src/com/b44t/messenger/geolocation/DcLocation.java create mode 100644 src/com/b44t/messenger/geolocation/DcLocationManager.java create mode 100644 src/com/b44t/messenger/geolocation/LocationBackgroundService.java create mode 100644 src/com/b44t/messenger/map/MapActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index d791f5155..772a968bd 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ + xmlns:tools="http://schemas.android.com/tools" + package="org.thoughtcrime.securesms"> @@ -15,21 +15,21 @@ - + - - + + - + - - - + + + @@ -262,7 +262,11 @@ android:theme="@style/TextSecure.LightTheme" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/> - + + + + + diff --git a/res/layout/activity_map.xml b/res/layout/activity_map.xml new file mode 100644 index 000000000..06e6cb116 --- /dev/null +++ b/res/layout/activity_map.xml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/res/menu/conversation.xml b/res/menu/conversation.xml index c9e4de636..128621c72 100644 --- a/res/menu/conversation.xml +++ b/res/menu/conversation.xml @@ -1,5 +1,7 @@ - + @@ -10,4 +12,9 @@ + + diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 3557f383a..276753894 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -112,6 +112,7 @@ + diff --git a/res/values/strings.xml b/res/values/strings.xml index be91a01ae..83f27a780 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -111,6 +111,7 @@ Send Toggle emoji keyboard Edit group + Show map Archive chat Unarchive chat Add attachment @@ -606,6 +607,7 @@ Open Log Folder Open Current Logfile + Delta Chat needs the location permission in order to show and share your location. @@ -619,4 +621,5 @@ Scan this to join the group \"%1$s\". + diff --git a/res/values/themes.xml b/res/values/themes.xml index ba1c9324a..7bf77fe6a 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -186,6 +186,7 @@ @drawable/ic_add_white_24dp @drawable/ic_group_white_24dp + @android:drawable/ic_dialog_map @drawable/ic_search_white_24dp @drawable/ic_launch_white_24dp @drawable/ic_unlocked_white_24dp @@ -331,6 +332,7 @@ @drawable/ic_add_white_24dp @drawable/ic_group_white_24dp + @android:drawable/ic_dialog_map @drawable/ic_search_white_24dp @drawable/ic_launch_white_24dp @drawable/ic_unlocked_white_24dp diff --git a/src/com/b44t/messenger/geolocation/DcLocation.java b/src/com/b44t/messenger/geolocation/DcLocation.java new file mode 100644 index 000000000..b31fb498f --- /dev/null +++ b/src/com/b44t/messenger/geolocation/DcLocation.java @@ -0,0 +1,43 @@ +package com.b44t.messenger.geolocation; + +import android.location.Location; + +import java.util.Observable; + + +/** + * Created by cyberta on 06.03.19. + */ + +public class DcLocation extends Observable { + private Location lastLocation; + private static DcLocation instance; + + private DcLocation() { + lastLocation = new Location("?"); + } + + public static DcLocation getInstance() { + if (instance == null) { + instance = new DcLocation(); + } + return instance; + } + + public Location getLastLocation() { + return instance.lastLocation; + } + + void updateLocation(Location location) { + lastLocation = location; + + instance.setChanged(); + instance.notifyObservers(); + } + + void reset() { + updateLocation(new Location("?")); + } + + +} diff --git a/src/com/b44t/messenger/geolocation/DcLocationManager.java b/src/com/b44t/messenger/geolocation/DcLocationManager.java new file mode 100644 index 000000000..37a82e994 --- /dev/null +++ b/src/com/b44t/messenger/geolocation/DcLocationManager.java @@ -0,0 +1,85 @@ +package com.b44t.messenger.geolocation; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.location.Location; +import android.os.IBinder; +import android.util.Log; + +import java.util.Observable; +import java.util.Observer; + +import static android.content.Context.BIND_AUTO_CREATE; + +/** + * Created by cyberta on 06.03.19. + */ + +public class DcLocationManager implements Observer { + + private static final String TAG = DcLocationManager.class.getSimpleName(); + private LocationBackgroundService.LocationBackgroundServiceBinder serviceBinder; + private Context context; + private DcLocation dcLocation = DcLocation.getInstance(); + private ServiceConnection serviceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + serviceBinder = (LocationBackgroundService.LocationBackgroundServiceBinder) service; + startLocationEngine(); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + serviceBinder = null; + } + }; + + public DcLocationManager(Context context) { + this.context = context.getApplicationContext(); + DcLocation.getInstance().addObserver(this); + } + + + private void initializeLocationEngine() { + Intent intent = new Intent(context.getApplicationContext(), LocationBackgroundService.class); + context.bindService(intent, serviceConnection, BIND_AUTO_CREATE); + } + + public void startLocationEngine() { + if (serviceBinder == null) { + initializeLocationEngine(); + } + } + + public void stopLocationEngine() { + if (serviceBinder == null) { + return; + } + serviceBinder.stop(); + } + + public void shareLastLocation() { + if (serviceBinder == null) { + initializeLocationEngine(); + return; + } + + Location location = dcLocation.getLastLocation(); + Log.d(TAG, "share lastLocation: " + location.getLatitude() + ", " + location.getLongitude()); + //TODO: implement me! write share location message + } + + @Override + public void update(Observable o, Object arg) { + if (o instanceof DcLocation) { + dcLocation = (DcLocation) o; + writeDcLocationUpdateMessage(); + } + } + + private void writeDcLocationUpdateMessage() { + //TODO: implement me! + } +} diff --git a/src/com/b44t/messenger/geolocation/LocationBackgroundService.java b/src/com/b44t/messenger/geolocation/LocationBackgroundService.java new file mode 100644 index 000000000..f561ec17a --- /dev/null +++ b/src/com/b44t/messenger/geolocation/LocationBackgroundService.java @@ -0,0 +1,193 @@ +package com.b44t.messenger.geolocation; + +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Binder; +import android.os.Bundle; +import android.os.IBinder; +import android.util.Log; + +/** + * Created by cyberta on 06.03.19. + */ + +public class LocationBackgroundService extends Service { + + private static final int TIMEOUT = 1000 * 30; + private static final String TAG = LocationBackgroundService.class.getSimpleName(); + private LocationManager locationManager = null; + private static final int LOCATION_INTERVAL = 1000; + private static final float LOCATION_DISTANCE = 20f; + ServiceLocationListener locationListener; + + private final IBinder mBinder = new LocationBackgroundServiceBinder(); + + @Override + public boolean bindService(Intent service, ServiceConnection conn, int flags) { + return super.bindService(service, conn, flags); + } + + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + @Override + public void onCreate() { + locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE); + if (locationManager == null) { + Log.e(TAG, "Unable to initialize location service"); + return; + } + + locationListener = new ServiceLocationListener(); + requestLocationUpdate(LocationManager.NETWORK_PROVIDER); + requestLocationUpdate(LocationManager.GPS_PROVIDER); + initialLocationUpdate(); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + super.onStartCommand(intent, flags, startId); + return START_STICKY; + } + + @Override + public void onDestroy() { + super.onDestroy(); + + if (locationManager == null) { + return; + } + + try { + locationManager.removeUpdates(locationListener); + } catch (Exception ex) { + Log.i(TAG, "fail to remove location listners, ignore", ex); + } + + + } + + + private void requestLocationUpdate(String provider) { + try { + locationManager.requestLocationUpdates( + provider, LOCATION_INTERVAL, LOCATION_DISTANCE, + locationListener); + } catch (SecurityException | IllegalArgumentException ex) { + Log.e(TAG, String.format("Unable to request %s provider based location updates.", provider), ex); + } + } + + private void initialLocationUpdate() { + try { + Location networkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + Location gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + locationListener.onLocationChanged(networkLocation); + locationListener.onLocationChanged(gpsLocation); + + } catch (NullPointerException | SecurityException e) { + e.printStackTrace(); + } + } + + class LocationBackgroundServiceBinder extends Binder { + LocationBackgroundServiceBinder getService() { + return LocationBackgroundServiceBinder.this; + } + + void stop() { + DcLocation.getInstance().reset(); + stopSelf(); + } + } + + private class ServiceLocationListener implements LocationListener { + + @Override + public void onLocationChanged(Location location) { + Log.e(TAG, "onLocationChanged: " + location); + if (isBetterLocation(location, DcLocation.getInstance().getLastLocation())) { + DcLocation.getInstance().updateLocation(location); + } + } + + @Override + public void onProviderDisabled(String provider) { + Log.e(TAG, "onProviderDisabled: " + provider); + } + + @Override + public void onProviderEnabled(String provider) { + Log.e(TAG, "onProviderEnabled: " + provider); + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + Log.e(TAG, "onStatusChanged: " + provider); + } + + + /** https://developer.android.com/guide/topics/location/strategies + * Determines whether one Location reading is better than the current Location fix + * @param location The new Location that you want to evaluate + * @param currentBestLocation The current Location fix, to which you want to compare the new one + */ + private boolean isBetterLocation(Location location, Location currentBestLocation) { + if (currentBestLocation == null) { + // A new location is always better than no location + return true; + } + + // Check whether the new location fix is newer or older + long timeDelta = location.getTime() - currentBestLocation.getTime(); + boolean isSignificantlyNewer = timeDelta > TIMEOUT; + boolean isSignificantlyOlder = timeDelta < -TIMEOUT; + boolean isNewer = timeDelta > 0; + + // If it's been more than two minutes since the current location, use the new location + // because the user has likely moved + if (isSignificantlyNewer) { + return true; + // If the new location is more than two minutes older, it must be worse + } else if (isSignificantlyOlder) { + return false; + } + + // Check whether the new location fix is more or less accurate + int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy()); + boolean isLessAccurate = accuracyDelta > 0; + boolean isMoreAccurate = accuracyDelta < 0; + boolean isSignificantlyLessAccurate = accuracyDelta > 200; + + // Check if the old and new location are from the same provider + boolean isFromSameProvider = isSameProvider(location.getProvider(), + currentBestLocation.getProvider()); + + // Determine location quality using a combination of timeliness and accuracy + if (isMoreAccurate) { + return true; + } else if (isNewer && !isLessAccurate) { + return true; + } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) { + return true; + } + return false; + } + + /** Checks whether two providers are the same */ + private boolean isSameProvider(String provider1, String provider2) { + if (provider1 == null) { + return provider2 == null; + } + return provider1.equals(provider2); + } + } + +} diff --git a/src/com/b44t/messenger/map/MapActivity.java b/src/com/b44t/messenger/map/MapActivity.java new file mode 100644 index 000000000..cf209f973 --- /dev/null +++ b/src/com/b44t/messenger/map/MapActivity.java @@ -0,0 +1,150 @@ +package com.b44t.messenger.map; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.util.Log; +import android.widget.Toast; + +import com.b44t.messenger.geolocation.DcLocation; +import com.b44t.messenger.geolocation.DcLocationManager; +import com.mapbox.android.core.permissions.PermissionsListener; +import com.mapbox.android.core.permissions.PermissionsManager; +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.Style; + +import org.thoughtcrime.securesms.ApplicationContext; +import org.thoughtcrime.securesms.BaseActivity; +import org.thoughtcrime.securesms.R; + +import java.util.List; +import java.util.Observable; +import java.util.Observer; + +public class MapActivity extends BaseActivity implements PermissionsListener, Observer { + + private static final String TAG = MapActivity.class.getSimpleName(); + private MapView mapView; + private PermissionsManager permissionsManager; + private DcLocation dcLocation; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_map); + + mapView = findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> { + + mapboxMap.setCameraPosition(new CameraPosition.Builder() + .target(new LatLng(53.5505D, 10.001D)) + .zoom(12) + .build()); + mapboxMap.getUiSettings().setLogoEnabled(false); + mapboxMap.getUiSettings().setAttributionEnabled(false); + + permissionsManager = new PermissionsManager(this); + + if (PermissionsManager.areLocationPermissionsGranted(this)) { + showDeviceLocation(); + } else { + permissionsManager = new PermissionsManager(this); + permissionsManager.requestLocationPermissions(this); + } + + })); + + dcLocation = DcLocation.getInstance(); + + } + + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onResume() { + super.onResume(); + mapView.onResume(); + DcLocation.getInstance().addObserver(this); + } + + @Override + protected void onPause() { + super.onPause(); + mapView.onPause(); + DcLocation.getInstance().deleteObserver(this); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + + //FIXME: only for testing --v + DcLocationManager locationManager = ApplicationContext.getInstance(this).dcLocationManager; + locationManager.stopLocationEngine(); + + } + + //Android SDK callback for the result from requesting permissions + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults); + } + + //map sdk callbacks for the result from requesting permissions + @Override + public void onPermissionResult(boolean granted) { + if (granted) { + showDeviceLocation(); + } else { + Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show(); + } + } + + @Override + public void onExplanationNeeded(List permissionsToExplain) { + // no explanation text before the permission pop up is shown + } + + private void showDeviceLocation() { + DcLocationManager locationManager = ApplicationContext.getInstance(this).dcLocationManager; + locationManager.startLocationEngine(); + + } + + + @Override + public void update(Observable o, Object arg) { + if (o instanceof DcLocation) { + this.dcLocation = (DcLocation) o; + Log.d(TAG, "show marker on map: " + dcLocation.getLastLocation().getLatitude() + ", " + dcLocation.getLastLocation().getLongitude()); + + } + } +} diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index eb277987d..e3adf67ca 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -26,6 +26,7 @@ import android.support.annotation.NonNull; import com.b44t.messenger.DcContext; import com.b44t.messenger.DcEventCenter; +import com.b44t.messenger.geolocation.DcLocationManager; import com.mapbox.mapboxsdk.Mapbox; import org.thoughtcrime.securesms.connect.ApplicationDcContext; @@ -50,11 +51,10 @@ public class ApplicationContext extends Application implements DefaultLifecycleO private static final String TAG = ApplicationContext.class.getName(); - private JobManager jobManager; - - private volatile boolean isAppVisible; - public ApplicationDcContext dcContext; + public DcLocationManager dcLocationManager; + private JobManager jobManager; + private volatile boolean isAppVisible; public static ApplicationContext getInstance(Context context) { return (ApplicationContext)context.getApplicationContext(); @@ -73,6 +73,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO initializeIncomingMessageNotifier(); ProcessLifecycleOwner.get().getLifecycle().addObserver(this); Mapbox.getInstance(getApplicationContext(), BuildConfig.MAP_ACCESS_TOKEN); + dcLocationManager = new DcLocationManager(this); } @Override diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index f8da81b7d..7a0375a92 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -63,6 +63,7 @@ import com.b44t.messenger.DcContact; import com.b44t.messenger.DcContext; import com.b44t.messenger.DcEventCenter; import com.b44t.messenger.DcMsg; +import com.b44t.messenger.map.MapActivity; import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.audio.AudioRecorder; @@ -446,6 +447,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity case R.id.menu_mute_notifications: handleMuteNotifications(); return true; case R.id.menu_unmute_notifications: handleUnmuteNotifications(); return true; case R.id.menu_conversation_settings: handleConversationSettings(); return true; + case R.id.menu_show_map: handleShowMap(); return true; case android.R.id.home: handleReturnToConversationList(); return true; } @@ -471,6 +473,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity //////// Event Handlers + private void handleShowMap() { + Intent intent = new Intent(this, MapActivity.class); + startActivity(intent); + } + private void handleReturnToConversationList() { Intent intent = new Intent(this, (archived ? ConversationListArchiveActivity.class : ConversationListActivity.class)); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); From 71d6972d0fc7bb7790b4865bc78f524d4de6e3a0 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 6 Mar 2019 12:31:48 +0100 Subject: [PATCH 04/13] move map and android related code to org.thoughtcrime.securesms --- AndroidManifest.xml | 4 ++-- res/layout/activity_map.xml | 2 +- src/org/thoughtcrime/securesms/ApplicationContext.java | 2 +- src/org/thoughtcrime/securesms/ConversationActivity.java | 2 +- .../thoughtcrime/securesms}/geolocation/DcLocation.java | 2 +- .../securesms}/geolocation/DcLocationManager.java | 2 +- .../securesms}/geolocation/LocationBackgroundService.java | 2 +- .../thoughtcrime/securesms}/map/MapActivity.java | 7 +++---- 8 files changed, 11 insertions(+), 12 deletions(-) rename src/{com/b44t/messenger => org/thoughtcrime/securesms}/geolocation/DcLocation.java (94%) rename src/{com/b44t/messenger => org/thoughtcrime/securesms}/geolocation/DcLocationManager.java (98%) rename src/{com/b44t/messenger => org/thoughtcrime/securesms}/geolocation/LocationBackgroundService.java (99%) rename src/{com/b44t/messenger => org/thoughtcrime/securesms}/map/MapActivity.java (96%) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 772a968bd..469780b31 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -262,11 +262,11 @@ android:theme="@style/TextSecure.LightTheme" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/> - + - + diff --git a/res/layout/activity_map.xml b/res/layout/activity_map.xml index 06e6cb116..ca3dc5dcb 100644 --- a/res/layout/activity_map.xml +++ b/res/layout/activity_map.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.b44t.messenger.map.MapActivity"> + tools:context=".map.MapActivity"> Date: Wed, 6 Mar 2019 15:24:32 +0100 Subject: [PATCH 05/13] add location-sending functions --- jni/Android.mk | 1 + jni/dc_wrapper.c | 17 +++++++++++++++++ src/com/b44t/messenger/DcContext.java | 3 +++ 3 files changed, 21 insertions(+) diff --git a/jni/Android.mk b/jni/Android.mk index fd9099d74..ab6df1b1a 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -906,6 +906,7 @@ messenger-backend/src/dc_keyring.c \ messenger-backend/src/dc_loginparam.c \ messenger-backend/src/dc_lot.c \ messenger-backend/src/dc_move.c \ +messenger-backend/src/dc_location.c \ messenger-backend/src/dc_context.c \ messenger-backend/src/dc_configure.c \ messenger-backend/src/dc_e2ee.c \ diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index 85bad523d..4d823997c 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -734,6 +734,23 @@ JNIEXPORT jint Java_com_b44t_messenger_DcContext_addAddressBook(JNIEnv *env, job } +JNIEXPORT void Java_com_b44t_messenger_DcContext_sendLocationsToChat(JNIEnv *env, jobject obj, jint chat_id, jint seconds) +{ + dc_send_locations_to_chat(get_dc_context(env, obj), chat_id, seconds); +} + + +JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_isSendingLocationsToChat(JNIEnv *env, jobject obj, jint chat_id) +{ + return (dc_is_sending_locations_to_chat(get_dc_context(env, obj), chat_id)!=0); +} + + +JNIEXPORT void Java_com_b44t_messenger_DcContext_setLocation(JNIEnv *env, jobject obj, jfloat latitude, jfloat longitude, jfloat accuracy) +{ + dc_set_location(get_dc_context(env, obj), latitude, longitude, accuracy); +} + /******************************************************************************* * DcChatlist diff --git a/src/com/b44t/messenger/DcContext.java b/src/com/b44t/messenger/DcContext.java index 38cb8b581..23646152a 100644 --- a/src/com/b44t/messenger/DcContext.java +++ b/src/com/b44t/messenger/DcContext.java @@ -152,6 +152,9 @@ public class DcContext { public @NonNull DcLot checkQr (String qr) { return new DcLot(checkQrCPtr(qr)); } public native String getSecurejoinQr (int chat_id); public native int joinSecurejoin (String qr); + public native void sendLocationsToChat (int chat_id, int seconds); + public native boolean isSendingLocationsToChat(int chat_id); + public native void setLocation (float latitude, float longitude, float accuracy); // event handling - you should @Override this function in derived classes public long handleEvent(int event, long data1, long data2) { From 3e28cbed05b2a6f596c0bde86cd36fd0ca5559a3 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 6 Mar 2019 15:34:50 +0100 Subject: [PATCH 06/13] DcContext.setLocation() returns the state --- jni/dc_wrapper.c | 4 ++-- src/com/b44t/messenger/DcContext.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index 4d823997c..4dd7bd885 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -746,9 +746,9 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_isSendingLocationsToChat(JN } -JNIEXPORT void Java_com_b44t_messenger_DcContext_setLocation(JNIEnv *env, jobject obj, jfloat latitude, jfloat longitude, jfloat accuracy) +JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_setLocation(JNIEnv *env, jobject obj, jfloat latitude, jfloat longitude, jfloat accuracy) { - dc_set_location(get_dc_context(env, obj), latitude, longitude, accuracy); + return (dc_set_location(get_dc_context(env, obj), latitude, longitude, accuracy)!=0); } diff --git a/src/com/b44t/messenger/DcContext.java b/src/com/b44t/messenger/DcContext.java index 23646152a..b9dab72de 100644 --- a/src/com/b44t/messenger/DcContext.java +++ b/src/com/b44t/messenger/DcContext.java @@ -154,7 +154,7 @@ public class DcContext { public native int joinSecurejoin (String qr); public native void sendLocationsToChat (int chat_id, int seconds); public native boolean isSendingLocationsToChat(int chat_id); - public native void setLocation (float latitude, float longitude, float accuracy); + public native boolean setLocation (float latitude, float longitude, float accuracy); // event handling - you should @Override this function in derived classes public long handleEvent(int event, long data1, long data2) { From be8a718b3fa68f0f53e5879523f1fceb400e4692 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 6 Mar 2019 17:25:01 +0100 Subject: [PATCH 07/13] implement share location button, share location timespan, rename threadId to chatId --- res/layout/attachment_type_selector.xml | 4 +- res/values/arrays.xml | 10 +++ res/values/strings.xml | 7 ++ .../securesms/ConversationActivity.java | 56 ++++++++-------- .../securesms/ConversationFragment.java | 2 +- .../securesms/ShareLocationDialog.java | 55 ++++++++++++++++ .../securesms/geolocation/DcLocation.java | 2 +- .../geolocation/DcLocationManager.java | 15 ++++- .../LocationBackgroundService.java | 64 +++++++++++-------- .../securesms/mms/AttachmentManager.java | 27 +++++--- .../securesms/service/DirectShareService.java | 2 +- 11 files changed, 176 insertions(+), 68 deletions(-) create mode 100644 src/org/thoughtcrime/securesms/ShareLocationDialog.java diff --git a/res/layout/attachment_type_selector.xml b/res/layout/attachment_type_selector.xml index 183fddfd5..ee8743be3 100644 --- a/res/layout/attachment_type_selector.xml +++ b/res/layout/attachment_type_selector.xml @@ -91,14 +91,14 @@ android:layout_height="53dp" android:src="@drawable/ic_location_on_white_24dp" android:scaleType="center" - android:visibility="gone" + android:visibility="visible" android:contentDescription="@string/location" app:circleColor="@color/location_icon"/> diff --git a/res/values/arrays.xml b/res/values/arrays.xml index e27e472cd..826b17568 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -129,6 +129,16 @@ @string/mute_for_one_year + + + @string/share_location_once + @string/share_location_for_5_minutes + @string/share_location_for_30_minutes + @string/share_location_for_one_hour + @string/share_location_for_two_hours + @string/share_location_for_six_hours + + @string/def @string/on diff --git a/res/values/strings.xml b/res/values/strings.xml index 83f27a780..8c2add155 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -144,6 +144,7 @@ Contact requests Press message to start chatting View profile + Share location Mute for 1 hour Mute for 2 hours @@ -151,6 +152,12 @@ Mute for 7 days Mute for 1 year + once + for 5 minutes + for 30 minutes + for 1 hour + for 2 hours + for 6 hours Are you sure you want to leave this group? diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index f546a7cd7..9be82b202 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -177,7 +177,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private Recipient recipient; private ApplicationDcContext dcContext; private DcChat dcChat = new DcChat(0); - private int threadId; + private int chatId; private boolean archived; private final boolean isSecureText = true; private boolean isDefaultSms = true; @@ -284,7 +284,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity titleView.setTitle(glideRequests, dcChat); - MessageNotifier.updateVisibleChat(this, threadId); + MessageNotifier.updateVisibleChat(this, chatId); markThreadAsRead(); } @@ -359,7 +359,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity addAttachmentContactInfo(data); break; case GROUP_EDIT: - dcChat = dcContext.getChat(threadId); + dcChat = dcContext.getChat(chatId); titleView.setTitle(glideRequests, dcChat); supportInvalidateOptionsMenu(); break; @@ -402,11 +402,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity MenuInflater inflater = this.getMenuInflater(); menu.clear(); - if(threadId==DcChat.DC_CHAT_ID_DEADDROP) { + if(chatId ==DcChat.DC_CHAT_ID_DEADDROP) { return true; } - if (recipient != null && Prefs.isChatMuted(this, threadId)) { + if (recipient != null && Prefs.isChatMuted(this, chatId)) { inflater.inflate(R.menu.conversation_muted, menu); } else { @@ -487,13 +487,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private void handleMuteNotifications() { MuteDialog.show(this, until -> { - Prefs.setChatMutedUntil(this, threadId, until); + Prefs.setChatMutedUntil(this, chatId, until); titleView.setTitle(glideRequests, dcChat); // update title-mute-icon }); } private void handleConversationSettings() { - if(threadId!=DcChat.DC_CHAT_ID_DEADDROP) { + if(chatId !=DcChat.DC_CHAT_ID_DEADDROP) { Intent intent = new Intent(ConversationActivity.this, RecipientPreferenceActivity.class); intent.putExtra(RecipientPreferenceActivity.ADDRESS_EXTRA, recipient.getAddress()); startActivitySceneTransition(intent, titleView.findViewById(R.id.contact_photo_image), "avatar"); @@ -501,7 +501,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void handleUnmuteNotifications() { - Prefs.setChatMutedUntil(this, threadId, 0); + Prefs.setChatMutedUntil(this, chatId, 0); titleView.setTitle(glideRequests, dcChat); // update title-mute-icon } @@ -515,7 +515,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity new AlertDialog.Builder(this) .setMessage(getString(R.string.ask_leave_group)) .setPositiveButton(R.string.yes, (dialog, which) -> { - dcContext.removeContactFromChat(threadId, DcContact.DC_CONTACT_ID_SELF); + dcContext.removeContactFromChat(chatId, DcContact.DC_CONTACT_ID_SELF); Toast.makeText(this, getString(R.string.done), Toast.LENGTH_SHORT).show(); }) .setNegativeButton(R.string.no, null) @@ -523,8 +523,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void handleArchiveChat() { - int doArchive = dcContext.getChat(threadId).getArchived()==0? 1: 0; - dcContext.archiveChat(threadId, doArchive); + int doArchive = dcContext.getChat(chatId).getArchived()==0? 1: 0; + dcContext.archiveChat(chatId, doArchive); Toast.makeText(this, getString(R.string.done), Toast.LENGTH_SHORT).show(); if( doArchive == 1 ) { finish(); @@ -535,7 +535,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity new AlertDialog.Builder(this) .setMessage(getResources().getQuantityString(R.plurals.ask_delete_chat, 1, 1)) .setPositiveButton(R.string.delete, (dialog, which) -> { - dcContext.deleteChat(threadId); + dcContext.deleteChat(chatId); Toast.makeText(this, getString(R.string.done), Toast.LENGTH_SHORT).show(); finish(); }) @@ -545,7 +545,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private void handleEditPushGroup() { Intent intent = new Intent(ConversationActivity.this, GroupCreateActivity.class); - intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, threadId); + intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, chatId); if (dcChat.isVerified()) { intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true); } @@ -614,7 +614,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity new AsyncTask() { @Override protected DcMsg doInBackground(Void... params) { - return dcContext.getDraft(threadId); + return dcContext.getDraft(chatId); } @Override @@ -764,10 +764,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void initializeResources() { - threadId = getIntent().getIntExtra(THREAD_ID_EXTRA, -1); - if(threadId == DcChat.DC_CHAT_NO_CHAT) + chatId = getIntent().getIntExtra(THREAD_ID_EXTRA, -1); + if(chatId == DcChat.DC_CHAT_NO_CHAT) throw new IllegalStateException("can't display a conversation for no chat."); - dcChat = dcContext.getChat(threadId); + dcChat = dcContext.getChat(chatId); recipient = dcContext.getRecipient(dcChat); archived = getIntent().getBooleanExtra(IS_ARCHIVED_EXTRA, false); glideRequests = GlideApp.with(this); @@ -779,7 +779,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity conversationContainer.setClipToPadding(true); } - if(threadId==DcChat.DC_CHAT_ID_DEADDROP) { + if(chatId ==DcChat.DC_CHAT_ID_DEADDROP) { composePanel.setVisibility(View.GONE); titleView.hideAvatar(); } @@ -799,7 +799,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity case AttachmentTypeSelector.ADD_CONTACT_INFO: startContactChooserActivity(); break; case AttachmentTypeSelector.ADD_LOCATION: - AttachmentManager.selectLocation(this, PICK_LOCATION); break; + AttachmentManager.selectLocation(this, chatId); break; case AttachmentTypeSelector.TAKE_PHOTO: attachmentManager.capturePhoto(this, TAKE_PHOTO); break; } @@ -840,8 +840,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity return this.recipient; } - protected long getThreadId() { - return this.threadId; + protected long getChatId() { + return this.chatId; } private MediaConstraints getCurrentMediaConstraints() { @@ -852,10 +852,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity new AsyncTask() { @Override protected Void doInBackground(Integer... params) { - MessageNotifier.updateNotification(ConversationActivity.this, threadId, false); + MessageNotifier.updateNotification(ConversationActivity.this, chatId, false); return null; } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId); + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, chatId); } private String getRealPathFromAttachment(Attachment attachment) { @@ -976,7 +976,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override protected void onPostExecute(Void result) { - future.set(threadId); + future.set(chatId); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, msg, recompress); @@ -984,8 +984,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } protected void sendComplete(int threadId) { - boolean refreshFragment = (threadId != this.threadId); - this.threadId = threadId; + boolean refreshFragment = (threadId != this.chatId); + this.chatId = threadId; if (fragment == null || !fragment.isVisible() || isFinishing()) { return; @@ -1279,8 +1279,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } @Override - public void setThreadId(int threadId) { - this.threadId = threadId; + public void setChatId(int chatId) { + this.chatId = chatId; } @Override diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index 4faa08858..0fedd5cf8 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -544,7 +544,7 @@ public class ConversationFragment extends Fragment } public interface ConversationFragmentListener { - void setThreadId(int threadId); + void setChatId(int threadId); void handleReplyMessage(DcMsg messageRecord); } diff --git a/src/org/thoughtcrime/securesms/ShareLocationDialog.java b/src/org/thoughtcrime/securesms/ShareLocationDialog.java new file mode 100644 index 000000000..1acde1306 --- /dev/null +++ b/src/org/thoughtcrime/securesms/ShareLocationDialog.java @@ -0,0 +1,55 @@ +package org.thoughtcrime.securesms; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.app.AlertDialog; + +import java.util.concurrent.TimeUnit; + +/** + * Created by cyberta on 06.03.19. + */ + +public class ShareLocationDialog extends AlertDialog { + + + protected ShareLocationDialog(Context context) { + super(context); + } + + protected ShareLocationDialog(Context context, boolean cancelable, OnCancelListener cancelListener) { + super(context, cancelable, cancelListener); + } + + protected ShareLocationDialog(Context context, int theme) { + super(context, theme); + } + + public static void show(final Context context, final @NonNull ShareLocationDurationSelectionListener listener) { + Builder builder = new Builder(context); + builder.setTitle(R.string.title_share_location); + builder.setItems(R.array.share_location_durations, (dialog, which) -> { + final int shareLocationUnit; + + switch (which) { + default: + case 0: shareLocationUnit = 1; break; + case 1: shareLocationUnit = 5 * 60; break; + case 2: shareLocationUnit = 30 * 60; break; + case 3: shareLocationUnit = 60 * 60; break; + case 4: shareLocationUnit = 60 * 60 * 2; break; + case 5: shareLocationUnit = 60 * 60 * 6; break; + } + + listener.onSelected(shareLocationUnit); + }); + + builder.show(); + + } + + public interface ShareLocationDurationSelectionListener { + void onSelected(int durationInSeconds); + } + +} diff --git a/src/org/thoughtcrime/securesms/geolocation/DcLocation.java b/src/org/thoughtcrime/securesms/geolocation/DcLocation.java index 4fde87000..73cbd044e 100644 --- a/src/org/thoughtcrime/securesms/geolocation/DcLocation.java +++ b/src/org/thoughtcrime/securesms/geolocation/DcLocation.java @@ -25,7 +25,7 @@ public class DcLocation extends Observable { } public Location getLastLocation() { - return instance.lastLocation; + return lastLocation; } void updateLocation(Location location) { diff --git a/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java b/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java index 86786ebbd..b3cba85c6 100644 --- a/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java +++ b/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java @@ -8,6 +8,7 @@ import android.location.Location; import android.os.IBinder; import android.util.Log; +import java.util.LinkedList; import java.util.Observable; import java.util.Observer; @@ -23,11 +24,14 @@ public class DcLocationManager implements Observer { private LocationBackgroundService.LocationBackgroundServiceBinder serviceBinder; private Context context; private DcLocation dcLocation = DcLocation.getInstance(); + private LinkedList pendingShareLastLocation = new LinkedList<>(); private ServiceConnection serviceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { serviceBinder = (LocationBackgroundService.LocationBackgroundServiceBinder) service; - startLocationEngine(); + while (pendingShareLastLocation.size() > 0) { + shareLastLocation(pendingShareLastLocation.pop()); + } } @Override @@ -60,8 +64,14 @@ public class DcLocationManager implements Observer { serviceBinder.stop(); } - public void shareLastLocation() { + public void shareLocation(int duration, int chatId) { + startLocationEngine(); + Log.d(TAG, String.format("Share location in chat %d for %d seconds", chatId, duration)); + } + + public void shareLastLocation(int chatId) { if (serviceBinder == null) { + pendingShareLastLocation.push(chatId); initializeLocationEngine(); return; } @@ -81,5 +91,6 @@ public class DcLocationManager implements Observer { private void writeDcLocationUpdateMessage() { //TODO: implement me! + Log.d(TAG, "Share location: " + dcLocation.getLastLocation().getLatitude() + ", " + dcLocation.getLastLocation().getLongitude()); } } diff --git a/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java b/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java index 56a812ed5..8ff367679 100644 --- a/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java +++ b/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java @@ -11,6 +11,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.util.Log; +import android.widget.Toast; /** * Created by cyberta on 06.03.19. @@ -22,7 +23,7 @@ public class LocationBackgroundService extends Service { private static final String TAG = LocationBackgroundService.class.getSimpleName(); private LocationManager locationManager = null; private static final int LOCATION_INTERVAL = 1000; - private static final float LOCATION_DISTANCE = 20f; + private static final float LOCATION_DISTANCE = 25F; ServiceLocationListener locationListener; private final IBinder mBinder = new LocationBackgroundServiceBinder(); @@ -80,7 +81,7 @@ public class LocationBackgroundService extends Service { locationManager.requestLocationUpdates( provider, LOCATION_INTERVAL, LOCATION_DISTANCE, locationListener); - } catch (SecurityException | IllegalArgumentException ex) { + } catch (SecurityException | IllegalArgumentException ex) { Log.e(TAG, String.format("Unable to request %s provider based location updates.", provider), ex); } } @@ -109,10 +110,11 @@ public class LocationBackgroundService extends Service { } private class ServiceLocationListener implements LocationListener { + private static final int EARTH_RADIUS = 6371; @Override public void onLocationChanged(Location location) { - Log.e(TAG, "onLocationChanged: " + location); + Log.d(TAG, "onLocationChanged: " + location); if (isBetterLocation(location, DcLocation.getInstance().getLastLocation())) { DcLocation.getInstance().updateLocation(location); } @@ -147,38 +149,50 @@ public class LocationBackgroundService extends Service { // Check whether the new location fix is newer or older long timeDelta = location.getTime() - currentBestLocation.getTime(); - boolean isSignificantlyNewer = timeDelta > TIMEOUT; boolean isSignificantlyOlder = timeDelta < -TIMEOUT; - boolean isNewer = timeDelta > 0; - // If it's been more than two minutes since the current location, use the new location - // because the user has likely moved - if (isSignificantlyNewer) { - return true; - // If the new location is more than two minutes older, it must be worse - } else if (isSignificantlyOlder) { + if (isSignificantlyOlder) { return false; } // Check whether the new location fix is more or less accurate int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy()); - boolean isLessAccurate = accuracyDelta > 0; - boolean isMoreAccurate = accuracyDelta < 0; - boolean isSignificantlyLessAccurate = accuracyDelta > 200; + boolean isSignificantlyMoreAccurate = accuracyDelta < -50; + boolean isSameProvider = isSameProvider(location.getProvider(), currentBestLocation.getProvider()); - // Check if the old and new location are from the same provider - boolean isFromSameProvider = isSameProvider(location.getProvider(), - currentBestLocation.getProvider()); - - // Determine location quality using a combination of timeliness and accuracy - if (isMoreAccurate) { - return true; - } else if (isNewer && !isLessAccurate) { - return true; - } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) { + if (isSignificantlyMoreAccurate && isSameProvider) { return true; } - return false; + + boolean isSignificantlyLessAccurate = accuracyDelta > 50; + boolean hasLocationChanged = hasLocationDistanceChanged(location, currentBestLocation); + return hasLocationChanged && !isSignificantlyLessAccurate; + } + + private boolean hasLocationDistanceChanged(Location location, Location currentBestLocation) { + return distance(location.getLatitude(), location.getLongitude(), currentBestLocation.getLatitude(), currentBestLocation.getLongitude()) > LOCATION_DISTANCE; + } + + private double distance(double startLat, double startLong, + double endLat, double endLong) { + + double dLat = Math.toRadians(endLat - startLat); + double dLong = Math.toRadians(endLong - startLong); + + startLat = Math.toRadians(startLat); + endLat = Math.toRadians(endLat); + + double a = haversin(dLat) + Math.cos(startLat) * Math.cos(endLat) * haversin(dLong); + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + double distance = EARTH_RADIUS * c * 1000; + Log.d(TAG, "Distance between location updates: " + distance); + Toast.makeText(LocationBackgroundService.this, "Distance in m between location updates: " + distance , Toast.LENGTH_LONG).show(); + return distance; + } + + private double haversin(double val) { + return Math.pow(Math.sin(val / 2), 2); } /** Checks whether two providers are the same */ diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index f60c21931..9f424a1b2 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -37,18 +37,23 @@ import android.util.Pair; import android.view.View; import android.widget.Toast; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.MediaPreviewActivity; +import org.thoughtcrime.securesms.MuteDialog; import org.thoughtcrime.securesms.R; +import org.thoughtcrime.securesms.ShareLocationDialog; import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.audio.AudioSlidePlayer; import org.thoughtcrime.securesms.components.AudioView; import org.thoughtcrime.securesms.components.DocumentView; import org.thoughtcrime.securesms.components.RemovableEditableMediaView; import org.thoughtcrime.securesms.components.ThumbnailView; +import org.thoughtcrime.securesms.geolocation.DcLocationManager; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.providers.PersistentBlobProvider; import org.thoughtcrime.securesms.scribbles.ScribbleActivity; import org.thoughtcrime.securesms.util.MediaUtil; +import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.ThemeUtil; import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; @@ -385,21 +390,27 @@ public class AttachmentManager { .execute(); } - public static void selectLocation(Activity activity, int requestCode) { - /* + public static void selectLocation(Activity activity, int chatId) { + Permissions.with(activity) .request(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION) .ifNecessary() .withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_location_denied)) .onAllGranted(() -> { - try { - activity.startActivityForResult(new PlacePicker.IntentBuilder().build(activity), requestCode); - } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { - Log.w(TAG, e); - } + + + ShareLocationDialog.show(activity, durationInSeconds -> { + DcLocationManager dcLocationManager = ApplicationContext.getInstance(activity).dcLocationManager; + switch (durationInSeconds) { + case 1: dcLocationManager.shareLastLocation(chatId); break; + default: + dcLocationManager.shareLocation(durationInSeconds, chatId); + break; + } + }); }) .execute(); - */ + } private @Nullable Uri getSlideUri() { diff --git a/src/org/thoughtcrime/securesms/service/DirectShareService.java b/src/org/thoughtcrime/securesms/service/DirectShareService.java index 11ac6b217..46bbe0f94 100644 --- a/src/org/thoughtcrime/securesms/service/DirectShareService.java +++ b/src/org/thoughtcrime/securesms/service/DirectShareService.java @@ -71,7 +71,7 @@ public class DirectShareService extends ChooserTargetService { // parcel.writeParcelable(recipient.getAddress(), 0); // // Bundle bundle = new Bundle(); -// bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId()); +// bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getChatId()); // bundle.putByteArray(ShareActivity.EXTRA_ADDRESS_MARSHALLED, parcel.marshall()); // bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType()); // bundle.setClassLoader(getClassLoader()); From 5f9646a0286bebc78df9f2367b6f6d6b0cc2bab1 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 6 Mar 2019 20:20:22 +0100 Subject: [PATCH 08/13] improve location sharing alert title --- res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 8c2add155..7727caa49 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -144,7 +144,7 @@ Contact requests Press message to start chatting View profile - Share location + Share location with all group members Mute for 1 hour Mute for 2 hours From 8fede3312aca95925c412276befe3807149a115d Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 6 Mar 2019 20:21:05 +0100 Subject: [PATCH 09/13] add location off icon --- res/drawable-hdpi/ic_location_off_white_24.png | Bin 0 -> 427 bytes res/drawable-xhdpi/ic_location_off_white_24.png | Bin 0 -> 490 bytes res/drawable-xxhdpi/ic_location_off_white_24.png | Bin 0 -> 739 bytes res/drawable-xxxhdpi/ic_location_off_white_24.png | Bin 0 -> 848 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100755 res/drawable-hdpi/ic_location_off_white_24.png create mode 100755 res/drawable-xhdpi/ic_location_off_white_24.png create mode 100755 res/drawable-xxhdpi/ic_location_off_white_24.png create mode 100755 res/drawable-xxxhdpi/ic_location_off_white_24.png diff --git a/res/drawable-hdpi/ic_location_off_white_24.png b/res/drawable-hdpi/ic_location_off_white_24.png new file mode 100755 index 0000000000000000000000000000000000000000..86b7b3108f938884611c48e701b21ecdb5976348 GIT binary patch literal 427 zcmV;c0aX5pP)}_r^5klQZo+ajr0;%9bf+yShoCJ>b&cly1H%?y!o* zLoM8nrTQhN=7vxV1|xA(fqmUY1pAgktuqkuSAdF~`)-6Kdu<002ovPDHLkV1hFj$Fl$c literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_location_off_white_24.png b/res/drawable-xhdpi/ic_location_off_white_24.png new file mode 100755 index 0000000000000000000000000000000000000000..b2b4d6e0ed853a45f6baab214658f3c429a0a932 GIT binary patch literal 490 zcmVx*7=Ym~+qPYsY}>YL8MfK2!a8iyGTYWB+qUiAthv*jZ!UhnyTj-BjKr6cqBPSv z$YtL0ip%U}HqA&ak%^}4!PXsmh))z?FC~q6McGNP){{rS`)k0RzX@vd7*`Kyt^;-f z{7bM0O`mD00g7_RB*@5NG(Dk!hA3$vvTz(tyG3-w{Qx4nlIWr%%JSGkoWb2C(M2T- zk&6q!4ti5igeEM~`z$S?{w(_eRzX&tdVYW>V+y)mxL(IflM#7r!{>MVt`d=m{P~4}Tyzm(|2tl8b+I1Sb(* zY>6^KX+A}pn2W2cVG(5EAw=~o=myay7V^KAaD(s((sLGDr$|lF$PkryhuJ&I$k!r8 z499GwF>DT-SjOM2whx=x5jv2Ti~Q;mS*#=TOW{3DRe1xzGs;>=<_E|l;YB+>@}7ng gy%@?sNh+T81r5xyFl&SF!Te;q!+qTU(DaE!*v2EM7ZQHiBI5E3sF+H;t>{s>~G?kQ;bp9fp*C|3z zwsF!Xx{`+%NKvBkG_}}{lQmT20VN9e(~2y;c4auLR&A1cfIe(HKcbzmqI^U9BPef9H;nbiG!`V(W%_Q%V{xFl+OL4B( zDg40(BH7L5-X(>NqzOE1F1;)vk`HBr%3vf#!F_DNSw-2PJGe;t4`;n(g9Q+O5-IG! z$zs`H6Szw1ij%FfK^WX5Q5`2C*{%GDbG& z2oaP1lSvf7Sr^%$FvOe0-E6^G3EAKyh&PE5*6Y19uHj(3N!-I~oa`Y*cIZuXVLsLw zc)&5KyKIq#SRCMkn3DdHEp8&_G-Uf?}qbtp>GTk;0; zERr^H(oA`UzaWmJuXP5VIGMz6@(QV}Aa(&W30Op`yh9eSO4>#id5JU@5Hs`2i>FAJ zxA=kh1o=_^V$6A##H$c@(jW2@Er?gx*CcLbuZyJr35>Zsbh?!FXRsz5J_L1U?d&% zDTxfG<772ANM|Jl6Or@~`!T@*UeP)DF)>NGFopS91|zAv{6QNdsI&}5(jYSA57HUR znTC@hMM>&IhWx{|Eas%;+@y&3k)EW>Up&QL0Jia{&JX+mg!n|~4+@b_Nl8f;gu{SX VcFEC#YS91y002ovPDHLkV1mQ_St|el literal 0 HcmV?d00001 diff --git a/res/drawable-xxxhdpi/ic_location_off_white_24.png b/res/drawable-xxxhdpi/ic_location_off_white_24.png new file mode 100755 index 0000000000000000000000000000000000000000..0ee2e63676df9db1c2dcd5d5d90d54ebcf179f3d GIT binary patch literal 848 zcmV-W1F!svP)CE|Z+N{-Q+1YiI$WkhmN~Kb)!YMq< zC;UYNx-o&VbfYeR@)3`56a^(0D|0zjnar|`CoWkTpI8lY~u~fZHdsMm;b}_y)IH zvPNgHN#G*fy2~1az$St1aT_XYOaq$)R>f_qtT7I35?BqlNwP*Sut{Ji+=j^-&A=vs z^Kt7XYg7W81pdRVrmXQUSR}ALQ*rx9*0=&J68M8CZj&{3hO#Gc1<~v)Yh)Q$)&w?W z5>ZShFMIq4WllJgDY#XV4_rgBUMw-;Hu=EXOruy&l$5ZQ{Gb}(KcTUF;Re8e!tL^f zm6_l@VG`@fA3g`q3BSrG4g${!C(AE78YfI>x== zN_d@OJg7MmlR$wcL{*!tBR!UcjTu4|Ls(yPB`o0xrs6V zS*nwDZ>fqmVN-^&Gy_<>$X#KNsQhspQ(2NJ94ZIiOU9?g9W2Ssih$3U>lVd_PfOie zPi9WSwTcrt>a(CG6r{)rpKz_>#(E57uHkH~@URz?0GPrt3KQ1?aD~Ff3p^=rQmIrb am6{Gnz{Cma>-sGK0000 Date: Wed, 6 Mar 2019 20:33:19 +0100 Subject: [PATCH 10/13] start/stop location streaming from attachment window, use location related core bindings --- jni/messenger-backend | 2 +- src/com/b44t/messenger/DcContext.java | 4 ++ .../securesms/ConversationActivity.java | 2 +- .../components/AttachmentTypeSelector.java | 23 +++++++++- .../components/CircleColorImageView.java | 5 +-- .../geolocation/DcLocationManager.java | 17 +++++++- .../securesms/map/MapActivity.java | 13 +----- .../securesms/mms/AttachmentManager.java | 43 ++++++++++--------- 8 files changed, 68 insertions(+), 41 deletions(-) diff --git a/jni/messenger-backend b/jni/messenger-backend index afee0f717..f49cd879b 160000 --- a/jni/messenger-backend +++ b/jni/messenger-backend @@ -1 +1 @@ -Subproject commit afee0f717f1b91a99e649a9d69d975eed811eee3 +Subproject commit f49cd879bd41f8c74e4f65835b0aa742b6e2745c diff --git a/src/com/b44t/messenger/DcContext.java b/src/com/b44t/messenger/DcContext.java index b9dab72de..a8c4dcfec 100644 --- a/src/com/b44t/messenger/DcContext.java +++ b/src/com/b44t/messenger/DcContext.java @@ -154,6 +154,10 @@ public class DcContext { public native int joinSecurejoin (String qr); public native void sendLocationsToChat (int chat_id, int seconds); public native boolean isSendingLocationsToChat(int chat_id); + + /** + * @return true if at least one chat has location streaming enabled + */ public native boolean setLocation (float latitude, float longitude, float accuracy); // event handling - you should @Override this function in derived classes diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 9be82b202..c59791b55 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -554,7 +554,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private void handleAddAttachment() { if (attachmentTypeSelector == null) { - attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener()); + attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener(), chatId); } attachmentTypeSelector.show(this, attachButton); } diff --git a/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java b/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java index 096ebc050..1b8691647 100644 --- a/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java +++ b/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java @@ -26,6 +26,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.util.ViewUtil; @@ -56,8 +57,9 @@ public class AttachmentTypeSelector extends PopupWindow { private @Nullable View currentAnchor; private @Nullable AttachmentClickedListener listener; + private int chatId; - public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener) { + public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener, int chatId) { super(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); @@ -65,6 +67,7 @@ public class AttachmentTypeSelector extends PopupWindow { this.listener = listener; this.loaderManager = loaderManager; + this.chatId = chatId; this.recentRail = ViewUtil.findById(layout, R.id.recent_photos); this.imageButton = ViewUtil.findById(layout, R.id.gallery_button); this.audioButton = ViewUtil.findById(layout, R.id.audio_button); @@ -83,6 +86,8 @@ public class AttachmentTypeSelector extends PopupWindow { this.closeButton.setOnClickListener(new CloseClickListener()); this.recentRail.setListener(new RecentPhotoSelectedListener()); + setLocationButtonImage(context); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { ViewUtil.findById(layout, R.id.location_linear_layout).setVisibility(View.INVISIBLE); } @@ -108,6 +113,7 @@ public class AttachmentTypeSelector extends PopupWindow { } this.currentAnchor = anchor; + setLocationButtonImage(activity); showAtLocation(anchor, Gravity.BOTTOM, 0, 0); @@ -149,6 +155,21 @@ public class AttachmentTypeSelector extends PopupWindow { this.listener = listener; } + private void setLocationButtonImage(Context context) { + int resId; + if (ApplicationContext.getInstance(context).dcContext.isSendingLocationsToChat(chatId)) { + resId = R.drawable.ic_location_off_white_24; + } else { + resId = R.drawable.ic_location_on_white_24dp; + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + this.locationButton.setImageDrawable(context.getDrawable(resId)); + } else { + this.locationButton.setImageDrawable(context.getResources().getDrawable(resId)); + } + } + private void animateButtonIn(View button, int delay) { AnimationSet animation = new AnimationSet(true); Animation scale = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, diff --git a/src/org/thoughtcrime/securesms/components/CircleColorImageView.java b/src/org/thoughtcrime/securesms/components/CircleColorImageView.java index 179c80aec..1bb04a48b 100644 --- a/src/org/thoughtcrime/securesms/components/CircleColorImageView.java +++ b/src/org/thoughtcrime/securesms/components/CircleColorImageView.java @@ -3,15 +3,14 @@ package org.thoughtcrime.securesms.components; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; -import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; +import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; -import android.widget.ImageView; import org.thoughtcrime.securesms.R; -public class CircleColorImageView extends ImageView { +public class CircleColorImageView extends AppCompatImageView { public CircleColorImageView(Context context) { this(context, null); diff --git a/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java b/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java index b3cba85c6..4b3054af7 100644 --- a/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java +++ b/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java @@ -8,6 +8,8 @@ import android.location.Location; import android.os.IBinder; import android.util.Log; +import org.thoughtcrime.securesms.ApplicationContext; + import java.util.LinkedList; import java.util.Observable; import java.util.Observer; @@ -64,9 +66,14 @@ public class DcLocationManager implements Observer { serviceBinder.stop(); } + public void stopSharingLocation(int chatId) { + ApplicationContext.getInstance(context).dcContext.sendLocationsToChat(chatId, 0); + } + public void shareLocation(int duration, int chatId) { startLocationEngine(); Log.d(TAG, String.format("Share location in chat %d for %d seconds", chatId, duration)); + ApplicationContext.getInstance(context).dcContext.sendLocationsToChat(chatId, duration); } public void shareLastLocation(int chatId) { @@ -78,7 +85,8 @@ public class DcLocationManager implements Observer { Location location = dcLocation.getLastLocation(); Log.d(TAG, "share lastLocation: " + location.getLatitude() + ", " + location.getLongitude()); - //TODO: implement me! write share location message + ApplicationContext.getInstance(context).dcContext.sendLocationsToChat(chatId, 1); + ApplicationContext.getInstance(context).dcContext.setLocation((float) location.getLatitude(), (float) location.getLongitude(), location.getAccuracy()); } @Override @@ -90,7 +98,12 @@ public class DcLocationManager implements Observer { } private void writeDcLocationUpdateMessage() { - //TODO: implement me! Log.d(TAG, "Share location: " + dcLocation.getLastLocation().getLatitude() + ", " + dcLocation.getLastLocation().getLongitude()); + Location lastLocation = dcLocation.getLastLocation(); + + boolean continueLocationStreaming = ApplicationContext.getInstance(context).dcContext.setLocation((float) lastLocation.getLatitude(), (float) lastLocation.getLongitude(), lastLocation.getAccuracy()); + if (!continueLocationStreaming) { + stopLocationEngine(); + } } } diff --git a/src/org/thoughtcrime/securesms/map/MapActivity.java b/src/org/thoughtcrime/securesms/map/MapActivity.java index a02678ce2..e38487a01 100644 --- a/src/org/thoughtcrime/securesms/map/MapActivity.java +++ b/src/org/thoughtcrime/securesms/map/MapActivity.java @@ -100,16 +100,6 @@ public class MapActivity extends BaseActivity implements PermissionsListener, Ob mapView.onSaveInstanceState(outState); } - @Override - public void onBackPressed() { - super.onBackPressed(); - - //FIXME: only for testing --v - DcLocationManager locationManager = ApplicationContext.getInstance(this).dcLocationManager; - locationManager.stopLocationEngine(); - - } - //Android SDK callback for the result from requesting permissions @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { @@ -132,8 +122,7 @@ public class MapActivity extends BaseActivity implements PermissionsListener, Ob } private void showDeviceLocation() { - DcLocationManager locationManager = ApplicationContext.getInstance(this).dcLocationManager; - locationManager.startLocationEngine(); + // TODO: draw own position on map } diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index 9f424a1b2..7b24e4928 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -39,7 +39,6 @@ import android.widget.Toast; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.MediaPreviewActivity; -import org.thoughtcrime.securesms.MuteDialog; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.ShareLocationDialog; import org.thoughtcrime.securesms.attachments.Attachment; @@ -53,14 +52,13 @@ import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.providers.PersistentBlobProvider; import org.thoughtcrime.securesms.scribbles.ScribbleActivity; import org.thoughtcrime.securesms.util.MediaUtil; -import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.ThemeUtil; import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener; import org.thoughtcrime.securesms.util.concurrent.SettableFuture; -import org.thoughtcrime.securesms.util.views.Stub; import org.thoughtcrime.securesms.util.guava.Optional; +import org.thoughtcrime.securesms.util.views.Stub; import java.io.IOException; import java.util.Iterator; @@ -391,26 +389,29 @@ public class AttachmentManager { } public static void selectLocation(Activity activity, int chatId) { + ApplicationContext applicationContext = ApplicationContext.getInstance(activity); + DcLocationManager dcLocationManager = applicationContext.dcLocationManager; + + if (applicationContext.dcContext.isSendingLocationsToChat(chatId)) { + dcLocationManager.stopSharingLocation(chatId); + return; + } Permissions.with(activity) - .request(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION) - .ifNecessary() - .withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_location_denied)) - .onAllGranted(() -> { - - - ShareLocationDialog.show(activity, durationInSeconds -> { - DcLocationManager dcLocationManager = ApplicationContext.getInstance(activity).dcLocationManager; - switch (durationInSeconds) { - case 1: dcLocationManager.shareLastLocation(chatId); break; - default: - dcLocationManager.shareLocation(durationInSeconds, chatId); - break; - } - }); - }) - .execute(); - + .request(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION) + .ifNecessary() + .withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_location_denied)) + .onAllGranted(() -> { + ShareLocationDialog.show(activity, durationInSeconds -> { + switch (durationInSeconds) { + case 1: dcLocationManager.shareLastLocation(chatId); break; + default: + dcLocationManager.shareLocation(durationInSeconds, chatId); + break; + } + }); + }) + .execute(); } private @Nullable Uri getSlideUri() { From 998e903e0d1da7f27194aee367fbde55ea41a8f5 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 6 Mar 2019 21:48:07 +0100 Subject: [PATCH 11/13] adapt to location-rendering-api --- jni/dc_wrapper.c | 67 +++++++++++++++++++++++++++ src/com/b44t/messenger/DcArray.java | 25 ++++++++++ src/com/b44t/messenger/DcContext.java | 3 ++ 3 files changed, 95 insertions(+) create mode 100644 src/com/b44t/messenger/DcArray.java diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index 4dd7bd885..fb44226c3 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -752,6 +752,73 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_setLocation(JNIEnv *env, jo } +JNIEXPORT jlong Java_com_b44t_messenger_DcContext_getLocationsCPtr(JNIEnv *env, jobject obj, jint chat_id, jint contact_id) +{ + return (jlong)dc_get_locations(get_dc_context(env, obj), chat_id, contact_id); +} + + +/******************************************************************************* + * DcArray + ******************************************************************************/ + + +static dc_array_t* get_dc_array(JNIEnv *env, jobject obj) +{ + static jfieldID fid = 0; + if (fid==0) { + jclass cls = (*env)->GetObjectClass(env, obj); + fid = (*env)->GetFieldID(env, cls, "arrayCPtr", "J" /*Signature, J=long*/); + } + if (fid) { + return (dc_array_t*)(*env)->GetLongField(env, obj, fid); + } + return NULL; +} + + +JNIEXPORT void Java_com_b44t_messenger_DcArray_unrefArrayCPtr(JNIEnv *env, jobject obj) +{ + dc_array_unref(get_dc_array(env, obj)); +} + + +JNIEXPORT jint Java_com_b44t_messenger_DcArray_getCnt(JNIEnv *env, jobject obj) +{ + return dc_array_get_cnt(get_dc_array(env, obj)); +} + + +JNIEXPORT jfloat Java_com_b44t_messenger_DcArray_getLatitude(JNIEnv *env, jobject obj, jint index) +{ + return (jfloat)dc_array_get_latitude(get_dc_array(env, obj), index); +} + + +JNIEXPORT jfloat Java_com_b44t_messenger_DcArray_getLongitude(JNIEnv *env, jobject obj, jint index) +{ + return (jfloat)dc_array_get_longitude(get_dc_array(env, obj), index); +} + + +JNIEXPORT jfloat Java_com_b44t_messenger_DcArray_getAccuracy(JNIEnv *env, jobject obj, jint index) +{ + return (jfloat)dc_array_get_accuracy(get_dc_array(env, obj), index); +} + + +JNIEXPORT jlong Java_com_b44t_messenger_DcArray_getTimestamp(JNIEnv *env, jobject obj, jint index) +{ + return JTIMESTAMP(dc_array_get_timestamp(get_dc_array(env, obj), index)); +} + + +JNIEXPORT jint Java_com_b44t_messenger_DcArray_getMsgId(JNIEnv *env, jobject obj, jint index) +{ + return dc_array_get_msg_id(get_dc_array(env, obj), index); +} + + /******************************************************************************* * DcChatlist ******************************************************************************/ diff --git a/src/com/b44t/messenger/DcArray.java b/src/com/b44t/messenger/DcArray.java new file mode 100644 index 000000000..fd69459da --- /dev/null +++ b/src/com/b44t/messenger/DcArray.java @@ -0,0 +1,25 @@ +package com.b44t.messenger; + +public class DcArray { + + public DcArray(long arrayCPtr) { + this.arrayCPtr = arrayCPtr; + } + + @Override protected void finalize() throws Throwable { + super.finalize(); + unrefArrayCPtr(); + arrayCPtr = 0; + } + + public native int getCnt (); + public native float getLatitude (int index); + public native float getLongitude(int index); + public native float getAccuracy (int index); + public native long getTimestamp(int index); + public native int getMsgId (int index); + + // working with raw c-data + private long arrayCPtr; // CAVE: the name is referenced in the JNI + private native void unrefArrayCPtr(); +} diff --git a/src/com/b44t/messenger/DcContext.java b/src/com/b44t/messenger/DcContext.java index a8c4dcfec..f148109fe 100644 --- a/src/com/b44t/messenger/DcContext.java +++ b/src/com/b44t/messenger/DcContext.java @@ -21,6 +21,7 @@ public class DcContext { public final static int DC_EVENT_MSG_READ = 2015; public final static int DC_EVENT_CHAT_MODIFIED = 2020; public final static int DC_EVENT_CONTACTS_CHANGED = 2030; + public final static int DC_EVENT_LOCATION_CHANGED = 2035; public final static int DC_EVENT_CONFIGURE_PROGRESS = 2041; public final static int DC_EVENT_IMEX_PROGRESS = 2051; public final static int DC_EVENT_IMEX_FILE_WRITTEN = 2052; @@ -154,6 +155,7 @@ public class DcContext { public native int joinSecurejoin (String qr); public native void sendLocationsToChat (int chat_id, int seconds); public native boolean isSendingLocationsToChat(int chat_id); + public @NonNull DcArray getLocations (int chat_id, int contact_id) { return new DcArray(getLocationsCPtr(chat_id, contact_id)); } /** * @return true if at least one chat has location streaming enabled @@ -180,4 +182,5 @@ public class DcContext { private native long getMsgCPtr (int id); private native long getDraftCPtr (int id); private native long getContactCPtr (int id); + private native long getLocationsCPtr (int chat_id, int contact_id); } From 0cb23b3dc5b1288b22f2c9d5836ff7337787f0cd Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 7 Mar 2019 00:48:44 +0100 Subject: [PATCH 12/13] show own location icon on a map, tweak location update filtering --- .../LocationBackgroundService.java | 36 +++--- .../securesms/map/MapActivity.java | 117 +++++++++++++----- 2 files changed, 109 insertions(+), 44 deletions(-) diff --git a/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java b/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java index 8ff367679..ac1668205 100644 --- a/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java +++ b/src/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java @@ -11,7 +11,6 @@ import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.util.Log; -import android.widget.Toast; /** * Created by cyberta on 06.03.19. @@ -19,7 +18,7 @@ import android.widget.Toast; public class LocationBackgroundService extends Service { - private static final int TIMEOUT = 1000 * 30; + private static final int TIMEOUT = 1000 * 15; private static final String TAG = LocationBackgroundService.class.getSimpleName(); private LocationManager locationManager = null; private static final int LOCATION_INTERVAL = 1000; @@ -71,11 +70,8 @@ public class LocationBackgroundService extends Service { } catch (Exception ex) { Log.i(TAG, "fail to remove location listners, ignore", ex); } - - } - private void requestLocationUpdate(String provider) { try { locationManager.requestLocationUpdates( @@ -132,7 +128,7 @@ public class LocationBackgroundService extends Service { @Override public void onStatusChanged(String provider, int status, Bundle extras) { - Log.e(TAG, "onStatusChanged: " + provider); + Log.e(TAG, "onStatusChanged: " + provider + " status: " + status); } @@ -157,24 +153,35 @@ public class LocationBackgroundService extends Service { // Check whether the new location fix is more or less accurate int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy()); - boolean isSignificantlyMoreAccurate = accuracyDelta < -50; + Log.d(TAG, "accuracyDelta: " + accuracyDelta); + boolean isSignificantlyMoreAccurate = accuracyDelta > 50; boolean isSameProvider = isSameProvider(location.getProvider(), currentBestLocation.getProvider()); if (isSignificantlyMoreAccurate && isSameProvider) { return true; } - boolean isSignificantlyLessAccurate = accuracyDelta > 50; - boolean hasLocationChanged = hasLocationDistanceChanged(location, currentBestLocation); - return hasLocationChanged && !isSignificantlyLessAccurate; + boolean isMoreAccurate = accuracyDelta > 0; + double distance = distance(location, currentBestLocation); + return hasLocationChanged(distance) && isMoreAccurate || + hasLocationSignificantlyChanged(distance); + } - private boolean hasLocationDistanceChanged(Location location, Location currentBestLocation) { - return distance(location.getLatitude(), location.getLongitude(), currentBestLocation.getLatitude(), currentBestLocation.getLongitude()) > LOCATION_DISTANCE; + private boolean hasLocationSignificantlyChanged(double distance) { + return distance > 30D; } - private double distance(double startLat, double startLong, - double endLat, double endLong) { + private boolean hasLocationChanged(double distance) { + return distance > 10D; + } + + private double distance(Location location, Location currentBestLocation) { + + double startLat = location.getLatitude(); + double startLong = location.getLongitude(); + double endLat = currentBestLocation.getLatitude(); + double endLong = currentBestLocation.getLongitude(); double dLat = Math.toRadians(endLat - startLat); double dLong = Math.toRadians(endLong - startLong); @@ -187,7 +194,6 @@ public class LocationBackgroundService extends Service { double distance = EARTH_RADIUS * c * 1000; Log.d(TAG, "Distance between location updates: " + distance); - Toast.makeText(LocationBackgroundService.this, "Distance in m between location updates: " + distance , Toast.LENGTH_LONG).show(); return distance; } diff --git a/src/org/thoughtcrime/securesms/map/MapActivity.java b/src/org/thoughtcrime/securesms/map/MapActivity.java index e38487a01..907f58db1 100644 --- a/src/org/thoughtcrime/securesms/map/MapActivity.java +++ b/src/org/thoughtcrime/securesms/map/MapActivity.java @@ -1,31 +1,45 @@ package org.thoughtcrime.securesms.map; +import android.graphics.BitmapFactory; +import android.graphics.Color; import android.os.Bundle; import android.support.annotation.NonNull; import android.util.Log; -import android.widget.Toast; import org.thoughtcrime.securesms.geolocation.DcLocation; -import org.thoughtcrime.securesms.geolocation.DcLocationManager; -import com.mapbox.android.core.permissions.PermissionsListener; + import com.mapbox.android.core.permissions.PermissionsManager; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.layers.LineLayer; +import com.mapbox.mapboxsdk.style.layers.Property; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; -import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.BaseActivity; import org.thoughtcrime.securesms.R; -import java.util.List; import java.util.Observable; import java.util.Observer; -public class MapActivity extends BaseActivity implements PermissionsListener, Observer { +public class MapActivity extends BaseActivity implements Observer { + + public static final String LINE_LAYER = "line_layer"; + public static final String LINE_SOURCE = "line_source"; + public static final String MARKER_LAYER = "symbol_layer"; + public static final String MARKER_ICON = "marker_icon_id"; + public static final String MARKER_POSITION_SOURCE = "marker_position"; private static final String TAG = MapActivity.class.getSimpleName(); private MapView mapView; + private MapboxMap mapboxMap; private PermissionsManager permissionsManager; private DcLocation dcLocation; @@ -38,27 +52,20 @@ public class MapActivity extends BaseActivity implements PermissionsListener, Ob mapView = findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> { + this.mapboxMap = mapboxMap; mapboxMap.setCameraPosition(new CameraPosition.Builder() - .target(new LatLng(53.5505D, 10.001D)) + .target(new LatLng(dcLocation.getLastLocation().getLatitude(), dcLocation.getLastLocation().getLongitude())) .zoom(12) .build()); mapboxMap.getUiSettings().setLogoEnabled(false); mapboxMap.getUiSettings().setAttributionEnabled(false); - permissionsManager = new PermissionsManager(this); - - if (PermissionsManager.areLocationPermissionsGranted(this)) { - showDeviceLocation(); - } else { - permissionsManager = new PermissionsManager(this); - permissionsManager.requestLocationPermissions(this); - } - + initMapDrawings(); + showDeviceLocation(); })); dcLocation = DcLocation.getInstance(); - } @@ -106,24 +113,73 @@ public class MapActivity extends BaseActivity implements PermissionsListener, Ob permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults); } - //map sdk callbacks for the result from requesting permissions - @Override - public void onPermissionResult(boolean granted) { - if (granted) { - showDeviceLocation(); - } else { - Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show(); + private void initMapDrawings() { + if (mapboxMap == null || mapboxMap.getStyle() == null) { + return; } + Style style = mapboxMap.getStyle(); + initGeoJsonSources(style); + initLayers(style); } - @Override - public void onExplanationNeeded(List permissionsToExplain) { - // no explanation text before the permission pop up is shown + private void initGeoJsonSources(Style style) { + GeoJsonSource markerPositionSource = new GeoJsonSource(MARKER_POSITION_SOURCE); + GeoJsonSource linePositionSource = new GeoJsonSource(LINE_SOURCE); + style.addSource(markerPositionSource); + style.addSource(linePositionSource); + } + + private void initLayers(Style style) { + style.addImage(MARKER_ICON, + BitmapFactory.decodeResource( + MapActivity.this.getResources(), R.drawable.mapbox_marker_icon_default)); + style.addLayer(new SymbolLayer(MARKER_LAYER, MARKER_POSITION_SOURCE) + .withProperties(PropertyFactory.iconImage(MARKER_ICON))); + + style.addLayer(new LineLayer(LINE_LAYER, LINE_SOURCE) + .withProperties(PropertyFactory.lineCap(Property.LINE_CAP_ROUND), + PropertyFactory.lineJoin(Property.LINE_JOIN_MITER), + PropertyFactory.lineOpacity(.7f), + PropertyFactory.lineWidth(7f), + PropertyFactory.lineColor(Color.parseColor("#3bb2d0")))); } private void showDeviceLocation() { - // TODO: draw own position on map + if (this.dcLocation.getLastLocation().getProvider().equals("?")) { + return; + } + FeatureCollection featureCollection = FeatureCollection.fromFeature(Feature.fromGeometry( + Point.fromLngLat(dcLocation.getLastLocation().getLongitude(), + dcLocation.getLastLocation().getLatitude()))); + + drawPoints(featureCollection); + } + + private void drawPoints(@NonNull FeatureCollection featureCollection) { + if (mapboxMap == null || + mapboxMap.getStyle() == null || + featureCollection.features() == null || + featureCollection.features().size() == 0) { + return; + } + + Style style = mapboxMap.getStyle(); + GeoJsonSource source = (GeoJsonSource) style.getSource(MARKER_POSITION_SOURCE); + source.setGeoJson(featureCollection); + } + + private void drawLines(@NonNull FeatureCollection featureCollection) { + if (mapboxMap == null || + mapboxMap.getStyle() == null || + featureCollection.features() == null || + featureCollection.features().size() == 0) { + return; + } + + Style style = mapboxMap.getStyle(); + GeoJsonSource source = (GeoJsonSource) style.getSource(LINE_SOURCE); + source.setGeoJson(featureCollection); } @@ -131,7 +187,10 @@ public class MapActivity extends BaseActivity implements PermissionsListener, Ob public void update(Observable o, Object arg) { if (o instanceof DcLocation) { this.dcLocation = (DcLocation) o; - Log.d(TAG, "show marker on map: " + dcLocation.getLastLocation().getLatitude() + ", " + dcLocation.getLastLocation().getLongitude()); + Log.d(TAG, "show marker on map: " + + dcLocation.getLastLocation().getLatitude() + ", " + + dcLocation.getLastLocation().getLongitude()); + showDeviceLocation(); } } From 9268b38d47c8fd914aa21df45f37cd5bb22994d4 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 7 Mar 2019 00:53:16 +0100 Subject: [PATCH 13/13] update submodule --- jni/messenger-backend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jni/messenger-backend b/jni/messenger-backend index f49cd879b..0631ef8e5 160000 --- a/jni/messenger-backend +++ b/jni/messenger-backend @@ -1 +1 @@ -Subproject commit f49cd879bd41f8c74e4f65835b0aa742b6e2745c +Subproject commit 0631ef8e5a05377e8865cd60c9da7d231e84ce5f