Skip to content

Commit

Permalink
Add House Styles Switcher (#803)
Browse files Browse the repository at this point in the history
* #793 - Updating SDK, Tools, and Support Libraries to API 25

* #793 - Updating CircleCI to use Android 25

*  #700 - Adding House Styles switcher to Settings

* #700 - Importing specific classes instead of wildcard package

* #700 - Updating tests
  • Loading branch information
bleege authored and ecgreb committed Dec 29, 2016
1 parent 47c49dc commit bdfddbe
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ gradle.startParameter.getTaskNames().each { task ->
}

dependencies {
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.mapzen:mapzen-android-sdk:1.2.1'
compile "com.google.dagger:dagger:$dagger_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import android.widget.RelativeLayout
import android.widget.Toast
import com.mapzen.android.graphics.MapView
import com.mapzen.android.graphics.MapzenMap
import com.mapzen.android.graphics.model.BubbleWrapStyle
import com.mapzen.android.graphics.model.CameraType
import com.mapzen.android.graphics.model.CinnabarStyle
import com.mapzen.android.graphics.model.MapStyle
import com.mapzen.android.graphics.model.RefillStyle
import com.mapzen.android.graphics.model.WalkaboutStyle
import com.mapzen.android.graphics.model.ZincStyle
import com.mapzen.android.lost.api.Status
import com.mapzen.android.search.MapzenSearch
import com.mapzen.erasermap.CrashReportService
Expand Down Expand Up @@ -211,6 +217,10 @@ class MainActivity : AppCompatActivity(), MainViewController,
autoCompleteAdapter?.notifyDataSetChanged()
invalidateOptionsMenu()

// Update Style all the time, as there's no access
// to MapzenMap.getStyle() (yet)
setMapStyle(settings.mapzenStyle)

if (enableLocation) {
enableLocation = false
checkPermissionAndEnableLocation()
Expand Down Expand Up @@ -668,6 +678,22 @@ class MainActivity : AppCompatActivity(), MainViewController,
mapzenMap?.setZoom(zoom, duration)
}

override fun setMapStyle(styleKey: String) {
val index = resources.getStringArray(R.array.mapzen_styles_values).indexOf(styleKey)
Log.i("MainActivity", "Style = " + styleKey + "; Index = " + index)

var mapStyle:MapStyle
when (index) {
0 -> mapStyle = BubbleWrapStyle()
1 -> mapStyle = RefillStyle()
2 -> mapStyle = WalkaboutStyle()
3 -> mapStyle = CinnabarStyle()
4 -> mapStyle = ZincStyle()
else -> mapStyle = BubbleWrapStyle()
}
mapzenMap?.setStyle(mapStyle)
}

override fun placeSearch(gid: String) {
mapzenSearch.setLocationProvider(presenter.getPeliasLocationProvider())
mapzenSearch.place(gid, (PlaceCallback()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface MainViewController {
fun setMapPosition(lngLat: LngLat, duration: Int)
fun setMapZoom(zoom: Float)
fun setMapZoom(zoom: Float, duration: Int)
fun setMapStyle(styleKey: String)
fun getCurrentSearchPosition(): Int
fun toastify(resId: Int)
fun focusSearchView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AndroidAppSettings(val application: EraserMapApplication) : AppSettings {

companion object {
val KEY_DISTANCE_UNITS: String = "list_distance_units"
val KEY_MAPZEN_STYLES: String = "list_mapzen_styles"
val KEY_MOCK_LOCATION_ENABLED: String = "checkbox_mock_location"
val KEY_MOCK_LOCATION_VALUE: String = "edittext_mock_location"
val KEY_MOCK_ROUTE_ENABLED: String = "checkbox_mock_route"
Expand Down Expand Up @@ -54,6 +55,18 @@ class AndroidAppSettings(val application: EraserMapApplication) : AppSettings {
prefs.edit().putString(KEY_DISTANCE_UNITS, value.toString()).commit()
}

override var mapzenStyle: String
get() {
val value = prefs.getString(KEY_MAPZEN_STYLES, null)
if (value != null) {
return value
}
return application.applicationContext.getString(R.string.styles_default);
}
set(value) {
prefs.edit().putString(KEY_MAPZEN_STYLES, value).commit()
}

/**
* Mock location checkbox setting.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.io.File

interface AppSettings {
var distanceUnits: MapzenRouter.DistanceUnits
var mapzenStyle: String
var isMockLocationEnabled: Boolean
var mockLocation: Location
var isMockRouteEnabled: Boolean
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/kotlin/com/mapzen/erasermap/view/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SettingsFragment : PreferenceFragment(), Preference.OnPreferenceCha
initMockDebugPrefs()
}
initDistanceUnitsPref()
initMapzenStylesPref()
initEraseHistoryPref()
}

Expand All @@ -50,6 +51,10 @@ public class SettingsFragment : PreferenceFragment(), Preference.OnPreferenceCha
updateDistanceUnitsPref(preference, value)
return true
}
if (AndroidAppSettings.KEY_MAPZEN_STYLES.equals(preference.key)) {
updateMapzenStylesPref(preference, value)
return true
}
}
if (preference is Preference && value is Boolean) {
if (AndroidAppSettings.KEY_TILE_DEBUG_ENABLED.equals(preference.key)) {
Expand Down Expand Up @@ -96,12 +101,25 @@ public class SettingsFragment : PreferenceFragment(), Preference.OnPreferenceCha
findPreference(key).onPreferenceChangeListener = this
}

private fun initMapzenStylesPref() {
val key = AndroidAppSettings.KEY_MAPZEN_STYLES
val value = settings?.mapzenStyle
updateMapzenStylesPref(findPreference(key), value.toString())
findPreference(key).onPreferenceChangeListener = this
}

private fun updateDistanceUnitsPref(preference: Preference, value: String) {
val index = resources.getStringArray(R.array.distance_units_values).indexOf(value)
val text = resources.getStringArray(R.array.distance_units_entries)[index]
preference.summary = text
}

private fun updateMapzenStylesPref(preference: Preference, value: String) {
val index = resources.getStringArray(R.array.mapzen_styles_values).indexOf(value)
val text = resources.getStringArray(R.array.mapzen_styles_entries)[index]
preference.summary = text
}

private fun initTileDebugPref() {
findPreference(AndroidAppSettings.KEY_TILE_DEBUG_ENABLED).onPreferenceChangeListener = this
updateTileDebugPref(settings?.isTileDebugEnabled ?: false)
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@
<item>miles</item>
<item>kilometers</item>
</string-array>
<string-array name="mapzen_styles_entries">
<item>Bubble Wrap</item>
<item>Refill</item>
<item>Walkabout</item>
<item>Cinnabar</item>
<item>Zinc</item>
</string-array>
<string-array name="mapzen_styles_values">
<item>bubbleWrap</item>
<item>refill</item>
<item>walkabout</item>
<item>cinnabar</item>
<item>zinc</item>
</string-array>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<!-- Routing category -->
<string name="category_routing_title">Routing</string>

<!-- Styles -->
<string name="category_styles">House Styles</string>
<string name="styles_title">Styles</string>
<string name="styles_default">bubbleWrap</string>

<!-- Privacy category -->
<string name="category_privacy_title">Privacy</string>

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

</PreferenceCategory>

<PreferenceCategory android:title="@string/category_styles">

<ListPreference
android:key="list_mapzen_styles"
android:title="@string/styles_title"
android:entries="@array/mapzen_styles_entries"
android:entryValues="@array/mapzen_styles_values"
android:defaultValue="@string/styles_default"/>

</PreferenceCategory>

<PreferenceCategory android:title="@string/category_privacy_title">

<com.mapzen.erasermap.view.ReadOnlyPreference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TestMainController : MainViewController {
var reverseGeoCodeResults: List<Feature>? = null
var lngLat: LngLat? = null
var zoom: Float = 0f
var mapzenStyle: String = ""
var tilt: Float = 0f
var muted: Boolean = false
var rotation: Float = 0f
Expand Down Expand Up @@ -214,7 +215,7 @@ class TestMainController : MainViewController {
override fun placeSearch(gid: String) {
placeSearchPoint = LngLat(0.0, 0.0)
}

// override fun emptyPlaceSearch() {
// isReverseGeocodeVisible = true
// }
Expand Down Expand Up @@ -369,6 +370,10 @@ class TestMainController : MainViewController {
this.zoom = zoom
}

override fun setMapStyle(styleKey: String) {
this.mapzenStyle = styleKey
}

override fun getCurrentSearchPosition(): Int {
return currentSearchItemPosition
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File

class TestAppSettings : AppSettings {
override var distanceUnits: MapzenRouter.DistanceUnits = MapzenRouter.DistanceUnits.MILES
override var mapzenStyle: String = "bubbleWrap"
override var isMockLocationEnabled: Boolean = false
override var mockLocation: Location = TestHelper.getTestAndroidLocation()
override var isMockRouteEnabled: Boolean = false
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.2.3'
}
}

Expand Down

0 comments on commit bdfddbe

Please sign in to comment.