-
Notifications
You must be signed in to change notification settings - Fork 170
feat: Add a ScaleBar composable widget #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d81198
feat: Add a ScaleBar composable component
barbeau 8d87719
chore: Fix typo in docs
barbeau 8985287
docs: Add documentation in README
barbeau 83454c6
docs: Tweak docs
barbeau d19596a
docs: Tweak docs
barbeau 1215f45
chore: Make DarkGray public for ScaleBar configuration
barbeau f2a67ae
docs: Tweak docs
barbeau 63c14e5
chore: Allow setting width and height
barbeau 6ba6d1a
refactor: Rename duration variable and change to Int
barbeau e749526
refactor: Convert unit conversion functions to extension functions
barbeau 32e5a4e
refactor: ScaleBar into maps-compose-widgets package
barbeau 33990bb
chore: Switch to local module so artifact is always tied to same vers…
barbeau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
99 changes: 99 additions & 0 deletions
99
app/src/main/java/com/google/maps/android/compose/ScaleBarActivity.kt
This file contains hidden or 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,99 @@ | ||
| // Copyright 2022 Google LLC | ||
| // | ||
| // 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. | ||
|
|
||
| package com.google.maps.android.compose | ||
|
|
||
| import android.os.Bundle | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.compose.setContent | ||
| import androidx.compose.animation.AnimatedVisibility | ||
| import androidx.compose.animation.EnterTransition | ||
| import androidx.compose.animation.fadeOut | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.wrapContentSize | ||
| import androidx.compose.material.CircularProgressIndicator | ||
| import androidx.compose.material.MaterialTheme | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import com.google.android.gms.maps.model.CameraPosition | ||
| import com.google.android.gms.maps.model.LatLng | ||
| import com.google.maps.android.compose.widgets.DisappearingScaleBar | ||
| import com.google.maps.android.compose.widgets.ScaleBar | ||
|
|
||
| private const val TAG = "ScaleBarActivity" | ||
|
|
||
| private const val zoom = 8f | ||
| private val singapore = LatLng(1.35, 103.87) | ||
| private val defaultCameraPosition = CameraPosition.fromLatLngZoom(singapore, zoom) | ||
|
|
||
| class ScaleBarActivity : ComponentActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
|
|
||
| setContent { | ||
| var isMapLoaded by remember { mutableStateOf(false) } | ||
|
|
||
| // To control and observe the map camera | ||
| val cameraPositionState = rememberCameraPositionState { | ||
| position = defaultCameraPosition | ||
| } | ||
|
|
||
| Box(Modifier.fillMaxSize()) { | ||
| GoogleMap( | ||
| modifier = Modifier.matchParentSize(), | ||
| cameraPositionState = cameraPositionState, | ||
| onMapLoaded = { | ||
| isMapLoaded = true | ||
| } | ||
| ) | ||
| DisappearingScaleBar( | ||
| modifier = Modifier | ||
| .padding(top = 5.dp, end = 15.dp) | ||
| .align(Alignment.TopStart), | ||
| cameraPositionState = cameraPositionState | ||
| ) | ||
| ScaleBar( | ||
| modifier = Modifier | ||
| .padding(top = 5.dp, end = 15.dp) | ||
| .align(Alignment.TopEnd), | ||
| cameraPositionState = cameraPositionState | ||
| ) | ||
| if (!isMapLoaded) { | ||
| AnimatedVisibility( | ||
| modifier = Modifier | ||
| .matchParentSize(), | ||
| visible = !isMapLoaded, | ||
| enter = EnterTransition.None, | ||
| exit = fadeOut() | ||
| ) { | ||
| CircularProgressIndicator( | ||
| modifier = Modifier | ||
| .background(MaterialTheme.colors.background) | ||
| .wrapContentSize() | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| /build |
This file contains hidden or 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,51 @@ | ||
| plugins { | ||
| id 'kotlin-android' | ||
| id 'kotlin-parcelize' | ||
| } | ||
|
|
||
| android { | ||
| compileSdk 31 | ||
|
|
||
| defaultConfig { | ||
| minSdk 21 | ||
| targetSdk 31 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| } | ||
|
|
||
| composeOptions { | ||
| kotlinCompilerExtensionVersion "$compose_version" | ||
| } | ||
|
|
||
| buildFeatures { | ||
| buildConfig false | ||
| compose true | ||
| } | ||
|
|
||
| kotlinOptions { | ||
| jvmTarget = '1.8' | ||
| freeCompilerArgs += '-Xexplicit-api=strict' | ||
| freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn' | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation "androidx.compose.foundation:foundation:$compose_version" | ||
| implementation project(':maps-compose') | ||
| implementation 'androidx.compose.material:material:1.1.1' | ||
| implementation 'androidx.core:core-ktx:1.7.0' | ||
| implementation 'com.google.android.gms:play-services-maps:18.0.2' | ||
| implementation 'com.google.maps.android:maps-ktx:3.4.0' | ||
| implementation 'com.google.maps.android:maps-utils-ktx:3.3.0' | ||
|
|
||
| testImplementation 'junit:junit:4.13.2' | ||
| androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
| androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
| implementation "androidx.core:core-ktx:1.7.0" | ||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
| } | ||
Empty file.
This file contains hidden or 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,21 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # You can control the set of applied configuration files using the | ||
| # proguardFiles setting in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} | ||
|
|
||
| # Uncomment this to preserve the line number information for | ||
| # debugging stack traces. | ||
| #-keepattributes SourceFile,LineNumberTable | ||
|
|
||
| # If you keep the line number information, uncomment this to | ||
| # hide the original source file name. | ||
| #-renamesourcefileattribute SourceFile |
36 changes: 36 additions & 0 deletions
36
...s/src/androidTest/java/com/google/maps/android/compose/widgets/ExampleInstrumentedTest.kt
This file contains hidden or 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,36 @@ | ||
| // Copyright 2021 Google LLC | ||
| // | ||
| // 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. | ||
|
|
||
| package com.google.maps.android.compose.widgets | ||
|
|
||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| /** | ||
| * Instrumented test, which will execute on an Android device. | ||
| * | ||
| * See [testing documentation](http://d.android.com/tools/testing). | ||
| */ | ||
| @RunWith(AndroidJUnit4::class) | ||
| internal class ExampleInstrumentedTest { | ||
| @Test | ||
| fun useAppContext() { | ||
| // Context of the app under test. | ||
| val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
| assertEquals("com.google.maps.android.compose.widgets.test", appContext.packageName) | ||
| } | ||
| } |
This file contains hidden or 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,20 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| Copyright 2021 Google LLC | ||
|
|
||
| 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. | ||
| --> | ||
|
|
||
| <manifest package="com.google.maps.android.compose.widgets"> | ||
|
|
||
| </manifest> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: dependencies shared across modules should be defined in a separate gradle file so there is one version used by both artifacts. doesn't have to be addressed now but something for future reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I opened #160 for this.