forked from raidzero/RZrecovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors_menu.c
186 lines (170 loc) · 3.67 KB
/
colors_menu.c
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/reboot.h>
#include <sys/time.h>
#include "recovery.h"
#include "roots.h"
#include "recovery_ui.h"
void
set_color (char red, char green, char blue)
{
char txt;
if (green >= 150) txt = 0; else txt = 255;
FILE *fp = fopen ("/cache/rgb", "wb");
fwrite (&red, 1, 1, fp);
fwrite (&green, 1, 1, fp);
fwrite (&blue, 1, 1, fp);
fwrite (&txt, 1, 1, fp);
fclose (fp);
if (access ("/cache/rnd", F_OK) != -1) remove("/cache/rnd");
ensure_path_mounted ("/sdcard");
if (access ("/sdcard/RZR/rnd", F_OK) != -1) remove("/sdcard/RZR/rnd");
}
void set_icon (char* icon) {
ensure_path_mounted("/sdcard");
__system("rm /sdcard/RZR/icon*");
__system("rm /cache/icon*");
if (strcmp(icon,"rz")==0) {
ui_set_background(BACKGROUND_ICON_RZ);
__system("echo > /sdcard/RZR/icon_rz && echo > /cache/icon_rz");
}
if (strcmp(icon,"rw")==0) {
ui_set_background(BACKGROUND_ICON_RW);
__system("echo > /sdcard/RZR/icon_rw && echo > /cache/icon_rw");
}
ensure_path_unmounted("/sdcard");
}
void
set_random (int rnd)
{
struct timeval tv;
struct timezone tz;
struct tm *tm;
gettimeofday (&tv, &tz);
tm = localtime (&tv.tv_sec);
srand (tv.tv_usec);
char cR = rand () % 255;
char cG = rand () % 255;
char cB = rand () % 255;
set_color (cR, cG, cB);
if (rnd == 1)
{
set_color(cR, cG, cB);
remove("/cache/rgb");
ensure_path_mounted("/sdcard");
remove("/sdcard/RZR/rgb");
__system("echo rnd > /cache/rnd");
ensure_path_unmounted("/sdcard");
}
}
void
show_colors_menu ()
{
static char *headers[] = { "Choose a color",
"",
NULL
};
char *items[] = { "Random",
"Blue",
"Cyan",
"Green",
"Orange",
"Pink",
"Purple",
"Red",
"Smoked",
"Yellow",
"Gold",
"White",
"Grey",
"RootzWiki",
"Rave mode",
NULL
};
#define RANDOM 0
#define BLUE 1
#define CYAN 2
#define GREEN 3
#define ORANGE 4
#define PINK 5
#define PURPLE 6
#define RED 7
#define SMOKED 8
#define YELLOW 9
#define GOLD 10
#define WHITE 11
#define GREY 12
#define ROOTZ 13
#define RAVE 14
int chosen_item = -1;
while (chosen_item != ITEM_BACK)
{
chosen_item =
get_menu_selection (headers, items, 0,
chosen_item < 0 ? 0 : chosen_item);
switch (chosen_item)
{
case RANDOM:
set_icon("rz");
set_random (0);
break;
case BLUE:
set_icon("rz");
set_color (54, 74, 255);
break;
case CYAN:
set_icon("rz");
set_color (0, 255, 255);
break;
case GREEN:
set_icon("rz");
set_color (30, 247, 115);
break;
case ORANGE:
set_icon("rz");
set_color (255, 115, 0);
break;
case PINK:
set_icon("rz");
set_color (255, 0, 255);
break;
case PURPLE:
set_icon("rz");
set_color (175, 0, 255);
break;
case RED:
set_icon("rz");
set_color (255, 0, 0);
break;
case SMOKED:
set_icon("rz");
set_color (200, 200, 200);
break;
case YELLOW:
set_icon("rz");
set_color (255, 255, 0);
break;
case GOLD:
set_icon("rz");
set_color (255, 204, 102);
break;
case WHITE:
set_icon("rz");
set_color (255, 255, 255);
break;
case GREY:
set_icon("rz");
set_color (100, 100, 100);
break;
case ROOTZ:
set_icon("rw");
set_color (139, 181, 79);
break;
case RAVE:
set_icon("rz");
set_random (1);
break;
}
}
}