Map Mode Toggle is a library that allows you to create a widget that will toggle between satellite and map mode when using Google Maps. It is written entirely in Kotlin, nonetheless it can still be used in Java based Android projects :)
Add this in your root build.gradle
file (not your module build.gradle
file):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add this to your module's build.gradle
file:
dependencies {
...
compile 'com.github.devicemagic:MapModeToggle:1.2'
}
}
The easiest way to get started with this simple widget is to look inside the app directory that contains example usage in both Kotlin and Java activities. Below is an overview of how the example project is utilizing the library.
To use this widget in your layout simply copy and paste the xml below. This provides the default functionality.
<devicemagic.map.toggle.ToggleView
android:layout_width="200dp"
android:id="@+id/toggle_view"
android:layout_height="20dp"
/>
There are several other attributes that can be used to configure the button's behaviour and appearance. Some of these attributes can be set programmatically via the widget itself.
<devicemagic.map.toggle.ToggleView
android:layout_width="200dp"
android:id="@+id/toggle_view"
app:primary_color="@color/colorPrimary"
app:stroke_color="@color/colorPrimary"
app:text_size="10dp"
app:stroke_size="2dp"
/>
To set the inital state of the Toggle view you simply use the set mode functionality via Kotlin or Java.
toggleView.setToggleViewState(Mode mode);
toggleView.setToggleViewState(mode: Mode)
To listen to events from your toggle view, simply implement the listener that's triggered once the respective buttons are tapped.
toggleView.setToggleModeListener(new ToggleListener() {
@Override
public void onMapModeSelected() {
}
@Override
public void onSatelliteModeSelected() {
}
});
toggle_view.toggleModeListener = this
override fun onMapModeSelected() {
}
override fun onSatelliteModeSelected() {
}
Espresso tests written in Kotlin :)
Please fork repository and contribute using pull requests.
Any contributions, large or small, major features, bug fixes, additional language translations, unit/integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.
Copyright 2017 Device Magic
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.