Create a night mode style for the Merchants & Tellers map and apply it only when the app is in night mode, use the default map theme otherwise.

This commit is contained in:
Severiano Jaramillo 2019-01-22 15:53:14 -06:00
parent 227e0224a1
commit 2ed39fabdd
2 changed files with 184 additions and 4 deletions

View file

@ -12,9 +12,6 @@ import android.view.ViewGroup
import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import cy.agorise.bitsybitshareswallet.R import cy.agorise.bitsybitshareswallet.R
@ -28,8 +25,9 @@ import java.io.IOException
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.preference.PreferenceManager
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.google.android.gms.maps.model.BitmapDescriptor import com.google.android.gms.maps.model.*
import cy.agorise.bitsybitshareswallet.database.entities.Merchant import cy.agorise.bitsybitshareswallet.database.entities.Merchant
import cy.agorise.bitsybitshareswallet.utils.Constants import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.utils.toast import cy.agorise.bitsybitshareswallet.utils.toast
@ -105,6 +103,8 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
override fun onMapReady(googleMap: GoogleMap) { override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap mMap = googleMap
applyMapTheme()
verifyLocationPermission() verifyLocationPermission()
val gson = GsonBuilder() val gson = GsonBuilder()
@ -120,6 +120,25 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
call.enqueue(this) call.enqueue(this)
} }
private fun applyMapTheme() {
val nightMode = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(Constants.KEY_NIGHT_MODE_ACTIVATED, false)
if (nightMode) {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
val success = mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
context, R.raw.map_style_night
)
)
if (!success) {
Log.e(TAG, "Style parsing failed.")
}
}
}
override fun onResponse(call: Call<FeathersResponse<Merchant>>, response: Response<FeathersResponse<Merchant>>) { override fun onResponse(call: Call<FeathersResponse<Merchant>>, response: Response<FeathersResponse<Merchant>>) {
if (response.isSuccessful) { if (response.isSuccessful) {
val res: FeathersResponse<Merchant>? = response.body() val res: FeathersResponse<Merchant>? = response.body()

View file

@ -0,0 +1,161 @@
[
{
"elementType": "geometry",
"stylers": [
{
"color": "#242f3e"
}
]
},
{
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#746855"
}
]
},
{
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#242f3e"
}
]
},
{
"featureType": "administrative.locality",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#d59563"
}
]
},
{
"featureType": "poi",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#d59563"
}
]
},
{
"featureType": "poi.park",
"elementType": "geometry",
"stylers": [
{
"color": "#263c3f"
}
]
},
{
"featureType": "poi.park",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#6b9a76"
}
]
},
{
"featureType": "road",
"elementType": "geometry",
"stylers": [
{
"color": "#38414e"
}
]
},
{
"featureType": "road",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#212a37"
}
]
},
{
"featureType": "road",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#9ca5b3"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry",
"stylers": [
{
"color": "#746855"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#1f2835"
}
]
},
{
"featureType": "road.highway",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#f3d19c"
}
]
},
{
"featureType": "transit",
"elementType": "geometry",
"stylers": [
{
"color": "#2f3948"
}
]
},
{
"featureType": "transit.station",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#d59563"
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{
"color": "#17263c"
}
]
},
{
"featureType": "water",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#515c6d"
}
]
},
{
"featureType": "water",
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#17263c"
}
]
}
]