-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from mapzen/78-add-compass
Add compass view
- Loading branch information
Showing
21 changed files
with
268 additions
and
101 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
32 changes: 32 additions & 0 deletions
32
app/src/main/kotlin/com/mapzen/erasermap/view/CompassView.kt
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,32 @@ | ||
package com.mapzen.erasermap.view | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.widget.ImageView | ||
import android.widget.RelativeLayout | ||
import com.mapzen.erasermap.R | ||
|
||
public class CompassView(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs) { | ||
|
||
val background: ImageView by lazy { findViewById(R.id.background) as ImageView } | ||
val compass: ImageView by lazy { findViewById(R.id.compass) as ImageView } | ||
|
||
init { | ||
(context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater) | ||
.inflate(R.layout.view_compass, this, true) | ||
} | ||
|
||
override fun setRotation(rotation: Float) { | ||
compass.rotation = rotation | ||
if (alpha == 0f) { | ||
alpha = 1f | ||
} | ||
} | ||
|
||
public fun reset() { | ||
val newRotation = if (compass.rotation < 180) 0f else 360f | ||
compass.animate().setDuration(1000).rotation(newRotation) | ||
animate().setDuration(1000).alpha(0f).setStartDelay(1000) | ||
} | ||
} |
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
Oops, something went wrong.