diff --git a/build.gradle b/build.gradle index 39e4b4e..d366219 100644 --- a/build.gradle +++ b/build.gradle @@ -36,6 +36,9 @@ dependencies { android { compileSdkVersion 22 buildToolsVersion "22.0.0" + lintOptions { + abortOnError false + } } if (file('user.gradle').exists()) { diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..6c6c37f --- /dev/null +++ b/circle.yml @@ -0,0 +1,190 @@ +machine: + timezone: + Europe/Vienna + java: + version: oraclejdk8 + environment: +###### custom 1 ###### + ZEMU_: "appemu23" + EMU_: "appemu21" + XEMU_: "appemu10" + Zsdpath: "/sdcard" + sdpath: "/storage/sdcard" + Xsdpath: "/mnt/sdcard" +###### custom 1 ###### + +###### custom 2 ###### + XGRADLE_HOME: ~/g/gradle-2.10 + XPATH: ~/g/gradle-2.10/bin:$PATH + GRADLE_CUSTOM_VERSION: N +###### custom 2 ###### + +###### custom 3 ###### + CLASS_P: org.microg.nlp.backend.nominatim + START_INTENT_P: .SettingsActivity + # switch glibc to a memory conserving mode + MALLOC_ARENA_MAX: "2" +###### custom 3 ###### + +############################### +# 0 -> no +# 1 -> C +# 2 -> Java + COVERITY_BUILD_: 0 + COV_PROJ: zoff99%2Fxyz +############################### + + ANDROID_HOME: /usr/local/android-sdk-linux + ANDROID_SDK: /usr/local/android-sdk-linux/ + _SDK_: /usr/local/android-sdk-linux/ + GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx1000m -XX:+HeapDumpOnOutOfMemoryError"' +dependencies: + cache_directories: + - ~/.android + - ~/.gradle + override: + - echo "dummy" + pre: + - sudo apt-get update > /dev/null 2> /dev/null + - sudo apt-get install xvfb > /dev/null 2> /dev/null + - sudo apt-get install xdotool > /dev/null 2> /dev/null + - sudo apt-get install telnet > /dev/null 2> /dev/null + - sudo apt-get install x11-utils > /dev/null 2> /dev/null + - sudo apt-get install xvkbd > /dev/null 2> /dev/null + - sudo apt-get install qrencode > /dev/null 2> /dev/null + - sudo apt-get install zip > /dev/null 2> /dev/null + - sudo apt-get install bc > /dev/null 2> /dev/null + + - gradle -v # display gradle version + - if [ "$GRADLE_CUSTOM_VERSION""x" == "1x" ]; then cd ~ ; wget https://services.gradle.org/distributions/gradle-2.10-bin.zip ; fi + - if [ "$GRADLE_CUSTOM_VERSION""x" == "1x" ]; then mkdir ~/g ; cd ~/g ; unzip ~/gradle-2.10-bin.zip ; fi + - gradle -v # display gradle version + + - echo y | android update sdk --no-ui --all --filter "tools" + - android list sdk --all | grep -i tools + - android list sdk --all --extended + + - echo y | android update sdk --no-ui --all --filter build-tools-22.0.0 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter build-tools-23.0.1 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter build-tools-23.0.2 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter build-tools-23.0.3 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter build-tools-24.0.0 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter android-21 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter android-22 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter android-23 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter android-24 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter platform-tools > /dev/null 2> /dev/null + + - echo y | android update sdk --no-ui --all --filter extra-android-m2repository > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter extra-google-m2repository > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter extra-android-support > /dev/null 2> /dev/null + + # - echo y | android update sdk --no-ui --all --filter extra-google-google_play_services > /dev/null 2> /dev/null + # - echo y | android update sdk --no-ui --all --filter extra-google-google_play_services_froyo > /dev/null 2> /dev/null + # - echo y | android update sdk --no-ui --all --filter extra-google-gcm > /dev/null 2> /dev/null + + #- echo y | android update sdk --no-ui --all --filter platform-tools-preview > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter sys-img-armeabi-v7a-android-23 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter sys-img-armeabi-v7a-android-24 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter sys-img-armeabi-v7a-addon-google_apis-google-23 > /dev/null 2> /dev/null + - echo y | android update sdk --no-ui --all --filter addon-google_apis-google-23 > /dev/null 2> /dev/null + + - if [ "$COVERITY_BUILD_""x" != "0x" ]; then mkdir ~/cov_scan/ && wget https://scan.coverity.com/download/linux-64 --post-data "token=$COVERITY_TOKEN&project=$COV_PROJ" -O ~/cov_scan/coverity_tool.tgz && wget 'http://www.catb.org/~esr/coverity-submit/coverity-submit-1.17.tar.gz' -O ~/cov_scan/coverity-submit.tar.gz && cd ~/cov_scan/ && tar -xzvf coverity_tool.tgz ; fi + + - pwd ; ls -al + +###### custom ###### + - sed -i -e 's,textReport .*,textReport true,' build.gradle ; exit 0 +###### custom ###### + + - ./gradlew lint --info + - ./gradlew assembleDebug --stacktrace --info --no-daemon + + - ls -al build/outputs/apk/ ; exit 0 + - find . -name '*.apk' ; exit 0 + + - if [ "$COVERITY_BUILD_""x" != "0x" ]; then ls -al build/cov-int/ ; exit 0 ; fi + - if [ "$COVERITY_BUILD_""x" != "0x" ]; then cp -v build/cov-int/build-log.txt $CIRCLE_ARTIFACTS/ ; exit 0 ; fi + - if [ "$COVERITY_BUILD_""x" != "0x" ]; then cd build/ ; tar -czvf $CIRCLE_ARTIFACTS/covint.tar.gz cov-int ; exit 0 ; fi + +# --- copy apk file to generic location --- + - mkdir -p ./app/build/outputs/apk/ + - if [ ! -e ./app/build/outputs/apk/app-debug-unaligned.apk ]; then cp -v `find ./build/outputs/apk/ -name '*.apk' 2> /dev/null | tail -1 2> /dev/null` ./app/build/outputs/apk/app-debug-unaligned.apk ; fi +# --- copy apk file to generic location --- + + - zip -d app/build/outputs/apk/app-debug-unaligned.apk META-INF/\* # remove signature !! + - cp -av app/build/outputs/apk/app-debug-unaligned.apk ~/app.apk ; + cd ~/ ; + echo xxxxxxrm -f ~/.android/debug.keystore ; + ls -al ~/.android/debug.keystore ; + if [ ! -f ~/.android/debug.keystore ]; then echo "*** generating new signer key ***" ; + echo "*** generating new signer key ***"; + echo "*** generating new signer key ***"; + keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -keyalg RSA -keysize 2048 -validity 10000 -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" ; + fi ; + ls -al ~/ ; + jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android -sigalg SHA1withRSA -digestalg SHA1 -sigfile CERT -signedjar app-signed.apk app.apk androiddebugkey ; + ls -al ~/ ; + $_SDK_/build-tools/23.0.3/zipalign -v 4 app-signed.apk app-signed-aligned.apk ; + ls -al ~/ ; + pwd ; + ls -al ; + cp -av app-signed-aligned.apk $CIRCLE_ARTIFACTS/${CIRCLE_PROJECT_REPONAME}.apk || exit 1 + +## also make apk files with different names for each build (for individual downloads) + - cp -av $CIRCLE_ARTIFACTS/${CIRCLE_PROJECT_REPONAME}.apk $CIRCLE_ARTIFACTS/${CIRCLE_PROJECT_REPONAME}_circleci_$CIRCLE_SHA1.apk ; exit 0 +## qr code to scan with your phone to directly download the apk file (for convenience) + - qrencode -o $CIRCLE_ARTIFACTS/QR_apk.png 'https://circle-artifacts.com/gh/'${CIRCLE_PROJECT_USERNAME}'/'${CIRCLE_PROJECT_REPONAME}'/'${CIRCLE_BUILD_NUM}'/artifacts/'${CIRCLE_NODE_INDEX}'/tmp/'`basename $CIRCLE_ARTIFACTS`'/'"${CIRCLE_PROJECT_REPONAME}_circleci_$CIRCLE_SHA1.apk" ; exit 0 +## qr code to go directly to the aritfacts (to scan with phone) + - qrencode -o $CIRCLE_ARTIFACTS/QR_artifacts.png 'https://circleci.com/gh/'${CIRCLE_PROJECT_USERNAME}'/'${CIRCLE_PROJECT_REPONAME}'/'${CIRCLE_BUILD_NUM}'#artifacts' ; exit 0 + +test: + pre: + - mksdcard -l e 180M sdcard.img + - echo 'mtools_skip_check=1' > ~/.mtoolsrc + - android list targets +# + - if [ "$EMU_" == "appemu23" ]; then echo "no" | android create avd -n appemu23 -f -t android-23 --abi default/armeabi-v7a --skin "WXGA720" ; fi + - if [ "$EMU_" == "appemu23" ]; then cat ~/.android/avd/appemu23.avd/config.ini ; fi +# + - if [ "$EMU_" == "appemu21" ]; then echo "no" | android create avd -n appemu21 -f -t android-21 --abi default/armeabi-v7a --skin "WXGA720" ; fi + - if [ "$EMU_" == "appemu21" ]; then cat ~/.android/avd/appemu21.avd/config.ini ; fi +# + - if [ "$EMU_" == "appemu10" ]; then echo "no" | android create avd -n appemu10 -f -t android-10 --abi default/armeabi --skin "WQVGA432" ; fi + - if [ "$EMU_" == "appemu10" ]; then cat ~/.android/avd/appemu10.avd/config.ini ; fi +# + - echo "$EMU_" + - echo "$sdpath" + override: + - emulator -avd "$EMU_" -sdcard sdcard.img -no-audio: + background: true + parallel: true + - circle-android wait-for-boot + + - sleep 210 # let the emulator settle down first + + - adb shell input keyevent 82 # remove lock screen on emulator + - sleep 10 + - import -window root $CIRCLE_ARTIFACTS/capture_emulator_running.png + + - fb-adb shell "cat /proc/meminfo" ; exit 0 + + - adb shell ls -al / ; exit 0 + - adb shell ls -al /storage/ ; exit 0 + - adb shell ls -al /sdcard/ ; exit 0 + + - adb install ~/app-signed-aligned.apk + + - adb logcat -v time > $CIRCLE_ARTIFACTS/adb_out.txt 2>&1 : + background: true + - sleep 60 # let the emulator settle down first + + - fb-adb shell am start -n $CLASS_P/$START_INTENT_P + - sleep 60 + - sleep 120 # wait to be sure the app has started fully + + - died_count=`cat $CIRCLE_ARTIFACTS/adb_out.txt|grep 'Process. '"$CLASS_P"', PID.'|wc -l|tr -d ' '` ; if [ $died_count -gt 0 ]; then echo "app crashed"; exit 1; fi + + - import -window root $CIRCLE_ARTIFACTS/capture_app_running.png # get proof that the app is running + - adb shell screencap -p | sed 's/\r$//' > $CIRCLE_ARTIFACTS/capture_app_running_2.png + diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 15a7e95..dcb7525 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,14 +1,15 @@ + android:versionName="1.1.1" + android:versionCode="10101" + package="org.microg.nlp.backend.nominatim"> - + + android:minSdkVersion="11" + android:targetSdkVersion="22" /> + - + + + + + + + + + diff --git a/src/main/java/org/microg/nlp/backend/nominatim/BackendService.java b/src/main/java/org/microg/nlp/backend/nominatim/BackendService.java index 0a4ec07..4f14148 100644 --- a/src/main/java/org/microg/nlp/backend/nominatim/BackendService.java +++ b/src/main/java/org/microg/nlp/backend/nominatim/BackendService.java @@ -1,10 +1,12 @@ package org.microg.nlp.backend.nominatim; import android.content.Context; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.location.Address; import android.net.Uri; import android.os.Build; +import android.preference.PreferenceManager; import android.util.Log; import org.json.JSONArray; @@ -28,11 +30,11 @@ public class BackendService extends GeocoderBackendService { private static final String SERVICE_URL_MAPQUEST = "http://open.mapquestapi.com/nominatim/v1/"; private static final String SERVICE_URL_OSM = " http://nominatim.openstreetmap.org/"; private static final String REVERSE_GEOCODE_URL = - "%sreverse?format=json&accept-language=%s&lat=%f&lon=%f"; + "%sreverse?format=json&key=%s&accept-language=%s&lat=%f&lon=%f"; private static final String SEARCH_GEOCODE_URL = - "%ssearch?format=json&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d"; + "%ssearch?format=json&key=%s&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d"; private static final String SEARCH_GEOCODE_WITH_BOX_URL = - "%ssearch?format=json&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d" + + "%ssearch?format=json&key=%s&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d" + "&viewbox=%f,%f,%f,%f"; private static final String WIRE_LATITUDE = "lat"; private static final String WIRE_LONGITUDE = "lon"; @@ -51,8 +53,12 @@ public class BackendService extends GeocoderBackendService { @Override protected List
getFromLocation(double latitude, double longitude, int maxResults, String locale) { + + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); + String mapquestApiKey = SP.getString("api_preference", "NA"); + String url = String.format(Locale.US, REVERSE_GEOCODE_URL, SERVICE_URL_MAPQUEST, - locale.split("_")[0], latitude, longitude); + mapquestApiKey, locale.split("_")[0], latitude, longitude); try { JSONObject result = new JSONObject(new AsyncGetRequest(this, url).asyncStart().retrieveString()); @@ -84,15 +90,19 @@ private static Locale localeFromLocaleString(String localeString) { protected List
getFromLocationName(String locationName, int maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude, String locale) { + + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); + String mapquestApiKey = SP.getString("api_preference", "NA"); + String query = Uri.encode(locationName); String url; if (lowerLeftLatitude == 0 && lowerLeftLongitude == 0 && upperRightLatitude == 0 && upperRightLongitude == 0) { url = String.format(Locale.US, SEARCH_GEOCODE_URL, SERVICE_URL_MAPQUEST, - locale.split("_")[0], query, maxResults); + mapquestApiKey, locale.split("_")[0], query, maxResults); } else { url = String.format(Locale.US, SEARCH_GEOCODE_WITH_BOX_URL, SERVICE_URL_MAPQUEST, - locale.split("_")[0], query, maxResults, lowerLeftLongitude, + mapquestApiKey, locale.split("_")[0], query, maxResults, lowerLeftLongitude, upperRightLatitude, upperRightLongitude, lowerLeftLatitude); } try { diff --git a/src/main/java/org/microg/nlp/backend/nominatim/SettingsActivity.java b/src/main/java/org/microg/nlp/backend/nominatim/SettingsActivity.java new file mode 100644 index 0000000..1957354 --- /dev/null +++ b/src/main/java/org/microg/nlp/backend/nominatim/SettingsActivity.java @@ -0,0 +1,58 @@ +package org.microg.nlp.backend.nominatim; + +import android.content.SharedPreferences; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.os.Bundle; + +public class SettingsActivity extends PreferenceActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Display the fragment as the main content. + getFragmentManager().beginTransaction() + .replace(android.R.id.content, new PrefsFragment()).commit(); + + } + + public static class PrefsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.preferences); + setSummaries(); + getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + updatePreference(findPreference(key), key); + } + + private void setSummaries(){ + + final SharedPreferences sh = getPreferenceManager().getSharedPreferences() ; + + Preference stylePref = findPreference("api_preference"); + stylePref.setSummary(sh.getString("api_preference", "")); + + } + private void updatePreference(Preference preference, String key) { + if (preference == null) return; + if (preference instanceof ListPreference) { + ListPreference listPreference = (ListPreference) preference; + listPreference.setSummary(listPreference.getEntry()); + return; + } + SharedPreferences sharedPrefs = getPreferenceManager().getSharedPreferences(); + preference.setSummary(sharedPrefs.getString(key, "Default")); + } + } + +} diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index ec5cbfd..db6198f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1,5 +1,10 @@ - NominatimGeocoderBackend + Nominatim Geocoder Backend Nominatim + + MapQuest Server Access + MapQuest Developer API Key + MapQuest Developer API Key + Enter your MapQuest developer API key. diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml new file mode 100644 index 0000000..379748c --- /dev/null +++ b/src/main/res/xml/preferences.xml @@ -0,0 +1,16 @@ + + + + + + + + + +