Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - modularise the sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Aug 15, 2018
1 parent f3ebdae commit d0fbde0
Show file tree
Hide file tree
Showing 53 changed files with 1,494 additions and 506 deletions.
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 206 files
3 changes: 1 addition & 2 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies {
}
implementation dependenciesList.supportAnnotations
implementation dependenciesList.supportFragmentV4
implementation dependenciesList.timber
implementation dependenciesList.okhttp3
testImplementation dependenciesList.junit
testImplementation dependenciesList.mockito
Expand Down Expand Up @@ -159,4 +158,4 @@ apply from: "${rootDir}/gradle/gradle-javadoc.gradle"
apply from: "${rootDir}/gradle/gradle-publish.gradle"
apply from: "${rootDir}/gradle/gradle-checkstyle.gradle"
apply from: "${rootDir}/gradle/gradle-tests-staticblockremover.gradle"
apply from: "${rootDir}/gradle/gradle-dependencies-graph.gradle"
apply from: "${rootDir}/gradle/gradle-dependencies-graph.gradle"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mapbox.mapboxsdk;

import timber.log.Timber;
import com.mapbox.mapboxsdk.log.Logger;

/**
* Loads the mapbox-gl shared library
Expand All @@ -11,6 +11,8 @@
*/
public abstract class LibraryLoader {

private static final String TAG = "LibraryLoader";

private static final LibraryLoader DEFAULT = new LibraryLoader() {
@Override
public void load(String name) {
Expand Down Expand Up @@ -39,7 +41,7 @@ public static void load() {
try {
loader.load("mapbox-gl");
} catch (UnsatisfiedLinkError error) {
Timber.e(error, "Failed to load native shared library.");
Logger.e(TAG, "Failed to load native shared library.", error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import android.support.annotation.UiThread;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
import com.mapbox.mapboxsdk.maps.Telemetry;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
import timber.log.Timber;

import static android.content.ContentValues.TAG;

/**
* The entry point to initialize the Mapbox Android SDK.
Expand All @@ -22,13 +24,16 @@
* </p>
*/
@UiThread
@SuppressLint("StaticFieldLeak")
public final class Mapbox {

@SuppressLint("StaticFieldLeak")
private static ModuleProvider moduleProvider;
private static Mapbox INSTANCE;

private Context context;
private String accessToken;
private Boolean connected;
private TelemetryDefinition telemetry;

/**
* Get an instance of Mapbox.
Expand Down Expand Up @@ -116,10 +121,42 @@ public static synchronized Boolean isConnected() {
*/
private static void initializeTelemetry() {
try {
Telemetry.initialize();
INSTANCE.telemetry = getModuleProvider().obtianTelemetry();
} catch (Exception exception) {
Timber.e(exception);
Logger.e(TAG, "Error occured while initializing telemetry", exception);
}
}

/**
* Get an instance of TelemetryImpl if initialised
*
* @return instance of telemetry
*/
@Nullable
public static TelemetryDefinition getTelemetry() {
return INSTANCE.telemetry;
}

/**
* Get the module provider
*
* @return moduleProvider
*/
@NonNull
public static ModuleProvider getModuleProvider() {
if (moduleProvider == null) {
moduleProvider = new ModuleProviderImpl();
}
return moduleProvider;
}

/**
* Set an alternate module provider.
*
* @param moduleProvider the module provider
*/
public static void setModuleProvider(@NonNull ModuleProvider moduleProvider) {
moduleProvider = moduleProvider;
}

/**
Expand All @@ -145,4 +182,4 @@ static boolean isAccessTokenValid(String accessToken) {
accessToken = accessToken.trim().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
return accessToken.length() != 0 && (accessToken.startsWith("pk.") || accessToken.startsWith("sk."));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mapbox.mapboxsdk;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.http.HttpRequest;
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;

public interface ModuleProvider {

@NonNull
HttpRequest createHttpRequest();

@Nullable
TelemetryDefinition obtianTelemetry();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mapbox.mapboxsdk;

import com.mapbox.mapboxsdk.http.HttpRequest;
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
import com.mapbox.mapboxsdk.module.http.HttpRequestImpl;
import com.mapbox.mapboxsdk.module.telemetry.TelemetryImpl;

/**
* Injects concrete instances of configurable abstractions
*/
public class ModuleProviderImpl implements ModuleProvider {

/**
* Create a new concrete implementation of HttpRequest.
*
* @return a new instance of an HttpRequest
*/
public HttpRequest createHttpRequest() {
return new HttpRequestImpl();
}

/**
* Get the concrete implementation of TelemetryDefinition
*
* @return a single instance of TelemetryImpl
*/
public TelemetryDefinition obtianTelemetry() {
// TODO remove singleton with next major release,
// this is needed to make static methods on TelemetryImpl
// backwards compatible without breaking semver
return TelemetryImpl.getInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Attribution {

private static final String OPENSTREETMAP = "OpenStreetMap";
private static final String OPENSTREETMAP_ABBR = "OSM";
static final String TELEMETRY = "Telemetry Settings";
static final String TELEMETRY = "TelemetryImpl Settings";

static final String IMPROVE_MAP_URL = "https://www.mapbox.com/map-feedback/";
static final String MAPBOX_URL = "https://www.mapbox.com/about/maps/";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mapbox.mapboxsdk.constants;

public class TelemetryConstants {

public static final String TWO_FINGER_TAP = "TwoFingerTap";
public static final String DOUBLE_TAP = "DoubleTap";
public static final String SINGLE_TAP = "SingleTap";
public static final String PAN = "Pan";
public static final String PINCH = "Pinch";
public static final String ROTATION = "Rotation";
public static final String PITCH = "Pitch";

}
Loading

0 comments on commit d0fbde0

Please sign in to comment.