-
Notifications
You must be signed in to change notification settings - Fork 105
/
ColorScheme.java
431 lines (412 loc) · 19.2 KB
/
ColorScheme.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/*
* Copyright (c) 2015 IRCCloud, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.irccloud.android;
import android.content.Context;
import android.content.res.ColorStateList;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.TypedValue;
public class ColorScheme {
private static ColorScheme instance = new ColorScheme();
public static ColorScheme getInstance() {
return instance;
}
public static String getUserTheme() {
return PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()).getString("theme", "dawn");
}
public static int getTheme(String theme, boolean actionbar) {
switch(theme) {
case "dawn":
return actionbar?R.style.dawn:R.style.dawnNoActionBar;
case "dusk":
return actionbar?R.style.dusk:R.style.duskNoActionBar;
case "tropic":
return actionbar?R.style.tropic:R.style.tropicNoActionBar;
case "emerald":
return actionbar?R.style.emerald:R.style.emeraldNoActionBar;
case "sand":
return actionbar?R.style.sand:R.style.sandNoActionBar;
case "rust":
return actionbar?R.style.rust:R.style.rustNoActionBar;
case "orchid":
return actionbar?R.style.orchid:R.style.orchidNoActionBar;
case "ash":
return actionbar?R.style.ash:R.style.ashNoActionBar;
case "midnight":
return actionbar?R.style.midnight:R.style.midnightNoActionBar;
default:
return actionbar?R.style.dawn:R.style.dawnNoActionBar;
}
}
public static int getPrefsTheme(String theme) {
switch(theme) {
case "dawn":
return R.style.dawnPrefsTheme;
case "dusk":
return R.style.duskPrefsTheme;
case "tropic":
return R.style.tropicPrefsTheme;
case "emerald":
return R.style.emeraldPrefsTheme;
case "sand":
return R.style.sandPrefsTheme;
case "rust":
return R.style.rustPrefsTheme;
case "orchid":
return R.style.orchidPrefsTheme;
case "ash":
return R.style.ashPrefsTheme;
case "midnight":
return R.style.midnightPrefsTheme;
default:
return R.style.dawnPrefsTheme;
}
}
public static int getDialogTheme(String theme) {
switch(theme) {
case "dawn":
return R.style.dawnDialog;
case "dusk":
return R.style.duskDialog;
case "tropic":
return R.style.tropicDialog;
case "emerald":
return R.style.emeraldDialog;
case "sand":
return R.style.sandDialog;
case "rust":
return R.style.rustDialog;
case "orchid":
return R.style.orchidDialog;
case "ash":
return R.style.ashDialog;
case "midnight":
return R.style.midnightDialog;
default:
return R.style.dawnDialog;
}
}
public static int getDialogWhenLargeTheme(String theme) {
switch(theme) {
case "dawn":
return R.style.dawnDialogWhenLarge;
case "dusk":
return R.style.duskDialogWhenLarge;
case "tropic":
return R.style.tropicDialogWhenLarge;
case "emerald":
return R.style.emeraldDialogWhenLarge;
case "sand":
return R.style.sandDialogWhenLarge;
case "rust":
return R.style.rustDialogWhenLarge;
case "orchid":
return R.style.orchidDialogWhenLarge;
case "ash":
return R.style.ashDialogWhenLarge;
case "midnight":
return R.style.midnightDialogWhenLarge;
default:
return R.style.dawnDialogWhenLarge;
}
}
private static String[] light_nick_colors = {
"b22222",
"d2691e",
"ff9166",
"fa8072",
"ff8c00",
"228b22",
"808000",
"b7b05d",
"8ebd2e",
"2ebd2e",
"82b482",
"37a467",
"57c8a1",
"1da199",
"579193",
"008b8b",
"00bfff",
"4682b4",
"1e90ff",
"4169e1",
"6a5acd",
"7b68ee",
"9400d3",
"8b008b",
"ba55d3",
"ff00ff",
"ff1493"
};
private static String dark_nick_colors[] = {
"deb887",
"ffd700",
"ff9166",
"fa8072",
"ff8c00",
"00ff00",
"ffff00",
"bdb76b",
"9acd32",
"32cd32",
"8fbc8f",
"3cb371",
"66cdaa",
"20b2aa",
"40e0d0",
"00ffff",
"00bfff",
"87ceeb",
"339cff",
"6495ed",
"b2a9e5",
"ff69b4",
"da70d6",
"ee82ee",
"d68fff",
"ff00ff",
"ffb6c1"
};
public static String colorForNick(String nick, boolean isDarkTheme) {
String colors[] = isDarkTheme ? dark_nick_colors : light_nick_colors;
// Normalise a bit
// typically ` and _ are used on the end alone
String normalizedNick = nick.toLowerCase().replaceAll("[`_]+$", "");
//remove |<anything> from the end
normalizedNick = normalizedNick.replaceAll("\\|.*$", "");
Double hash = 0.0;
for (int i = 0; i < normalizedNick.length(); i++) {
hash = ((int) normalizedNick.charAt(i)) + (double) ((int) (hash.longValue()) << 6) + (double) ((int) (hash.longValue()) << 16) - hash;
}
return colors[(int) Math.abs(hash.longValue() % colors.length)];
}
public void setThemeFromContext(Context ctx, String theme_name) {
theme = theme_name;
contentBackgroundColor = colorForAttribute(ctx, R.attr.contentBackgroundColor);
messageTextColor = colorForAttribute(ctx, R.attr.messageTextColor);
opersGroupColor = colorForAttribute(ctx, R.attr.opersGroupColor);
ownersGroupColor = colorForAttribute(ctx, R.attr.ownersGroupColor);
adminsGroupColor = colorForAttribute(ctx, R.attr.adminsGroupColor);
opsGroupColor = colorForAttribute(ctx, R.attr.opsGroupColor);
halfopsGroupColor = colorForAttribute(ctx, R.attr.halfopsGroupColor);
voicedGroupColor = colorForAttribute(ctx, R.attr.voicedGroupColor);
membersGroupColor = colorForAttribute(ctx, R.attr.membersGroupColor);
opersHeadingColor = colorForAttribute(ctx, R.attr.opersHeadingColor);
ownersHeadingColor = colorForAttribute(ctx, R.attr.ownersHeadingColor);
adminsHeadingColor = colorForAttribute(ctx, R.attr.adminsHeadingColor);
opsHeadingColor = colorForAttribute(ctx, R.attr.opsHeadingColor);
halfopsHeadingColor = colorForAttribute(ctx, R.attr.halfopsHeadingColor);
voicedHeadingColor = colorForAttribute(ctx, R.attr.voicedHeadingColor);
membersHeadingColor = colorForAttribute(ctx, R.attr.membersHeadingColor);
memberListTextColor = colorForAttribute(ctx, R.attr.memberListTextColor);
memberListAwayTextColor = colorForAttribute(ctx, R.attr.memberListAwayTextColor);
timestampColor = colorForAttribute(ctx, R.attr.timestampColor);
darkBlueColor = colorForAttribute(ctx, R.attr.darkBlueColor);
networkErrorBackgroundColor = colorForAttribute(ctx, R.attr.networkErrorBackgroundColor);
networkErrorColor = colorForAttribute(ctx, R.attr.networkErrorColor);
errorBackgroundColor = colorForAttribute(ctx, R.attr.errorBackgroundColor);
statusBackgroundColor = colorForAttribute(ctx, R.attr.statusBackgroundColor);
selfBackgroundColor = colorForAttribute(ctx, R.attr.selfBackgroundColor);
highlightBackgroundColor = colorForAttribute(ctx, R.attr.highlightBackgroundColor);
highlightTimestampColor = colorForAttribute(ctx, R.attr.highlightTimestampColor);
noticeBackgroundColor = colorForAttribute(ctx, R.attr.noticeBackgroundColor);
timestampBackgroundColor = colorForAttribute(ctx, R.attr.timestampBackgroundColor);
newMsgsBackgroundColor = colorForAttribute(ctx, R.attr.newMsgsBackgroundColor);
collapsedRowTextColor = colorForAttribute(ctx, R.attr.collapsedRowTextColor);
collapsedRowNickColor = colorForAttribute(ctx, R.attr.collapsedRowNickColor);
collapsedHeadingBackgroundColor = colorForAttribute(ctx, R.attr.collapsedHeadingBackgroundColor);
navBarColor = colorForAttribute(ctx, R.attr.navBarColor);
navBarHeadingColor = colorForAttribute(ctx, R.attr.navBarHeadingColor);
navBarSubheadingColor = colorForAttribute(ctx, R.attr.navBarSubheadingColor);
navBarBorderColor = colorForAttribute(ctx, R.attr.navBarBorderColor);
textareaTextColor = colorForAttribute(ctx, R.attr.textareaTextColor);
textareaBackgroundColor = colorForAttribute(ctx, R.attr.textareaBackgroundColor);
linkColor = colorForAttribute(ctx, R.attr.linkColor);
lightLinkColor = colorForAttribute(ctx, R.attr.lightLinkColor);
serverBackgroundColor = colorForAttribute(ctx, R.attr.serverBackgroundColor);
bufferBackgroundColor = colorForAttribute(ctx, R.attr.bufferBackgroundColor);
unreadBorderColor = colorForAttribute(ctx, R.attr.unreadBorderColor);
highlightBorderColor = colorForAttribute(ctx, R.attr.highlightBorderColor);
networkErrorBorderColor = colorForAttribute(ctx, R.attr.networkErrorBorderColor);
bufferTextColor = colorForAttribute(ctx, R.attr.bufferTextColor);
inactiveBufferTextColor = colorForAttribute(ctx, R.attr.inactiveBufferTextColor);
unreadBufferTextColor = colorForAttribute(ctx, R.attr.unreadBufferTextColor);
selectedBufferTextColor = colorForAttribute(ctx, R.attr.selectedBufferTextColor);
selectedBufferBackgroundColor = colorForAttribute(ctx, R.attr.selectedBufferBackgroundColor);
bufferBorderColor = colorForAttribute(ctx, R.attr.bufferBorderColor);
selectedBufferBorderColor = colorForAttribute(ctx, R.attr.selectedBufferBorderColor);
backlogDividerColor = colorForAttribute(ctx, R.attr.backlogDividerColor);
chatterBarTextColor = colorForAttribute(ctx, R.attr.chatterBarTextColor);
chatterBarColor = colorForAttribute(ctx, R.attr.chatterBarColor);
awayBarTextColor = colorForAttribute(ctx, R.attr.awayBarTextColor);
awayBarColor = colorForAttribute(ctx, R.attr.awayBarColor);
connectionBarTextColor = colorForAttribute(ctx, R.attr.connectionBarTextColor);
connectionBarColor = colorForAttribute(ctx, R.attr.connectionBarColor);
placeholderColor = colorForAttribute(ctx, R.attr.placeholderColor);
unreadBlueColor = colorForAttribute(ctx, R.attr.unreadBlueColor);
serverBorderColor = colorForAttribute(ctx, R.attr.serverBorderColor);
failedServerBorderColor = colorForAttribute(ctx, R.attr.failedServerBorderColor);
archivesHeadingTextColor = colorForAttribute(ctx, R.attr.archivesHeadingTextColor);
archivedChannelTextColor = colorForAttribute(ctx, R.attr.archivedChannelTextColor);
archivedBufferTextColor = colorForAttribute(ctx, R.attr.archivedBufferTextColor);
selectedArchivesHeadingColor = colorForAttribute(ctx, R.attr.selectedArchivesHeadingColor);
timestampTopBorderColor = colorForAttribute(ctx, R.attr.timestampTopBorderColor);
timestampBottomBorderColor = colorForAttribute(ctx, R.attr.timestampBottomBorderColor);
expandCollapseIndicatorColor = colorForAttribute(ctx, R.attr.expandCollapseIndicatorColor);
bufferHighlightColor = colorForAttribute(ctx, R.attr.bufferHighlightColor);
selectedBufferHighlightColor = colorForAttribute(ctx, R.attr.selectedBufferHighlightColor);
archivedBufferHighlightColor = colorForAttribute(ctx, R.attr.archivedBufferHighlightColor);
selectedArchivedBufferHighlightColor = colorForAttribute(ctx, R.attr.selectedArchivedBufferHighlightColor);
selectedArchivedBufferBackgroundColor = colorForAttribute(ctx, R.attr.selectedArchivedBufferBackgroundColor);
contentBorderColor = colorForAttribute(ctx, R.attr.contentBorderColor);
bufferBorderDrawable = resourceForAttribute(ctx, R.attr.bufferBorderDrawable);
serverBorderDrawable = resourceForAttribute(ctx, R.attr.serverBorderDrawable);
selectedBorderDrawable = resourceForAttribute(ctx, R.attr.selectedBorderDrawable);
bufferBackgroundDrawable = resourceForAttribute(ctx, R.attr.bufferBackgroundDrawable);
serverBackgroundDrawable = resourceForAttribute(ctx, R.attr.serverBackgroundDrawable);
selectedBackgroundDrawable = resourceForAttribute(ctx, R.attr.selectedBackgroundDrawable);
lastSeenEIDBackgroundDrawable = resourceForAttribute(ctx, R.attr.lastSeenEIDBackgroundDrawable);
socketclosedBackgroundDrawable = resourceForAttribute(ctx, R.attr.socketclosedBackgroundDrawable);
timestampBackgroundDrawable = resourceForAttribute(ctx, R.attr.timestampBackgroundDrawable);
actionBarDrawable = resourceForAttribute(ctx, R.attr.actionbarDrawable);
colorControlNormal = colorForAttribute(ctx, R.attr.colorControlNormal);
dialogBackgroundColor = colorForAttribute(ctx, R.attr.dialogBackgroundColor);
windowBackgroundDrawable = resourceForAttribute(ctx, R.attr.windowBackgroundDrawable);
row_opers_bg_drawable = resourceForAttribute(ctx, R.attr.row_opers_bg_drawable);
row_owners_bg_drawable = resourceForAttribute(ctx, R.attr.row_owners_bg_drawable);
row_admins_bg_drawable = resourceForAttribute(ctx, R.attr.row_admins_bg_drawable);
row_ops_bg_drawable = resourceForAttribute(ctx, R.attr.row_ops_bg_drawable);
row_halfops_bg_drawable = resourceForAttribute(ctx, R.attr.row_halfops_bg_drawable);
row_voiced_bg_drawable = resourceForAttribute(ctx, R.attr.row_voiced_bg_drawable);
row_members_bg_drawable = resourceForAttribute(ctx, R.attr.row_members_bg_drawable);
if(Build.VERSION.SDK_INT >= 21)
statusBarColor = colorForAttribute(ctx, android.R.attr.statusBarColor);
isDarkTheme = !theme.equals("dawn");
selfTextColor = isDarkTheme?"ffffff":"142b43";
}
private int colorForAttribute(Context ctx, int attribute) {
TypedValue v = new TypedValue();
ctx.getTheme().resolveAttribute(attribute, v, true);
return v.data;
}
private int resourceForAttribute(Context ctx, int attribute) {
TypedValue v = new TypedValue();
ctx.getTheme().resolveAttribute(attribute, v, true);
return v.resourceId;
}
public int contentBackgroundColor;
public int messageTextColor;
public int opersGroupColor;
public int ownersGroupColor;
public int adminsGroupColor;
public int opsGroupColor;
public int halfopsGroupColor;
public int voicedGroupColor;
public int membersGroupColor;
public int opersHeadingColor;
public int ownersHeadingColor;
public int adminsHeadingColor;
public int opsHeadingColor;
public int halfopsHeadingColor;
public int voicedHeadingColor;
public int membersHeadingColor;
public int memberListTextColor;
public int memberListAwayTextColor;
public int timestampColor;
public int darkBlueColor;
public int networkErrorBackgroundColor;
public int networkErrorColor;
public int errorBackgroundColor;
public int statusBackgroundColor;
public int selfBackgroundColor;
public int highlightBackgroundColor;
public int highlightTimestampColor;
public int noticeBackgroundColor;
public int timestampBackgroundColor;
public int newMsgsBackgroundColor;
public int collapsedRowTextColor;
public int collapsedRowNickColor;
public int collapsedHeadingBackgroundColor;
public int navBarColor;
public int navBarHeadingColor;
public int navBarSubheadingColor;
public int navBarBorderColor;
public int textareaTextColor;
public int textareaBackgroundColor;
public int linkColor;
public int lightLinkColor;
public int serverBackgroundColor;
public int bufferBackgroundColor;
public int unreadBorderColor;
public int highlightBorderColor;
public int networkErrorBorderColor;
public int bufferTextColor;
public int inactiveBufferTextColor;
public int unreadBufferTextColor;
public int selectedBufferTextColor;
public int selectedBufferBackgroundColor;
public int bufferBorderColor;
public int selectedBufferBorderColor;
public int backlogDividerColor;
public int chatterBarTextColor;
public int chatterBarColor;
public int awayBarTextColor;
public int awayBarColor;
public int connectionBarTextColor;
public int connectionBarColor;
public int placeholderColor;
public int unreadBlueColor;
public int serverBorderColor;
public int failedServerBorderColor;
public int archivesHeadingTextColor;
public int archivedChannelTextColor;
public int archivedBufferTextColor;
public int selectedArchivesHeadingColor;
public int timestampTopBorderColor;
public int timestampBottomBorderColor;
public int expandCollapseIndicatorColor;
public int bufferHighlightColor;
public int selectedBufferHighlightColor;
public int archivedBufferHighlightColor;
public int selectedArchivedBufferHighlightColor;
public int selectedArchivedBufferBackgroundColor;
public int contentBorderColor;
public int bufferBorderDrawable;
public int serverBorderDrawable;
public int selectedBorderDrawable;
public int bufferBackgroundDrawable;
public int serverBackgroundDrawable;
public int selectedBackgroundDrawable;
public int lastSeenEIDBackgroundDrawable;
public int socketclosedBackgroundDrawable;
public int timestampBackgroundDrawable;
public int colorControlNormal;
public int actionBarDrawable;
public int dialogBackgroundColor;
public int windowBackgroundDrawable;
public int statusBarColor;
public int row_opers_bg_drawable;
public int row_owners_bg_drawable;
public int row_admins_bg_drawable;
public int row_ops_bg_drawable;
public int row_halfops_bg_drawable;
public int row_voiced_bg_drawable;
public int row_members_bg_drawable;
public String theme;
public boolean isDarkTheme;
public String selfTextColor;
}