This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] MapStrictMode implementation
(cherry picked from commit 7227b4a)
- Loading branch information
1 parent
50fee28
commit ce6c382
Showing
16 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapStrictMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.mapbox.mapboxsdk; | ||
|
||
/** | ||
* Using this class you can enable a strict mode that will throw the {@link MapStrictModeException} | ||
* whenever the map would fail silently otherwise. | ||
*/ | ||
public class MapStrictMode { | ||
private static volatile boolean strictModeEnabled; | ||
|
||
/** | ||
* Set the strict mode that will throw the {@link MapStrictModeException} | ||
* whenever the map would fail silently otherwise. | ||
* | ||
* @param strictModeEnabled true to enable the strict mode, false otherwise | ||
*/ | ||
public static synchronized void setStrictModeEnabled(boolean strictModeEnabled) { | ||
MapStrictMode.strictModeEnabled = strictModeEnabled; | ||
} | ||
|
||
/** | ||
* Internal use. Called whenever the strict mode violation occurs. | ||
*/ | ||
public static void strictModeViolation(String message) { | ||
if (strictModeEnabled) { | ||
throw new MapStrictModeException(message); | ||
} | ||
} | ||
|
||
/** | ||
* Internal use. Called whenever the strict mode violation occurs. | ||
*/ | ||
public static void strictModeViolation(String message, Exception exception) { | ||
if (strictModeEnabled) { | ||
throw new MapStrictModeException(String.format("%s - %s", message, exception)); | ||
} | ||
} | ||
|
||
/** | ||
* Internal use. Called whenever the strict mode violation occurs. | ||
*/ | ||
public static void strictModeViolation(String message, Error error) { | ||
if (strictModeEnabled) { | ||
throw new MapStrictModeException(String.format("%s - %s", message, error)); | ||
} | ||
} | ||
|
||
/** | ||
* Internal use. Called whenever the strict mode violation occurs. | ||
*/ | ||
public static void strictModeViolation(Error error) { | ||
if (strictModeEnabled) { | ||
throw new MapStrictModeException(String.format("%s", error)); | ||
} | ||
} | ||
|
||
/** | ||
* Internal use. Called whenever the strict mode violation occurs. | ||
*/ | ||
public static void strictModeViolation(Exception exception) { | ||
if (strictModeEnabled) { | ||
throw new MapStrictModeException(String.format("%s", exception)); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapStrictModeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mapbox.mapboxsdk; | ||
|
||
class MapStrictModeException extends RuntimeException { | ||
MapStrictModeException(String message) { | ||
super(String.format("Map detected an error that would fail silently otherwise: %s", message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters