/LuckyWheelView

A custom lightweight component that displays a Lucky Wheel developed with Kotlin. Features easy customize of colors , text, icon, arrow, animation, rotation and addition of items and it's very easy to integrate in your application.

Primary LanguageKotlinApache License 2.0Apache-2.0

Lucky Wheel View

Contributors Forks Stargazers Issues MIT License LinkedIn

Android Weekly JitPack Version JitPack Download Week JitPack Download Month

Table of Contents
  1. About The Project
  2. Installation
  3. Usage
  4. Examples
  5. Customization
  6. Support
  7. Roadmap
  8. Contributing
  9. License
  10. Contact

About The Project

There are many great Lucky Wheel View available on GitHub; however, I didn't find one that really suited my needs so I created this enhanced one. I want to create a Lucky Wheel View so amazing that it'll be the last one you ever need -- I think this is it.

Here's why:

  • Almost all views/elements can be customize
  • Almost all events can listenable
  • Random or specific target can be set
  • Almost no need for work on logic, all logic is settle

Of course, your needs may be different. So I'll be adding more in the near future. You may also suggest changes by forking this repo and creating a pull request or opening an issue. Thanks to all the people have contributed to expanding this library!

Use the Lucky Wheel View to get started.

(back to top)

Installation

  1. Add it in your root build.gradle at the end of repositories:
  allprojects {
  	repositories {
  		maven { url 'https://jitpack.io' }
  	}
  }

or

dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}
  1. Add the dependency
dependencies {
          implementation 'com.github.caneryilmaz52:LuckyWheelView:LATEST_VERSION'
  }

(back to top)

Usage

<com.caneryilmaz.apps.luckywheel.ui.LuckyWheelView
        android:id="@+id/luckyWheelView"
        android:layout_width="350dp"
        android:layout_height="350dp" />

Populate a list of WheelData (Note: icon default value is null and null icons are not drawn)

val wheelData = ArrayList<WheelData>()
val item = WheelData(
                text = itemText,
                textColor = textColor,
                backgroundColor = backgroundColor,
                icon = itemIconBitmap
            )

Set data to LuckyWheelView

luckyWheelView.setWheelData(wheelData = wheelData)

Set winner target (default is 0)

luckyWheelView.setTarget(
            target = 3
            rotateRandomTarget = false
        )

Set TargetReachListener listener to LuckyWheelView

luckyWheelView.setTargetReachListener { wheelData ->
            // do something with winner wheel data
        }

Set RotationStatusListener listener to LuckyWheelView if you need

luckyWheelView.setRotationStatusListener { status ->
            when (status) {
                RotationStatus.ROTATING -> { // do something
                }

                RotationStatus.IDLE -> { // do something
                }

                RotationStatus.COMPLETED -> { // do something
                }

                RotationStatus.CANCELED -> { // do something
                }
            }
        }

Rotate wheel to target

luckyWheelView.rotateWheel()

Examples

(back to top)

Customization

Get the perfect look with customization combinations.

