From 598f62dc2434bfc83e227b8ce1b2324e674827aa Mon Sep 17 00:00:00 2001 From: tobrun Date: Wed, 5 Jun 2019 10:15:59 +0200 Subject: [android] - add downstream test app --- platform/android/.gitignore | 1 + .../MapboxGLAndroidSDKDownstreamApp/.gitignore | 1 + .../MapboxGLAndroidSDKDownstreamApp/build.gradle | 78 ++++++++++++++ .../proguard-rules.pro | 21 ++++ .../downstream/ExampleInstrumentedTest.kt | 24 +++++ .../src/main/AndroidManifest.xml | 23 +++++ .../mapbox/mapboxsdk/downstream/MainActivity.java | 94 +++++++++++++++++ .../mapbox/mapboxsdk/downstream/MapActivity.java | 112 +++++++++++++++++++++ .../res/drawable-v24/ic_launcher_foreground.xml | 34 +++++++ .../main/res/drawable/ic_launcher_background.xml | 74 ++++++++++++++ .../src/main/res/layout/activity_donwload.xml | 13 +++ .../src/main/res/layout/activity_main.xml | 33 ++++++ .../src/main/res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../res/mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../src/main/res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../src/main/res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../main/res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../main/res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../main/res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes .../src/main/res/values/colors.xml | 6 ++ .../src/main/res/values/developer-config.xml | 4 + .../src/main/res/values/strings.xml | 3 + .../src/main/res/values/styles.xml | 11 ++ .../mapbox/mapboxsdk/downstream/ExampleUnitTest.kt | 17 ++++ .../android/MapboxGLAndroidSDKTestApp/build.gradle | 5 +- platform/android/build.gradle | 8 +- platform/android/settings.gradle | 2 +- 32 files changed, 566 insertions(+), 8 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/.gitignore create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/build.gradle create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/proguard-rules.pro create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/androidTest/java/com/mapbox/mapboxsdk/downstream/ExampleInstrumentedTest.kt create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/AndroidManifest.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MainActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MapActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable/ic_launcher_background.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/layout/activity_donwload.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/layout/activity_main.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/values/colors.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/values/developer-config.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/values/strings.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/values/styles.xml create mode 100644 platform/android/MapboxGLAndroidSDKDownstreamApp/src/test/java/com/mapbox/mapboxsdk/downstream/ExampleUnitTest.kt diff --git a/platform/android/.gitignore b/platform/android/.gitignore index f5affd93c7..af68f9c007 100644 --- a/platform/android/.gitignore +++ b/platform/android/.gitignore @@ -20,6 +20,7 @@ gradle/configuration.gradle # Token file MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml +MapboxGLAndroidSDKDownstreamApp/src/main/res/values/developer-config.xml # Capture files captures/ diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/.gitignore b/platform/android/MapboxGLAndroidSDKDownstreamApp/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/.gitignore @@ -0,0 +1 @@ +/build diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/build.gradle b/platform/android/MapboxGLAndroidSDKDownstreamApp/build.gradle new file mode 100644 index 0000000000..6805837205 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/build.gradle @@ -0,0 +1,78 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + + defaultConfig { + applicationId "com.mapbox.mapboxsdk.downstream" + minSdkVersion androidVersions.minSdkVersion + targetSdkVersion androidVersions.targetSdkVersion + versionCode 1 + versionName "0.0.1" + testInstrumentationRunner "com.mapbox.mapboxsdk.InstrumentationRunner" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + lintOptions { + baseline file("lint-baseline-local.xml") + checkAllWarnings true + warningsAsErrors true + disable 'MissingTranslation', 'GoogleAppIndexingWarning', 'UnpackedNativeCode', 'IconDipSize', 'TypographyQuotes' + abortOnError false + } + + buildTypes { + release { + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.debug + } + } + + dexOptions { + maxProcessCount 8 + javaMaxHeapSize "2g" + preDexLibraries true + } +} + +dependencies { + implementation dependenciesList.kotlinLib + + implementation project(':MapboxGLAndroidSDK') + implementation dependenciesList.mapboxJavaTurf + + implementation dependenciesList.supportAppcompatV7 + implementation dependenciesList.supportRecyclerView + implementation dependenciesList.supportDesign + implementation dependenciesList.supportConstraintLayout + + implementation dependenciesList.gmsLocation + implementation dependenciesList.timber + debugImplementation dependenciesList.leakCanaryDebug + releaseImplementation dependenciesList.leakCanaryRelease + + androidTestImplementation dependenciesList.supportAnnotations + androidTestImplementation dependenciesList.testRunner + androidTestImplementation dependenciesList.testRules + androidTestImplementation dependenciesList.testEspressoCore + androidTestImplementation dependenciesList.testEspressoIntents + androidTestImplementation dependenciesList.testEspressoContrib + androidTestImplementation dependenciesList.testUiAutomator + + implementation('com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.6.0') { + exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-sdk' + } +} + +apply from: "${rootDir}/gradle/gradle-make.gradle" +apply from: "${rootDir}/gradle/gradle-config.gradle" +apply from: "${rootDir}/gradle/gradle-checkstyle.gradle" +apply from: "${rootDir}/gradle/gradle-lint.gradle" +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/proguard-rules.pro b/platform/android/MapboxGLAndroidSDKDownstreamApp/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/src/androidTest/java/com/mapbox/mapboxsdk/downstream/ExampleInstrumentedTest.kt b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/androidTest/java/com/mapbox/mapboxsdk/downstream/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..19a89dcb9e --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/androidTest/java/com/mapbox/mapboxsdk/downstream/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.mapbox.mapboxsdk.downstream + +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext() + assertEquals("com.mapbox.mapboxsdk.downstream", appContext.packageName) + } +} diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..4ff2ca67a4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MainActivity.java b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MainActivity.java new file mode 100644 index 0000000000..49a509432a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MainActivity.java @@ -0,0 +1,94 @@ +package com.mapbox.mapboxsdk.downstream; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import com.google.gson.JsonObject; +import com.mapbox.mapboxsdk.Mapbox; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.log.Logger; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.offline.OfflineManager; +import com.mapbox.mapboxsdk.offline.OfflineRegion; +import com.mapbox.mapboxsdk.offline.OfflineRegionError; +import com.mapbox.mapboxsdk.offline.OfflineRegionStatus; +import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; +import timber.log.Timber; + +public class MainActivity extends AppCompatActivity { + + private final static String TAG = "Main"; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_donwload); + + Mapbox.getInstance(this, getString(R.string.mapbox_access_token)); + + OfflineManager offlineManager = OfflineManager.getInstance(this); + + LatLngBounds latLngBounds = new LatLngBounds.Builder() + .include(new LatLng(50.849772, 5.688173)) + .include(new LatLng(50.843630, 5.710903)) + .build(); + + float pixelRatio = getResources().getDisplayMetrics().density; + + OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition( + Style.MAPBOX_STREETS, latLngBounds, 16, 20, pixelRatio + ); + + offlineManager.createOfflineRegion(definition, convertRegionName("test"), new OfflineManager.CreateOfflineRegionCallback() { + @Override + public void onCreate(OfflineRegion offlineRegion) { + offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE); + offlineRegion.setObserver(new OfflineRegion.OfflineRegionObserver() { + @Override + public void onStatusChanged(OfflineRegionStatus status) { + if (status.isComplete()) { + View button = findViewById(R.id.button); + button.setVisibility(View.VISIBLE); + button.setOnClickListener(v -> { + Intent intent = new Intent(v.getContext(), MapActivity.class); + startActivity(intent); + }); + } + } + + @Override + public void onError(OfflineRegionError error) { + Logger.e(TAG, error.getMessage()); + } + + @Override + public void mapboxTileCountLimitExceeded(long limit) { + + } + }); + } + + @Override + public void onError(String error) { + Logger.e(TAG, error); + } + }); + } + + public static final String JSON_CHARSET = "UTF-8"; + public static final String JSON_FIELD_REGION_NAME = "FIELD_REGION_NAME"; + + public static byte[] convertRegionName(String regionName) { + try { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty(JSON_FIELD_REGION_NAME, regionName); + return jsonObject.toString().getBytes(JSON_CHARSET); + } catch (Exception exception) { + Timber.e(exception, "Failed to encode metadata: "); + } + return null; + } +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MapActivity.java b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MapActivity.java new file mode 100644 index 0000000000..47309c3fc5 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/java/com/mapbox/mapboxsdk/downstream/MapActivity.java @@ -0,0 +1,112 @@ +package com.mapbox.mapboxsdk.downstream; + +import android.animation.ValueAnimator; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.TextView; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.plugins.annotation.Symbol; +import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager; +import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions; +import com.mapbox.mapboxsdk.utils.BitmapUtils; +import timber.log.Timber; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * Activity showcasing adding symbols using the annotation plugin + */ +public class MapActivity extends AppCompatActivity { + + private static final String ID_ICON = "airport"; + + private MapView mapView; + private SymbolManager symbolManager; + private Symbol symbol; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mapView = findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> { + findViewById(R.id.fabStyles).setOnClickListener(v -> mapboxMap.setStyle(Style.DARK)); + + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(50.846317, 5.698414), 17)); + + style.addImage(ID_ICON, BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.mapbox_marker_icon_default)), false); + + // create symbol manager + symbolManager = new SymbolManager(mapView, mapboxMap, style); + symbolManager.setIconAllowOverlap(true); + symbolManager.setTextAllowOverlap(true); + + // create a symbol + SymbolOptions symbolOptions = new SymbolOptions() + .withLatLng(new LatLng(50.846202, 5.69738)) + .withIconImage(ID_ICON) + .withTextFont(new String[]{"Open Sans Regular","Arial Unicode MS Regular"}) + .withIconSize(1.3f) + .withTextField("Hello World") + .withZIndex(10); + symbol = symbolManager.create(symbolOptions); + Timber.e(symbol.toString()); + + + })); + } + + @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(); + + if (symbolManager != null) { + symbolManager.onDestroy(); + } + + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable-v24/ic_launcher_foreground.xml b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000000..6348baae39 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable/ic_launcher_background.xml b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000000..a0ad202f9e --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/layout/activity_donwload.xml b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/layout/activity_donwload.xml new file mode 100644 index 0000000000..b8364d4a8a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKDownstreamApp/src/main/res/layout/activity_donwload.xml @@ -0,0 +1,13 @@ + + + +