-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swapped interval slider for number pickers
- Loading branch information
1 parent
93a725f
commit 4958a01
Showing
5 changed files
with
123 additions
and
66 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
57 changes: 17 additions & 40 deletions
57
app/src/main/java/com/iboism/gpxrecorder/recording/configurator/RecordingConfiguratorView.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 |
---|---|---|
@@ -1,61 +1,38 @@ | ||
package com.iboism.gpxrecorder.recording.configurator | ||
|
||
import android.content.Context | ||
import android.graphics.PorterDuff | ||
import android.support.v4.content.ContextCompat | ||
import android.view.View | ||
import android.widget.Button | ||
import android.widget.SeekBar | ||
import android.widget.TextView | ||
import android.widget.EditText | ||
import android.widget.NumberPicker | ||
import com.iboism.gpxrecorder.R | ||
import kotlin.math.roundToInt | ||
|
||
/** | ||
* Created by brad on 5/8/18. | ||
*/ | ||
|
||
private const val INTERVAL_MIN = 1 | ||
|
||
class RecordingConfiguratorView(root: View, | ||
initialIntervalMinutes: Float, | ||
intervalValueTextView: TextView = root.findViewById(R.id.interval_value), | ||
private val intervalSlider: SeekBar = root.findViewById(R.id.interval_seekBar), | ||
initialIntervalMillis: Float, | ||
val titleEditText: EditText = root.findViewById(R.id.config_title_editText), | ||
val doneButton: Button = root.findViewById(R.id.start_button)) { | ||
val doneButton: Button = root.findViewById(R.id.start_button), | ||
val hoursPicker: NumberPicker = root.findViewById(R.id.interval_hours_picker), | ||
val minutesPicker: NumberPicker = root.findViewById(R.id.interval_minutes_picker), | ||
val secondsPicker: NumberPicker = root.findViewById(R.id.interval_seconds_picker)) { | ||
private val context: Context = root.context | ||
|
||
init { | ||
val primaryColor = ContextCompat.getColor(context, R.color.colorPrimary) | ||
|
||
intervalSlider.progressDrawable.setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN) | ||
intervalSlider.thumb.setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN) | ||
intervalSlider.max -= INTERVAL_MIN | ||
|
||
intervalSlider.bindProgress(intervalValueTextView, initialIntervalMinutes) | ||
} | ||
|
||
fun actualInterval(): Float { | ||
return (intervalSlider.progress + INTERVAL_MIN) / 2f | ||
hoursPicker.minValue = 0 | ||
hoursPicker.maxValue = 24 | ||
hoursPicker.wrapSelectorWheel = false | ||
minutesPicker.minValue = 0 | ||
minutesPicker.maxValue = 60 | ||
minutesPicker.wrapSelectorWheel = false | ||
secondsPicker.minValue = 1 | ||
secondsPicker.maxValue = 60 | ||
secondsPicker.wrapSelectorWheel = false | ||
} | ||
|
||
private fun sliderProgressFromActual(interval: Float): Int { | ||
return ((interval * 2) - (INTERVAL_MIN.toFloat() / 2f)).toInt() | ||
} | ||
|
||
private fun SeekBar.bindProgress(textView: TextView, initialValueMinutes: Float) { | ||
this.progress = sliderProgressFromActual(initialValueMinutes) | ||
textView.text = actualInterval().toString() | ||
this.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||
override fun onStartTrackingTouch(p0: SeekBar?) {} | ||
|
||
override fun onStopTrackingTouch(p0: SeekBar?) {} | ||
|
||
override fun onProgressChanged(seekBar: SeekBar?, p1: Int, p2: Boolean) { | ||
seekBar?.let { | ||
textView.text = actualInterval().toString() | ||
} | ||
} | ||
}) | ||
fun getIntervalMillis(): Long { | ||
return (hoursPicker.value * 3600000L) + (minutesPicker.value * 60000L) + (secondsPicker.value * 1000L) | ||
} | ||
} |
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