This library is used on my Chef Buddy app. It displays a rotating fling-able prize wheel, with settable sections (the little pizza shaped slices?). Whenever the wheel settles after being flung, the library notifies a listening class about the winning section.
The sections can be programatically set, and they require a custom List of Section objects. Please see the sample application below!
Add this to your project build.gradle
repositories {
// ...
maven { url 'https://jitpack.io' }
}
Add this to your app module:
dependencies {
// ...
implementation 'com.github.abicelis:PrizeWheelView:1.1.0'
}
- Add the view to your layout
<ve.com.abicelis.prizewheellib.PrizeWheelView
android:id="@+id/home_prize_wheel_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
Note that you can set layout_width and layout_height to predefined values, or one or both to match_parent. The View will take as much space as it can, while still being square.
- In your view class (activity/fragment)
//Get the wheel view
wheelView = (PrizeWheelView) findViewById(R.id.home_prize_wheel_view);
//Populate a List of Sections
List<WheelSection> wheelSections = new ArrayList<>();
wheelSections.add(new WheelBitmapSection(someBitmap));
wheelSections.add(new WheelDrawableSection(R.drawable.some_drawable));
wheelSections.add(new WheelColorSection(R.color.some_color));
//Set those sections
wheelView.setWheelSections(wheelSections);
//Finally, generate wheel
wheelView.generateWheel();
- Listen for wheel events
mWheelView.setWheelEventsListener(new WheelEventsListener() {
@Override
public void onWheelStopped() {
//Handle wheel stopped here
}
@Override
public void onWheelFlung() {
//Handle wheel flinging here
}
@Override
public void onWheelSettled(int sectionIndex, double angle) {
//Handle wheel settle here
}
});
- Set even more options
wheelView.setMarkerPosition(MarkerPosition.TOP_RIGHT);
wheelView.setWheelBorderLineColor(R.color.border);
wheelView.setWheelBorderLineThickness(5);
wheelView.setWheelSeparatorLineColor(R.color.separator);
wheelView.setWheelSeparatorLineThickness(5);
//Set onSettled listener
wheelView.setWheelEventsListener(new WheelEventsListener() {...});
Note that wheelView.generateWheel(); must be called after setting all the options!!
For more options and code, please check the sample project
- Alejandro Bicelis - Coding - abicelis
This project is licensed under the MIT License - see the LICENSE file for details