summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjandegr <jandegr@users.noreply.github.com>2018-05-25 06:58:49 +0200
committerGitHub <noreply@github.com>2018-05-25 06:58:49 +0200
commitac688b1c67fcfbbf6c59129f817cd406ae87dfb6 (patch)
tree90648c500ebe935a96fd18bfd10e56d169462ed9
parentb74329764358cd2e34c87f5a235967f3736dd04d (diff)
downloadnavit-ac688b1c67fcfbbf6c59129f817cd406ae87dfb6.tar.gz
Add:Android:checkstyle-javadoc (#595)
* Android checkstyle and javadoc * bump gradle version * bump gradle version * Android checkstyle and javadoc * ArrayTypeStyle as failure * fix Array brackets at illegal position. * typo * fix Array brackets at illegal position. * CustomImportOrder severity error * optimize imports * optimize imports
-rw-r--r--.circleci/config.yml34
-rw-r--r--build.gradle11
-rw-r--r--gradle/wrapper/gradle-wrapper.properties11
-rw-r--r--navit/android/build.gradle49
-rw-r--r--navit/android/navit_checkstyle.xml257
-rw-r--r--navit/android/src/org/navitproject/navit/Navit.java10
-rw-r--r--navit/android/src/org/navitproject/navit/NavitActivityResult.java1
-rw-r--r--navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java10
-rwxr-xr-xnavit/android/src/org/navitproject/navit/NavitAppConfig.java119
-rw-r--r--navit/android/src/org/navitproject/navit/NavitCamera.java30
-rw-r--r--navit/android/src/org/navitproject/navit/NavitDialogs.java2
-rw-r--r--navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java4
-rw-r--r--navit/android/src/org/navitproject/navit/NavitGraphics.java4
-rw-r--r--navit/android/src/org/navitproject/navit/NavitMapDownloader.java4
-rw-r--r--navit/android/src/org/navitproject/navit/NavitSensors.java49
-rw-r--r--navit/android/src/org/navitproject/navit/NavitVehicle.java319
-rw-r--r--navit/android/src/org/navitproject/navit/NavitWatch.java147
17 files changed, 689 insertions, 372 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
index af3daeb79..af7aadabd 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -61,7 +61,6 @@ jobs:
command: |
cd navit/icons
make
- sudo ls -la
mkdir ../android/res/drawable-nodpi
rename 'y/A-Z/a-z/' *
cp *.png ../android/res/drawable-nodpi
@@ -71,13 +70,12 @@ jobs:
command: |
cd po
make
- sudo ls -la
mkdir ../navit/android/res/raw
rename 'y/A-Z/a-z/' *
cp *.mo ../navit/android/res/raw
cd ../
- run:
- name: Move xml's
+ name: Process xml's
command: |
cd navit
saxonb-xslt -s:navit_shipped.xml -xsl:xslt/android.xslt -o:navitldpi.xml OSD_SIZE=1 ICON_SMALL=24 ICON_MEDIUM=32 ICON_BIG=48
@@ -86,7 +84,6 @@ jobs:
saxonb-xslt -s:navit_shipped.xml -xsl:xslt/android.xslt -o:navitxhdpi.xml OSD_SIZE=2.67 ICON_SMALL=64 ICON_MEDIUM=96 ICON_BIG=128
saxonb-xslt -s:navit_shipped.xml -xsl:xslt/android.xslt -o:navitxxhdpi.xml OSD_SIZE=4 ICON_SMALL=96 ICON_MEDIUM=128 ICON_BIG=192
saxonb-xslt -s:navit_shipped.xml -xsl:xslt/android.xslt -o:navitxxxhdpi.xml OSD_SIZE=5.33 ICON_SMALL=128 ICON_MEDIUM=192 ICON_BIG=256
- sudo ls -la
mv *dpi.xml android/res/raw
cd ../
- run:
@@ -103,26 +100,39 @@ jobs:
name: Build
command: ./gradlew assembleDebug
- run:
- name: Run Tests
+ name: Run Lint Test
command: |
ln -s navit/navit.dtd navit.dtd
- ls -la
- ./gradlew tasks --all
+ mkdir /home/circleci/code/test-results
./gradlew lint test
+ - run:
+ name: Run CheckStyle Test
+ command: ./gradlew checkstyleMain
+ - run:
+ name: Run Javadoc
+ command: ./gradlew generateDebugJavadoc
- store_artifacts:
+ name: Store APK
path: navit/android/build/outputs/apk
destination: apk
- store_artifacts:
- name: Store translations
- path: po
- destination: translations
- - store_artifacts:
+ name: Store logs
path: navit/android/build/outputs/logs
destination: logs
- store_artifacts:
- name: Store reports
+ name: Store Javadoc
+ path: navit/android/build/outputs/docs/javadoc
+ destination: doc
+ - store_artifacts:
+ name: Store Lint reports
path: navit/android/build/reports
destination: reports
+ - store_artifacts:
+ name: Store checkstyle report
+ path: /home/circleci/code/navit/android/checkstyle
+ destination: reports
+ - store_test_results:
+ path: test-results
build_win32:
<<: *defaults
steps:
diff --git a/build.gradle b/build.gradle
index 1ea4bd055..ec95872d8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,9 +3,14 @@
buildscript {
repositories {
jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.0'
+ classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -15,6 +20,10 @@ buildscript {
allprojects {
repositories {
jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index cb189a155..73bb13d55 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Fri Mar 03 10:50:57 CET 2017
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
diff --git a/navit/android/build.gradle b/navit/android/build.gradle
index 4ae19a148..edd6f4272 100644
--- a/navit/android/build.gradle
+++ b/navit/android/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'checkstyle'
android {
compileSdkVersion 27
@@ -43,13 +44,51 @@ android {
path '../../CMakeLists.txt'
}
}
-}
+ task checkstyleMain(type: Checkstyle){
+ source 'src'
+ include '**/*.java'
+ configFile = rootProject.file('navit/android/navit_checkstyle.xml')
+ ignoreFailures = false
+ showViolations = true
+ // empty classpath
+ classpath = files()
+ reports {
+ include ('**/*.java')
+ exclude ('**/FileBrowserActivity.java')
+ xml.enabled = true
+ html.enabled = true
+ xml {
+ destination "checkstyle/checkstyleMain.xml"
+ }
+ html {
+ destination "checkstyle/checkstyleMain.html"
+ }
+ }
+
+ checkstyle {
+ toolVersion = '8.10'
+ }
+ }
+ applicationVariants.all { variant ->
+ // create tasks to generate Javadocs
+ task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
+ source = variant.javaCompile.source
+ classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+ destinationDir = file("build/outputs/docs/javadoc/")
+ title = rootProject.name
+ verbose = true
+ failOnError false
+ }
+ }
+
+}
dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
+ androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- testCompile 'junit:junit:4.12'
- compile 'ch.acra:acra:4.9.2'
+ testImplementation 'junit:junit:4.12'
+ implementation 'ch.acra:acra:4.9.2'
+// implementation 'com.android.support:support-v4:27.1.1'
}
diff --git a/navit/android/navit_checkstyle.xml b/navit/android/navit_checkstyle.xml
new file mode 100644
index 000000000..cff784874
--- /dev/null
+++ b/navit/android/navit_checkstyle.xml
@@ -0,0 +1,257 @@
+<?xml version="1.0"?>
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+ "http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
+
+<!--
+
+
+ Tuned for Navit and based on :
+
+ Checkstyle configuration that checks the Google coding conventions from Google Java Style
+ that can be found at https://google.github.io/styleguide/javaguide.html.
+
+ Checkstyle is very configurable. Be sure to read the documentation at
+ http://checkstyle.sf.net (or in your downloaded distribution).
+
+ To completely disable a check, just comment it out or delete it from the file.
+
+ Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
+ -->
+
+<module name = "Checker">
+ <property name="charset" value="UTF-8"/>
+
+ <property name="severity" value="warning"/>
+
+ <property name="fileExtensions" value="java, properties, xml"/>
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="FileTabCharacter">
+ <property name="eachLine" value="true"/>
+ </module>
+
+ <module name="TreeWalker">
+ <module name="OuterTypeFilename"/>
+ <module name="IllegalTokenText">
+ <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
+ <property name="format"
+ value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
+ <property name="message"
+ value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
+ </module>
+ <module name="AvoidEscapedUnicodeCharacters">
+ <property name="allowEscapesForControlCharacters" value="true"/>
+ <property name="allowByTailComment" value="true"/>
+ <property name="allowNonPrintableEscapes" value="true"/>
+ </module>
+ <module name="LineLength">
+ <property name="max" value="120"/>
+ <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
+ </module>
+ <module name="AvoidStarImport"/>
+ <module name="OneTopLevelClass"/>
+ <module name="NoLineWrap"/>
+ <module name="EmptyBlock">
+ <property name="option" value="TEXT"/>
+ <property name="tokens"
+ value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
+ </module>
+ <module name="NeedBraces"/>
+ <module name="LeftCurly"/>
+ <module name="RightCurly">
+ <property name="id" value="RightCurlySame"/>
+ <property name="tokens"
+ value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
+ LITERAL_DO"/>
+ </module>
+ <module name="RightCurly">
+ <property name="id" value="RightCurlyAlone"/>
+ <property name="option" value="alone"/>
+ <property name="tokens"
+ value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
+ INSTANCE_INIT"/>
+ </module>
+ <module name="WhitespaceAround">
+ <property name="allowEmptyConstructors" value="true"/>
+ <property name="allowEmptyMethods" value="true"/>
+ <property name="allowEmptyTypes" value="true"/>
+ <property name="allowEmptyLoops" value="true"/>
+ <message key="ws.notFollowed"
+ value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
+ <message key="ws.notPreceded"
+ value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
+ </module>
+ <module name="OneStatementPerLine"/>
+ <module name="MultipleVariableDeclarations"/>
+ <module name="ArrayTypeStyle">
+ <property name="severity" value="error"/>
+ </module>
+ <module name="MissingSwitchDefault"/>
+ <module name="FallThrough"/>
+ <module name="UpperEll"/>
+ <module name="ModifierOrder"/>
+ <module name="EmptyLineSeparator">
+ <property name="allowNoEmptyLineBetweenFields" value="true"/>
+ </module>
+ <module name="SeparatorWrap">
+ <property name="id" value="SeparatorWrapDot"/>
+ <property name="tokens" value="DOT"/>
+ <property name="option" value="nl"/>
+ </module>
+ <module name="SeparatorWrap">
+ <property name="id" value="SeparatorWrapComma"/>
+ <property name="tokens" value="COMMA"/>
+ <property name="option" value="EOL"/>
+ </module>
+ <module name="SeparatorWrap">
+ <!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 -->
+ <property name="id" value="SeparatorWrapEllipsis"/>
+ <property name="tokens" value="ELLIPSIS"/>
+ <property name="option" value="EOL"/>
+ </module>
+ <module name="SeparatorWrap">
+ <!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 -->
+ <property name="id" value="SeparatorWrapArrayDeclarator"/>
+ <property name="tokens" value="ARRAY_DECLARATOR"/>
+ <property name="option" value="EOL"/>
+ </module>
+ <module name="SeparatorWrap">
+ <property name="id" value="SeparatorWrapMethodRef"/>
+ <property name="tokens" value="METHOD_REF"/>
+ <property name="option" value="nl"/>
+ </module>
+ <module name="PackageName">
+ <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
+ <message key="name.invalidPattern"
+ value="Package name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="TypeName">
+ <message key="name.invalidPattern"
+ value="Type name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="MemberName">
+ <property name="format" value="^m[A-Z][a-zA-Z0-9]*$"/>
+ <message key="name.invalidPattern"
+ value="Member name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="ParameterName">
+ <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
+ <message key="name.invalidPattern"
+ value="Parameter name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="CatchParameterName">
+ <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
+ <message key="name.invalidPattern"
+ value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="LocalVariableName">
+ <property name="tokens" value="VARIABLE_DEF"/>
+ <property name="format" value="^[a-z]([a-zA-Z0-9]*)?$"/>
+ <message key="name.invalidPattern"
+ value="Local variable name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="ClassTypeParameterName">
+ <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
+ <message key="name.invalidPattern"
+ value="Class type name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="MethodTypeParameterName">
+ <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
+ <message key="name.invalidPattern"
+ value="Method type name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="InterfaceTypeParameterName">
+ <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
+ <message key="name.invalidPattern"
+ value="Interface type name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="NoFinalizer"/>
+ <module name="GenericWhitespace">
+ <message key="ws.followed"
+ value="GenericWhitespace ''{0}'' is followed by whitespace."/>
+ <message key="ws.preceded"
+ value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
+ <message key="ws.illegalFollow"
+ value="GenericWhitespace ''{0}'' should followed by whitespace."/>
+ <message key="ws.notPreceded"
+ value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
+ </module>
+ <module name="Indentation">
+ <property name="basicOffset" value="4"/>
+ <property name="braceAdjustment" value="0"/>
+ <property name="caseIndent" value="4"/>
+ <property name="throwsIndent" value="4"/>
+ <property name="lineWrappingIndentation" value="8"/>
+ <property name="arrayInitIndent" value="2"/>
+ </module>
+ <module name="AbbreviationAsWordInName">
+ <property name="ignoreFinal" value="false"/>
+ <property name="allowedAbbreviationLength" value="2"/>
+ </module>
+ <module name="OverloadMethodsDeclarationOrder"/>
+ <module name="VariableDeclarationUsageDistance"/>
+ <module name="CustomImportOrder">
+ <property name="sortImportsInGroupAlphabetically" value="true"/>
+ <property name="separateLineBetweenGroups" value="true"/>
+ <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
+ <property name="severity" value="error"/>
+ </module>
+ <module name="MethodParamPad"/>
+ <module name="NoWhitespaceBefore">
+ <property name="tokens"
+ value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/>
+ <property name="allowLineBreaks" value="true"/>
+ </module>
+ <module name="ParenPad"/>
+ <module name="OperatorWrap">
+ <property name="option" value="NL"/>
+ <property name="tokens"
+ value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
+ LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
+ </module>
+ <module name="AnnotationLocation">
+ <property name="id" value="AnnotationLocationMostCases"/>
+ <property name="tokens"
+ value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
+ </module>
+ <module name="AnnotationLocation">
+ <property name="id" value="AnnotationLocationVariables"/>
+ <property name="tokens" value="VARIABLE_DEF"/>
+ <property name="allowSamelineMultipleAnnotations" value="true"/>
+ </module>
+ <module name="NonEmptyAtclauseDescription"/>
+ <module name="JavadocTagContinuationIndentation"/>
+ <module name="SummaryJavadoc">
+ <property name="forbiddenSummaryFragments"
+ value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
+ </module>
+ <module name="JavadocParagraph"/>
+ <module name="AtclauseOrder">
+ <property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
+ <property name="target"
+ value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
+ </module>
+ <module name="JavadocMethod">
+ <property name="scope" value="public"/>
+ <property name="allowMissingParamTags" value="true"/>
+ <property name="allowMissingThrowsTags" value="true"/>
+ <property name="allowMissingReturnTag" value="true"/>
+ <property name="minLineCount" value="2"/>
+ <property name="allowedAnnotations" value="Override, Test"/>
+ <property name="allowThrowsTagsForSubclasses" value="true"/>
+ </module>
+ <module name="MethodName">
+ <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
+ <message key="name.invalidPattern"
+ value="Method name ''{0}'' must match pattern ''{1}''."/>
+ </module>
+ <module name="SingleLineJavadoc">
+ <property name="ignoreInlineTags" value="false"/>
+ </module>
+ <module name="EmptyCatchBlock">
+ <property name="exceptionVariableName" value="expected"/>
+ </module>
+ <module name="CommentsIndentation"/>
+ </module>
+</module>
diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java
index 75a513ef1..d6c3a609d 100644
--- a/navit/android/src/org/navitproject/navit/Navit.java
+++ b/navit/android/src/org/navitproject/navit/Navit.java
@@ -72,7 +72,7 @@ public class Navit extends Activity
private NavitDialogs dialogs;
private PowerManager.WakeLock wl;
- private NavitActivityResult ActivityResults[];
+ private NavitActivityResult[] ActivityResults;
public static InputMethodManager mgr = null;
public static DisplayMetrics metrics = null;
public static int status_bar_height = 0;
@@ -144,7 +144,7 @@ public class Navit extends Activity
os = new FileOutputStream(destination);
int len;
- byte buffer[] = new byte[1024];
+ byte[] buffer = new byte[1024];
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
@@ -464,7 +464,7 @@ public class Navit extends Activity
}
@Override
- public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_ALL: {
if (grantResults.length > 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED
@@ -487,7 +487,7 @@ public class Navit extends Activity
}
private void parseNavigationURI(String schemeSpecificPart) {
- String naviData[]= schemeSpecificPart.split("&");
+ String[] naviData = schemeSpecificPart.split("&");
Pattern p = Pattern.compile("(.*)=(.*)");
Map<String,String> params = new HashMap<String,String>();
for (int count=0; count < naviData.length; count++) {
@@ -518,7 +518,7 @@ public class Navit extends Activity
if ( geoString != null) {
if (geoString.matches("^[+-]{0,1}\\d+(|\\.\\d*),[+-]{0,1}\\d+(|\\.\\d*)$")) {
- String geo[] = geoString.split(",");
+ String[] geo = geoString.split(",");
if (geo.length == 2) {
try {
lat = Float.valueOf(geo[0]);
diff --git a/navit/android/src/org/navitproject/navit/NavitActivityResult.java b/navit/android/src/org/navitproject/navit/NavitActivityResult.java
index 63b4e798f..f52f06c9c 100644
--- a/navit/android/src/org/navitproject/navit/NavitActivityResult.java
+++ b/navit/android/src/org/navitproject/navit/NavitActivityResult.java
@@ -1,4 +1,5 @@
package org.navitproject.navit;
+
import android.content.Intent;
public interface NavitActivityResult {
diff --git a/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java b/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java
index c174e3eba..48ff266d0 100644
--- a/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java
+++ b/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java
@@ -105,13 +105,13 @@ public class NavitAddressSearchActivity extends Activity {
// We have all images stored as drawable_nodpi resources which allows native code to manipulate them
// without interference with android builtin choosing and scaling system. But that makes us to
// reinvent the wheel here to show an image in android native interface.
- int flag_icon_sizes[]={24,32,48,64,96};
+ int[] flag_icon_sizes = {24,32,48,64,96};
int exact_size, nearest_size;
- exact_size=(int)(Navit.metrics.density*24.0 -.5);
- nearest_size=flag_icon_sizes[0];
+ exact_size = (int)(Navit.metrics.density*24.0 -.5);
+ nearest_size = flag_icon_sizes[0];
for(int size: flag_icon_sizes) {
- nearest_size=size;
- if(exact_size<=size)
+ nearest_size = size;
+ if(exact_size <= size)
break;
}
mCountryButton.setImageResource(getDrawableID("country_" + mCountry+"_"+nearest_size+"_"+nearest_size));
diff --git a/navit/android/src/org/navitproject/navit/NavitAppConfig.java b/navit/android/src/org/navitproject/navit/NavitAppConfig.java
index 7cc5a6173..f9569825f 100755
--- a/navit/android/src/org/navitproject/navit/NavitAppConfig.java
+++ b/navit/android/src/org/navitproject/navit/NavitAppConfig.java
@@ -1,70 +1,69 @@
package org.navitproject.navit;
+import android.app.Application;
+import android.content.SharedPreferences;
+
import java.util.ArrayList;
import java.util.List;
import org.navitproject.navit.NavitAddressSearchActivity.NavitAddress;
-import android.app.Application;
-import android.content.SharedPreferences;
-
-
public class NavitAppConfig extends Application {
- private static final int MAX_LAST_ADDRESSES = 10;
- private static final String TAG = "Navit";
-
- private List<NavitAddress> mLastAddresses = null;
- private int mLastAddressField;
- private SharedPreferences mSettings;
-
- @Override
- public void onCreate() {
- mSettings = getSharedPreferences(Navit.NAVIT_PREFS, MODE_PRIVATE);
- super.onCreate();
- }
-
- public List<NavitAddress> getLastAddresses() {
- if (mLastAddresses == null) {
- mLastAddresses = new ArrayList<NavitAddress>();
- int mLastAddressField = mSettings.getInt("LastAddress", -1);
- if (mLastAddressField >= 0) {
- int index = mLastAddressField;
- do {
- String addr_str = mSettings.getString("LastAddress_" + String.valueOf(index), "");
-
- if (addr_str.length() > 0) {
- mLastAddresses.add(new NavitAddress(
- 1,
- mSettings.getFloat("LastAddress_Lat_" + String.valueOf(index), 0),
- mSettings.getFloat("LastAddress_Lon_" + String.valueOf(index), 0),
- addr_str));
- }
-
- if (--index < 0) index = MAX_LAST_ADDRESSES - 1;
-
- } while (index != mLastAddressField);
- }
- }
- return mLastAddresses;
- }
-
- public void addLastAddress(NavitAddress newAddress) {
- getLastAddresses();
-
- mLastAddresses.add(newAddress);
- if (mLastAddresses.size() > MAX_LAST_ADDRESSES) mLastAddresses.remove(0);
-
- mLastAddressField++;
- if (mLastAddressField >= MAX_LAST_ADDRESSES) mLastAddressField = 0;
-
- SharedPreferences.Editor editSettings = mSettings.edit();
-
- editSettings.putInt("LastAddress", mLastAddressField);
- editSettings.putString("LastAddress_" + String.valueOf(mLastAddressField), newAddress.addr);
- editSettings.putFloat("LastAddress_Lat_" + String.valueOf(mLastAddressField), newAddress.lat);
- editSettings.putFloat("LastAddress_Lon_" + String.valueOf(mLastAddressField), newAddress.lon);
-
- editSettings.apply();
- }
+ private static final int MAX_LAST_ADDRESSES = 10;
+ private static final String TAG = "Navit";
+
+ private List<NavitAddress> mLastAddresses = null;
+ private int mLastAddressField;
+ private SharedPreferences mSettings;
+
+ @Override
+ public void onCreate() {
+ mSettings = getSharedPreferences(Navit.NAVIT_PREFS, MODE_PRIVATE);
+ super.onCreate();
+ }
+
+ public List<NavitAddress> getLastAddresses() {
+ if (mLastAddresses == null) {
+ mLastAddresses = new ArrayList<NavitAddress>();
+ int mLastAddressField = mSettings.getInt("LastAddress", -1);
+ if (mLastAddressField >= 0) {
+ int index = mLastAddressField;
+ do {
+ String addr_str = mSettings.getString("LastAddress_" + String.valueOf(index), "");
+
+ if (addr_str.length() > 0) {
+ mLastAddresses.add(new NavitAddress(
+ 1,
+ mSettings.getFloat("LastAddress_Lat_" + String.valueOf(index), 0),
+ mSettings.getFloat("LastAddress_Lon_" + String.valueOf(index), 0),
+ addr_str));
+ }
+
+ if (--index < 0) index = MAX_LAST_ADDRESSES - 1;
+
+ } while (index != mLastAddressField);
+ }
+ }
+ return mLastAddresses;
+ }
+
+ public void addLastAddress(NavitAddress newAddress) {
+ getLastAddresses();
+
+ mLastAddresses.add(newAddress);
+ if (mLastAddresses.size() > MAX_LAST_ADDRESSES) mLastAddresses.remove(0);
+
+ mLastAddressField++;
+ if (mLastAddressField >= MAX_LAST_ADDRESSES) mLastAddressField = 0;
+
+ SharedPreferences.Editor editSettings = mSettings.edit();
+
+ editSettings.putInt("LastAddress", mLastAddressField);
+ editSettings.putString("LastAddress_" + String.valueOf(mLastAddressField), newAddress.addr);
+ editSettings.putFloat("LastAddress_Lat_" + String.valueOf(mLastAddressField), newAddress.lat);
+ editSettings.putFloat("LastAddress_Lon_" + String.valueOf(mLastAddressField), newAddress.lon);
+
+ editSettings.apply();
+ }
}
diff --git a/navit/android/src/org/navitproject/navit/NavitCamera.java b/navit/android/src/org/navitproject/navit/NavitCamera.java
index bd78b36b2..1f08afca8 100644
--- a/navit/android/src/org/navitproject/navit/NavitCamera.java
+++ b/navit/android/src/org/navitproject/navit/NavitCamera.java
@@ -15,47 +15,47 @@
*/
package org.navitproject.navit;
-import java.io.IOException;
-
import android.content.Context;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
+import java.io.IOException;
+
public class NavitCamera extends SurfaceView implements SurfaceHolder.Callback {
- SurfaceHolder mHolder;
- Camera mCamera;
+ SurfaceHolder mHolder;
+ Camera mCamera;
- NavitCamera(Context context)
- {
- super(context);
- mHolder = getHolder();
+ NavitCamera(Context context)
+ {
+ super(context);
+ mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- Log.e("NavitCamera","Creator");
+ Log.e("NavitCamera","Creator");
-
- }
+
+ }
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
try {
- mCamera = Camera.open();
+ mCamera = Camera.open();
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
- Log.e("NavitCamera","surfaceCreated");
+ Log.e("NavitCamera","surfaceCreated");
}
public void surfaceDestroyed(SurfaceHolder holder) {
@@ -64,13 +64,13 @@ public class NavitCamera extends SurfaceView implements SurfaceHolder.Callback {
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera = null;
- Log.e("NavitCamera","surfaceDestroyed");
+ Log.e("NavitCamera","surfaceDestroyed");
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
- Log.e("NavitCamera","surfaceChanged "+w+"x"+h);
+ Log.e("NavitCamera","surfaceChanged "+w+"x"+h);
mCamera.stopPreview();
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
diff --git a/navit/android/src/org/navitproject/navit/NavitDialogs.java b/navit/android/src/org/navitproject/navit/NavitDialogs.java
index 426acb76f..465db9133 100644
--- a/navit/android/src/org/navitproject/navit/NavitDialogs.java
+++ b/navit/android/src/org/navitproject/navit/NavitDialogs.java
@@ -1,6 +1,5 @@
package org.navitproject.navit;
-
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
@@ -13,6 +12,7 @@ import android.os.Message;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Toast;
+
import java.io.File;
public class NavitDialogs extends Handler {
diff --git a/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java b/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
index e32b48ace..365c0d312 100644
--- a/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
+++ b/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
@@ -85,7 +85,7 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
}
}
- private void updateMapsForLocation(NavitMapDownloader.osm_map_values osm_maps[]) {
+ private void updateMapsForLocation(NavitMapDownloader.osm_map_values[] osm_maps) {
Location currentLocation = NavitVehicle.lastLocation;
if (maps_current_position_childs.size() == 0 || (currentLocation != null
&& !currentLocationKnown)) {
@@ -139,7 +139,7 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
private SimpleExpandableListAdapter createAdapter() {
- NavitMapDownloader.osm_map_values osm_maps[] = NavitMapDownloader.osm_maps;
+ NavitMapDownloader.osm_map_values[] osm_maps = NavitMapDownloader.osm_maps;
ArrayList<HashMap<String, String>> resultGroups = new ArrayList<HashMap<String, String>>();
ArrayList<ArrayList<HashMap<String, String>>> resultChilds =
diff --git a/navit/android/src/org/navitproject/navit/NavitGraphics.java b/navit/android/src/org/navitproject/navit/NavitGraphics.java
index e8394dfb8..227e7509b 100644
--- a/navit/android/src/org/navitproject/navit/NavitGraphics.java
+++ b/navit/android/src/org/navitproject/navit/NavitGraphics.java
@@ -882,7 +882,7 @@ public class NavitGraphics
}
- protected void draw_polyline(Paint paint, int c[])
+ protected void draw_polyline(Paint paint, int[] c)
{
int i, ndashes;
float [] intervals;
@@ -913,7 +913,7 @@ public class NavitGraphics
paint.setPathEffect(null);
}
- protected void draw_polygon(Paint paint, int c[])
+ protected void draw_polygon(Paint paint, int[] c)
{
paint.setStrokeWidth(c[0]);
paint.setARGB(c[1],c[2],c[3],c[4]);
diff --git a/navit/android/src/org/navitproject/navit/NavitMapDownloader.java b/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
index 0c7d19ca8..08821175c 100644
--- a/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
+++ b/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
@@ -498,9 +498,9 @@ public class NavitMapDownloader extends Thread {
return (filename.endsWith(".bin"));
}
}
- NavitMap maps[] = new NavitMap[0];
+ NavitMap[] maps = new NavitMap[0];
File map_dir = new File(Navit.map_filename_path);
- String map_file_names[] = map_dir.list(new filterMaps());
+ String[] map_file_names = map_dir.list(new filterMaps());
if (map_file_names != null) {
maps = new NavitMap[map_file_names.length];
for (int map_file_index = 0; map_file_index < map_file_names.length; map_file_index++) {
diff --git a/navit/android/src/org/navitproject/navit/NavitSensors.java b/navit/android/src/org/navitproject/navit/NavitSensors.java
index b263ed082..a0d300223 100644
--- a/navit/android/src/org/navitproject/navit/NavitSensors.java
+++ b/navit/android/src/org/navitproject/navit/NavitSensors.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.navitproject.navit;
import android.content.Context;
@@ -24,29 +25,29 @@ import android.hardware.SensorManager;
public class NavitSensors implements SensorEventListener {
- private SensorManager mSensorManager;
- private int callbackid;
- public native void SensorCallback(int id, int sensor, float x, float y, float z);
-
-
- NavitSensors(Context context, int cbid)
- {
- mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
- mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
- callbackid=cbid;
- }
-
- public void
- onAccuracyChanged(Sensor sensor, int accuracy)
- {
- }
-
- public void
- onSensorChanged(SensorEvent sev)
- {
- // Log.e("NavitSensor","Type:" + sev.sensor.getType() + " X:" + sev.values[0] + " Y:"+sev.values[1]+" Z:"+sev.values[2]);
- SensorCallback(callbackid, sev.sensor.getType(), sev.values[0], sev.values[1], sev.values[2]);
- }
+ private SensorManager mSensorManager;
+ private int callbackid;
+ public native void SensorCallback(int id, int sensor, float x, float y, float z);
+
+
+ NavitSensors(Context context, int cbid)
+ {
+ mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
+ mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
+ callbackid=cbid;
+ }
+
+ public void
+ onAccuracyChanged(Sensor sensor, int accuracy)
+ {
+ }
+
+ public void
+ onSensorChanged(SensorEvent sev)
+ {
+ // Log.e("NavitSensor","Type:" + sev.sensor.getType() + " X:" + sev.values[0] + " Y:"+sev.values[1]+" Z:"+sev.values[2]);
+ SensorCallback(callbackid, sev.sensor.getType(), sev.values[0], sev.values[1], sev.values[2]);
+ }
}
diff --git a/navit/android/src/org/navitproject/navit/NavitVehicle.java b/navit/android/src/org/navitproject/navit/NavitVehicle.java
index 583d044c1..b224f9e3a 100644
--- a/navit/android/src/org/navitproject/navit/NavitVehicle.java
+++ b/navit/android/src/org/navitproject/navit/NavitVehicle.java
@@ -19,7 +19,6 @@
package org.navitproject.navit;
-import java.util.List;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -32,167 +31,169 @@ import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
-import android.util.Log;
import android.support.v4.content.ContextCompat;
+import android.util.Log;
+
+import java.util.List;
public class NavitVehicle {
-
- private static final String GPS_FIX_CHANGE = "android.location.GPS_FIX_CHANGE";
-
- public static Location lastLocation = null;
-
- private static LocationManager sLocationManager = null;
- private static Context context = null;
- private int vehicle_pcbid;
- private int vehicle_scbid;
- private int vehicle_fcbid;
- private String preciseProvider;
- private String fastProvider;
-
- private static NavitLocationListener preciseLocationListener = null;
- private static NavitLocationListener fastLocationListener = null;
-
- public native void VehicleCallback(int id, Location location);
- public native void VehicleCallback(int id, int satsInView, int satsUsed);
- public native void VehicleCallback(int id, int enabled);
-
- private class NavitLocationListener extends BroadcastReceiver implements GpsStatus.Listener, LocationListener {
- public boolean precise = false;
- public void onLocationChanged(Location location) {
- lastLocation = location;
- // Disable the fast provider if still active
- if (precise && fastProvider != null) {
- sLocationManager.removeUpdates(fastLocationListener);
- fastProvider = null;
- }
-
- VehicleCallback(vehicle_pcbid, location);
- VehicleCallback(vehicle_fcbid, 1);
- }
- public void onProviderDisabled(String provider){}
- public void onProviderEnabled(String provider) {}
- public void onStatusChanged(String provider, int status, Bundle extras) {}
-
- /**
- * Called when the status of the GPS changes.
- */
- public void onGpsStatusChanged (int event) {
- if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
- != PackageManager.PERMISSION_GRANTED) {
- // Permission is not granted
- return;
- }
- GpsStatus status = sLocationManager.getGpsStatus(null);
- int satsInView = 0;
- int satsUsed = 0;
- Iterable<GpsSatellite> sats = status.getSatellites();
- for (GpsSatellite sat : sats) {
- satsInView++;
- if (sat.usedInFix()) {
- satsUsed++;
- }
- }
- VehicleCallback(vehicle_scbid, satsInView, satsUsed);
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(GPS_FIX_CHANGE)) {
- if (intent.getBooleanExtra("enabled", false))
- VehicleCallback(vehicle_fcbid, 1);
- else if (!intent.getBooleanExtra("enabled", true))
- VehicleCallback(vehicle_fcbid, 0);
- }
- }
- }
-
- /**
- * @brief Creates a new {@code NavitVehicle}
- *
- * @param context
- * @param pcbid The address of the position callback function which will be called when a location update is received
- * @param scbid The address of the status callback function which will be called when a status update is received
- * @param fcbid The address of the fix callback function which will be called when a
- * {@code android.location.GPS_FIX_CHANGE} is received, indicating a change in GPS fix status
- */
- NavitVehicle (Context context, int pcbid, int scbid, int fcbid) {
- if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
- != PackageManager.PERMISSION_GRANTED) {
- // Permission is not granted
- return;
- }
- this.context = context;
- sLocationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
- preciseLocationListener = new NavitLocationListener();
- preciseLocationListener.precise = true;
- fastLocationListener = new NavitLocationListener();
-
- /* Use 2 LocationProviders, one precise (usually GPS), and one
- not so precise, but possible faster. The fast provider is
- disabled when the precise provider gets its first fix. */
-
- // Selection criteria for the precise provider
- Criteria highCriteria = new Criteria();
- highCriteria.setAccuracy(Criteria.ACCURACY_FINE);
- highCriteria.setAltitudeRequired(true);
- highCriteria.setBearingRequired(true);
- highCriteria.setCostAllowed(true);
- highCriteria.setPowerRequirement(Criteria.POWER_HIGH);
-
- // Selection criteria for the fast provider
- Criteria lowCriteria = new Criteria();
- lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
- lowCriteria.setAltitudeRequired(false);
- lowCriteria.setBearingRequired(false);
- lowCriteria.setCostAllowed(true);
- lowCriteria.setPowerRequirement(Criteria.POWER_HIGH);
-
- Log.e("NavitVehicle", "Providers " + sLocationManager.getAllProviders());
-
- preciseProvider = sLocationManager.getBestProvider(highCriteria, false);
- Log.e("NavitVehicle", "Precise Provider " + preciseProvider);
- fastProvider = sLocationManager.getBestProvider(lowCriteria, false);
- Log.e("NavitVehicle", "Fast Provider " + fastProvider);
- vehicle_pcbid = pcbid;
- vehicle_scbid = scbid;
- vehicle_fcbid = fcbid;
-
- context.registerReceiver(preciseLocationListener, new IntentFilter(GPS_FIX_CHANGE));
- sLocationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener);
- sLocationManager.addGpsStatusListener(preciseLocationListener);
-
- /*
- * Since Android criteria have no way to specify "fast fix", lowCriteria may return the same
- * provider as highCriteria, even if others are available. In this case, do not register two
- * listeners for the same provider but pick the fast provider manually. (Usually there will
- * only be two providers in total, which makes the choice easy.)
- */
- if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0) {
- List<String> fastProviderList = sLocationManager.getProviders(lowCriteria, false);
- fastProvider = null;
- for (String fastCandidate: fastProviderList) {
- if (preciseProvider.compareTo(fastCandidate) != 0) {
- fastProvider = fastCandidate;
- break;
- }
- }
- }
- if (fastProvider != null) {
- sLocationManager.requestLocationUpdates(fastProvider, 0, 0, fastLocationListener);
- }
- }
-
- public static void removeListener() {
- if (sLocationManager != null) {
- if (preciseLocationListener != null) {
- sLocationManager.removeUpdates(preciseLocationListener);
- sLocationManager.removeGpsStatusListener(preciseLocationListener);
- context.unregisterReceiver(preciseLocationListener);
- }
- if (fastLocationListener != null) sLocationManager.removeUpdates(fastLocationListener);
- }
-
- }
+
+ private static final String GPS_FIX_CHANGE = "android.location.GPS_FIX_CHANGE";
+
+ public static Location lastLocation = null;
+
+ private static LocationManager sLocationManager = null;
+ private static Context context = null;
+ private int vehicle_pcbid;
+ private int vehicle_scbid;
+ private int vehicle_fcbid;
+ private String preciseProvider;
+ private String fastProvider;
+
+ private static NavitLocationListener preciseLocationListener = null;
+ private static NavitLocationListener fastLocationListener = null;
+
+ public native void VehicleCallback(int id, Location location);
+ public native void VehicleCallback(int id, int satsInView, int satsUsed);
+ public native void VehicleCallback(int id, int enabled);
+
+ private class NavitLocationListener extends BroadcastReceiver implements GpsStatus.Listener, LocationListener {
+ public boolean precise = false;
+ public void onLocationChanged(Location location) {
+ lastLocation = location;
+ // Disable the fast provider if still active
+ if (precise && fastProvider != null) {
+ sLocationManager.removeUpdates(fastLocationListener);
+ fastProvider = null;
+ }
+
+ VehicleCallback(vehicle_pcbid, location);
+ VehicleCallback(vehicle_fcbid, 1);
+ }
+ public void onProviderDisabled(String provider){}
+ public void onProviderEnabled(String provider) {}
+ public void onStatusChanged(String provider, int status, Bundle extras) {}
+
+ /**
+ * Called when the status of the GPS changes.
+ */
+ public void onGpsStatusChanged (int event) {
+ if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED) {
+ // Permission is not granted
+ return;
+ }
+ GpsStatus status = sLocationManager.getGpsStatus(null);
+ int satsInView = 0;
+ int satsUsed = 0;
+ Iterable<GpsSatellite> sats = status.getSatellites();
+ for (GpsSatellite sat : sats) {
+ satsInView++;
+ if (sat.usedInFix()) {
+ satsUsed++;
+ }
+ }
+ VehicleCallback(vehicle_scbid, satsInView, satsUsed);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(GPS_FIX_CHANGE)) {
+ if (intent.getBooleanExtra("enabled", false))
+ VehicleCallback(vehicle_fcbid, 1);
+ else if (!intent.getBooleanExtra("enabled", true))
+ VehicleCallback(vehicle_fcbid, 0);
+ }
+ }
+ }
+
+ /**
+ * @brief Creates a new {@code NavitVehicle}
+ *
+ * @param context
+ * @param pcbid The address of the position callback function which will be called when a location update is received
+ * @param scbid The address of the status callback function which will be called when a status update is received
+ * @param fcbid The address of the fix callback function which will be called when a
+ * {@code android.location.GPS_FIX_CHANGE} is received, indicating a change in GPS fix status
+ */
+ NavitVehicle (Context context, int pcbid, int scbid, int fcbid) {
+ if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED) {
+ // Permission is not granted
+ return;
+ }
+ this.context = context;
+ sLocationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
+ preciseLocationListener = new NavitLocationListener();
+ preciseLocationListener.precise = true;
+ fastLocationListener = new NavitLocationListener();
+
+ /* Use 2 LocationProviders, one precise (usually GPS), and one
+ not so precise, but possible faster. The fast provider is
+ disabled when the precise provider gets its first fix. */
+
+ // Selection criteria for the precise provider
+ Criteria highCriteria = new Criteria();
+ highCriteria.setAccuracy(Criteria.ACCURACY_FINE);
+ highCriteria.setAltitudeRequired(true);
+ highCriteria.setBearingRequired(true);
+ highCriteria.setCostAllowed(true);
+ highCriteria.setPowerRequirement(Criteria.POWER_HIGH);
+
+ // Selection criteria for the fast provider
+ Criteria lowCriteria = new Criteria();
+ lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
+ lowCriteria.setAltitudeRequired(false);
+ lowCriteria.setBearingRequired(false);
+ lowCriteria.setCostAllowed(true);
+ lowCriteria.setPowerRequirement(Criteria.POWER_HIGH);
+
+ Log.e("NavitVehicle", "Providers " + sLocationManager.getAllProviders());
+
+ preciseProvider = sLocationManager.getBestProvider(highCriteria, false);
+ Log.e("NavitVehicle", "Precise Provider " + preciseProvider);
+ fastProvider = sLocationManager.getBestProvider(lowCriteria, false);
+ Log.e("NavitVehicle", "Fast Provider " + fastProvider);
+ vehicle_pcbid = pcbid;
+ vehicle_scbid = scbid;
+ vehicle_fcbid = fcbid;
+
+ context.registerReceiver(preciseLocationListener, new IntentFilter(GPS_FIX_CHANGE));
+ sLocationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener);
+ sLocationManager.addGpsStatusListener(preciseLocationListener);
+
+ /*
+ * Since Android criteria have no way to specify "fast fix", lowCriteria may return the same
+ * provider as highCriteria, even if others are available. In this case, do not register two
+ * listeners for the same provider but pick the fast provider manually. (Usually there will
+ * only be two providers in total, which makes the choice easy.)
+ */
+ if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0) {
+ List<String> fastProviderList = sLocationManager.getProviders(lowCriteria, false);
+ fastProvider = null;
+ for (String fastCandidate: fastProviderList) {
+ if (preciseProvider.compareTo(fastCandidate) != 0) {
+ fastProvider = fastCandidate;
+ break;
+ }
+ }
+ }
+ if (fastProvider != null) {
+ sLocationManager.requestLocationUpdates(fastProvider, 0, 0, fastLocationListener);
+ }
+ }
+
+ public static void removeListener() {
+ if (sLocationManager != null) {
+ if (preciseLocationListener != null) {
+ sLocationManager.removeUpdates(preciseLocationListener);
+ sLocationManager.removeGpsStatusListener(preciseLocationListener);
+ context.unregisterReceiver(preciseLocationListener);
+ }
+ if (fastLocationListener != null) sLocationManager.removeUpdates(fastLocationListener);
+ }
+
+ }
}
diff --git a/navit/android/src/org/navitproject/navit/NavitWatch.java b/navit/android/src/org/navitproject/navit/NavitWatch.java
index ebe5c8727..c73d451be 100644
--- a/navit/android/src/org/navitproject/navit/NavitWatch.java
+++ b/navit/android/src/org/navitproject/navit/NavitWatch.java
@@ -19,84 +19,85 @@
package org.navitproject.navit;
-import java.lang.Thread;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
+import java.lang.Thread;
+
public class NavitWatch implements Runnable {
- private Thread thread;
- private static Handler handler =new Handler() {
- public void handleMessage(Message m) {
- Log.e("NavitWatch","Handler received message");
- }
- };
- private boolean removed;
- private int watch_func;
- private int watch_fd;
- private int watch_cond;
- private int watch_callbackid;
- private boolean callback_pending;
- private Runnable callback_runnable;
- public native void poll(int func, int fd, int cond);
- public native void WatchCallback(int id);
+ private Thread thread;
+ private static Handler handler =new Handler() {
+ public void handleMessage(Message m) {
+ Log.e("NavitWatch","Handler received message");
+ }
+ };
+ private boolean removed;
+ private int watch_func;
+ private int watch_fd;
+ private int watch_cond;
+ private int watch_callbackid;
+ private boolean callback_pending;
+ private Runnable callback_runnable;
+ public native void poll(int func, int fd, int cond);
+ public native void WatchCallback(int id);
- NavitWatch(int func, int fd, int cond, int callbackid)
- {
- // Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread " + java.lang.Thread.currentThread().getName());
- watch_func=func;
- watch_fd=fd;
- watch_cond=cond;
- watch_callbackid=callbackid;
- final NavitWatch navitwatch=this;
- callback_runnable = new Runnable() {
- public void run()
- {
- navitwatch.callback();
- }
- };
- thread = new Thread(this, "poll thread");
- thread.start();
- }
- public void run()
- {
- for (;;) {
- // Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + java.lang.Thread.currentThread().getName());
- poll(watch_func, watch_fd, watch_cond);
- // Log.e("NavitWatch","poll returned");
- if (removed)
- break;
- callback_pending=true;
- handler.post(callback_runnable);
- try {
- // Log.e("NavitWatch","wait");
- synchronized(this) {
- if (callback_pending)
- this.wait();
- }
- // Log.e("NavitWatch","wait returned");
- } catch (Exception e) {
- Log.e("NavitWatch","Exception "+e.getMessage());
- }
- if (removed)
- break;
- }
- }
- public void callback()
- {
- // Log.e("NavitWatch","Calling Callback");
- if (!removed)
- WatchCallback(watch_callbackid);
- synchronized(this) {
- callback_pending=false;
- // Log.e("NavitWatch","Waking up");
- this.notify();
- }
- }
- public void remove()
- {
- removed=true;
- thread.interrupt();
- }
+ NavitWatch(int func, int fd, int cond, int callbackid)
+ {
+ // Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread " + java.lang.Thread.currentThread().getName());
+ watch_func=func;
+ watch_fd=fd;
+ watch_cond=cond;
+ watch_callbackid=callbackid;
+ final NavitWatch navitwatch=this;
+ callback_runnable = new Runnable() {
+ public void run()
+ {
+ navitwatch.callback();
+ }
+ };
+ thread = new Thread(this, "poll thread");
+ thread.start();
+ }
+ public void run()
+ {
+ for (;;) {
+ // Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + java.lang.Thread.currentThread().getName());
+ poll(watch_func, watch_fd, watch_cond);
+ // Log.e("NavitWatch","poll returned");
+ if (removed)
+ break;
+ callback_pending=true;
+ handler.post(callback_runnable);
+ try {
+ // Log.e("NavitWatch","wait");
+ synchronized(this) {
+ if (callback_pending)
+ this.wait();
+ }
+ // Log.e("NavitWatch","wait returned");
+ } catch (Exception e) {
+ Log.e("NavitWatch","Exception "+e.getMessage());
+ }
+ if (removed)
+ break;
+ }
+ }
+ public void callback()
+ {
+ // Log.e("NavitWatch","Calling Callback");
+ if (!removed)
+ WatchCallback(watch_callbackid);
+ synchronized(this) {
+ callback_pending=false;
+ // Log.e("NavitWatch","Waking up");
+ this.notify();
+ }
+ }
+ public void remove()
+ {
+ removed=true;
+ thread.interrupt();
+ }
}