Skip to content

abicelis/PrizeWheelView

Repository files navigation

Prize Wheel View

jcenter jcenter jcenter

About the library

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!

Sample application

Get it on Google Play

Gradle dependency

	dependencies {
    		compile 've.com.abicelis:prizewheelview:1.0.6'
	}

Usage

  1. 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.

  1. 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();
  1. 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
		}
	});
  1. 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

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Rotating and fling-able PrizeWheel for android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages