-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass global variable scene updates when switching styles (#371)
- Loading branch information
1 parent
90f7267
commit 5b54aaf
Showing
9 changed files
with
120 additions
and
16 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
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
29 changes: 29 additions & 0 deletions
29
core/src/main/java/com/mapzen/android/graphics/SceneUpdateManager.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,29 @@ | ||
package com.mapzen.android.graphics; | ||
|
||
import com.mapzen.tangram.SceneUpdate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Manages creation of {@link SceneUpdate}s for api keys and languages. | ||
*/ | ||
class SceneUpdateManager { | ||
|
||
static final String STYLE_GLOBAL_VAR_API_KEY = "global.sdk_mapzen_api_key"; | ||
static final String STYLE_GLOBAL_VAR_LANGUAGE = "global.ux_language"; | ||
|
||
/** | ||
* Creates {@link SceneUpdate}s given an api key and locale. | ||
* @param apiKey user's api key. | ||
* @param locale user's preferred map locale. | ||
* @return scene updates for api key and locale. | ||
*/ | ||
List<SceneUpdate> getUpdatesFor(String apiKey, Locale locale) { | ||
final ArrayList<SceneUpdate> sceneUpdates = new ArrayList<>(2); | ||
sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, apiKey)); | ||
sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, locale.getLanguage())); | ||
return sceneUpdates; | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
core/src/test/java/com/mapzen/android/graphics/SceneUpdateManagerTest.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,33 @@ | ||
package com.mapzen.android.graphics; | ||
|
||
import com.mapzen.tangram.SceneUpdate; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SceneUpdateManagerTest { | ||
|
||
SceneUpdateManager manager; | ||
String apiKey; | ||
Locale locale; | ||
|
||
@Before public void setUp() throws Exception { | ||
manager = new SceneUpdateManager(); | ||
apiKey = "test_key"; | ||
locale = new Locale("fr_fr"); | ||
} | ||
|
||
@Test public void shouldReturnCorrectKeysAndValues() { | ||
List<SceneUpdate> updates = manager.getUpdatesFor(apiKey, locale); | ||
assertThat(updates.size()).isEqualTo(2); | ||
assertThat(updates.get(0).getPath()).isEqualTo("global.sdk_mapzen_api_key"); | ||
assertThat(updates.get(0).getValue()).isEqualTo(apiKey); | ||
assertThat(updates.get(1).getPath()).isEqualTo("global.ux_language"); | ||
assertThat(updates.get(1).getValue()).isEqualTo(locale.getLanguage()); | ||
} | ||
} |
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