-
Notifications
You must be signed in to change notification settings - Fork 87
/
MainActivity.java
140 lines (112 loc) · 4.38 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.ryan.luckywheel;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import rubikstudio.library.LuckyWheelView;
import rubikstudio.library.model.LuckyItem;
import rubikstudio.library.PielView;
public class MainActivity extends Activity {
List<LuckyItem> data = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LuckyWheelView luckyWheelView = (LuckyWheelView) findViewById(R.id.luckyWheel);
LuckyItem luckyItem1 = new LuckyItem();
luckyItem1.topText = "100";
luckyItem1.icon = R.drawable.test1;
luckyItem1.color = 0xffFFF3E0;
data.add(luckyItem1);
LuckyItem luckyItem2 = new LuckyItem();
luckyItem2.topText = "200";
luckyItem2.icon = R.drawable.test2;
luckyItem2.color = 0xffFFE0B2;
data.add(luckyItem2);
LuckyItem luckyItem3 = new LuckyItem();
luckyItem3.topText = "300";
luckyItem3.icon = R.drawable.test3;
luckyItem3.color = 0xffFFCC80;
data.add(luckyItem3);
//////////////////
LuckyItem luckyItem4 = new LuckyItem();
luckyItem4.topText = "400";
luckyItem4.icon = R.drawable.test4;
luckyItem4.color = 0xffFFF3E0;
data.add(luckyItem4);
LuckyItem luckyItem5 = new LuckyItem();
luckyItem5.topText = "500";
luckyItem5.icon = R.drawable.test5;
luckyItem5.color = 0xffFFE0B2;
data.add(luckyItem5);
LuckyItem luckyItem6 = new LuckyItem();
luckyItem6.topText = "600";
luckyItem6.icon = R.drawable.test6;
luckyItem6.color = 0xffFFCC80;
data.add(luckyItem6);
//////////////////
//////////////////////
LuckyItem luckyItem7 = new LuckyItem();
luckyItem7.topText = "700";
luckyItem7.icon = R.drawable.test7;
luckyItem7.color = 0xffFFF3E0;
data.add(luckyItem7);
LuckyItem luckyItem8 = new LuckyItem();
luckyItem8.topText = "800";
luckyItem8.icon = R.drawable.test8;
luckyItem8.color = 0xffFFE0B2;
data.add(luckyItem8);
LuckyItem luckyItem9 = new LuckyItem();
luckyItem9.topText = "900";
luckyItem9.icon = R.drawable.test9;
luckyItem9.color = 0xffFFCC80;
data.add(luckyItem9);
////////////////////////
LuckyItem luckyItem10 = new LuckyItem();
luckyItem10.topText = "1000";
luckyItem10.icon = R.drawable.test10;
luckyItem10.color = 0xffFFE0B2;
data.add(luckyItem10);
LuckyItem luckyItem11 = new LuckyItem();
luckyItem11.topText = "2000";
luckyItem11.icon = R.drawable.test10;
luckyItem11.color = 0xffFFE0B2;
data.add(luckyItem11);
LuckyItem luckyItem12 = new LuckyItem();
luckyItem12.topText = "3000";
luckyItem12.icon = R.drawable.test10;
luckyItem12.color = 0xffFFE0B2;
data.add(luckyItem12);
/////////////////////
luckyWheelView.setData(data);
luckyWheelView.setRound(5);
/*luckyWheelView.setLuckyWheelBackgrouldColor(0xff0000ff);
luckyWheelView.setLuckyWheelTextColor(0xffcc0000);
luckyWheelView.setLuckyWheelCenterImage(getResources().getDrawable(R.drawable.icon));
luckyWheelView.setLuckyWheelCursorImage(R.drawable.ic_cursor);*/
findViewById(R.id.play).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int index = getRandomIndex();
luckyWheelView.startLuckyWheelWithTargetIndex(index);
}
});
luckyWheelView.setLuckyRoundItemSelectedListener(new LuckyWheelView.LuckyRoundItemSelectedListener() {
@Override
public void LuckyRoundItemSelected(int index) {
Toast.makeText(getApplicationContext(), data.get(index).topText, Toast.LENGTH_SHORT).show();
}
});
}
private int getRandomIndex() {
Random rand = new Random();
return rand.nextInt(data.size() - 1) + 0;
}
private int getRandomRound() {
Random rand = new Random();
return rand.nextInt(10) + 15;
}
}