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
private fun calculateAngle(x: Float, y: Float): Float { | |
val px = (x / width.toFloat()) - 0.5 | |
val py = ( 1 - y / height.toFloat()) - 0.5 | |
var angle = -(Math.toDegrees(atan2(py, px))) | |
.toFloat() + 90 | |
if (angle > 180) angle -= 360 | |
return angle | |
} |
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
private fun setKnobPosition(angle: Float) { | |
val matrix = Matrix() | |
knobImageView.scaleType = ScaleType.MATRIX | |
matrix.postRotate(angle, width.toFloat() / 2, height.toFloat() / 2) | |
knobImageView.imageMatrix = matrix | |
} |
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
<geva.oren.rotaryknobdemo.RotaryKnobView | |
android:id="@+id/knob" | |
class="geva.oren.rotaryknobdemo.RotaryKnobView" | |
android:layout_width="@dimen/knob_width" | |
android:layout_height="@dimen/knob_height" | |
android:layout_marginBottom="312dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/textView" |
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
package geva.oren.rotaryknobdemo | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import kotlinx.android.synthetic.main.activity_main.* | |
class MainActivity : AppCompatActivity(), RotaryKnobView.RotaryKnobListener { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) |
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
override fun onTouchEvent(event: MotionEvent): Boolean { | |
return if (gestureDetector.onTouchEvent(event)) | |
true | |
else | |
super.onTouchEvent(event) | |
} | |
override fun onDown(event: MotionEvent): Boolean { | |
return true | |
} |
OlderNewer