From 7fbc4f9daab2efe81a38686d367d3633d27faf78 Mon Sep 17 00:00:00 2001 From: Dmitry Yunitsky Date: Fri, 19 Aug 2022 12:53:19 +0300 Subject: [PATCH] Fix nullable motion events (#101) * Bump Maps to v10. * Remove developer-config from tracked files. * Remove wrong NonNull annotations from SimpleStandardOnGestureListener. * Update changelog. * Update README and gradle properties with new version. * Update docker. * Fix checkstyle. * Review comments. * Fix lint. --- CHANGELOG.md | 6 ++ README.md | 16 ++++-- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 25 +++++++++ .../gestures/testapp/MapboxActivity.java | 56 ++----------------- .../android/gestures/testapp/Utils.java | 24 ++------ app/src/main/res/layout/activity_mapbox.xml | 2 +- app/src/main/res/values/developer-config.xml | 4 -- build.gradle | 27 +++++++-- circle.yml | 4 +- gradle/dependencies.gradle | 32 +++++------ gradle/wrapper/gradle-wrapper.properties | 6 +- library/gradle.properties | 2 +- .../gestures/StandardGestureDetector.java | 18 +++--- 14 files changed, 106 insertions(+), 118 deletions(-) delete mode 100644 app/src/main/res/values/developer-config.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 183935b..584a252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog for the Mapbox Gestures for Android +## 0.8.0 - August 19, 2022 +#### Minor features + - Updated dependencies : Maps 10.7.0, targetSdk 31, compileSdk 30. [#101](https://github.com/mapbox/mapbox-gestures-android/pull/101) +#### Breaking changes + - Remove NonNull annotations from SimpleStandardOnGestureListener that have no such annotations in Android sources. [#101](https://github.com/mapbox/mapbox-gestures-android/pull/101) + ## 0.7.0 - April 30, 2020 #### Minor features - Expose a `MoveGestureDetector#moveThresholdRect`. When set, the defined screen area prohibits move gesture to be started. [#96](https://github.com/mapbox/mapbox-gestures-android/pull/96) diff --git a/README.md b/README.md index ebe0ebb..8df7f1b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Mapbox Gestures for Android was inspired by [Android Gesture Detector Framework] The library is implemented in the projects found below, where you can head for more examples: -- [The Mapbox Maps SDK for Android](https://github.com/mapbox/mapbox-gl-native) +- [The Mapbox Maps SDK for Android](https://github.com/mapbox/mapbox-maps-android) - [This library's sample app](https://github.com/mapbox/mapbox-gestures-android/tree/master/app/src/main/java/com/mapbox/android/gestures/testapp) included in this repository Are you using the library in your project as well? Let us know or create a PR, we'll be more than happy to add it to the list! @@ -14,12 +14,12 @@ Are you using the library in your project as well? Let us know or create a PR, w ## Documentation -You'll find all of this library's documentation on [our Mapbox Gestures page](https://www.mapbox.com/android-docs/map-sdk/overview/gestures). This includes information on installation, using the API, and links to the API reference. +You'll find all of this library's documentation on [our Maps Guides user interaction page](https://docs.mapbox.com/android/maps/guides/user-interaction/). This includes information on installation, using the API, and links to the API reference. ## Getting Started -If you are looking to include Mapbox Gestures for Android inside of your project, please take a look at [the detailed instructions](https://www.mapbox.com/android-docs/map-sdk/overview/gestures/) found in our docs. If you are interested in building from source, read the contributing guide inside of this project. +If you are looking to include Mapbox Gestures for Android inside of your project, please take a look at [the detailed instructions](https://docs.mapbox.com/android/maps/guides/user-interaction/) found in our docs. If you are interested in building from source, read the contributing guide inside of this project. To use the Gestures library, include it in your app-level `build.gradle` file. @@ -33,7 +33,7 @@ repositories { ```java // In the app build.gradle file dependencies { - implementation 'com.mapbox.mapboxsdk:mapbox-android-gestures:0.7.0' + implementation 'com.mapbox.mapboxsdk:mapbox-android-gestures:0.8.0' } ``` @@ -49,11 +49,15 @@ repositories { ```java // In the app build.gradle file dependencies { - implementation 'com.mapbox.mapboxsdk:mapbox-android-gestures:0.8.0-SNAPSHOT' + implementation 'com.mapbox.mapboxsdk:mapbox-android-gestures:0.9.0-SNAPSHOT' } ``` -To run the specific Mapbox activity in this repo's test application, include your [developer access token](https://www.mapbox.com/help/define-access-token/) in the `developer-config.xml` file. An access token is not required to run this repo's test application. +#### Mapbox access tokens + +To build test application you need to configure Mapbox access tokens as described at https://docs.mapbox.com/android/maps/guides/install/#configure-credentials. +To build the project you need to specify SDK_REGISTRY_TOKEN as an environmental variable or a gradle property. It is a secret token used to access the SDK Registry (Mapbox Maven instance) during compile time, with a scope set to `DOWNLOADS:READ`. +To run the specific Mapbox activity in this repo's test application, you need to include public token in the [app/src/main/res/values/developer-config.xml] resource file. ## Getting Help diff --git a/app/build.gradle b/app/build.gradle index a0ba554..85b1570 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ dependencies { implementation dependenciesList.kotlinLib implementation dependenciesList.supportAppcompatV7 implementation dependenciesList.timber - implementation(dependenciesList.mapboxSdk) { + implementation(dependenciesList.mapboxMaps) { exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-gestures' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8b458d4..6d2b0fb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,32 @@ + + mapboxMap.setStyle(Style.MAPBOX_STREETS)); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); + MapView mapView = (MapView) findViewById(R.id.map_view); + mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS); } } diff --git a/app/src/main/java/com/mapbox/android/gestures/testapp/Utils.java b/app/src/main/java/com/mapbox/android/gestures/testapp/Utils.java index de90d0c..e6d7d4b 100644 --- a/app/src/main/java/com/mapbox/android/gestures/testapp/Utils.java +++ b/app/src/main/java/com/mapbox/android/gestures/testapp/Utils.java @@ -1,9 +1,8 @@ package com.mapbox.android.gestures.testapp; import android.content.Context; -import androidx.annotation.NonNull; -import com.mapbox.mapboxsdk.Mapbox; +import androidx.annotation.NonNull; public class Utils { @@ -11,26 +10,15 @@ public class Utils { *

* Returns the Mapbox access token set in the app resources. *

- * It will first search for a token in the Mapbox object. If not found it - * will then attempt to load the access token from the - * {@code res/values/dev.xml} development file. + * It will attempt to load the access token from the + * {@code res/values/developer-config.xml} development file. * * @param context The {@link Context} of the {@link android.app.Activity} or {@link android.app.Fragment}. * @return The Mapbox access token or null if not found. */ public static String getMapboxAccessToken(@NonNull Context context) { - try { - // Read out AndroidManifest - String token = Mapbox.getAccessToken(); - if (token == null || token.isEmpty()) { - throw new IllegalArgumentException(); - } - return token; - } catch (Exception exception) { - // Use fallback on string resource, used for development - int tokenResId = context.getResources() - .getIdentifier("mapbox_access_token", "string", context.getPackageName()); - return tokenResId != 0 ? context.getString(tokenResId) : null; - } + int tokenResId = context.getResources().getIdentifier( + "mapbox_access_token", "string", context.getPackageName()); + return tokenResId != 0 ? context.getString(tokenResId) : null; } } diff --git a/app/src/main/res/layout/activity_mapbox.xml b/app/src/main/res/layout/activity_mapbox.xml index 158b13b..1bec076 100644 --- a/app/src/main/res/layout/activity_mapbox.xml +++ b/app/src/main/res/layout/activity_mapbox.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" tools:context="com.mapbox.android.gestures.testapp.MapboxActivity"> - diff --git a/app/src/main/res/values/developer-config.xml b/app/src/main/res/values/developer-config.xml deleted file mode 100644 index 7569782..0000000 --- a/app/src/main/res/values/developer-config.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index dba0cee..c80e374 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,19 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { apply from: "gradle/dependencies.gradle" repositories { google() jcenter() + mavenCentral() + maven { + url 'https://api.mapbox.com/downloads/v2/releases/maven' + authentication { + basic(BasicAuthentication) + } + credentials { + username = "mapbox" + password = System.getenv("SDK_REGISTRY_TOKEN") ?: project.property("SDK_REGISTRY_TOKEN") as String + } + } } dependencies { classpath pluginDependencies.gradle @@ -12,15 +21,23 @@ buildscript { classpath pluginDependencies.androidPublishPlugin classpath pluginDependencies.artifactory classpath pluginDependencies.kotlinPlugin - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } allprojects { repositories { google() - jcenter() + mavenCentral() + maven { + url 'https://api.mapbox.com/downloads/v2/releases/maven' + authentication { + basic(BasicAuthentication) + } + credentials { + username = "mapbox" + password = password = System.getenv("SDK_REGISTRY_TOKEN") ?: project.property("SDK_REGISTRY_TOKEN") as String + } + } maven { url 'https://mapbox.bintray.com/mapbox' } } } diff --git a/circle.yml b/circle.yml index 1b941ce..5885215 100644 --- a/circle.yml +++ b/circle.yml @@ -13,7 +13,7 @@ jobs: build: working_directory: ~/code docker: - - image: mbgl/android-ndk-r20:7b7c4b42cf + - image: mbgl/android-ndk-r21e:latest environment: JVM_OPTS: -Xmx3200m steps: @@ -48,7 +48,7 @@ jobs: only: - master docker: - - image: mbgl/android-ndk-r20:7b7c4b42cf + - image: mbgl/android-ndk-r21e:latest working_directory: ~/code steps: - checkout diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 513c6e6..2310cd9 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -1,36 +1,36 @@ ext { androidVersions = [ minSdkVersion : 14, - targetSdkVersion : 28, - compileSdkVersion: 28, + targetSdkVersion : 30, + compileSdkVersion: 31, ] version = [ - mapboxSdkVersion : '8.6.0', + mapboxMaps : '10.7.0', timber : '4.7.1', - junit : '4.12', + junit : '4.13.2', mockito : '3.2.4', - robolectric : '4.3', - testRunner : '1.1.1', - espresso : '3.2.0', - kotlin : '1.3.41', - appCompat : '1.0.0', - core : '1.0.0', - annotation : '1.0.0' + robolectric : '4.8.1', + testRunner : '1.1.3', + espresso : '3.4.0', + kotlin : '1.5.31', + appCompat : '1.3.0', + core : '1.7.0', // last version compatible with kotlin 1.5.31 + annotation : '1.1.0' ] pluginVersion = [ checkstyle : '8.4', - gradle : '3.4.2', - bintray : '1.8.4', - androidPublish: '3.6.2', - artifactory : '4.9.3', + gradle : '7.0.4', + bintray : '1.8.5', + androidPublish: '3.6.3', + artifactory : '4.29.0' ] dependenciesList = [ // mapbox - mapboxSdk : "com.mapbox.mapboxsdk:mapbox-android-sdk:${version.mapboxSdkVersion}", + mapboxMaps : "com.mapbox.maps:android:${version.mapboxMaps}", // support supportAppcompatV7 : "androidx.appcompat:appcompat:${version.appCompat}", diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f0bed66..3696b8a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jan 18 15:22:24 CET 2019 +#Thu Aug 18 15:53:42 EEST 2022 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/library/gradle.properties b/library/gradle.properties index 01ce881..e5985c6 100644 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.8.0-SNAPSHOT +VERSION_NAME=0.9.0-SNAPSHOT POM_ARTIFACT_ID=mapbox-android-gestures POM_NAME=Mapbox Android Gestures Library POM_DESCRIPTION=Mapbox Android Gestures Library diff --git a/library/src/main/java/com/mapbox/android/gestures/StandardGestureDetector.java b/library/src/main/java/com/mapbox/android/gestures/StandardGestureDetector.java index 6ff6f1d..127ae75 100644 --- a/library/src/main/java/com/mapbox/android/gestures/StandardGestureDetector.java +++ b/library/src/main/java/com/mapbox/android/gestures/StandardGestureDetector.java @@ -97,47 +97,47 @@ public interface StandardOnGestureListener extends GestureDetector.OnGestureList */ public static class SimpleStandardOnGestureListener implements StandardOnGestureListener { @Override - public boolean onSingleTapConfirmed(@NonNull MotionEvent e) { + public boolean onSingleTapConfirmed(MotionEvent e) { return false; } @Override - public boolean onDoubleTap(@NonNull MotionEvent e) { + public boolean onDoubleTap(MotionEvent e) { return false; } @Override - public boolean onDoubleTapEvent(@NonNull MotionEvent e) { + public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override - public boolean onDown(@NonNull MotionEvent e) { + public boolean onDown(MotionEvent e) { return false; } @Override - public void onShowPress(@NonNull MotionEvent e) { + public void onShowPress(MotionEvent e) { } @Override - public boolean onSingleTapUp(@NonNull MotionEvent e) { + public boolean onSingleTapUp(MotionEvent e) { return false; } @Override - public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { + public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override - public void onLongPress(@NonNull MotionEvent e) { + public void onLongPress(MotionEvent e) { } @Override - public boolean onFling(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }