Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21fbca36fe | ||
|
|
cb507e9a8c | ||
|
|
e32460116f | ||
|
|
cfb2fcbe2f | ||
|
|
4ea3d60932 | ||
|
|
6c4ca9d622 | ||
|
|
62d0331a32 | ||
|
|
5553dd4757 | ||
|
|
3f89f50492 | ||
|
|
b96615419e | ||
|
|
e1b5c70fb7 | ||
|
|
11f5d372b6 | ||
|
|
bbe51ebbf4 | ||
|
|
8319f56304 | ||
|
|
e9704b46f6 | ||
|
|
34a98136be | ||
|
|
f8d1a96d0b | ||
|
|
c5b69a12e7 | ||
|
|
08db82b1f7 | ||
|
|
fcd899f25f | ||
|
|
85c026fa8f | ||
|
|
8f7aeec0ab | ||
|
|
d3ba3f570a | ||
|
|
3c63e9530f | ||
|
|
cc66a682f0 | ||
|
|
f5691ef3a3 | ||
|
|
8e3dc80fb8 | ||
|
|
20108b282d | ||
|
|
aac6c5f5f3 | ||
|
|
3b644cece3 | ||
|
|
6b5f01a573 | ||
|
|
98212476f4 | ||
|
|
eac84438f1 | ||
|
|
dfacfd4ff4 | ||
|
|
301578f241 | ||
|
|
41dc0030c3 | ||
|
|
73ea8185a4 | ||
|
|
ff89c9a7cc | ||
|
|
7451e492c6 | ||
|
|
cf1cdb653b | ||
|
|
850f8add53 | ||
|
|
0d577ee938 | ||
|
|
fc7f9f0ed4 | ||
|
|
6d140284fa | ||
|
|
4e31cdcad7 | ||
|
|
2d1bf8a3bc | ||
|
|
c49fe8fcb4 | ||
|
|
cf74b4fdc8 | ||
|
|
bf90db3620 | ||
|
|
6bd1076e75 | ||
|
|
0772ea42d8 | ||
|
|
751f3f17e6 | ||
|
|
7885c7bb3c | ||
|
|
899b651ab1 | ||
|
|
4d40e47492 | ||
|
|
281831dbc9 | ||
|
|
2e9107dbc0 | ||
|
|
fa4714169a | ||
|
|
3ff2bf8d21 | ||
|
|
b728be2f86 | ||
|
|
d10ceef29b | ||
|
|
92f7027ca4 | ||
|
|
afe4776f59 | ||
|
|
06fb703f31 | ||
|
|
a1fc342862 | ||
|
|
ac06575858 | ||
|
|
58485d2db2 | ||
|
|
0abb3e2663 | ||
|
|
9c2934926f | ||
|
|
9a9bc07051 | ||
|
|
bf635a00ed | ||
|
|
4c5ff0d9e1 | ||
|
|
80f3195e32 | ||
|
|
524802d209 | ||
|
|
95116a30fd | ||
|
|
077cecb670 | ||
|
|
6e5c90acd9 | ||
|
|
c2b52164d9 | ||
|
|
efd893de8a | ||
|
|
5ab1224dcf | ||
|
|
7da98783c4 | ||
|
|
3447709f01 | ||
|
|
509baeaf00 | ||
|
|
72767c4a87 | ||
|
|
f1d01741f6 | ||
|
|
7b5d96f6b9 | ||
|
|
7085f910f7 | ||
|
|
c2e25c0945 | ||
|
|
2f2de2eba7 | ||
|
|
70c9a07469 | ||
|
|
32d97e9c78 | ||
|
|
9ac137b9f7 | ||
|
|
204c1b3e7a | ||
|
|
4a13f36971 | ||
|
|
e1022fb785 | ||
|
|
35785b719c | ||
|
|
4f85f70d3e | ||
|
|
5bb2e6fee6 | ||
|
|
d577cadf39 | ||
|
|
cb4b3331f4 | ||
|
|
12c5d79686 | ||
|
|
1a1219625f | ||
|
|
7633ca1053 | ||
|
|
274b9cb259 | ||
|
|
9876848156 | ||
|
|
e193eec1f8 | ||
|
|
8922e67858 | ||
|
|
a86053b4e3 | ||
|
|
44a1543c6d | ||
|
|
f351ad1412 | ||
|
|
4aea00d0b0 | ||
|
|
8b9fdf6aa1 | ||
|
|
6429ee23ef |
@@ -3,13 +3,6 @@
|
||||
// this groovy script is executed by jenkins
|
||||
node {
|
||||
|
||||
|
||||
def gradleInfo
|
||||
def server = Artifactory.server 'project.nes.uni-due.de'
|
||||
def gradleBuild = Artifactory.newGradleBuild()
|
||||
gradleBuild.tool = 'gradle-5.5.1'
|
||||
gradleBuild.usesPlugin = true
|
||||
|
||||
environment {
|
||||
ANDROID_SDK_ROOT = '/var/lib/android-sdk'
|
||||
}
|
||||
@@ -21,49 +14,44 @@ node {
|
||||
}
|
||||
|
||||
def version = ''
|
||||
def release = false
|
||||
|
||||
// configure the deployer based on the version
|
||||
stage('Configure') {
|
||||
version = sh(returnStdout: true, script: "./gradlew properties -q | grep \"version:\" | awk '{print \$2}'", label: "Detecting project version.").trim()
|
||||
println "Version is: '${version}'"
|
||||
if (version.endsWith("-SNAPSHOT")) {
|
||||
println "Using internal-snapshots for publication."
|
||||
gradleBuild.deployer server: server, repo: 'internal-snapshots'
|
||||
} else {
|
||||
println "Using internal-releases for publication."
|
||||
gradleBuild.deployer server: server, repo: 'internal-releases'
|
||||
}
|
||||
println "Version is: '${version}'"
|
||||
release = (! version.endsWith("-SNAPSHOT"))
|
||||
}
|
||||
|
||||
// build the source code with gradle
|
||||
stage('Build') {
|
||||
withCredentials([string(credentialsId: 'maptology-keystore-password', variable: 'PASSWD')]) {
|
||||
def switches = "-Djenkins.build.number=${env.BUILD_NUMBER} -Dandroid.keystore.password=${PASSWD}".toString()
|
||||
gradleInfo = gradleBuild.run buildFile: 'build.gradle', tasks: 'clean build', switches: switches
|
||||
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD clean build', label: "Building project.")
|
||||
}
|
||||
}
|
||||
|
||||
// deploy the maven publications to artifactory
|
||||
// deploy the maven publications to nexus
|
||||
stage ('Publish') {
|
||||
if (env.BRANCH_NAME == "master") {
|
||||
withCredentials([string(credentialsId: 'maptology-keystore-password', variable: 'PASSWD')]) {
|
||||
def switches = "-Djenkins.build.number=${env.BUILD_NUMBER} -Dandroid.keystore.password=${PASSWD}".toString()
|
||||
gradleInfo = gradleBuild.run buildFile: 'build.gradle', tasks: 'artifactoryPublish', switches: switches
|
||||
}
|
||||
withCredentials([string(credentialsId: 'jenkins-nexus-password', variable: 'NEXUS')]) {
|
||||
withCredentials([string(credentialsId: 'maptology-keystore-password', variable: 'PASSWD')]) {
|
||||
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD -Djenkins.nexus.password=$NEXUS publishAllPublicationsToMavenRepository', label: "Publishing project.")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "Skipping deployment for non-master branch."
|
||||
echo "Skipping publication for non-master branch."
|
||||
}
|
||||
}
|
||||
|
||||
// deploy the build output on the server
|
||||
stage ('Deploy') {
|
||||
if (env.BRANCH_NAME == "master") {
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "maptology-server-key", keyFileVariable: "keyfile")]) {
|
||||
sh "scp -i ${keyfile} site-ear/build/libs/site-ear-${version}.ear wildfly@srv.nes.uni-due.de:~/standalone/deployments/maptology.ear"
|
||||
sh "scp -i ${keyfile} android-app/build/outputs/apk/release/*.apk wildfly@srv.nes.uni-due.de:/opt/android/"
|
||||
if (env.BRANCH_NAME == "master" && release) {
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "maptology-server-key", keyFileVariable: "KEYFILE")]) {
|
||||
sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-21-maptology/standalone/deployments/maptology.ear'
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/apk/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/maptology/'
|
||||
}
|
||||
} else {
|
||||
echo "Skipping deployment for non-master branch."
|
||||
echo "Skipping deployment for non-master branch or non-release build."
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,16 +3,16 @@ description = "Maptology Android App"
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation project(":android-feign")
|
||||
implementation "com.android.support:support-v4:${versionSupport}"
|
||||
implementation "com.android.support:appcompat-v7:${versionSupport}"
|
||||
implementation "com.android.support:design:${versionSupport}"
|
||||
implementation "com.android.support:preference-v7:${versionSupport}"
|
||||
implementation "com.android.support:cardview-v7:${versionSupport}"
|
||||
implementation "com.android.support:recyclerview-v7:${versionSupport}"
|
||||
implementation "androidx.legacy:legacy-support-v4:${versionAndroidxLegacy}"
|
||||
implementation "androidx.appcompat:appcompat:${versionAndroidxCompat}"
|
||||
implementation "androidx.preference:preference:${versionAndroidxPreference}"
|
||||
implementation "androidx.cardview:cardview:${versionAndroidxCard}"
|
||||
implementation "androidx.recyclerview:recyclerview:${versionAndroidxRecycler}"
|
||||
implementation "com.google.android.material:material:${versionAndroidxMaterial}"
|
||||
implementation "com.google.android.gms:play-services-oss-licenses:${versionPlay}"
|
||||
testImplementation "junit:junit:${versionJunit}"
|
||||
testImplementation "org.robolectric:robolectric:${versionRobolectric}"
|
||||
testImplementation "org.robolectric:shadows-supportv4:${versionRobolectric}"
|
||||
testImplementation "androidx.test:core:${versionAndroidx}"
|
||||
testImplementation "androidx.test:core:${versionAndroidxTest}"
|
||||
}
|
||||
|
||||
configurations {
|
||||
@@ -22,15 +22,18 @@ configurations {
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
compileSdkVersion 30
|
||||
defaultConfig {
|
||||
applicationId "com.maptology.android.app"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
versionCode 4
|
||||
versionName "1.0.0"
|
||||
targetSdkVersion 30
|
||||
versionCode 13
|
||||
versionName "${version}"
|
||||
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
resValue "string", "application_long", "Maptology"
|
||||
resValue "string", "application_short", "Maptology"
|
||||
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
@@ -44,14 +47,21 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
useProguard false
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
// add signing config if key is provided via system property
|
||||
if (System.properties['android.keystore.password'] != null) signingConfig signingConfigs.release
|
||||
}
|
||||
|
||||
debug {
|
||||
applicationIdSuffix ".debug"
|
||||
versionNameSuffix "-dbg"
|
||||
resValue "string", "application_long", "Maptology (Debug)"
|
||||
resValue "string", "application_short", "M (Debug)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
testOptions {
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
@@ -62,12 +72,18 @@ android {
|
||||
disable 'RtlSymmetry', 'RelativeOverlap'
|
||||
// abortOnError false
|
||||
}
|
||||
dexOptions {
|
||||
javaMaxHeapSize "512m"
|
||||
}
|
||||
defaultConfig {
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('makeEclipseDir') {
|
||||
doLast {
|
||||
file('build/generated/source/aidl/debug').mkdirs();
|
||||
file('build/generated/source/r/debug').mkdirs();
|
||||
file('build/generated/source/aidl/debug').mkdirs()
|
||||
file('build/generated/source/r/debug').mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<!-- required for notification with LED lights, this is idiotic -->
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
@@ -50,9 +52,11 @@
|
||||
android:exported="false"
|
||||
android:label="@string/application_long">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:launchMode="singleTask"
|
||||
android:name=".MainActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true"
|
||||
android:label="@string/application_long">
|
||||
</activity>
|
||||
@@ -61,11 +65,17 @@
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".UpdateReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".NoticeReceiver" android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.maptology.android.app.NOTICE_SYNC"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service android:name=".LocationService"/>
|
||||
<service android:name=".LocationService"/>
|
||||
<service android:name=".LoggerService"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -71,4 +71,7 @@
|
||||
|
||||
<p>Email: <a href="mailto:marcus.handte@uni-due.de">marcus.handte@uni-due.de</a></p>
|
||||
|
||||
<h2>Lizenzhinweise</h2>
|
||||
<p>Grundlage unserer Kartendarstellung und unserer Adressauflösung sind die Daten der <a href="http://www.openstreetmap.org">OpenStreetMap</a>, die gemäß der <a href="https://opendatacommons.org/licenses/odbl/">Open Data Commons Open Database Lizenz</a> (ODbL) durch die <a href="https://osmfoundation.org/">OpenStreetMap Foundation</a> (OSMF) verfügbar sind (© OpenStreetMap-Mitwirkende). Die Visualisierung der Kartendaten erfolgt mit Hilfe einer Bibliothek zur Bilderzeugung der<a href="http://www.locoslab.com"> Locoslab GmbH</a>. Die Auflösung von Adressen wird ebenfalls über Werkzeuge der <a href="http://www.locoslab.com">Locoslab GmbH</a> bewerkstelligt. Weitere Hinweise zu den Lizenzen verwendeten Bibliotheken findest Du in den Einstellungen der Android App und am unteren Rand der Webanwendung.</p>
|
||||
|
||||
</body></html>
|
||||
@@ -0,0 +1,306 @@
|
||||
package com.maptology.android.app;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.pm.PackageInfoCompat;
|
||||
|
||||
import com.maptology.android.app.task.UploadLocationTask;
|
||||
import com.maptology.android.feign.model.Coordinate;
|
||||
import com.maptology.android.feign.model.DeviceHandle;
|
||||
|
||||
/**
|
||||
* An abstract base class for the location and logger
|
||||
* service to share common functions without duplicating
|
||||
* code.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public abstract class AbstractService extends Service {
|
||||
|
||||
/**
|
||||
* The channel id of the localization channel.
|
||||
*/
|
||||
private static final String CHANNEL_ID = "localization";
|
||||
|
||||
/**
|
||||
* The application.
|
||||
*/
|
||||
protected MaptologyApp app;
|
||||
|
||||
/**
|
||||
* The location manager to capture locations.
|
||||
*/
|
||||
protected LocationManager locationManager;
|
||||
|
||||
/**
|
||||
* The handler to process timeouts in the ui thread.
|
||||
*/
|
||||
protected Handler handler;
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// nothing to bind to
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
handler = new Handler();
|
||||
app = (MaptologyApp)getApplicationContext();
|
||||
createNotificationChannel(app);
|
||||
locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the location is sharable.
|
||||
*
|
||||
* @return True if sharable, false otherwise.
|
||||
*/
|
||||
protected boolean isSharable() {
|
||||
return app.getRepository().isSharable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the location is analyzable.
|
||||
*
|
||||
* @return True if analyzable.
|
||||
*/
|
||||
protected boolean isAnalyzable() {
|
||||
DeviceHandle handle = app.getRepository().deviceHandle.getValue();
|
||||
boolean hasUser = handle != null && handle.getUser() != null;
|
||||
return hasUser && app.getRepository().isAnalyzeable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the app version or -1 if an error occurs.
|
||||
*
|
||||
* @return The app version.
|
||||
*/
|
||||
protected long getVersion() {
|
||||
try {
|
||||
PackageInfo info = this.getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
return PackageInfoCompat.getLongVersionCode(info);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the gps provider can be used.
|
||||
*
|
||||
* @return True if gps is available, enabled and we have all permissions.
|
||||
*/
|
||||
protected boolean canUseGps() {
|
||||
boolean gps = app.getRepository().canUseGps();
|
||||
return gps && canUseProvider(LocationManager.GPS_PROVIDER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a particular location provider can be used.
|
||||
*
|
||||
* @param provider The provider.
|
||||
* @return True if we have all permissions and the provider is available and enabled.
|
||||
*/
|
||||
protected boolean canUseProvider(String provider) {
|
||||
return hasLocationPermissions() && locationManager.getAllProviders().contains(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the app has the permissions to capture location.
|
||||
*
|
||||
* @return True if the app has permission to capture locations.
|
||||
*/
|
||||
protected boolean hasLocationPermissions() {
|
||||
return ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
||||
ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the coordinate displayed in the user interface.
|
||||
*
|
||||
* @param longitude The longitude.
|
||||
* @param latitude The latitude.
|
||||
*/
|
||||
protected void setCoordinate(double longitude, double latitude) {
|
||||
Coordinate c = new Coordinate();
|
||||
c.setLatitude(latitude);
|
||||
c.setLongitude(longitude);
|
||||
app.getRepository().gpsPosition.setValue(c);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the locations, if an upload task is not running already.
|
||||
*/
|
||||
protected void onUploadUpdates() {
|
||||
// upload the location, if the upload is not yet running
|
||||
boolean uploading = app.getRepository().uploadingLocations.getValue();
|
||||
DeviceHandle handle = app.getRepository().deviceHandle.getValue();
|
||||
updateNotification(R.string.localization_notification_upload);
|
||||
if (!uploading && handle != null ) {
|
||||
UploadLocationTask task = new UploadLocationTask(app);
|
||||
task.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the id for the foreground service notification.
|
||||
*
|
||||
* @return The notification id.
|
||||
*/
|
||||
protected abstract int getNotificationId();
|
||||
|
||||
/**
|
||||
* Updates the foreground service notification with new text.
|
||||
*
|
||||
* @param content The content.
|
||||
*/
|
||||
protected void updateNotification(int content) {
|
||||
Notification notification = getNotification(content);
|
||||
NotificationManager manager = (NotificationManager)app.getSystemService(NOTIFICATION_SERVICE);
|
||||
manager.notify(getNotificationId(), notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the notification that is displayed during upload.
|
||||
*
|
||||
* @param content The notification content (res id).
|
||||
* @return The notification.
|
||||
*/
|
||||
protected Notification getNotification(int content) {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(app, CHANNEL_ID)
|
||||
.setContentTitle(getText(R.string.localization_notification_title))
|
||||
.setContentText(getText(content))
|
||||
.setOngoing(true)
|
||||
.setContentIntent(PendingIntent.getActivity(app, 445, new Intent(app, StartActivity.class), PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.setSmallIcon(R.drawable.icon_notification_small);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification channel for the app.
|
||||
*
|
||||
* @param app The app to retrieve the notification manager.
|
||||
*/
|
||||
public static void createNotificationChannel(MaptologyApp app) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
CharSequence name = app.getString(R.string.localization_channel_name);
|
||||
String description = app.getString(R.string.localization_channel_description);
|
||||
int importance = NotificationManager.IMPORTANCE_LOW;
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
|
||||
channel.setDescription(description);
|
||||
NotificationManager notificationManager = app.getSystemService(NotificationManager.class);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts the service, if it is not running already.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void runService(Context context) {
|
||||
if (!isLocalizable(context) || !hasDevice(context)) return;
|
||||
Intent intent = new Intent();
|
||||
if (isLoggable(context) && isPowerCordPlugged(context)) {
|
||||
intent.setClass(context, LoggerService.class);
|
||||
} else {
|
||||
intent.setClass(context, LocationService.class);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
context.startService(intent);
|
||||
} else {
|
||||
context.startForegroundService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops all services unconditionally.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void stopServices(Context context) {
|
||||
for (Class<?> service : new Class[] { LocationService.class, LoggerService.class }) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, service);
|
||||
context.stopService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the data logging is enabled.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if data logging is enabled, false otherwise.
|
||||
*/
|
||||
protected static boolean isLoggable(Context context) {
|
||||
MaptologyApp app = (MaptologyApp)context.getApplicationContext();
|
||||
return app.getRepository().isLoggable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the device localization is enabled.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if localization is enabled, false otherwise.
|
||||
*/
|
||||
protected static boolean isLocalizable(Context context) {
|
||||
MaptologyApp app = (MaptologyApp)context.getApplicationContext();
|
||||
return app.getRepository().isLocalizable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether there is a device handle.
|
||||
*
|
||||
* @return True if there is a device handle, false otherwise.
|
||||
*/
|
||||
protected static boolean hasDevice(Context context) {
|
||||
MaptologyApp app = (MaptologyApp)context.getApplicationContext();
|
||||
return (app.getRepository().deviceHandle.getValue() != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the power cord is plugged based on the
|
||||
* information contained in the battery intent.
|
||||
*
|
||||
* @param context The context to fetch the intent.
|
||||
* @return True if the power cord is plugged, false otherwise.
|
||||
*/
|
||||
protected static boolean isPowerCordPlugged(Context context) {
|
||||
Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
int p = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
if (Build.VERSION.SDK_INT < 17) {
|
||||
return p == BatteryManager.BATTERY_PLUGGED_AC ||
|
||||
p == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
} else {
|
||||
return p == BatteryManager.BATTERY_PLUGGED_AC ||
|
||||
p == BatteryManager.BATTERY_PLUGGED_USB ||
|
||||
p == BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
MaptologyApp app = (MaptologyApp)context.getApplicationContext();
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
||||
NoticeReceiver.schedulePeriodicSync(app);
|
||||
LocationService.runService(app);
|
||||
AbstractService.runService(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.maptology.android.app.location.LocationState;
|
||||
import com.maptology.android.app.model.Network;
|
||||
import com.maptology.android.app.model.Position;
|
||||
import com.maptology.android.app.location.LocationNetwork;
|
||||
import com.maptology.android.app.location.LocationPosition;
|
||||
import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.UploadLocationTask;
|
||||
@@ -15,13 +15,8 @@ import com.maptology.android.feign.model.DeviceHandle;
|
||||
import com.maptology.android.feign.model.ReleasedLocation;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -35,14 +30,12 @@ import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.pm.PackageInfoCompat;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.pm.PackageInfoCompat;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
@@ -50,7 +43,7 @@ import android.util.Log;
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class LocationService extends Service {
|
||||
public class LocationService extends AbstractService {
|
||||
|
||||
/**
|
||||
* The code for the alarm.
|
||||
@@ -66,7 +59,7 @@ public class LocationService extends Service {
|
||||
/**
|
||||
* The minimum time between two localization attempts.
|
||||
*/
|
||||
private static final long LOCALIZATION_TIMEOUT = 60000;
|
||||
private static final long LOCALIZATION_TIMEOUT = 55000;
|
||||
|
||||
/**
|
||||
* The time to wait for wifi scans.
|
||||
@@ -124,25 +117,11 @@ public class LocationService extends Service {
|
||||
*/
|
||||
private static final String TAG = "LocationService";
|
||||
|
||||
/**
|
||||
* The channel id of the localization channel.
|
||||
*/
|
||||
private static final String CHANNEL_ID = "localization";
|
||||
|
||||
/**
|
||||
* The notification id of the foreground service indicator.
|
||||
*/
|
||||
private static final int NOTIFICATION_ID = 5544;
|
||||
|
||||
/**
|
||||
* The application.
|
||||
*/
|
||||
private MaptologyApp app;
|
||||
|
||||
/**
|
||||
* The location manager to capture locations.
|
||||
*/
|
||||
private LocationManager locationManager;
|
||||
/**
|
||||
* The wifi manager to perform wifi scans and request wifi locks.
|
||||
*/
|
||||
@@ -152,11 +131,6 @@ public class LocationService extends Service {
|
||||
*/
|
||||
private PowerManager powerManager;
|
||||
|
||||
/**
|
||||
* The handler to process timeouts in the ui thread.
|
||||
*/
|
||||
private Handler handler;
|
||||
|
||||
/**
|
||||
* The current state of the service.
|
||||
*/
|
||||
@@ -165,7 +139,7 @@ public class LocationService extends Service {
|
||||
/**
|
||||
* The current list of networks.
|
||||
*/
|
||||
private List<Network> currentNetworks = null;
|
||||
private List<LocationNetwork> currentNetworks = null;
|
||||
|
||||
/**
|
||||
* The time of the last localization attempt of the service.
|
||||
@@ -196,6 +170,17 @@ public class LocationService extends Service {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A broadcast receiver to receive timer ticks in the background.
|
||||
*/
|
||||
private BroadcastReceiver timeTickReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "Tick received.");
|
||||
onStartCommand(null, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A location listener that simply forwards its locations to
|
||||
* the service.
|
||||
@@ -234,7 +219,7 @@ public class LocationService extends Service {
|
||||
};
|
||||
|
||||
/**
|
||||
* A listern that deactivates the service when the upload completes.
|
||||
* A listener that deactivates the service when the upload completes.
|
||||
*/
|
||||
private IValueListener<Boolean> uploadListener = new IValueListener<Boolean>() {
|
||||
@Override
|
||||
@@ -259,30 +244,19 @@ public class LocationService extends Service {
|
||||
*/
|
||||
private Runnable timeoutListener = null;
|
||||
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// do not support binding
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("InlinedApi")
|
||||
public void onCreate() {
|
||||
Log.d(TAG, "Creating location service.");
|
||||
super.onCreate();
|
||||
handler = new Handler();
|
||||
app = (MaptologyApp) getApplicationContext();
|
||||
createNotificationChannel(app);
|
||||
startForeground(NOTIFICATION_ID, getNotification(R.string.localization_notification_idle));
|
||||
app.getRepository().uploadingLocations.addValueListener(uploadListener);
|
||||
locationManager = (LocationManager) app.getSystemService(LOCATION_SERVICE);
|
||||
wifiManager = (WifiManager) app.getSystemService(WIFI_SERVICE);
|
||||
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, TAG);
|
||||
powerManager = (PowerManager) app.getSystemService(POWER_SERVICE);
|
||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1)
|
||||
registerReceiver(idleModeReceiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
|
||||
registerReceiver(timeTickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,6 +278,7 @@ public class LocationService extends Service {
|
||||
app.getRepository().uploadingLocations.removeValueListener(uploadListener);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1)
|
||||
unregisterReceiver(idleModeReceiver);
|
||||
unregisterReceiver(timeTickReceiver);
|
||||
Log.d(TAG, "Releasing wake lock.");
|
||||
if (wakeLock.isHeld()) wakeLock.release();
|
||||
stopForeground(true);
|
||||
@@ -312,32 +287,36 @@ public class LocationService extends Service {
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (!app.getRepository().isLocalizable()) {
|
||||
if (!isLocalizable(this)) {
|
||||
Log.d(TAG, "Stopping since localization is disabled.");
|
||||
cancelExecution(this);
|
||||
stopSelf();
|
||||
return START_NOT_STICKY;
|
||||
} else if (!hasDeviceHandle()) {
|
||||
} else if (!hasDevice(this)) {
|
||||
Log.d(TAG, "Stopping since device is not available.");
|
||||
cancelExecution(this);
|
||||
stopSelf();
|
||||
return START_NOT_STICKY;
|
||||
} else if (isLoggable(this) && isPowerCordPlugged(this)) {
|
||||
Log.d(TAG, "Switching to logger service.");
|
||||
cancelExecution(this);
|
||||
stopSelf();
|
||||
runService(app);
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
if (!isPeriodicExecution(intent)) {
|
||||
Log.d(TAG, "Scheduling periodic execution.");
|
||||
scheduleExecution(this, localizationTime);
|
||||
}
|
||||
// ensure that localization is only running, if it is not
|
||||
// running already or has been run only seconds ago
|
||||
// start localization, if we are not running one already
|
||||
long now = SystemClock.elapsedRealtime();
|
||||
if (currentState == LocationState.IDLE) {
|
||||
if (isDeviceIdle()) {
|
||||
onDeviceIdle();
|
||||
} else if (now - localizationTime > LOCALIZATION_TIMEOUT - 1000) {
|
||||
if (now - localizationTime > LOCALIZATION_TIMEOUT / 2) {
|
||||
Log.d(TAG, "Starting localization state machine.");
|
||||
changeState();
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring start request while timeout has not expired.");
|
||||
if (isDeviceIdle()) {
|
||||
onDeviceIdle();
|
||||
}
|
||||
Log.d(TAG, "Scheduling periodic execution.");
|
||||
scheduleExecution(this, localizationTime);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring start request while service is " + currentState + ".");
|
||||
@@ -345,16 +324,6 @@ public class LocationService extends Service {
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether there is a device handle.
|
||||
*
|
||||
* @return True if there is a device handle, false otherwise.
|
||||
*/
|
||||
private boolean hasDeviceHandle() {
|
||||
return (app.getRepository().deviceHandle.getValue() != null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Triggers a state change to the next logical state of the state machine.
|
||||
*/
|
||||
@@ -437,7 +406,7 @@ public class LocationService extends Service {
|
||||
* already.
|
||||
*
|
||||
* @param success True to indicate success, false to indicate
|
||||
* an unrecovable failure.
|
||||
* an unrecoverable failure.
|
||||
*/
|
||||
private void resetState(boolean success) {
|
||||
currentState = LocationState.IDLE;
|
||||
@@ -489,8 +458,17 @@ public class LocationService extends Service {
|
||||
* @return True if gps permissions are set.
|
||||
*/
|
||||
private boolean hasGpsPermissions() {
|
||||
return ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
List<String> permissions = new ArrayList<>();
|
||||
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
permissions.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
|
||||
}
|
||||
boolean granted = true;
|
||||
for (String permission: permissions) {
|
||||
granted &= ActivityCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
return granted;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -552,18 +530,14 @@ public class LocationService extends Service {
|
||||
changeState();
|
||||
} else {
|
||||
Log.d(TAG, "Starting cache lookup.");
|
||||
Position p = app.getLocationStore().findPosition(currentNetworks, NETWORK_MINIMUM, MAXIMUM_WIFI_DEVIATION);
|
||||
LocationPosition p = app.getLocationStore().findPosition(currentNetworks, NETWORK_MINIMUM, MAXIMUM_WIFI_DEVIATION);
|
||||
if (p != null) {
|
||||
long now = System.currentTimeMillis();
|
||||
p.setUsageTime(now);
|
||||
if (isFresh(p)) {
|
||||
Log.d(TAG, "Using cached location.");
|
||||
// update the user interface
|
||||
// update the user interface
|
||||
Coordinate c = new Coordinate();
|
||||
c.setLatitude(p.getLatitude());
|
||||
c.setLongitude(p.getLongitude());
|
||||
app.getRepository().gpsPosition.setValue(c);
|
||||
setCoordinate(p.getLongitude(), p.getLatitude());
|
||||
// create a release
|
||||
ReleasedLocation update = createLocation();
|
||||
update.setAvailability(ReleasedLocation.AvailabilityEnum.CACHED);
|
||||
@@ -592,19 +566,6 @@ public class LocationService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the locations, if an upload task is not running already.
|
||||
*/
|
||||
private void onUploadUpdates() {
|
||||
// upload the location, if the upload is not yet running
|
||||
boolean uploading = app.getRepository().uploadingLocations.getValue();
|
||||
DeviceHandle handle = app.getRepository().deviceHandle.getValue();
|
||||
updateNotification(R.string.localization_notification_upload);
|
||||
if (!uploading && handle != null ) {
|
||||
UploadLocationTask task = new UploadLocationTask(app);
|
||||
task.execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an idle position update, unless we already created it.
|
||||
@@ -646,7 +607,7 @@ public class LocationService extends Service {
|
||||
* @param p The position to check.
|
||||
* @return True if the position is young enough, false if it is too old.
|
||||
*/
|
||||
private boolean isFresh(Position p) {
|
||||
private boolean isFresh(LocationPosition p) {
|
||||
return p.getUsageTime() - p.getCreationTime() <= MAXIMUM_CACHE_DURATION;
|
||||
}
|
||||
|
||||
@@ -692,10 +653,10 @@ public class LocationService extends Service {
|
||||
* @param results The results.
|
||||
*/
|
||||
private void setScan(List<ScanResult> results) {
|
||||
List<Network> networks = new ArrayList<>();
|
||||
List<LocationNetwork> networks = new ArrayList<>();
|
||||
for (ScanResult r: results) {
|
||||
if (r.level >= MINIMUM_WIFI_RSSI) {
|
||||
Network n = new Network();
|
||||
LocationNetwork n = new LocationNetwork();
|
||||
n.setBssid(r.BSSID);
|
||||
n.setRssi(r.level);
|
||||
networks.add(n);
|
||||
@@ -716,10 +677,7 @@ public class LocationService extends Service {
|
||||
if (currentState == LocationState.GPS) cleanupGps();
|
||||
if (currentState == LocationState.NET) cleanupNet();
|
||||
// update the user interface
|
||||
Coordinate c = new Coordinate();
|
||||
c.setLatitude(location.getLatitude());
|
||||
c.setLongitude(location.getLongitude());
|
||||
app.getRepository().gpsPosition.setValue(c);
|
||||
setCoordinate(location.getLongitude(), location.getLatitude());
|
||||
// create final location
|
||||
ReleasedLocation update = createLocation();
|
||||
update.setCoordinate(new Coordinate());
|
||||
@@ -735,7 +693,7 @@ public class LocationService extends Service {
|
||||
onStoreUpdate(update);
|
||||
// store location in cache
|
||||
if (hasMinimumNetworks()) {
|
||||
Position p = new Position();
|
||||
LocationPosition p = new LocationPosition();
|
||||
p.setLatitude(location.getLatitude());
|
||||
p.setLongitude(location.getLongitude());
|
||||
p.setCreationTime(System.currentTimeMillis());
|
||||
@@ -776,40 +734,6 @@ public class LocationService extends Service {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the location is sharable.
|
||||
*
|
||||
* @return True if sharable, false otherwise.
|
||||
*/
|
||||
private boolean isSharable() {
|
||||
return app.getRepository().isSharable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the location is analyzable.
|
||||
*
|
||||
* @return True if analyzable.
|
||||
*/
|
||||
private boolean isAnalyzable() {
|
||||
DeviceHandle handle = app.getRepository().deviceHandle.getValue();
|
||||
boolean hasUser = handle != null && handle.getUser() != null;
|
||||
return hasUser && app.getRepository().isAnalyzeable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the app version or -1 if an error occurs.
|
||||
*
|
||||
* @return The app version.
|
||||
*/
|
||||
private long getVersion() {
|
||||
try {
|
||||
PackageInfo info = this.getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
return PackageInfoCompat.getLongVersionCode(info);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the current networks exceed the minimum network threshold.
|
||||
*
|
||||
@@ -844,17 +768,6 @@ public class LocationService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the gps provider can be used.
|
||||
*
|
||||
* @return True if gps is available, enabled and we have all permissions.
|
||||
*/
|
||||
private boolean canUseGps() {
|
||||
boolean gps = app.getRepository().canUseGps();
|
||||
if (!gps) Log.d(TAG, "Gps is manually disabled.");
|
||||
return gps && canUseProvider(LocationManager.GPS_PROVIDER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the network provider can be used.
|
||||
*
|
||||
@@ -872,19 +785,8 @@ public class LocationService extends Service {
|
||||
* @param provider The provider.
|
||||
* @return True if we have all permissions and the provider is available and enabled.
|
||||
*/
|
||||
private boolean canUseProvider(String provider) {
|
||||
return hasLocationPermissions() && locationManager.getAllProviders().contains(provider) &&
|
||||
locationManager.isProviderEnabled(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the app has the permissions to capture location.
|
||||
*
|
||||
* @return True if the app has permission to capture locations.
|
||||
*/
|
||||
private boolean hasLocationPermissions() {
|
||||
return ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
||||
ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
protected boolean canUseProvider(String provider) {
|
||||
return super.canUseProvider(provider) && locationManager.isProviderEnabled(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -914,43 +816,23 @@ public class LocationService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service, if it is not running already.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void runService(Context context) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, LocationService.class);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
context.startService(intent);
|
||||
} else {
|
||||
context.startForegroundService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the service unconditionally.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void stopService(Context context) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, LocationService.class);
|
||||
context.stopService(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the service for periodic execution.
|
||||
* Schedules the service for the next execution.
|
||||
*
|
||||
* @param context The context used to schedule this.
|
||||
*/
|
||||
private static void scheduleExecution(Context context, long lastTime) {
|
||||
PendingIntent pending = createIntent(context);
|
||||
AlarmManager manager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
||||
long now = SystemClock.elapsedRealtime();
|
||||
long next = Math.max(0, (lastTime + LOCALIZATION_TIMEOUT) - now);
|
||||
long next = Math.max(5000, (lastTime + LOCALIZATION_TIMEOUT) - now);
|
||||
Log.d(TAG, "Updating alarm to execute in " + next + " ms.");
|
||||
manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, LOCALIZATION_TIMEOUT, pending);
|
||||
// this is too imprecise on Android 9
|
||||
//manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, LOCALIZATION_TIMEOUT, pending);
|
||||
PendingIntent pending = createIntent(context);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, pending);
|
||||
} else {
|
||||
manager.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, LOCALIZATION_TIMEOUT / 2, pending);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -980,66 +862,8 @@ public class LocationService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the intent is a periodic execution.
|
||||
*
|
||||
* @param intent The intent.
|
||||
* @return True if the intent is a periodic execution by the alarm manager.
|
||||
*/
|
||||
private static boolean isPeriodicExecution(Intent intent) {
|
||||
try {
|
||||
if (intent == null) return false;
|
||||
return intent.getBooleanExtra(EXTRA_ALARM, false);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Invalid intent, cannot extract alarm although it is defined.");
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected int getNotificationId() {
|
||||
return NOTIFICATION_ID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the foreground service notification with new text.
|
||||
*
|
||||
* @param content The content.
|
||||
*/
|
||||
private void updateNotification(int content) {
|
||||
Notification notification = getNotification(content);
|
||||
NotificationManager manager = (NotificationManager)app.getSystemService(NOTIFICATION_SERVICE);
|
||||
manager.notify(NOTIFICATION_ID, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the notification that is displayed during upload.
|
||||
*
|
||||
* @param content The notification content (res id).
|
||||
* @return The notification.
|
||||
*/
|
||||
private Notification getNotification(int content) {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(app, CHANNEL_ID)
|
||||
.setContentTitle(getText(R.string.localization_notification_title))
|
||||
.setContentText(getText(content))
|
||||
.setOngoing(true)
|
||||
.setContentIntent(PendingIntent.getActivity(app, 445, new Intent(app, StartActivity.class), PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.setSmallIcon(R.drawable.icon_notification_small);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification channel for the app.
|
||||
*
|
||||
* @param app The app to retrieve the notification manager.
|
||||
*/
|
||||
public static void createNotificationChannel(MaptologyApp app) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
CharSequence name = app.getString(R.string.localization_channel_name);
|
||||
String description = app.getString(R.string.localization_channel_description);
|
||||
int importance = NotificationManager.IMPORTANCE_LOW;
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
|
||||
channel.setDescription(description);
|
||||
NotificationManager notificationManager = app.getSystemService(NotificationManager.class);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,686 @@
|
||||
package com.maptology.android.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.util.DeltaCodec;
|
||||
import com.maptology.android.feign.model.Coordinate;
|
||||
import com.maptology.android.feign.model.ReleasedLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A service for data logger configurations.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class LoggerService extends AbstractService {
|
||||
|
||||
/**
|
||||
* The key for the detailed gps data.
|
||||
*/
|
||||
private static final String METADATA_GPS = "gps";
|
||||
|
||||
/**
|
||||
* The key for the acceleration sensor.
|
||||
*/
|
||||
private static final String METADATA_ACCELEROMETER = "accel";
|
||||
|
||||
/**
|
||||
* The key for the gyroscope.
|
||||
*/
|
||||
private static final String METADATA_GYROSCOPE = "gyro";
|
||||
|
||||
/**
|
||||
* The key for the magnetometer.
|
||||
*/
|
||||
private static final String METADATA_MAGNETOMETER = "magnet";
|
||||
|
||||
/**
|
||||
* The notification id of the foreground service indicator.
|
||||
*/
|
||||
private static final int NOTIFICATION_ID = 5545;
|
||||
|
||||
/**
|
||||
* The log tag for the service.
|
||||
*/
|
||||
private static final String TAG = "LoggerService";
|
||||
|
||||
/**
|
||||
* The tag for the cpu wakelock.
|
||||
*/
|
||||
private static final String WAKELOCK_TAG = "maptology:logger";
|
||||
|
||||
/**
|
||||
* The approximate delay between two sensor values
|
||||
* in milliseconds (10/sec).
|
||||
*/
|
||||
private static int SAMPLING_DELAY_SENSOR = 100;
|
||||
|
||||
/**
|
||||
* The approximate delay between two gps values
|
||||
* in milliseconds (1/sec).
|
||||
*/
|
||||
private static int SAMPLING_DELAY_GPS = 1000;
|
||||
|
||||
/**
|
||||
* The number of digits kept for sensors.
|
||||
*/
|
||||
private static int PRECISION_SENSOR = 7;
|
||||
|
||||
/**
|
||||
* The amount of time between the creation of a
|
||||
* position update in milliseconds.
|
||||
*/
|
||||
private static int UPDATE_DELAY = 60000;
|
||||
|
||||
/**
|
||||
* A scale factor to ensure that there are enough data bins,
|
||||
* even if the update generation process is not executed at
|
||||
* exactly the right frequency. 2 means that we provide twice
|
||||
* as many data bins as we would require if the timing is perfect.
|
||||
*/
|
||||
private int UPDATE_FACTOR = 2;
|
||||
|
||||
/**
|
||||
* A gps listener that memorizes a number of locations.
|
||||
*/
|
||||
private GpsListener gpsListener;
|
||||
|
||||
/**
|
||||
* A listener that is attached to the acceleration sensor.
|
||||
*/
|
||||
private SensorListener accelerometerListener = new SensorListener(3, PRECISION_SENSOR, UPDATE_DELAY * UPDATE_FACTOR / SAMPLING_DELAY_SENSOR);
|
||||
|
||||
/**
|
||||
* A listener that is attached to the gyroscope sensor.
|
||||
*/
|
||||
private SensorListener gyroscopeListener = new SensorListener(3, PRECISION_SENSOR, UPDATE_DELAY * UPDATE_FACTOR / SAMPLING_DELAY_SENSOR);
|
||||
|
||||
/**
|
||||
* A listener that is attached to the magnetometer sensor.
|
||||
*/
|
||||
private SensorListener magnetometerListener = new SensorListener(3, PRECISION_SENSOR, UPDATE_DELAY * UPDATE_FACTOR / SAMPLING_DELAY_SENSOR);
|
||||
|
||||
/**
|
||||
* The cpu wake lock.
|
||||
*/
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
|
||||
/**
|
||||
* The sensor manager.
|
||||
*/
|
||||
private SensorManager sensorManager;
|
||||
|
||||
/**
|
||||
* A listener that deactivates the service when the upload completes.
|
||||
*/
|
||||
private IValueListener<Boolean> uploadListener = new IValueListener<Boolean>() {
|
||||
@Override
|
||||
public void onValueChanged(Value<Boolean> source, Boolean oldValue, Boolean newValue) {
|
||||
if (!newValue) updateNotification(R.string.localization_notification_logger);
|
||||
else updateNotification(R.string.localization_notification_upload);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The listener that will capture the data.
|
||||
*/
|
||||
private Runnable captureListener = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onCapture();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressLint("WakelockTimeout") // the device is plugged, so we can ignore safely the energy usage
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
gpsListener = new GpsListener(LocationManager.GPS_PROVIDER, UPDATE_DELAY * UPDATE_FACTOR / SAMPLING_DELAY_GPS);
|
||||
startForeground(NOTIFICATION_ID, getNotification(R.string.localization_notification_logger));
|
||||
app.getRepository().uploadingLocations.addValueListener(uploadListener, true);
|
||||
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
|
||||
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
|
||||
wakeLock.acquire();
|
||||
prepareCapture();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes all listeners and registers the listeners that are not registered
|
||||
* already and can be registered due to sensor availability and schedules the
|
||||
* next capturing iteration.
|
||||
*/
|
||||
public void prepareCapture() {
|
||||
flushListeners();
|
||||
registerSensorListeners();
|
||||
registerGpsListener();
|
||||
Log.d(TAG, "Scheduling capture operation.");
|
||||
handler.postDelayed(captureListener, UPDATE_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the timeout expires and an update must be created,
|
||||
* stored and possibly uploaded.
|
||||
*/
|
||||
public void onCapture() {
|
||||
Log.d(TAG, "Performing capture operation.");
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
ReleasedLocation location = gpsListener.getLocation();
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
if (magnetometerListener.isRegistered()) metadata.put(METADATA_MAGNETOMETER, magnetometerListener.encode());
|
||||
if (accelerometerListener.isRegistered()) metadata.put(METADATA_ACCELEROMETER, accelerometerListener.encode());
|
||||
if (gyroscopeListener.isRegistered()) metadata.put(METADATA_GYROSCOPE, gyroscopeListener.encode());
|
||||
if (gpsListener.isRegistered()) metadata.put(METADATA_GPS, gpsListener.encode());
|
||||
int length = 0;
|
||||
for (String s: metadata.keySet()) {
|
||||
Log.d(TAG, "Metadata " + s + " size is " + metadata.get(s).length() + " bytes.");
|
||||
length += metadata.get(s).length();
|
||||
}
|
||||
Log.d(TAG, "Total sensor data size is " + length + " bytes.");
|
||||
location.setMetadata(metadata);
|
||||
app.getLocationStore().addUpdate(location);
|
||||
app.getRepository().lastUpdate.setValue(location);
|
||||
Log.d(TAG, "Total duration for packaging is " + (System.currentTimeMillis() - start) + " ms.");
|
||||
onUploadUpdates();
|
||||
} finally {
|
||||
if (isLocalizable(this) && isLoggable(this) && isPowerCordPlugged(this)) {
|
||||
Log.d(TAG, "Preparing next capture operation.");
|
||||
prepareCapture();
|
||||
} else {
|
||||
Log.d(TAG, "Switching to localization service.");
|
||||
stopSelf();
|
||||
runService(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
app.getRepository().uploadingLocations.removeValueListener(uploadListener);
|
||||
handler.removeCallbacks(captureListener);
|
||||
unregisterGpsListener();
|
||||
unregisterSensorListeners();
|
||||
if (wakeLock.isHeld()) wakeLock.release();
|
||||
stopForeground(true);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (! isLocalizable(this)) {
|
||||
Log.d(TAG, "Stopping since localization is disabled.");
|
||||
stopSelf();
|
||||
return START_NOT_STICKY;
|
||||
} else if (!hasDevice(this)) {
|
||||
Log.d(TAG, "Stopping since device is not available.");
|
||||
stopSelf();
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a flush operation on all listeners.
|
||||
*/
|
||||
private void flushListeners() {
|
||||
gpsListener.flush();
|
||||
accelerometerListener.flush();
|
||||
magnetometerListener.flush();
|
||||
gyroscopeListener.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the gps listener, if that is possible and did not happen already.
|
||||
*/
|
||||
private void registerGpsListener() {
|
||||
if (!gpsListener.isRegistered() && canUseGps()) {
|
||||
try {
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, SAMPLING_DELAY_GPS, 0, gpsListener);
|
||||
gpsListener.setRegistered(true);
|
||||
} catch (SecurityException e) {
|
||||
Log.e(TAG, "Failed to register gps listener.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the gps listener, if it was registered successfully already.
|
||||
*/
|
||||
private void unregisterGpsListener() {
|
||||
if (gpsListener.isRegistered()) {
|
||||
locationManager.removeUpdates(gpsListener);
|
||||
gpsListener.setRegistered(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all sensor listeners for the sensors that are available.
|
||||
*/
|
||||
private void registerSensorListeners() {
|
||||
registerSensorListener(Sensor.TYPE_ACCELEROMETER, accelerometerListener);
|
||||
registerSensorListener(Sensor.TYPE_GYROSCOPE, gyroscopeListener);
|
||||
registerSensorListener(Sensor.TYPE_MAGNETIC_FIELD, magnetometerListener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers the sensor listener for the specified sensor type, if the sensor
|
||||
* is available.
|
||||
*
|
||||
* @param sensorType The sensor type.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
private void registerSensorListener(int sensorType, SensorListener listener) {
|
||||
if (listener.isRegistered()) return;
|
||||
Sensor sensor = sensorManager.getDefaultSensor(sensorType);
|
||||
if (sensor != null) {
|
||||
int period = SAMPLING_DELAY_SENSOR * 1000;
|
||||
if (Build.VERSION.SDK_INT > 21) {
|
||||
period = Math.max(sensor.getMinDelay(), Math.min(sensor.getMaxDelay(), period));
|
||||
}
|
||||
boolean registered = sensorManager.registerListener(listener, sensor, period);
|
||||
listener.setRegistered(registered);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters all sensor listeners that are registered.
|
||||
*/
|
||||
private void unregisterSensorListeners() {
|
||||
unregisterSensorListener(accelerometerListener);
|
||||
unregisterSensorListener(gyroscopeListener);
|
||||
unregisterSensorListener(magnetometerListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a particular sensor listener, if it was registered already.
|
||||
*
|
||||
* @param listener The listener to unregister.
|
||||
*/
|
||||
private void unregisterSensorListener(SensorListener listener) {
|
||||
if (listener.isRegistered()) {
|
||||
sensorManager.unregisterListener(listener);
|
||||
listener.setRegistered(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the service's foreground notification.
|
||||
*
|
||||
* @return The notification id.
|
||||
*/
|
||||
@Override
|
||||
protected int getNotificationId() {
|
||||
return NOTIFICATION_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* A location listener that memorizes it's first location and
|
||||
* enables the retrieval of a string-encoded trace.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
private class GpsListener implements LocationListener {
|
||||
|
||||
/**
|
||||
* The flag for a valid accuracy.
|
||||
*/
|
||||
private static final int FLAG_ACCURACY = 1;
|
||||
/**
|
||||
* The flag for a valid altitude.
|
||||
*/
|
||||
private static final int FLAG_ALTITUDE = 2;
|
||||
/**
|
||||
* The flag for a valid bearing.
|
||||
*/
|
||||
private static final int FLAG_BEARING = 8;
|
||||
/**
|
||||
* The flag for a valid speed.
|
||||
*/
|
||||
private static final int FLAG_SPEED = 16;
|
||||
/**
|
||||
* The flag for a valid speed accuracy.
|
||||
*/
|
||||
private static final int FLAG_SPEED_ACCURACY = 32;
|
||||
/**
|
||||
* The flag for a valid vertical accuracy.
|
||||
*/
|
||||
private static final int FLAG_VERTICAL_ACCURACY = 64;
|
||||
/**
|
||||
* The flag for a valid bearing accuracy.
|
||||
*/
|
||||
private static final int FLAG_BEARING_ACCURACY = 128;
|
||||
|
||||
/**
|
||||
* The delta codec.
|
||||
*/
|
||||
private DeltaCodec codec;
|
||||
|
||||
/**
|
||||
* The unused data items.
|
||||
*/
|
||||
private List<long[]> cache;
|
||||
|
||||
/**
|
||||
* The used data items.
|
||||
*/
|
||||
private List<long[]> data;
|
||||
|
||||
/**
|
||||
* The first location since the flush.
|
||||
*/
|
||||
private ReleasedLocation location;
|
||||
|
||||
/**
|
||||
* The location provider name.
|
||||
*/
|
||||
private String provider;
|
||||
|
||||
/**
|
||||
* A flag to indicate whether the listener is
|
||||
* registered.
|
||||
*/
|
||||
private boolean registered;
|
||||
|
||||
/**
|
||||
* Creates a position listener with
|
||||
* the specified limit on positions.
|
||||
*
|
||||
* @param limit The limit.
|
||||
* @param provider The location provider name.
|
||||
*/
|
||||
GpsListener(String provider, int limit) {
|
||||
int values = Math.max(1, limit);
|
||||
this.provider = provider;
|
||||
cache = new ArrayList<>(values);
|
||||
data = new ArrayList<>(values);
|
||||
codec = new DeltaCodec(11);
|
||||
for (int i = 0; i < values; i++) {
|
||||
// time, flags, 9 values
|
||||
cache.add(new long[11]);
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) { }
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) { }
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) { }
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if (this.location.getAvailability() != ReleasedLocation.AvailabilityEnum.FRESH) {
|
||||
this.location.setAvailability(ReleasedLocation.AvailabilityEnum.FRESH);
|
||||
this.location.setTimestamp(location.getTime());
|
||||
this.location.setCoordinate(new Coordinate());
|
||||
this.location.getCoordinate().setLatitude(location.getLatitude());
|
||||
this.location.getCoordinate().setLongitude(location.getLongitude());
|
||||
setCoordinate(location.getLongitude(), location.getLatitude());
|
||||
if (location.hasAccuracy()) this.location.setAccuracy((double)location.getAccuracy());
|
||||
if (location.hasAltitude()) this.location.setAltitude(location.getAltitude());
|
||||
if (location.hasBearing()) this.location.setBearing((double)location.getBearing());
|
||||
if (location.hasSpeed()) this.location.setSpeed((double)location.getSpeed());
|
||||
}
|
||||
long[] next = remove();
|
||||
next[0] = location.getTime();
|
||||
next[1] = getFlags(location);
|
||||
next[2] = Math.round(location.getLongitude() * 10e6);
|
||||
next[3] = Math.round(location.getLatitude() * 10e6);
|
||||
next[4] = Math.round(location.getAccuracy() * 10e3);
|
||||
next[5] = Math.round(location.getAltitude() * 10e3);
|
||||
next[6] = Math.round(location.getBearing() * 10e3);
|
||||
next[7] = Math.round(location.getSpeed() * 10e3);
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
next[8] = Math.round(location.getSpeedAccuracyMetersPerSecond() * 10e3);
|
||||
next[9] = Math.round(location.getVerticalAccuracyMeters() * 10e3);
|
||||
next[10] = Math.round(location.getBearingAccuracyDegrees() * 10e3);
|
||||
}
|
||||
data.add(next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the hasXXX values into a flag vector.
|
||||
*
|
||||
* @param location The location.
|
||||
* @return The long representing the flags.
|
||||
*/
|
||||
private long getFlags(Location location) {
|
||||
long flags = 0;
|
||||
if (location.hasAccuracy()) flags += FLAG_ACCURACY;
|
||||
if (location.hasAltitude()) flags += FLAG_ALTITUDE;
|
||||
if (location.hasBearing()) flags += FLAG_BEARING;
|
||||
if (location.hasSpeed()) flags += FLAG_SPEED;
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
if (location.hasSpeedAccuracy()) flags += FLAG_SPEED_ACCURACY;
|
||||
if (location.hasVerticalAccuracy()) flags += FLAG_VERTICAL_ACCURACY;
|
||||
if (location.hasBearingAccuracy()) flags += FLAG_BEARING_ACCURACY;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next entry to encode sensor data.
|
||||
*
|
||||
* @return The next entry removed either from cache
|
||||
* or from the data segment.
|
||||
*/
|
||||
private long[] remove() {
|
||||
if (cache.size() > 0) {
|
||||
return cache.remove(cache.size() - 1);
|
||||
} else {
|
||||
return data.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last location since the
|
||||
* flush.
|
||||
*
|
||||
* @return The location.
|
||||
*/
|
||||
public ReleasedLocation getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the current sensor data as a string.
|
||||
*
|
||||
* @return The sensor data.
|
||||
*/
|
||||
public String encode() {
|
||||
return codec.encode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the sensor data buffer.
|
||||
*/
|
||||
public void flush() {
|
||||
cache.addAll(data);
|
||||
data.clear();
|
||||
location = new ReleasedLocation();
|
||||
location.setTimestamp(System.currentTimeMillis());
|
||||
location.setAvailability(ReleasedLocation.AvailabilityEnum.UNABLE);
|
||||
location.setSharable(isSharable());
|
||||
location.setAnalyzable(isAnalyzable());
|
||||
location.setVersion((int)getVersion());
|
||||
location.setProvider(provider);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the listener is registered.
|
||||
*
|
||||
* @return True if registered, false otherwise.
|
||||
*/
|
||||
public boolean isRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag to indicate whether the listener is registered.
|
||||
*
|
||||
* @param registered True if registered, false otherwise.
|
||||
*/
|
||||
public void setRegistered(boolean registered) {
|
||||
this.registered = registered;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A listener for sensor data that performs delta encoding.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
private static class SensorListener implements SensorEventListener {
|
||||
|
||||
/**
|
||||
* The delta codec.
|
||||
*/
|
||||
private DeltaCodec codec;
|
||||
/**
|
||||
* The precision.
|
||||
*/
|
||||
private double multiplier;
|
||||
|
||||
/**
|
||||
* The unused data items.
|
||||
*/
|
||||
private List<long[]> cache;
|
||||
|
||||
/**
|
||||
* The used data items.
|
||||
*/
|
||||
private List<long[]> data;
|
||||
|
||||
/**
|
||||
* A flag to indicate whether the listener is registered.
|
||||
*/
|
||||
private boolean registered;
|
||||
|
||||
/**
|
||||
* Creates a new sensor listener that will buffer
|
||||
* at most limit values
|
||||
*
|
||||
* @param length The length of the senor data generated
|
||||
* by the sensor. For a 3D sensor, this would be 3.
|
||||
* @param precision The precision of the sensor data in
|
||||
* decimal digits. For encoding, the data will be multiplied
|
||||
* with 10^precision. Thus, for decoding, the data must
|
||||
* be divided by the same precision.
|
||||
* @param limit The maximum number of elements to keep in
|
||||
* the buffer.
|
||||
*/
|
||||
public SensorListener(int length, int precision, int limit) {
|
||||
multiplier = Math.pow(10, precision);
|
||||
// timestamp, accuracy, values
|
||||
int values = Math.max(1, limit);
|
||||
cache = new ArrayList<>(values);
|
||||
data = new ArrayList<>(values);
|
||||
codec = new DeltaCodec(2 + length);
|
||||
for (int i = 0; i < values; i++) {
|
||||
cache.add(new long[2 + length]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// nothing to be done
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
if (data.size() > 0) {
|
||||
long prev = data.get(data.size() - 1)[0];
|
||||
long diff = event.timestamp / 1000 - prev;
|
||||
if (diff / 1000 < SAMPLING_DELAY_SENSOR) return;
|
||||
}
|
||||
|
||||
|
||||
long[] next = remove();
|
||||
next[0] = event.timestamp / 1000;
|
||||
next[1] = event.accuracy;
|
||||
for (int i = 0, s = event.values.length; i < s; i++) {
|
||||
next[2 + i] = Math.round(event.values[i] * multiplier);
|
||||
}
|
||||
data.add(next);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the next entry to encode sensor data.
|
||||
*
|
||||
* @return The next entry removed either from cache
|
||||
* or from the data segment.
|
||||
*/
|
||||
private long[] remove() {
|
||||
if (cache.size() > 0) {
|
||||
return cache.remove(cache.size() - 1);
|
||||
} else {
|
||||
return data.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the current sensor data.
|
||||
*
|
||||
* @return The sensor data.
|
||||
*/
|
||||
public String encode() {
|
||||
Log.d(TAG, "Data size is: " + data.size());
|
||||
return codec.encode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the sensor data buffer.
|
||||
*/
|
||||
public void flush() {
|
||||
cache.addAll(data);
|
||||
data.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the listener is registered.
|
||||
*
|
||||
* @return True if registered, false otherwise.
|
||||
*/
|
||||
public boolean isRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag to indicate whether the listener is registered.
|
||||
*
|
||||
* @param registered True if registered, false otherwise.
|
||||
*/
|
||||
public void setRegistered(boolean registered) {
|
||||
this.registered = registered;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.maptology.android.app;
|
||||
|
||||
import com.maptology.android.app.fragment.LoginFragment;
|
||||
import com.maptology.android.app.fragment.AbstractLoginFragment;
|
||||
import com.maptology.android.app.fragment.LoginCreateFragment;
|
||||
import com.maptology.android.app.fragment.LoginUpdateFragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
/**
|
||||
* The activity to login or create a device. The
|
||||
@@ -23,11 +25,25 @@ public class LoginActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_login);
|
||||
Fragment f = getSupportFragmentManager().findFragmentById(R.id.coordinator);
|
||||
if (f == null) {
|
||||
// do everything in the fragment
|
||||
AbstractLoginFragment loginFragment = null;
|
||||
if (getApp().getRepository().deviceHandle.getValue() == null) {
|
||||
loginFragment = new LoginCreateFragment();
|
||||
} else {
|
||||
loginFragment = new LoginUpdateFragment();
|
||||
}
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.coordinator, new LoginFragment());
|
||||
ft.replace(R.id.coordinator, loginFragment);
|
||||
ft.commit();
|
||||
}
|
||||
}
|
||||
|
||||
private MaptologyApp getApp() {
|
||||
return (MaptologyApp) getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (isFinishing()) getApp().getRepository().creatingDevice.setValue(null);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.maptology.android.app;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.maptology.android.app.fragment.GrantListFragment;
|
||||
import com.maptology.android.app.fragment.ManageFragment;
|
||||
import com.maptology.android.app.fragment.MapFragment;
|
||||
@@ -10,6 +12,7 @@ import com.maptology.android.app.fragment.ShareListFragment;
|
||||
import com.maptology.android.app.fragment.TermsFragment;
|
||||
import com.maptology.android.app.model.LocalShare;
|
||||
import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.UpdateUserTask;
|
||||
import com.maptology.android.app.util.TabletUtil;
|
||||
@@ -18,19 +21,28 @@ import com.maptology.android.feign.model.User;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.PermissionChecker;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -86,6 +98,36 @@ public class MainActivity extends AppCompatActivity implements
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the visibility of the menu items based on the login state.
|
||||
*/
|
||||
private IValueListener<DeviceHandle> deviceListener = new IValueListener<DeviceHandle>() {
|
||||
@Override
|
||||
public void onValueChanged(Value<DeviceHandle> source, DeviceHandle oldValue, DeviceHandle newValue) {
|
||||
if (newValue != null) {
|
||||
MenuItem webapp = navigationView.getMenu().findItem(R.id.menu_webapp);
|
||||
MenuItem connect = navigationView.getMenu().findItem(R.id.menu_connect);
|
||||
connect.setVisible(newValue.getUser() == null);
|
||||
webapp.setVisible(newValue.getUser() != null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A listener that performs a permission check whenever the user enables localization.
|
||||
*/
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener preferenceListener =new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (Repository.KEY_PRIVACY_LOCALIZE.equals(key)) {
|
||||
if (sharedPreferences.getBoolean(key, false)) {
|
||||
checkPermissions();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Navigation Drawer menu.
|
||||
*/
|
||||
@@ -105,11 +147,17 @@ public class MainActivity extends AppCompatActivity implements
|
||||
*/
|
||||
private MaptologyApp app;
|
||||
|
||||
/**
|
||||
* The preferences to keep on watching the localization state.
|
||||
*/
|
||||
private SharedPreferences prefs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = (MaptologyApp) getApplicationContext();
|
||||
LocationService.runService(this);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
AbstractService.runService(this);
|
||||
setTitle(R.string.application_short);
|
||||
if (TabletUtil.isLandscapeTablet(this)) {
|
||||
setContentView(R.layout.activity_main_tablet);
|
||||
@@ -120,7 +168,6 @@ public class MainActivity extends AppCompatActivity implements
|
||||
setScreen(Screen.MAP);
|
||||
}
|
||||
createNavigationDrawer();
|
||||
checkPermissions();
|
||||
new UpdateUserTask(app).execute();
|
||||
}
|
||||
|
||||
@@ -128,10 +175,14 @@ public class MainActivity extends AppCompatActivity implements
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
app.getRepository().user.addValueListener(userListener, true);
|
||||
app.getRepository().deviceHandle.addValueListener(deviceListener, true);
|
||||
prefs.registerOnSharedPreferenceChangeListener(preferenceListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
prefs.unregisterOnSharedPreferenceChangeListener(preferenceListener);
|
||||
app.getRepository().deviceHandle.removeValueListener(deviceListener);
|
||||
app.getRepository().user.removeValueListener(userListener);
|
||||
super.onPause();
|
||||
}
|
||||
@@ -151,29 +202,23 @@ public class MainActivity extends AppCompatActivity implements
|
||||
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_notice:
|
||||
setScreen(Screen.NOTICE);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_map:
|
||||
setScreen(Screen.MAP);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_share:
|
||||
createShare();
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_manage:
|
||||
setScreen(Screen.MANAGE);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_settings:
|
||||
showSettings();
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.menu_notice) {
|
||||
setScreen(Screen.NOTICE);
|
||||
} else if (itemId == R.id.menu_map) {
|
||||
setScreen(Screen.MAP);
|
||||
} else if (itemId == R.id.menu_share) {
|
||||
createShare();
|
||||
} else if (itemId == R.id.menu_manage) {
|
||||
setScreen(Screen.MANAGE);
|
||||
} else if (itemId == R.id.menu_settings) {
|
||||
showSettings();
|
||||
} else if (itemId == R.id.menu_connect) {
|
||||
showLogin();
|
||||
} else if (itemId == R.id.menu_webapp) {
|
||||
showPlaces();
|
||||
}
|
||||
closeDrawerIfNeeded();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -216,7 +261,6 @@ public class MainActivity extends AppCompatActivity implements
|
||||
super.onDrawerClosed(view);
|
||||
setTitle(R.string.application_short);
|
||||
}
|
||||
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
setTitle(R.string.drawer_title);
|
||||
@@ -242,30 +286,91 @@ public class MainActivity extends AppCompatActivity implements
|
||||
* Method to request location permission for the app.
|
||||
*/
|
||||
private void checkPermissions() {
|
||||
boolean permissionGranted = PermissionChecker.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
||||
PermissionChecker.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
if (!permissionGranted) {
|
||||
Log.d(TAG, "Requesting permissions.");
|
||||
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, CODE_REQUEST_PERMISSIONS);
|
||||
if (! app.getRepository().isLocalizable()) return;
|
||||
boolean coarse = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
boolean fine = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
if (!(coarse && fine)) {
|
||||
Log.d(TAG, "Requesting foreground localization.");
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
PermissionDialogFragment dialog = new PermissionDialogFragment();
|
||||
dialog.setForeground(true);
|
||||
getSupportFragmentManager().beginTransaction().add(dialog, "foreground").commit();
|
||||
} else {
|
||||
requestForegroundLocalization();
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||
boolean background = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
if (!background){
|
||||
Log.d(TAG, "Requesting background localization.");
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
|
||||
PermissionDialogFragment dialog = new PermissionDialogFragment();
|
||||
dialog.setForeground(false);
|
||||
getSupportFragmentManager().beginTransaction().add(dialog, "background").commit();
|
||||
} else {
|
||||
requestBackgroundLocalization();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the foreground localization permission.
|
||||
*/
|
||||
private void requestForegroundLocalization() {
|
||||
ActivityCompat.requestPermissions(this, new String[] {
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION
|
||||
}, CODE_REQUEST_PERMISSIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request background localization permission.
|
||||
*/
|
||||
private void requestBackgroundLocalization() {
|
||||
ActivityCompat.requestPermissions(this, new String[] {
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
||||
}, CODE_REQUEST_PERMISSIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the localization request.
|
||||
*/
|
||||
private void cancelLocalization() {
|
||||
app.getRepository().setLocalizable(false);
|
||||
AbstractService.stopServices(this);
|
||||
Snackbar.make(findViewById(R.id.coordinator), R.string.permission_missing,
|
||||
Snackbar.LENGTH_LONG).setAction(R.string.permission_configure, v -> {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivity(intent);
|
||||
}).show();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method handles the requested permission (whether it was given or not).
|
||||
*
|
||||
* @param requestCode requestCode identifies requested permission
|
||||
* @param permissions permissions The permissions.
|
||||
* @param grantResults results The results for the permissions.
|
||||
* @param requestCode Identifies requested permission.
|
||||
* @param permissions The permissions.
|
||||
* @param grantResults The results for the permissions.
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
switch (requestCode) {
|
||||
case CODE_REQUEST_PERMISSIONS: {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (int i = 0, s = Math.min(permissions.length, grantResults.length); i < s; i++) {
|
||||
b.append(permissions[i] + " " + (grantResults[i] == PackageManager.PERMISSION_GRANTED) + "\n");
|
||||
boolean granted = true;
|
||||
for (int i = 0; i < grantResults.length; i++) {
|
||||
boolean value = grantResults[i] == PackageManager.PERMISSION_GRANTED;
|
||||
granted &= value;
|
||||
Log.d(TAG, permissions[i] + ": " + value);
|
||||
}
|
||||
Log.d(TAG, "All permissions granted: " + granted);
|
||||
if (!granted) {
|
||||
cancelLocalization();
|
||||
} else {
|
||||
checkPermissions();
|
||||
}
|
||||
Log.d(TAG, "Permission result:\n" + b.toString());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -348,6 +453,16 @@ public class MainActivity extends AppCompatActivity implements
|
||||
showSlave(new SettingsFragment());
|
||||
}
|
||||
|
||||
private void showLogin() {
|
||||
startActivity(new Intent(this, LoginActivity.class));
|
||||
}
|
||||
|
||||
private void showPlaces() {
|
||||
// start browser to goto places
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.maptology_url_places)));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void showSlave(Fragment fragment) {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.container, fragment);
|
||||
@@ -383,4 +498,46 @@ public class MainActivity extends AppCompatActivity implements
|
||||
MANAGE
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A dialog to explain the permissions.
|
||||
*/
|
||||
public static class PermissionDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Marks the fragment either as foreground or background.
|
||||
*
|
||||
* @param foreground True for foreground, false for background.
|
||||
*/
|
||||
public void setForeground(boolean foreground) {
|
||||
Bundle b = new Bundle();
|
||||
b.putBoolean("foreground", foreground);
|
||||
setArguments(b);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
boolean foreground = getArguments().getBoolean("foreground");
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
|
||||
builder.setTitle(R.string.permission_required);
|
||||
builder.setMessage(foreground ? R.string.permission_foreground_explain : R.string.permission_background_explain);
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
if (foreground) {
|
||||
((MainActivity)getActivity()).requestForegroundLocalization();
|
||||
} else {
|
||||
((MainActivity)getActivity()).requestBackgroundLocalization();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
builder.setOnCancelListener(dialog -> ((MainActivity)getActivity()).cancelLocalization());
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.maptology.android.app;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.maptology.android.app.location.LocationStore;
|
||||
import com.maptology.android.app.notice.NoticeStore;
|
||||
@@ -16,7 +19,7 @@ import com.maptology.android.feign.model.Message;
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
@@ -76,10 +79,13 @@ public class MaptologyApp extends Application {
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (Repository.KEY_PRIVACY_LOCALIZE.equals(key)) {
|
||||
if (sharedPreferences.getBoolean(key, false)) {
|
||||
LocationService.runService(MaptologyApp.this);
|
||||
AbstractService.runService(MaptologyApp.this);
|
||||
} else {
|
||||
LocationService.stopService(MaptologyApp.this);
|
||||
AbstractService.stopServices(MaptologyApp.this);
|
||||
}
|
||||
} else if (Repository.KEY_PRIVACY_LOGGABLE.equals(key)) {
|
||||
AbstractService.stopServices(MaptologyApp.this);
|
||||
AbstractService.runService(MaptologyApp.this);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -195,6 +201,19 @@ public class MaptologyApp extends Application {
|
||||
ApiClient client = new ApiClient();
|
||||
client.setBasePath(getMaptologyUrl());
|
||||
client.addAuthorization("basic", new BasicAuthRequestInterceptor(username, password));
|
||||
if (repository.deviceHandle.getValue() != null) {
|
||||
final String token = repository.deviceHandle.getValue().getToken();
|
||||
client.addAuthorization("bearer", new RequestInterceptor() {
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
Collection<String> headers = requestTemplate.headers().get("Authorization");
|
||||
List<String> newHeaders = new ArrayList<>();
|
||||
if (headers != null) newHeaders.addAll(headers);
|
||||
newHeaders.add("Bearer " + token);
|
||||
requestTemplate.header("Authorization", newHeaders);
|
||||
}
|
||||
});
|
||||
}
|
||||
return client.buildClient(DefaultApi.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,13 @@ import com.maptology.android.app.fragment.TermsFragment;
|
||||
import com.maptology.android.app.model.Grant;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.maptology.android.app;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A broadcast receiver that receives messages on package replacements.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class UpdateReceiver extends BroadcastReceiver {
|
||||
|
||||
/**
|
||||
* The log tag for this class.
|
||||
*/
|
||||
private static final String TAG = "UpdateReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// should not happen but nobody likes crashing apps in background
|
||||
if (intent == null || context == null) return;
|
||||
Log.d(TAG, "Received an intent with action " + intent.getAction() + ".");
|
||||
if (context.getApplicationContext() instanceof MaptologyApp) {
|
||||
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
|
||||
Log.d(TAG, "Restarting services due to my package replacement.");
|
||||
NoticeReceiver.schedulePeriodicSync((MaptologyApp)context.getApplicationContext());
|
||||
AbstractService.runService(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.maptology.android.app.util.DateFormatter;
|
||||
import com.maptology.android.feign.model.Location;
|
||||
import com.maptology.android.feign.model.ShareInfo;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@@ -184,7 +184,7 @@ public class DetailViewHolder extends RecyclerView.ViewHolder {
|
||||
setText(positionText, null, positionLine);
|
||||
if (share.getExpirationTime() < System.currentTimeMillis()) {
|
||||
statusImage.setImageResource(R.drawable.ic_alarm_off_black_48dp);
|
||||
} else if (share.getPaused()) {
|
||||
} else if (share.isPaused()) {
|
||||
statusImage.setImageResource(R.drawable.ic_pause_black_48dp);
|
||||
} else {
|
||||
statusImage.setImageResource(R.drawable.ic_share_black_48dp);
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.maptology.android.app.model.Grant;
|
||||
import com.maptology.android.app.share.ShareStore;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.maptology.android.app.notice.NoticeContract;
|
||||
import com.maptology.android.app.util.DateFormatter;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.maptology.android.app.model.LocalShare;
|
||||
import com.maptology.android.app.share.ShareStore;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.maptology.android.app.MaptologyApp;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,72 +1,82 @@
|
||||
package com.maptology.android.app.fragment;
|
||||
|
||||
import com.maptology.android.app.MainActivity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.maptology.android.app.R;
|
||||
import com.maptology.android.app.repository.AsyncError;
|
||||
import com.maptology.android.app.repository.AsyncInteraction;
|
||||
import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.CreateDeviceTask;
|
||||
import com.maptology.android.feign.model.DeviceHandle;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Fragment that handles the login.
|
||||
* A base class for fragment that handle the login.
|
||||
*
|
||||
* @author sarah
|
||||
*/
|
||||
public class LoginFragment extends AbstractFragment {
|
||||
|
||||
/**
|
||||
* The listener that keeps track of the device creation.
|
||||
*/
|
||||
private IValueListener<DeviceHandle> deviceListener = new IValueListener<DeviceHandle>() {
|
||||
@Override
|
||||
public void onValueChanged(Value<DeviceHandle> source, DeviceHandle oldValue, DeviceHandle newValue) {
|
||||
if (newValue != null) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(getActivity(), MainActivity.class);
|
||||
getActivity().startActivity(intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
public abstract class AbstractLoginFragment extends AbstractFragment {
|
||||
|
||||
private Button loginButton;
|
||||
private Button noLoginButton;
|
||||
private ImageButton passwordButton;
|
||||
private TextView registerText;
|
||||
private EditText usernameText;
|
||||
private EditText passwordText;
|
||||
private AlertDialog dialog;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
private int title;
|
||||
private int explanation;
|
||||
private int login;
|
||||
private boolean passwordVisible = false;
|
||||
|
||||
/**
|
||||
* The listener that listens to changes announced by the async task.
|
||||
*/
|
||||
private IValueListener<AsyncInteraction> creationListener = new IValueListener<AsyncInteraction>() {
|
||||
private IValueListener<AsyncInteraction> loginListener = new IValueListener<AsyncInteraction>() {
|
||||
@Override
|
||||
public void onValueChanged(Value<AsyncInteraction> source, AsyncInteraction oldValue, AsyncInteraction newValue) {
|
||||
onUpdateInteraction(newValue);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a login fragment with the specified title resource,
|
||||
* explanation resource and login button resource.
|
||||
*
|
||||
* @param title The string resource with the title.
|
||||
* @param explanation The string resource with the explanation.
|
||||
* @param login The string resource with the login button.
|
||||
*/
|
||||
public AbstractLoginFragment(int title, int explanation, int login) {
|
||||
this.title = title;
|
||||
this.explanation = explanation;
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.fragment_login, container, false);
|
||||
TextView titleView = (TextView)view.findViewById(R.id.login_title);
|
||||
titleView.setText(title);
|
||||
TextView explainView = (TextView)view.findViewById(R.id.login_explain);
|
||||
explainView.setText(explanation);
|
||||
loginButton = (Button) view.findViewById(R.id.button_login);
|
||||
loginButton.setText(login);
|
||||
noLoginButton = (Button) view.findViewById(R.id.button_no_login);
|
||||
registerText = (TextView) view.findViewById(R.id.text_register);
|
||||
usernameText = (EditText) view.findViewById(R.id.input_username);
|
||||
@@ -77,7 +87,6 @@ public class LoginFragment extends AbstractFragment {
|
||||
public void onClick(View v) {
|
||||
String username = usernameText.getText().toString();
|
||||
String password = passwordText.getText().toString();
|
||||
|
||||
username = analyzeInput(username);
|
||||
password = analyzeInput(password);
|
||||
if (username == null || password == null) {
|
||||
@@ -85,19 +94,22 @@ public class LoginFragment extends AbstractFragment {
|
||||
builder.setMessage(R.string.login_failed_msg);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.create().show();
|
||||
return;
|
||||
} else {
|
||||
onLogin(username, password);
|
||||
}
|
||||
|
||||
CreateDeviceTask task = new CreateDeviceTask(getApp(), username, password);
|
||||
task.execute();
|
||||
}
|
||||
});
|
||||
passwordButton = (ImageButton) view.findViewById(R.id.button_password);
|
||||
passwordButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setPasswordVisible(!passwordVisible);
|
||||
}
|
||||
});
|
||||
noLoginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getApp().getRepository().setAnalyzeable(false);
|
||||
CreateDeviceTask task = new CreateDeviceTask(getApp());
|
||||
task.execute();
|
||||
onContinue();
|
||||
}
|
||||
});
|
||||
registerText.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -111,6 +123,10 @@ public class LoginFragment extends AbstractFragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
public abstract void onLogin(String username, String password);
|
||||
|
||||
public abstract void onContinue();
|
||||
|
||||
private void onUpdateInteraction(AsyncInteraction interaction) {
|
||||
if (interaction == null) {
|
||||
setEnabled(true);
|
||||
@@ -151,6 +167,17 @@ public class LoginFragment extends AbstractFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void setPasswordVisible(boolean visible) {
|
||||
if (visible) {
|
||||
passwordButton.setImageResource(R.drawable.ic_visibility_off_black_24dp);
|
||||
passwordText.setTransformationMethod(null);
|
||||
} else {
|
||||
passwordButton.setImageResource(R.drawable.ic_visibility_black_24dp);
|
||||
passwordText.setTransformationMethod(new PasswordTransformationMethod());
|
||||
}
|
||||
this.passwordVisible = visible;
|
||||
}
|
||||
|
||||
private void setEnabled(boolean enabled) {
|
||||
loginButton.setEnabled(enabled);
|
||||
noLoginButton.setEnabled(enabled);
|
||||
@@ -158,6 +185,7 @@ public class LoginFragment extends AbstractFragment {
|
||||
usernameText.setEnabled(enabled);
|
||||
passwordText.setEnabled(enabled);
|
||||
progressBar.setVisibility(enabled?View.GONE:View.VISIBLE);
|
||||
if (!enabled) setPasswordVisible(false);
|
||||
}
|
||||
|
||||
private String analyzeInput(String input) {
|
||||
@@ -172,15 +200,13 @@ public class LoginFragment extends AbstractFragment {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Repository repository = getRepository();
|
||||
repository.creatingDevice.addValueListener(creationListener, true);
|
||||
repository.deviceHandle.addValueListener(deviceListener, true);
|
||||
repository.creatingDevice.addValueListener(loginListener, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
Repository repository = getRepository();
|
||||
repository.deviceHandle.removeValueListener(deviceListener);
|
||||
repository.creatingDevice.removeValueListener(creationListener);
|
||||
repository.creatingDevice.removeValueListener(loginListener);
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.maptology.android.app.fragment;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
/**
|
||||
* A simple dialog with a date picker.
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.maptology.android.app.map.MapMode;
|
||||
import com.maptology.android.app.model.Grant;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -7,13 +7,13 @@ import com.maptology.android.app.R;
|
||||
import com.maptology.android.app.model.Grant;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -15,10 +15,10 @@ import com.maptology.android.app.util.TabletUtil;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -132,7 +132,7 @@ public class GrantListFragment extends AbstractFragment {
|
||||
explainText = view.findViewById(R.id.fragment_list_grant_explain);
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.grant_recycler);
|
||||
int span = (TabletUtil.isLandscapeTablet(view.getContext()))?2:1;
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), span));
|
||||
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(span, StaggeredGridLayoutManager.VERTICAL));
|
||||
swipeRefreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.fragment_grant_swipe);
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.maptology.android.app.fragment;
|
||||
|
||||
import com.maptology.android.app.MainActivity;
|
||||
import com.maptology.android.app.R;
|
||||
import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.CreateDeviceTask;
|
||||
import com.maptology.android.feign.model.DeviceHandle;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
/**
|
||||
* Fragment that handles the login.
|
||||
*
|
||||
* @author sarah
|
||||
*/
|
||||
public class LoginCreateFragment extends AbstractLoginFragment {
|
||||
|
||||
/**
|
||||
* The listener that keeps track of the device creation.
|
||||
*/
|
||||
private IValueListener<DeviceHandle> deviceListener = new IValueListener<DeviceHandle>() {
|
||||
@Override
|
||||
public void onValueChanged(Value<DeviceHandle> source, DeviceHandle oldValue, DeviceHandle newValue) {
|
||||
if (newValue != null) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(getActivity(), MainActivity.class);
|
||||
getActivity().startActivity(intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the fragment and sets the strings.
|
||||
*/
|
||||
public LoginCreateFragment() {
|
||||
super(R.string.login_title_create, R.string.login_explain_create, R.string.login_button_create);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogin(String username, String password) {
|
||||
CreateDeviceTask task = new CreateDeviceTask(getApp(), username, password);
|
||||
task.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContinue() {
|
||||
getApp().getRepository().setAnalyzeable(false);
|
||||
CreateDeviceTask task = new CreateDeviceTask(getApp());
|
||||
task.execute();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Repository repository = getRepository();
|
||||
repository.deviceHandle.addValueListener(deviceListener, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
Repository repository = getRepository();
|
||||
repository.deviceHandle.removeValueListener(deviceListener);
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.maptology.android.app.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.maptology.android.app.MainActivity;
|
||||
import com.maptology.android.app.R;
|
||||
import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.UpdateDeviceTask;
|
||||
import com.maptology.android.feign.model.DeviceHandle;
|
||||
|
||||
/**
|
||||
* A fragment that enables the user to associate an existing device
|
||||
* with an account.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class LoginUpdateFragment extends AbstractLoginFragment {
|
||||
|
||||
/**
|
||||
* The listener that keeps track of the device updates.
|
||||
*/
|
||||
private IValueListener<DeviceHandle> deviceListener = new IValueListener<DeviceHandle>() {
|
||||
@Override
|
||||
public void onValueChanged(Value<DeviceHandle> source, DeviceHandle oldValue, DeviceHandle newValue) {
|
||||
if (newValue != null && newValue.getUser() != null) {
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the fragment and sets the strings.
|
||||
*/
|
||||
public LoginUpdateFragment() {
|
||||
super(R.string.login_title_update, R.string.login_explain_update, R.string.login_button_update);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogin(String username, String password) {
|
||||
UpdateDeviceTask task = new UpdateDeviceTask(getApp(), username, password);
|
||||
task.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContinue() {
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Repository repository = getRepository();
|
||||
repository.deviceHandle.addValueListener(deviceListener, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
Repository repository = getRepository();
|
||||
repository.deviceHandle.removeValueListener(deviceListener);
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.maptology.android.app.fragment;
|
||||
import com.maptology.android.app.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -3,12 +3,12 @@ package com.maptology.android.app.fragment;
|
||||
import com.maptology.android.app.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.maptology.android.app.fragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.locoslab.android.leafless.IMapStateListener;
|
||||
import com.locoslab.android.leafless.ITouchListener;
|
||||
import com.locoslab.android.leafless.MapOptions;
|
||||
@@ -33,18 +33,16 @@ import com.maptology.android.feign.model.Coordinate;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.BottomSheetBehavior;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.collection.LongSparseArray;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
/**
|
||||
* A fragment that displays a map.
|
||||
@@ -290,7 +288,7 @@ public class MapFragment extends AbstractFragment {
|
||||
// apply the state
|
||||
getRepository().mapState.getValue().applyTo(map);
|
||||
// add a tile layer
|
||||
map.addLayer(new TileLayer(new TileLayerOptions("https://cloud.locoslab.com/carta/restful-services/tile/{z}/{x}/{y}.png")));
|
||||
map.addLayer(new TileLayer(new TileLayerOptions("https://www.maptology.com/carta/tile/{z}/{x}/{y}.png")));
|
||||
// add map interaction
|
||||
map.addShortTapListener(new ITouchListener() {
|
||||
@Override
|
||||
@@ -463,7 +461,7 @@ public class MapFragment extends AbstractFragment {
|
||||
getRepository().mapMode.setValue(MapMode.values()[code]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Applies the current map mode.
|
||||
*/
|
||||
|
||||
@@ -8,10 +8,10 @@ import com.maptology.android.app.task.SyncNoticeTask;
|
||||
import com.maptology.android.app.util.TabletUtil;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -89,7 +89,8 @@ public class NoticeListFragment extends AbstractFragment {
|
||||
swipeLayout.setOnRefreshListener(refreshListener);
|
||||
recyclerView = (RecyclerView)v.findViewById(R.id.fragment_notice_recycler);
|
||||
int span = (TabletUtil.isLandscapeTablet(v.getContext()))?2:1;
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), span));
|
||||
StaggeredGridLayoutManager glm = new StaggeredGridLayoutManager(span, StaggeredGridLayoutManager.VERTICAL);
|
||||
recyclerView.setLayoutManager(glm);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,31 +2,35 @@
|
||||
package com.maptology.android.app.fragment;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity;
|
||||
import com.maptology.android.app.BuildConfig;
|
||||
import com.maptology.android.app.MaptologyApp;
|
||||
import com.maptology.android.app.R;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
import com.maptology.android.feign.model.DeviceHandle;
|
||||
import com.maptology.android.feign.model.User;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.content.pm.PackageInfoCompat;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import androidx.core.content.pm.PackageInfoCompat;
|
||||
import androidx.preference.CheckBoxPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -50,6 +54,16 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
void showTerms();
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the scientist role that enables the data logger.
|
||||
*/
|
||||
private static final String ROLE_SCIENTIST = "scientist";
|
||||
|
||||
/**
|
||||
* The name of the admin role that enables the data logger.
|
||||
*/
|
||||
private static final String ROLE_ADMIN = "admin";
|
||||
|
||||
/**
|
||||
* The number of times a user must click the version button to switch
|
||||
* between developer mode and non-developer mode.
|
||||
@@ -71,6 +85,11 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
*/
|
||||
private static final String KEY_ABOUT_TERMS = "about_terms";
|
||||
|
||||
/**
|
||||
* The key to show the oss licenses.
|
||||
*/
|
||||
private static final String KEY_ABOUT_LICENSES = "about_licenses";
|
||||
|
||||
/**
|
||||
* Key to clear the cache.
|
||||
*/
|
||||
@@ -128,6 +147,18 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
*/
|
||||
private PreferenceGroup developmentGroup;
|
||||
|
||||
/**
|
||||
* A listener for shared preferences.
|
||||
*/
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener preferenceListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (Repository.KEY_PRIVACY_LOCALIZE.equals(key)) {
|
||||
updateLocalize();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
@@ -145,6 +176,10 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
bindReset();
|
||||
bindClear();
|
||||
bindTerms();
|
||||
bindLicenses();
|
||||
if (!isLoggerAvailable()) {
|
||||
disableLogger();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -159,6 +194,48 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(preferenceListener);
|
||||
updateLocalize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(preferenceListener);
|
||||
}
|
||||
|
||||
private void updateLocalize() {
|
||||
CheckBoxPreference p = findPreference(Repository.KEY_PRIVACY_LOCALIZE);
|
||||
if (p != null) {
|
||||
boolean state = getApp().getRepository().isLocalizable();
|
||||
if (p.isChecked() != state) {
|
||||
p.setChecked(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the logger switch is available.
|
||||
*
|
||||
* @return True if available, false otherwise.
|
||||
*/
|
||||
private boolean isLoggerAvailable() {
|
||||
User user = getRepository().user.getValue();
|
||||
if (user == null || user.getRoles() == null) return false;
|
||||
else return user.getRoles().contains(ROLE_ADMIN) || user.getRoles().contains(ROLE_SCIENTIST);
|
||||
}
|
||||
|
||||
private void disableLogger() {
|
||||
Preference logger = findPreference(Repository.KEY_PRIVACY_LOGGABLE);
|
||||
if (logger != null) {
|
||||
logger.getParent().removePreference(logger);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the version information by reading out the package version and
|
||||
* the build date of classes.dex.
|
||||
@@ -244,6 +321,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
* otherwise it will open the channel settings.
|
||||
* @return The preference listener to trigger the action.
|
||||
*/
|
||||
@TargetApi(26)
|
||||
private Preference.OnPreferenceClickListener createNotificationSettingsListener(final String packageName, final String channelId) {
|
||||
return new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
@@ -328,6 +406,17 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
}
|
||||
|
||||
|
||||
private void bindLicenses() {
|
||||
setClickListener(KEY_ABOUT_LICENSES, new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
OssLicensesMenuActivity.setActivityTitle(getString(R.string.setting_about_licenses_title));
|
||||
startActivity(new Intent(getApp(), OssLicensesMenuActivity.class));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the developmentGroup mode.
|
||||
*/
|
||||
|
||||
@@ -21,8 +21,8 @@ import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -344,7 +344,7 @@ public class ShareFragment extends AbstractFragment implements DatePickerDialog.
|
||||
expirationDateView.setText(format.asDate(share.getExpirationTime()));
|
||||
creationTimeView.setText(format.asTime(share.getCreationTime()));
|
||||
creationDateView.setText(format.asDate(share.getCreationTime()));
|
||||
pausedBox.setChecked(share.getPaused());
|
||||
pausedBox.setChecked(share.isPaused());
|
||||
messageText.setText(share.getMessage());
|
||||
messageText.setSelection(messageText.getText().length());
|
||||
messageText.clearFocus();
|
||||
|
||||
@@ -6,9 +6,9 @@ import com.maptology.android.app.model.LocalShare;
|
||||
import com.maptology.android.app.util.TabletUtil;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -81,7 +81,7 @@ public class ShareListFragment extends AbstractFragment {
|
||||
explainText = view.findViewById(R.id.fragment_list_share_explain);
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.share_recycler);
|
||||
int span = (TabletUtil.isLandscapeTablet(view.getContext()))?2:1;
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), span));
|
||||
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(span, StaggeredGridLayoutManager.VERTICAL));
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import android.net.MailTo;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -83,12 +83,18 @@ public class TermsFragment extends AbstractFragment {
|
||||
View acceptView = view.findViewById(R.id.fragment_terms_accept);
|
||||
acceptView.setVisibility(getRepository().isTermsAccepted()?View.GONE:View.VISIBLE);
|
||||
final CheckBox permissionCheckbox = (CheckBox) view.findViewById(R.id.permission_checkbox_start);
|
||||
Button continueButton = (Button) view.findViewById(R.id.start_button_continue);
|
||||
final Button continueButton = (Button) view.findViewById(R.id.start_button_continue);
|
||||
continueButton.setEnabled(permissionCheckbox.isChecked());
|
||||
permissionCheckbox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
continueButton.setEnabled(permissionCheckbox.isChecked());
|
||||
}
|
||||
});
|
||||
continueButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getRepository().setTermsAccepted(true);
|
||||
getRepository().setShareable(permissionCheckbox.isChecked());
|
||||
if (continueListener != null) continueListener.onClick(v);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.maptology.android.app.fragment;
|
||||
import android.app.Dialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
/**
|
||||
* A simple fragment that shows a time picker dialog.
|
||||
|
||||
@@ -11,7 +11,7 @@ public class LocationContract {
|
||||
/**
|
||||
* The table to store the released locations when they
|
||||
* are captured. This table is required to handle
|
||||
* transient network failsures.
|
||||
* transient network failures.
|
||||
*/
|
||||
public class Update {
|
||||
/**
|
||||
@@ -72,6 +72,33 @@ public class LocationContract {
|
||||
public static final String VERSION = "version";
|
||||
}
|
||||
|
||||
/**
|
||||
* The table to store the metadata for updates.
|
||||
*/
|
||||
public class Metadata {
|
||||
/**
|
||||
* The name of the table.
|
||||
*/
|
||||
public static final String TABLE = "location_metadata";
|
||||
/**
|
||||
* The id of the row.
|
||||
*/
|
||||
public static final String ID = "_id";
|
||||
/**
|
||||
* The id of the update to which this metadata refers to.
|
||||
*/
|
||||
public static final String UPDATE_ID = "update_id";
|
||||
/**
|
||||
* The tag describing the metadata type.
|
||||
*/
|
||||
public static final String TAG = "tag";
|
||||
/**
|
||||
* The value containing the actual data.
|
||||
*/
|
||||
public static final String VALUE = "value";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The table to store locations with their associated
|
||||
* networks so that we do not have to compute them
|
||||
@@ -150,7 +177,7 @@ public class LocationContract {
|
||||
/**
|
||||
* The db schema version.
|
||||
*/
|
||||
public static int VERSION = 6;
|
||||
public static int VERSION = 7;
|
||||
|
||||
/**
|
||||
* The name of the database.
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.maptology.android.app.notice.NoticeContract;
|
||||
|
||||
/**
|
||||
* Implements an sqlite open helper for the the location db.
|
||||
*
|
||||
@@ -99,6 +101,33 @@ public class LocationHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
private static String SQL_DROP_UPDATE = "DROP TABLE IF EXISTS " + LocationContract.Update.TABLE;
|
||||
|
||||
/**
|
||||
* Creates the metadata table.
|
||||
*/
|
||||
private static String SQL_CREATE_METADATA = "CREATE TABLE " + LocationContract.Metadata.TABLE + " ( "
|
||||
+ LocationContract.Metadata.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ LocationContract.Metadata.TAG + " TEXT, "
|
||||
+ LocationContract.Metadata.VALUE + " TEXT, "
|
||||
+ LocationContract.Metadata.UPDATE_ID + " INTEGER NOT NULL "
|
||||
+ "REFERENCES " + LocationContract.Update.TABLE + " ( " + LocationContract.Update.ID + " ) ON DELETE CASCADE"
|
||||
+ " )";
|
||||
|
||||
/**
|
||||
* Drops the metadata table.
|
||||
*/
|
||||
private static String SQL_DROP_METADATA = "DROP TABLE IF EXISTS " + LocationContract.Metadata.TABLE;
|
||||
|
||||
/**
|
||||
* Creates an index over the metadata update id to resolve the foreign key.
|
||||
*/
|
||||
private static String SQL_INDEX_METADATA_UI = "CREATE INDEX " + LocationContract.Metadata.TABLE + "_UI "
|
||||
+ "ON " + LocationContract.Metadata.TABLE + " ( " +LocationContract.Metadata.UPDATE_ID +" )";
|
||||
|
||||
/**
|
||||
* Drops the index on the metadata's update id.
|
||||
*/
|
||||
private static String SQL_DROP_METADATA_UI = "DROP INDEX IF EXISTS " + LocationContract.Metadata.TABLE + "_UI";
|
||||
|
||||
/**
|
||||
* Creates a new helper from the context.
|
||||
*
|
||||
@@ -130,11 +159,13 @@ public class LocationHelper extends SQLiteOpenHelper {
|
||||
try {
|
||||
// create tables
|
||||
db.execSQL(SQL_CREATE_UPDATE);
|
||||
db.execSQL(SQL_CREATE_METADATA);
|
||||
db.execSQL(SQL_CREATE_POSITION);
|
||||
db.execSQL(SQL_CREATE_NETWORK);
|
||||
// create indexes
|
||||
db.execSQL(SQL_INDEX_POSITION_UT);
|
||||
db.execSQL(SQL_INDEX_NETWORK_BS);
|
||||
db.execSQL(SQL_INDEX_METADATA_UI);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
@@ -153,20 +184,36 @@ public class LocationHelper extends SQLiteOpenHelper {
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
Log.d(TAG, "Migrating database from " + oldVersion + " to " + newVersion + ".");
|
||||
// a quite crude "upgrade" script
|
||||
db.beginTransaction();
|
||||
try {
|
||||
// drop indexes
|
||||
db.execSQL(SQL_DROP_NETWORK_BS);
|
||||
db.execSQL(SQL_DROP_POSITION_UT);
|
||||
// drop tables
|
||||
db.execSQL(SQL_DROP_NETWORK);
|
||||
db.execSQL(SQL_DROP_POSITION);
|
||||
db.execSQL(SQL_DROP_UPDATE);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
if (oldVersion == 6 && newVersion == 7) {
|
||||
// only add new table from 6 to 7
|
||||
db.beginTransaction();
|
||||
try {
|
||||
db.execSQL(SQL_CREATE_METADATA);
|
||||
db.execSQL(SQL_INDEX_METADATA_UI);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
} else {
|
||||
// otherwise recreate database
|
||||
db.beginTransaction();
|
||||
try {
|
||||
// drop indexes
|
||||
db.execSQL(SQL_DROP_METADATA_UI);
|
||||
db.execSQL(SQL_DROP_NETWORK_BS);
|
||||
db.execSQL(SQL_DROP_POSITION_UT);
|
||||
// drop tables
|
||||
db.execSQL(SQL_DROP_NETWORK);
|
||||
db.execSQL(SQL_DROP_POSITION);
|
||||
db.execSQL(SQL_DROP_METADATA);
|
||||
db.execSQL(SQL_DROP_UPDATE);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
// recreate everything
|
||||
onCreate(db);
|
||||
}
|
||||
// recreate everything
|
||||
onCreate(db);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.maptology.android.app.model;
|
||||
package com.maptology.android.app.location;
|
||||
|
||||
/**
|
||||
* A stored network.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class Network {
|
||||
public class LocationNetwork {
|
||||
|
||||
/**
|
||||
* The id in the database.
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.maptology.android.app.model;
|
||||
package com.maptology.android.app.location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class Position {
|
||||
public class LocationPosition {
|
||||
|
||||
/**
|
||||
* The id of the position.
|
||||
@@ -19,7 +19,7 @@ public class Position {
|
||||
/**
|
||||
* The networks of the position.
|
||||
*/
|
||||
private List<Network> networks = new ArrayList<>();
|
||||
private List<LocationNetwork> networks = new ArrayList<>();
|
||||
/**
|
||||
* The longitude of the position.
|
||||
*/
|
||||
@@ -72,7 +72,7 @@ public class Position {
|
||||
*
|
||||
* @return The list of networks.
|
||||
*/
|
||||
public List<Network> getNetworks() {
|
||||
public List<LocationNetwork> getNetworks() {
|
||||
return networks;
|
||||
}
|
||||
|
||||
@@ -209,13 +209,13 @@ public class Position {
|
||||
* @param maximumDeviation The maximum deviation to consider a network as matching.
|
||||
* @return The number of matching networks.
|
||||
*/
|
||||
public int getMatches(List<Network> networks, int maximumDeviation) {
|
||||
public int getMatches(List<LocationNetwork> networks, int maximumDeviation) {
|
||||
Map<String, Integer> bssids = new HashMap<>();
|
||||
for (Network n: this.networks) {
|
||||
for (LocationNetwork n: this.networks) {
|
||||
bssids.put(n.getBssid(), n.getRssi());
|
||||
}
|
||||
int count = 0;
|
||||
for (Network n: networks) {
|
||||
for (LocationNetwork n: networks) {
|
||||
if (bssids.containsKey(n.getBssid()) && Math.abs(n.getRssi() - bssids.get(n.getBssid())) <= maximumDeviation) {
|
||||
count += 1;
|
||||
}
|
||||
@@ -229,15 +229,15 @@ public class Position {
|
||||
* @param networks The networks.
|
||||
* @return The squared distance sum in vector space.
|
||||
*/
|
||||
public long getDistance(List<Network> networks) {
|
||||
Map<String, Network> nets = new HashMap<>();
|
||||
for (Network n: this.networks) {
|
||||
public long getDistance(List<LocationNetwork> networks) {
|
||||
Map<String, LocationNetwork> nets = new HashMap<>();
|
||||
for (LocationNetwork n: this.networks) {
|
||||
nets.put(n.getBssid(), n);
|
||||
}
|
||||
long distance = 0;
|
||||
for (Network n: networks) {
|
||||
for (LocationNetwork n: networks) {
|
||||
int rssiOut = -100;
|
||||
Network o = nets.get(n.getBssid());
|
||||
LocationNetwork o = nets.get(n.getBssid());
|
||||
if (o != null) {
|
||||
rssiOut = o.getRssi();
|
||||
}
|
||||
@@ -261,7 +261,7 @@ public class Position {
|
||||
b.append("ALTITUDE(" + altitude + ") ");
|
||||
b.append("ACCURACY(" + accuracy + ") ");
|
||||
b.append("NETWORKS( ");
|
||||
for (Network n: networks) {
|
||||
for (LocationNetwork n: networks) {
|
||||
b.append(n.toString());
|
||||
b.append(" ");
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.maptology.android.app.location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.maptology.android.app.model.Network;
|
||||
import com.maptology.android.app.model.Position;
|
||||
import com.maptology.android.feign.model.Coordinate;
|
||||
import com.maptology.android.feign.model.ReleasedLocation;
|
||||
|
||||
@@ -13,8 +13,8 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ public class LocationStore {
|
||||
*
|
||||
* @param p The position to add.
|
||||
*/
|
||||
public void addPosition(Position p) {
|
||||
public void addPosition(LocationPosition p) {
|
||||
if (db == null) return;
|
||||
db.beginTransaction();
|
||||
try {
|
||||
@@ -73,7 +73,7 @@ public class LocationStore {
|
||||
// get the position id
|
||||
p.setId(getPositionId());
|
||||
// add the networks
|
||||
for (Network n: p.getNetworks()) {
|
||||
for (LocationNetwork n: p.getNetworks()) {
|
||||
addNetwork(p.getId(), n);
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
@@ -100,6 +100,13 @@ public class LocationStore {
|
||||
return getCreatedId(LocationContract.Network.TABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last created update id.
|
||||
*
|
||||
* @return The last created update id.
|
||||
*/
|
||||
private long getUpdateId() { return getCreatedId(LocationContract.Update.TABLE); }
|
||||
|
||||
/**
|
||||
* Returns the last created id of the specified table.
|
||||
*
|
||||
@@ -123,7 +130,7 @@ public class LocationStore {
|
||||
* @param position The position.
|
||||
* @param n The network.
|
||||
*/
|
||||
private void addNetwork(long position, Network n) {
|
||||
private void addNetwork(long position, LocationNetwork n) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(LocationContract.Network.POSITION, position);
|
||||
values.put(LocationContract.Network.BSSID, n.getBssid());
|
||||
@@ -138,8 +145,8 @@ public class LocationStore {
|
||||
* @param position The position.
|
||||
* @return The list of networks.
|
||||
*/
|
||||
private List<Network> getNetworks(long position) {
|
||||
List<Network> result = new ArrayList<>();
|
||||
private List<LocationNetwork> getNetworks(long position) {
|
||||
List<LocationNetwork> result = new ArrayList<>();
|
||||
if (db == null) return result;
|
||||
Cursor c = db.query(LocationContract.Network.TABLE, new String[] {
|
||||
LocationContract.Network.ID,
|
||||
@@ -148,7 +155,7 @@ public class LocationStore {
|
||||
|
||||
}, LocationContract.Network.POSITION + " = " + position, null, null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
Network n = new Network();
|
||||
LocationNetwork n = new LocationNetwork();
|
||||
n.setId(c.getLong(0));
|
||||
n.setBssid(c.getString(1));
|
||||
n.setRssi(c.getInt(2));
|
||||
@@ -174,7 +181,7 @@ public class LocationStore {
|
||||
* @param updateNetworks True to update the networks, false
|
||||
* to update only the position.
|
||||
*/
|
||||
public void setPosition(Position p, boolean updateNetworks) {
|
||||
public void setPosition(LocationPosition p, boolean updateNetworks) {
|
||||
if (db == null) return;
|
||||
db.beginTransaction();
|
||||
try {
|
||||
@@ -189,7 +196,7 @@ public class LocationStore {
|
||||
db.update(LocationContract.Position.TABLE, values, LocationContract.Position.ID + " = " + p.getId(), null);
|
||||
if (updateNetworks) {
|
||||
removeNetworks(p.getId());
|
||||
for (Network n: p.getNetworks()) {
|
||||
for (LocationNetwork n: p.getNetworks()) {
|
||||
addNetwork(p.getId(), n);
|
||||
}
|
||||
}
|
||||
@@ -205,8 +212,8 @@ public class LocationStore {
|
||||
* @param id The id to load.
|
||||
* @return The position with its networks.
|
||||
*/
|
||||
public Position getPosition(long id) {
|
||||
Position result = null;
|
||||
public LocationPosition getPosition(long id) {
|
||||
LocationPosition result = null;
|
||||
if (db == null) return result;
|
||||
db.beginTransaction();
|
||||
try {
|
||||
@@ -221,7 +228,7 @@ public class LocationStore {
|
||||
LocationContract.Position.ID + " = " + id,
|
||||
null, null, null, null);
|
||||
if (c.moveToNext()) {
|
||||
result = new Position();
|
||||
result = new LocationPosition();
|
||||
result.setId(id);
|
||||
result.setLatitude(c.getDouble(0));
|
||||
result.setLongitude(c.getDouble(1));
|
||||
@@ -267,7 +274,7 @@ public class LocationStore {
|
||||
* @param maximumDeviation The maximum deviation of rssi values to consider a network matching.
|
||||
* @return The position or null, if no match is good enough.
|
||||
*/
|
||||
public Position findPosition(List<Network> networks, int minimumMatching, int maximumDeviation) {
|
||||
public LocationPosition findPosition(List<LocationNetwork> networks, int minimumMatching, int maximumDeviation) {
|
||||
if (networks.size() == 0 || networks.size() < minimumMatching) return null;
|
||||
if (db == null) return null;
|
||||
StringBuilder b = new StringBuilder();
|
||||
@@ -279,7 +286,7 @@ public class LocationStore {
|
||||
b.append(", ");
|
||||
}
|
||||
}
|
||||
Position best = null;
|
||||
LocationPosition best = null;
|
||||
int matches = 0;
|
||||
double distance = 0;
|
||||
db.beginTransaction();
|
||||
@@ -289,7 +296,7 @@ public class LocationStore {
|
||||
LocationContract.Network.BSSID + " IN (" + b.toString() + ")",
|
||||
null, null, null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
Position p = getPosition(c.getLong(0));
|
||||
LocationPosition p = getPosition(c.getLong(0));
|
||||
if (p != null) {
|
||||
long d = p.getDistance(networks);
|
||||
int m = p.getMatches(networks, maximumDeviation);
|
||||
@@ -356,10 +363,29 @@ public class LocationStore {
|
||||
values.put(LocationContract.Update.ACCURACY, location.getAccuracy());
|
||||
values.put(LocationContract.Update.BEARING, location.getBearing());
|
||||
values.put(LocationContract.Update.SPEED, location.getSpeed());
|
||||
values.put(LocationContract.Update.ANALYZABLE, location.getAnalyzable()==null?0:(location.getAnalyzable()?1:0));
|
||||
values.put(LocationContract.Update.SHARABLE, location.getSharable()==null?0:(location.getSharable()?1:0));
|
||||
values.put(LocationContract.Update.ANALYZABLE, location.isAnalyzable()==null?0:(location.isAnalyzable()?1:0));
|
||||
values.put(LocationContract.Update.SHARABLE, location.isSharable()==null?0:(location.isSharable()?1:0));
|
||||
values.put(LocationContract.Update.VERSION, location.getVersion()==null?0:location.getVersion());
|
||||
db.insert(LocationContract.Update.TABLE, null, values);
|
||||
addMetadata(getUpdateId(), location.getMetadata());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the meta for the update id.
|
||||
*
|
||||
* @param updateId The update id.
|
||||
* @param metadata The metadata to store.
|
||||
*/
|
||||
private void addMetadata(long updateId, Map<String, String> metadata) {
|
||||
if (metadata != null) {
|
||||
for (Map.Entry<String, String> entry: metadata.entrySet()) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(LocationContract.Metadata.UPDATE_ID, updateId);
|
||||
values.put(LocationContract.Metadata.TAG, entry.getKey());
|
||||
values.put(LocationContract.Metadata.VALUE, entry.getValue());
|
||||
db.insert(LocationContract.Metadata.TABLE, null, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,11 +431,35 @@ public class LocationStore {
|
||||
cor.setLongitude(c.getDouble(11));
|
||||
r.setCoordinate(cor);
|
||||
}
|
||||
r.setMetadata(getMetadata(id));
|
||||
}
|
||||
c.close();;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metadata stored for the update.
|
||||
*
|
||||
* @param updateId The update id.
|
||||
* @return The metadata (never null).
|
||||
*/
|
||||
private Map<String, String> getMetadata(long updateId) {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
if (db == null) return result;
|
||||
Cursor c = db.query(LocationContract.Metadata.TABLE, new String[]{
|
||||
LocationContract.Metadata.TAG,
|
||||
LocationContract.Metadata.VALUE
|
||||
}, LocationContract.Metadata.UPDATE_ID + " = " + updateId, null, null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
String tag = c.isNull(0)?null:c.getString(0);
|
||||
String value = c.isNull(1)?null:c.getString(1);
|
||||
result.put(tag, value);
|
||||
}
|
||||
c.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the update with the specified id.
|
||||
*
|
||||
@@ -418,6 +468,17 @@ public class LocationStore {
|
||||
public void removeUpdate(long id) {
|
||||
if (db == null) return;
|
||||
db.execSQL("DELETE FROM " + LocationContract.Update.TABLE + " WHERE " + LocationContract.Update.ID + " = " + id);
|
||||
removeMetadata(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the metadata fr the update with the specified id.
|
||||
*
|
||||
* @param updateId The id of the update.
|
||||
*/
|
||||
private void removeMetadata(long updateId) {
|
||||
if (db == null) return;
|
||||
db.execSQL("DELETE FROM " + LocationContract.Metadata.TABLE + " WHERE " + LocationContract.Metadata.UPDATE_ID + " = " + updateId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,6 +508,13 @@ public class LocationStore {
|
||||
return getCount(LocationContract.Network.TABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of entries in the metadata table.
|
||||
*
|
||||
* @return The number of metadata entries.
|
||||
*/
|
||||
public long getMetadataCount() { return getCount(LocationContract.Metadata.TABLE); }
|
||||
|
||||
/**
|
||||
* Returns the element count in the table.
|
||||
*
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,8 +12,8 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ public class NoticeStore {
|
||||
}
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(NoticeContract.Notice.ID, notice.getId());
|
||||
values.put(NoticeContract.Notice.ANNOUNCED, notice.getAnnounced());
|
||||
values.put(NoticeContract.Notice.ANNOUNCED, notice.isAnnounced());
|
||||
values.put(NoticeContract.Notice.CREATION_TIME, notice.getCreationTime());
|
||||
values.put(NoticeContract.Notice.MODIFICATION_TIME, notice.getModificationTime());
|
||||
values.put(NoticeContract.Notice.EXPIRATION_TIME, notice.getExpirationTime());
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.maptology.android.feign.model.User;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
||||
/**
|
||||
@@ -38,6 +38,11 @@ public class Repository {
|
||||
*/
|
||||
public static final String KEY_PRIVACY_LOCALIZE = "privacy_localize";
|
||||
|
||||
/**
|
||||
* The key to globally enable or disable the high precision logger service.
|
||||
*/
|
||||
public static final String KEY_PRIVACY_LOGGABLE = "privacy_loggable";
|
||||
|
||||
/**
|
||||
* The key to memorize whether we are in development mode.
|
||||
*/
|
||||
@@ -144,9 +149,9 @@ public class Repository {
|
||||
*/
|
||||
public Repository(Context context) {
|
||||
this.context = context;
|
||||
this.deviceHandle = new PersistentValue<DeviceHandle>(this, new JacksonSerializer<DeviceHandle>(DeviceHandle.class), "device.json");
|
||||
this.user = new PersistentValue<User>(this, new JacksonSerializer<User>(User.class), "user.json");
|
||||
this.lastUpdate = new PersistentValue<ReleasedLocation>(this, new JacksonSerializer<ReleasedLocation>(ReleasedLocation.class), "update.json");
|
||||
this.deviceHandle = new PersistentValue<>(this, new JacksonSerializer<>(DeviceHandle.class), "device.json");
|
||||
this.user = new PersistentValue<>(this, new JacksonSerializer<>(User.class), "user.json");
|
||||
this.lastUpdate = new PersistentValue<>(this, new JacksonSerializer<>(ReleasedLocation.class), "update.json");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,6 +172,24 @@ public class Repository {
|
||||
return getPreference(KEY_PRIVACY_LOCALIZE, R.bool.privacy_localize_default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables localization.
|
||||
*
|
||||
* @param value True to enable, false to disable.
|
||||
*/
|
||||
public void setLocalizable(boolean value) {
|
||||
setPreference(KEY_PRIVACY_LOCALIZE, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether logging is enabled.
|
||||
*
|
||||
* @return True if logging is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isLoggable() {
|
||||
return getPreference(KEY_PRIVACY_LOGGABLE, R.bool.privacy_loggable_default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the user has allowed that his positions can be used for research.
|
||||
*
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.maptology.android.app.repository;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A value that can be observed by a value listener.
|
||||
|
||||
@@ -12,8 +12,8 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
@@ -164,9 +164,9 @@ public class ShareStore {
|
||||
values.put(ShareContract.Share.MESSAGE, share.getMessage());
|
||||
values.put(ShareContract.Share.DESTINATION, share.getDestination());
|
||||
values.put(ShareContract.Share.TOKEN, share.getToken());
|
||||
values.put(ShareContract.Share.PAUSED, share.getPaused() ? 1 : 0);
|
||||
values.put(ShareContract.Share.PAUSED, share.isPaused() ? 1 : 0);
|
||||
values.put(ShareContract.Share.DEVICE, share.getDevice());
|
||||
values.put(ShareContract.Share.DELETED, share.getDeleted() ? 1 : 0);
|
||||
values.put(ShareContract.Share.DELETED, share.isDeleted() ? 1 : 0);
|
||||
if (!exists) {
|
||||
values.put(ShareContract.Share.ID, share.getId());
|
||||
database.insert(ShareContract.Share.TABLE, null, values);
|
||||
|
||||
@@ -83,11 +83,11 @@ public class CreateShareTask extends AbstractApiTask<Void, Void, AsyncError> {
|
||||
super.onPostExecute(asyncError);
|
||||
if (app.getRepository().updatingShare.getValue() != interaction) return;
|
||||
if (asyncError == null) {
|
||||
share.setDeleted(createdShare.getDeleted());
|
||||
share.setDeleted(createdShare.isDeleted());
|
||||
share.setId(createdShare.getId());
|
||||
share.setToken(createdShare.getToken());
|
||||
share.setDestination(createdShare.getDestination());
|
||||
share.setPaused(createdShare.getPaused());
|
||||
share.setPaused(createdShare.isPaused());
|
||||
share.setModificationTime(createdShare.getModificationTime());
|
||||
share.setCreationTime(createdShare.getCreationTime());
|
||||
share.setDevice(createdShare.getDevice());
|
||||
|
||||
@@ -19,8 +19,8 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.pm.PackageInfoCompat;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.content.pm.PackageInfoCompat;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
@@ -150,7 +150,7 @@ public class SyncNoticeTask extends AbstractApiTask<Void, Void, List<Notice>> {
|
||||
Log.d(TAG, "Received a notice without id (this is a problem, fix it).");
|
||||
continue;
|
||||
}
|
||||
if (n.getDeleted() != null && n.getDeleted()) {
|
||||
if (n.isDeleted() != null && n.isDeleted()) {
|
||||
// delete outdated data
|
||||
store.removeNotice(n.getId());
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.maptology.android.app.task;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import com.maptology.android.app.MaptologyApp;
|
||||
import com.maptology.android.app.R;
|
||||
import com.maptology.android.app.repository.AsyncError;
|
||||
import com.maptology.android.app.repository.AsyncInteraction;
|
||||
import com.maptology.android.feign.model.Device;
|
||||
import com.maptology.android.feign.model.DeviceHandle;
|
||||
import com.maptology.android.feign.model.DeviceInfo;
|
||||
import com.maptology.android.feign.model.User;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
import feign.FeignException;
|
||||
|
||||
/**
|
||||
* A task that will associate an existing device with a user.
|
||||
* The task will report the result through the repository.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class UpdateDeviceTask extends AbstractApiTask<Void, Void, AsyncError> {
|
||||
|
||||
/**
|
||||
* The log tag for the task.
|
||||
*/
|
||||
private static final String TAG = "UpdateDeviceTask";
|
||||
|
||||
/**
|
||||
* The error code for network errors.
|
||||
*/
|
||||
public static final int ERROR_NETWORK = 1;
|
||||
/**
|
||||
* The error code for login errors.
|
||||
*/
|
||||
public static final int ERROR_LOGIN = 2;
|
||||
/**
|
||||
* The error code if the device has been associated already.
|
||||
*/
|
||||
public static final int ERROR_UPDATE = 3;
|
||||
|
||||
/**
|
||||
* The optional username.
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* The optional password.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* The device that has been registered.
|
||||
*/
|
||||
private Device device;
|
||||
|
||||
/**
|
||||
* The user that has been fetched.
|
||||
*/
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* Creates a create device task with the specified username and
|
||||
* password.
|
||||
*
|
||||
* @param app The app.
|
||||
* @param username The username.
|
||||
* @param password The password.
|
||||
*/
|
||||
public UpdateDeviceTask(MaptologyApp app, String username, String password) {
|
||||
super(app);
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
apiClient = app.getApiClient(username, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the task.
|
||||
*/
|
||||
public void execute() {
|
||||
app.getRepository().creatingDevice.setValue(new AsyncInteraction(false));
|
||||
super.execute(new Void[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AsyncError doInBackground(Void... voids) {
|
||||
try {
|
||||
user = apiClient.getCurrentUser();
|
||||
Log.d(TAG, "Login success for " + username + " with id " + (user==null?"":user.getId()) + ".");
|
||||
} catch (FeignException e) {
|
||||
Log.d(TAG, "Login failure for user: " + e.status() + " " + e.getMessage());
|
||||
return getError(e);
|
||||
}
|
||||
try {
|
||||
device = apiClient.getCurrentDevice();
|
||||
Log.d(TAG, "Login success for device with id " + (device==null?"":device.getId()) + ".");
|
||||
} catch (FeignException e) {
|
||||
Log.d(TAG, "Login failure for device:" + e.status() + " " + e.getMessage());
|
||||
return getError(e);
|
||||
}
|
||||
try {
|
||||
device = apiClient.setCurrentUserDevice(device);
|
||||
Log.d(TAG, "Device associated for user id " + device.getUser() + ".");
|
||||
} catch (FeignException e) {
|
||||
Log.d(TAG, "Device creation failure: " + e.status() + " " + e.getMessage());
|
||||
return getError(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a feign exception into an error.
|
||||
*
|
||||
* @param e The exception.
|
||||
* @return The associated error.
|
||||
*/
|
||||
private AsyncError getError(FeignException e) {
|
||||
if (e.status() == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
return new AsyncError(ERROR_LOGIN, R.string.login_failed_msg);
|
||||
} else if (e.status() == HttpURLConnection.HTTP_CONFLICT) {
|
||||
return new AsyncError(ERROR_UPDATE, R.string.login_conflict_msg);
|
||||
} else {
|
||||
return new AsyncError(ERROR_NETWORK, R.string.login_device_failed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(AsyncError asyncError) {
|
||||
AsyncInteraction interaction;
|
||||
if (asyncError == null) {
|
||||
interaction = new AsyncInteraction(true);
|
||||
} else if (asyncError.getCode() == ERROR_LOGIN || asyncError.getCode() == ERROR_UPDATE){
|
||||
// do not allow retry when username and password are wrong
|
||||
interaction = new AsyncInteraction(asyncError);
|
||||
} else {
|
||||
// allow retry for everything else
|
||||
final UpdateDeviceTask retry = new UpdateDeviceTask(app, username, password);
|
||||
interaction = new AsyncInteraction(asyncError, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
retry.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
app.getRepository().creatingDevice.setValue(interaction);
|
||||
DeviceHandle handle = app.getRepository().deviceHandle.getValue();
|
||||
if (device != null && device.getUser() != null) {
|
||||
Log.d(TAG, "Updating device handle.");
|
||||
handle.setUser(device.getUser());
|
||||
app.getRepository().deviceHandle.setValue(handle);
|
||||
if (user != null && device.getUser().equals(user.getId())) {
|
||||
Log.d(TAG, "Setting user directly.");
|
||||
app.getRepository().user.setValue(user);
|
||||
} else {
|
||||
Log.d(TAG, "Setting user via task.");
|
||||
new UpdateUserTask(app).execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class UploadLocationTask extends AbstractApiTask<Void, Void, Void> {
|
||||
/**
|
||||
* The maximum number of locations to be uploaded in one batch.
|
||||
*/
|
||||
private static final int MAXIMUM_BATCH_SIZE = 100;
|
||||
private static final int MAXIMUM_BATCH_SIZE = 5;
|
||||
|
||||
/**
|
||||
* The respository of the app.
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.maptology.android.app.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.maptology.android.app.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A delta compression codec based on Google's WGS84 encoder that
|
||||
* supports multiple data streams to encode other data than latitude
|
||||
* and longitude values. Callers must supply the number of streams
|
||||
* encoded in the data and the streams must exhibit the same number
|
||||
* of data items.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class DeltaCodec {
|
||||
|
||||
/**
|
||||
* The number of streams to encode or decode.
|
||||
*/
|
||||
private int streams;
|
||||
|
||||
/**
|
||||
* Creates a delta compressor for the specified number of streams.
|
||||
*
|
||||
* @param streams The number of streams to encode in the string.
|
||||
*/
|
||||
public DeltaCodec(int streams) {
|
||||
this.streams = streams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of streams expected by this codec.
|
||||
*
|
||||
* @return The number of streams.
|
||||
*/
|
||||
public int getStreams() {
|
||||
return streams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a list of values into a string.
|
||||
*
|
||||
* @param values The values consisting of arrays that represent
|
||||
* the individual streams.
|
||||
* @return The string.
|
||||
*/
|
||||
public String encode(List<long[]> values) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
long[] previous = new long[streams];
|
||||
for (int i = 0, s = values.size(); i < s; i++) {
|
||||
long[] current = values.get(i);
|
||||
for (int j = 0; j < streams; j++) {
|
||||
long delta = current[j] - previous[j];
|
||||
builder.append(encodeSignedNumber(delta));
|
||||
previous[j] = current[j];
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the list of data from an encoded string.
|
||||
*
|
||||
* @param encoded The encoded string.
|
||||
* @param data An optional list of data items to be reused
|
||||
* to avoid object allocations. Can be null.
|
||||
* @return The list of data items representing the streams.
|
||||
*/
|
||||
public List<long[]> decode(String encoded, List<long[]> data) {
|
||||
List<long[]> list = new ArrayList<>();
|
||||
int index = 0;
|
||||
int length = encoded.length();
|
||||
long[] current = new long[streams];
|
||||
while (index < length) {
|
||||
long[] next;
|
||||
if (data != null && data.size() > 0) {
|
||||
next = data.remove(0);
|
||||
} else {
|
||||
next = new long[streams];
|
||||
}
|
||||
long c;
|
||||
for (int i = 0; i < streams; i++) {
|
||||
long shift = 0;
|
||||
long result = 0;
|
||||
do {
|
||||
c = encoded.charAt(index++) - 63;
|
||||
result |= (c & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (c >= 0x20);
|
||||
long delta = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
||||
current[i] += delta;
|
||||
next[i] = current[i];
|
||||
}
|
||||
list.add(next);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a signed number as string.
|
||||
*
|
||||
* @param num The number.
|
||||
* @return The string.
|
||||
*/
|
||||
private static String encodeSignedNumber(long num) {
|
||||
long sgn_num = num << 1;
|
||||
if (num < 0) {
|
||||
sgn_num = ~(sgn_num);
|
||||
}
|
||||
return (encodeNumber(sgn_num));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes an unsigned number as string.
|
||||
*
|
||||
* @param num The number.
|
||||
* @return The string.
|
||||
*/
|
||||
private static String encodeNumber(long num) {
|
||||
StringBuilder encodeString = new StringBuilder();
|
||||
while (num >= 0x20) {
|
||||
int nextValue = (int)(0x20 | (num & 0x1f)) + 63;
|
||||
encodeString.append((char) (nextValue));
|
||||
num >>= 5;
|
||||
}
|
||||
num += 63;
|
||||
encodeString.append((char) (num));
|
||||
return encodeString.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 134 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
@@ -1,4 +1,6 @@
|
||||
<vector android:height="48dp" android:viewportHeight="24.0"
|
||||
<vector
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:height="48dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M12,6c3.87,0 7,3.13 7,7 0,0.84 -0.16,1.65 -0.43,2.4l1.52,1.52c0.58,-1.19 0.91,-2.51 0.91,-3.92 0,-4.97 -4.03,-9 -9,-9 -1.41,0 -2.73,0.33 -3.92,0.91L9.6,6.43C10.35,6.16 11.16,6 12,6zM22,5.72l-4.6,-3.86 -1.29,1.53 4.6,3.86L22,5.72zM2.92,2.29L1.65,3.57 2.98,4.9l-1.11,0.93 1.42,1.42 1.11,-0.94 0.8,0.8C3.83,8.69 3,10.75 3,13c0,4.97 4.02,9 9,9 2.25,0 4.31,-0.83 5.89,-2.2l2.2,2.2 1.27,-1.27L3.89,3.27l-0.97,-0.98zM16.47,18.39C15.26,19.39 13.7,20 12,20c-3.87,0 -7,-3.13 -7,-7 0,-1.7 0.61,-3.26 1.61,-4.47l9.86,9.86zM8.02,3.28L6.6,1.86l-0.86,0.71 1.42,1.42 0.86,-0.71z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM19,18H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h0.71C7.37,7.69 9.48,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3s-1.34,3 -3,3z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/>
|
||||
</vector>
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<vector android:height="48dp" android:viewportHeight="24.0"
|
||||
<vector
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:height="48dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94V1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11H1v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94V23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94H23v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<vector android:height="48dp" android:viewportHeight="24.0"
|
||||
<vector
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:height="48dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M15.9,5c-0.17,0 -0.32,0.09 -0.41,0.23l-0.07,0.15 -5.18,11.65c-0.16,0.29 -0.26,0.61 -0.26,0.96 0,1.11 0.9,2.01 2.01,2.01 0.96,0 1.77,-0.68 1.96,-1.59l0.01,-0.03L16.4,5.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM1,9l2,2c2.88,-2.88 6.79,-4.08 10.53,-3.62l1.19,-2.68C9.89,3.84 4.74,5.27 1,9zM21,11l2,-2c-1.64,-1.64 -3.55,-2.82 -5.59,-3.57l-0.53,2.82c1.5,0.62 2.9,1.53 4.12,2.75zM17,15l2,-2c-0.8,-0.8 -1.7,-1.42 -2.66,-1.89l-0.55,2.92c0.42,0.27 0.83,0.59 1.21,0.97zM5,13l2,2c1.13,-1.13 2.56,-1.79 4.03,-2l1.28,-2.88c-2.63,-0.08 -5.3,0.87 -7.31,2.88z"/>
|
||||
</vector>
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector android:height="48dp" android:viewportHeight="24.0"
|
||||
<vector android:tint="?attr/colorControlNormal"
|
||||
android:height="48dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||
</vector>
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<vector android:height="48dp" android:viewportHeight="24.0"
|
||||
<vector android:tint="?attr/colorControlNormal" android:height="48dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
|
||||
</vector>
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:id="@+id/coordinator">
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/coordinator">
|
||||
|
||||
<android.support.v4.widget.DrawerLayout
|
||||
<androidx.drawerlayout.widget.DrawerLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:itemIconTint="@color/white"
|
||||
android:id="@+id/drawer_layout">
|
||||
|
||||
<FrameLayout
|
||||
@@ -20,7 +21,7 @@
|
||||
android:orientation="vertical">
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/navigation_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
@@ -30,5 +31,5 @@
|
||||
|
||||
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||