Skip to content
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

Add compass view #177

Merged
merged 11 commits into from
Dec 7, 2015
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface MainPresenter {
public fun onResume()
public fun onPause()
public fun onFindMeButtonClick()
public fun onCompassClick()
public fun getPeliasLocationProvider(): PeliasLocationProvider
public fun onReroute(location: Location)
public fun onMapMotionEvent(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ public open class MainPresenterImpl(val mapzenLocation: MapzenLocation, val bus:
}
}

override fun onCompassClick() {
mainViewController?.setMapRotation(0f)
}

override fun getPeliasLocationProvider(): PeliasLocationProvider {
return mapzenLocation
}
Expand Down Expand Up @@ -290,4 +294,9 @@ public open class MainPresenterImpl(val mapzenLocation: MapzenLocation, val bus:
mainViewController?.resumeRoutingMode(feature)
}
}

override fun onMapMotionEvent(): Boolean {
mainViewController?.rotateCompass()
return true
}
}
32 changes: 32 additions & 0 deletions app/src/main/kotlin/com/mapzen/erasermap/view/CompassView.kt
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)
}
}
24 changes: 10 additions & 14 deletions app/src/main/kotlin/com/mapzen/erasermap/view/InstructionAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.widget.TextView
import com.mapzen.erasermap.R
import com.mapzen.erasermap.util.DisplayHelper
import com.mapzen.valhalla.Instruction
import java.util.*
import java.util.ArrayList

public class InstructionAdapter(val context: Context, val instructions: ArrayList<Instruction>,
val pager: RouteModeView) : PagerAdapter() {
Expand All @@ -23,30 +23,26 @@ public class InstructionAdapter(val context: Context, val instructions: ArrayLis
var iconId: Int = DisplayHelper.getRouteDrawable(context,
instruction.getIntegerInstruction())
distance.distanceInMeters = instruction.distance
title.setText(instruction.getName())
title.text = instruction.getName()
icon.setImageResource(iconId)
if (position == 0) {
view.findViewById(R.id.left_arrow).setVisibility(View.INVISIBLE)
view.findViewById(R.id.left_arrow).visibility = View.INVISIBLE
}
if (position == getCount() - 1) {
view.findViewById(R.id.right_arrow).setVisibility(View.INVISIBLE)
if (position == count - 1) {
view.findViewById(R.id.right_arrow).visibility = View.INVISIBLE
}
initArrowOnClickListeners(view, position)
setTagId(view, position)
container?.addView(view)
return view
}

fun getView(): View {
return this.getView()
}

override fun getCount(): Int {
return instructions.size()
return instructions.size
}

private fun setTagId(view: View, position: Int) {
view.setTag(RouteModeView.VIEW_TAG + position)
view.tag = RouteModeView.VIEW_TAG + position
}

private fun initArrowOnClickListeners(view: View, position: Int) {
Expand All @@ -59,15 +55,15 @@ public class InstructionAdapter(val context: Context, val instructions: ArrayLis
}

public fun setBackgroundColorActive(view: View?) {
view?.setBackgroundColor(context.getResources().getColor(R.color.transparent_white))
view?.setBackgroundColor(context.resources.getColor(android.R.color.white))
}

public fun setBackgroundColorInactive(view: View?) {
view?.setBackgroundColor(context.getResources().getColor(R.color.transparent_light_gray))
view?.setBackgroundColor(context.resources.getColor(R.color.light_gray))
}

public fun setBackgroundColorArrived(view: View?) {
view?.setBackgroundColor(context.getResources().getColor(R.color.you_have_arrived))
view?.setBackgroundColor(context.resources.getColor(R.color.you_have_arrived))
}

override fun isViewFromObject(view: View?, `object`: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,47 @@ import android.view.View
import android.widget.ListView
import android.widget.TextView
import com.mapzen.erasermap.R
import java.util.ArrayList

public class InstructionListActivity : AppCompatActivity() {
companion object {
@JvmStatic val EXTRA_STRINGS = "instruction_strings"
@JvmStatic val EXTRA_TYPES = "instruction_types"
@JvmStatic val EXTRA_DISTANCES = "instruction_distances"
@JvmStatic val EXTRA_REVERSE = "reverse"
@JvmStatic val EXTRA_DESTINATION = "destination"
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_instructions)
getSupportActionBar()?.hide()
supportActionBar?.hide()
val listView = findViewById(R.id.instruction_list_view) as ListView
findViewById(R.id.route_reverse).setVisibility(View.GONE)
val bundle = getIntent()?.getExtras()
val instruction_strings: ArrayList<String>? = bundle?.getStringArrayList("instruction_strings")
val instruction_types: ArrayList<Int>? = bundle?.getIntegerArrayList("instruction_types")
val instruction_distances: ArrayList<Int>? = bundle?.getIntegerArrayList("instruction_distances")
val reverse : Boolean? = bundle?.getBoolean("reverse", true)
setHeaderOrigins(bundle, reverse)
if (instruction_strings != null) {
listView.setAdapter(DirectionListAdapter(this, instruction_strings, instruction_types, instruction_distances, reverse))
findViewById(R.id.route_reverse).visibility = View.GONE
val bundle = intent?.extras
val strings = bundle?.getStringArrayList(EXTRA_STRINGS)
val types = bundle?.getIntegerArrayList(EXTRA_TYPES)
val distances = bundle?.getIntegerArrayList(EXTRA_DISTANCES)
val destination = bundle?.getString(EXTRA_DESTINATION) ?: getString(R.string.destination)
val reverse = bundle?.getBoolean(EXTRA_REVERSE, true) ?: false
setHeaderOrigins(destination, reverse)
if (strings != null) {
listView.adapter = DirectionListAdapter(this, strings, types, distances, reverse)
listView.setOnItemClickListener { parent, view, position, id ->
setResult(position)
finish()
}
}
}

private fun setHeaderOrigins(bundle: Bundle?, reverse: Boolean?) {
if (reverse == true) {
(findViewById(R.id.starting_point) as TextView).setText(bundle?.getString("destination"))
(findViewById(R.id.destination) as TextView).setText(R.string.current_location)
private fun setHeaderOrigins(destination: String, reverse: Boolean) {
val startTextView = findViewById(R.id.starting_point) as TextView
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay programming

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

val destinationTextView = findViewById(R.id.destination) as TextView
if (reverse) {
startTextView.text = destination
destinationTextView.setText(R.string.current_location)
} else {
(findViewById(R.id.starting_point) as TextView).setText(R.string.current_location)
(findViewById(R.id.destination) as TextView).setText(bundle?.getString("destination"))
startTextView.setText(R.string.current_location)
destinationTextView.text = destination
}
}

Expand Down