Background Customization
Function Attributes Description Type Default Value
setRootLayoutBackgroundDrawable rootLayoutBackgroundDrawable set a drawable to lucky wheel view background drawable null
setRootLayoutBackgroundColor rootLayoutBackgroundColor set a color to lucky wheel view background color transparent
setRootLayoutPadding rootLayoutPadding, rootLayoutPaddingLeft, rootLayoutPaddingTop, rootLayoutPaddingRight, rootLayoutPaddingBottom set padding of lucky wheel view dimension 5dp
Arrow Customization
Function Attributes Description Type Default Value
setArrowPosition arrowPosition set arrow position to top or center enum ArrowPosition.TOP
setArrowAnimationStatus arrowAnimationEnable set arrow animation status boolean true
setArrowSwingDuration arrowSwingDuration set arrow swing animation duration integer 50ms
setArrowSwingDistance arrowSwingDistance set arrow swing animation distance integer 100
setArrowSwingSlowdownMultiplier arrowSwingSlowdownMultiplier set arrow swing animation slowdown multiplier float 0.1F
setWheelTopArrow wheelTopArrow set top arrow image resource drawable -
setWheelTopArrowSize wheelTopArrowWidth, wheelTopArrowHeight set top arrow size dimension 48dp
setWheelTopArrowColor wheelTopArrowColor set top arrow color color -
setWheelTopArrowMargin wheelTopArrowMargin set top arrow margin dimension 0dp
setWheelCenterArrow wheelCenterArrow set center arrow image resource drawable -
setWheelCenterArrowSize wheelCenterArrowWidth, wheelCenterArrowHeight set center arrow size dimension 30dp
setWheelCenterArrowColor wheelCenterArrowColor set center arrow color color -
setWheelCenterArrowMargin wheelCenterArrowMarginTop, wheelCenterArrowMarginBottom set center arrow margin dimension 0dp
Wheel Center Text Customization
Function Attributes Description Type Default Value
setWheelCenterText wheelCenterText set a text to lucky wheel view center string -
setWheelCenterTextColor wheelCenterTextColor set center text color color #000000
setWheelCenterTextSize wheelCenterTextSize set center text size dimension 16sp
setWheelCenterTextFont wheelCenterTextFont set text font of center text typeface Sans Serif
setWheelCenterTextFont wheelCenterTextFont set text font resource of center text reference Sans Serif
Wheel Center Image Customization
Function Attributes Description Type Default Value
setWheelCenterImage wheelCenterImage set center image resource drawable -
setWheelCenterImageSize wheelCenterImageWidth, wheelCenterImageHeight set center image size dimension 30dp
Wheel Rotation Customization
Function Attributes Description Type Default Value
setTarget - set winner item position integer 0
setRotateRandomTarget - set random winner target boolean false
setRotationViaSwipe rotationViaSwipe set rotate wheel via user swipe boolean false
setSwipeDistance swipeDistance set rotate wheel via swipe distance integer 100
stopCenterOfItem stopCenterOfItem set wheel stop position center or random position of wheel slice boolean false
setRotateTime rotateTime set wheel rotation time in ms long 5000L
setRotateSpeed rotateSpeed set wheel rotation speed enum RotationSpeed.Normal
setRotateSpeedMultiplier rotateSpeedMultiplier set wheel rotation speed multiplier float 1F
enableVibration enableVibration set vibration enable when wheel rotation stop boolean false
setVibratePattern - set vibration pattern LongArray longArrayOf(200, 500, 250)
Wheel Customization
Function Attributes Description Type Default Value
setWheelColor wheelColor set wheel color color #FFFFFF
setWheelPadding wheelPadding set wheel padding dimension 2dp
Wheel Item Separator Customization
Function Attributes Description Type Default Value
drawItemSeparator drawItemSeparator set draw item separator boolean false
setWheelItemSeparatorColor wheelItemSeparatorColor set item separator color color #000000
setItemSeparatorThickness itemSeparatorThickness set item separator thickness float 1F
Wheel Center Point Customization
Function Attributes Description Type Default Value
drawCenterPoint drawCenterPoint set draw a point center of wheel boolean false
setCenterPointColor centerPointColor set center point color color #FFFFFF
setCenterPointRadius centerPointRadius set center point size float 30F
Wheel Item Text Customization
Function Attributes Description Type Default Value
setTextOrientation textOrientation set wheel item text orientation enum TextOrientation.HORIZONTAL
setTextPadding textPadding set wheel item text padding dimension 20dp
setTextSize textSize set wheel item text size dimension 16sp
setTextLetterSpacing letterSpacing set wheel item text letter spacing between 0.1F - 1.0F float 0.1F
setTextFont textFont set text font of center text typeface Sans Serif
setTextFont textFont set text font resource of center text reference Sans Serif
Wheel Item Icon Customization
Function Attributes Description Type Default Value
setIconPosition iconPosition set wheel item icon position float 2.0F
setIconSizeMultiplier iconSizeMultiplier set wheel item icon size multiplier float 1.0F

(back to top)

Support

Having amazing people like you behind me is a huge motivation to keep pushing forward and improving my work. 💪

If you like the work that I do, you can help and support me by buying a cup of coffee. ☕️

"Buy Me A Coffee"

(back to top)

Roadmap

  • Any won effect (confetti, sound etc) when wheel stop
  • Light effect like carnival zone
  • Gradient item background

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the Apache 2.0 License. See LICENSE.txt for more information.

(back to top)

Contact

Made with ❤️ by Caner YILMAZ
caneryilmaz.apps@gmail.com

(back to top)