How to Make a Draggable Music Knob in Jetpack Compose - Android Studio Tutorial

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • In this video you will learn how you can create a music knob composable that you can rotate using drag gestures.
    ⭐ Get certificates for your future job
    ⭐ Save countless hours of time
    ⭐ 100% money back guarantee for 30 days
    ⭐ Become a professional Android developer now:
    pl-coding.com/...
    💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
    elopage.com/s/...
    Get the source code for this video here:
    github.com/phi...
    Regular programming advice on my Instagram page: / _philipplackner_
    Checkout my GitHub: github.com/phi...
    You like my free content? Here you can buy me a coffee:
    www.buymeacoff...

КОМЕНТАРІ • 53

  • @codinginflow
    @codinginflow 3 роки тому +34

    nice knob bro

  • @Ayor88
    @Ayor88 7 місяців тому +2

    your videos are gold for self learner !

  • @mehulbisht9708
    @mehulbisht9708 3 роки тому +8

    When you posted that video that declared the end of the ongoing Web dev series on your channel, I really felt confused with your decision after that video, but the very next video you uploaded after that, I still remember the smile that you had when you started the series on Jetpack Compose. Compose is like irresistible for Philipp! Cheers! keep composing happily :)

  • @johanneshuotari
    @johanneshuotari 3 роки тому +2

    The angle calculation solved my games ridiculous bug! Random dynamite got me this time, thanks.

  • @harshrastogi1996
    @harshrastogi1996 7 місяців тому +1

    your videos helps me a lot whenever people ask me the resources to learn Android advice them to learn from the GOAT . U explain things very nicely sir ,really admire you a lot .This video was really amazing learned a lot from your videos LOVE FROM INDIA

  • @Javier_Chang
    @Javier_Chang 3 роки тому +1

    I had checked your code, and thank you for your kindness to add knob photo on the source code, it allows me to create it easily.

  • @titkot96
    @titkot96 2 роки тому

    You are making the best modern Android among YT, thank you so much!

  • @SahilGargjava
    @SahilGargjava 3 роки тому +5

    Just a suggestion,
    if you could try creating the custom composable element first then show all the custom parameters that can be passed into it. By this way I think we can understand better like okay this is why we are adding this parameter. Now what happens is I wouldn't be able to relate to the parameter usage in the beginning itself.
    Anyhow, great tutorials ❤️

  • @valtteri_its_james
    @valtteri_its_james Рік тому +1

    Mate, you are LEGEND!!!

  • @sokrates297
    @sokrates297 3 роки тому +1

    Been waiting to make one of these for a long time!

  • @mohamedzahar7877
    @mohamedzahar7877 19 днів тому

    That was impressive 👏👏👏

  • @tonnie7079
    @tonnie7079 2 роки тому

    Thanks for reminding me about the dreaded Trig fxns, they are not dreaded after all when you use them practically like in this knob.

  • @prateekkumar151
    @prateekkumar151 2 роки тому +3

    Why he had to multiply by -1 to get the correct result?
    The correct explanation (might be wrong):-
    In normal trigonometry, we calculate the angle from the horizontal axis, but in android, the angle is calculated from the vertical axis.
    tan(@) = Base/Height
    What he assumed to be base was actually height in android.
    Also, in the android coordinate system, the top left corner is (0,0)
    So the correct way to calculate tan will be(assuming we are starting our calculation from 1st quadrant):-
    val height =touchX - centerX
    val base = centerY - touchY
    val radianAngle = atan2(height,base)
    val degreeAngle = radianAngle * (180f / PI).toFloat()

  • @halvtysk
    @halvtysk 2 роки тому +1

    Great example that covers a practical use of compose. However, my OCD doesn't like that when you turn the knob all the way to the bottom, there is still one bar that is green... :P

    • @rollebonmarquis7574
      @rollebonmarquis7574 Рік тому

      I suppose, one more problem for your OCD: similar thing happens when you turn the knob to the half. there would be 11 active bars instead of 10, etc.
      The solution imho is simple though: color = if (index < numberActiveBars) barColor else Color.DarkGray. "< than" instead of in range.

  • @abdullahalqahtani3841
    @abdullahalqahtani3841 3 роки тому +2

    Good work 👏. Can we have a tut on how to use google maps with jetpack compose?

  • @Kunal-jp8tn
    @Kunal-jp8tn 2 роки тому

    Thank you so much for this video. Would really appreciate if you make another tutorials for the 'Side Effects & Effect Handlers'.
    It would be really helpful.

  • @Blackops1990
    @Blackops1990 Рік тому

    ThxWorks 100% just small changes starting @9:26 you'll get some red for Int convert and some Doubles + Float Converts. other then at all good

  • @Chintanparmar
    @Chintanparmar 3 роки тому

    Commenting for better reach!

  • @safsfsfdfgdg
    @safsfsfdfgdg Рік тому +3

    The atan2 function takes Y coord first and in the code we took X coord first. I suspect that is the reason you had to negate the value. Also, I am curious why we did not add left coordinate to width/2 to compute centerX and likewise top coordinate to height / 2 to compute centerY?

    • @rollebonmarquis7574
      @rollebonmarquis7574 Рік тому

      In regards to the second part, I think he doesn't add the left and the top coordinate to compute the center because the touch coordinate that we get from the "modifier.pointerInteropFilter {...}" seems to be in respect to the view itself as opposed to anything else (window/parent/etc.). At least that's the impression that I got, and, if that's the case, then size/2 is all that we need for the center (no need for offseting it).

  • @hellosagar
    @hellosagar 3 роки тому

    Great explanation

  • @tanjimahmed213
    @tanjimahmed213 3 роки тому

    Thanks for your amazeing video

  • @leendeiri540
    @leendeiri540 2 роки тому +1

    Great video thank you very much! The knob keeps rotating after it reaches the end and repeating the process from the beginning, is this the normal behavior or am I missing something? :D

  • @junaidahsan66ify
    @junaidahsan66ify 2 роки тому

    You are awesome bro

  • @harisai3580
    @harisai3580 2 роки тому

    You are too great !

  • @toBeABetterTranslator
    @toBeABetterTranslator 3 роки тому

    very intuitive!

  • @rollebonmarquis7574
    @rollebonmarquis7574 Рік тому

    If you don't want to use the minus sign in front of the angle, I think this should be working too:
    touchX = event.x
    touchY = event.y
    val angle = atan2(-(centerX - touchX), centerY - touchY) * (180f / PI).toFloat()
    That's also my answer as to why we need the minus. I don't think it has to do anything with the fact that the first param in kotlin function is y instead of x... Inho it has to do more with how we calculate dy in this case for example (the param that we pass to atan2).
    Here's one more calculation that seems to be working for me:
    val opposite: Float = touchX - centerX
    val adjacent: Float = (touchY - centerY)
    val angleRadians: Float = atan2(y = opposite, x = -adjacent)
    val angleDegrees: Float = (angleRadians * 180 / Math.PI).toFloat()

    • @harishgaming2274
      @harishgaming2274 8 місяців тому

      Could you xplain y there is a - here?

    • @rollebonmarquis7574
      @rollebonmarquis7574 8 місяців тому

      ​@@harishgaming2274 probably, both the minus here and the minus in the video stem from the fact that the y axis in android coordinate system is flipped as opposed to a normal one.

    • @either-king
      @either-king 5 місяців тому

      @@rollebonmarquis7574 may be this angle representing tan inverse function to get angle ?

  • @mustafaammar551
    @mustafaammar551 3 роки тому

    WOW Very cool

  • @surajmaity6194
    @surajmaity6194 Рік тому

    Amazing

  • @mdjahidulislam9205
    @mdjahidulislam9205 3 роки тому

    Thanks a lot

  • @vikrantghadge9356
    @vikrantghadge9356 2 роки тому

    Just curious.. Can we not just add colored surfaces instead of manually drawing rectangle, calculating offsets by hand?

  • @tamilcartoontv720
    @tamilcartoontv720 3 роки тому +1

    Please Make video on following bro,
    1.Jetpack Compose with Room Database
    2.Jetpack Compose with Navigation Compose Crash Course
    3.Jetpack Compose with most used UI (like Textfield, buttons, Dialog box, fab etc.. )Crash Course
    4.Jetpack Compose Notification and Backround Services Crash Course
    5.Jetpack Compose with Google Maps
    6.Jetpack Compose with Exoplayer
    7.Jetpack Compose with Firebase Authentication
    8.Jetpack Compose with firestore etc..
    Above all courses will help us a lot to learn Jetpack Compose bro..
    So pls make it happen 🤗🤗

  • @mohitmotwani9256
    @mohitmotwani9256 2 роки тому

    Thankssss

  • @mrjackson9137
    @mrjackson9137 Рік тому

    just tested this out, maybe I did smth wrong but the knob is overscrolling when reaching 100% and then getting back to 0. Is that intentional behaviour?

  • @abhisekpattnaik2282
    @abhisekpattnaik2282 2 місяці тому

    I am learning Android developer and currently transition xml to compose but when creating modern ui and custom ui and animation then I am not able do that because my math is very so weak how to improve math skill also

  • @hinrichwrage3004
    @hinrichwrage3004 2 роки тому

    Das ist verdammt viel Grün, aber eindeutig nicht hinter Deinen Ohren! :D

  • @doniyorartikov5879
    @doniyorartikov5879 3 роки тому

    Hello
    How saving to listview in sharedpreference with Kotlin ?
    I couldn't do it ,Can you help me ?

  • @bhanuprakashtr2542
    @bhanuprakashtr2542 3 роки тому

    Hi Philipp, I am working on android tv. Does jetpack compose support dpad events for android tv. if yes, Could you please make some vertical and grid layout videos for android tv. I have searched the internet no one has published jetpack compose related to android tv articles. if
    you're able to do it it is really appreciatable

  • @crazythunder6196
    @crazythunder6196 3 роки тому

    Make video about TrafficStats

  • @topgearIQ
    @topgearIQ 2 роки тому

    Sin cos tan 😁
    Or knob rotary

  • @amitmusic2m929
    @amitmusic2m929 3 роки тому

    Amit music 🎶

  • @username-dh4tq
    @username-dh4tq 2 роки тому

    #trimuda :

  • @chad_the_stud
    @chad_the_stud 2 роки тому

    this language is so overwhelming. It's just a volume knob and look at the amount of math and the code to make it

    • @PhilippLackner
      @PhilippLackner  2 роки тому +6

      What has that to do with the language? 😂 You'll need this math in all languages