-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandColors.java
More file actions
36 lines (33 loc) · 922 Bytes
/
RandColors.java
File metadata and controls
36 lines (33 loc) · 922 Bytes
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
package org.efalk.utils
import java.util.Random;
import android.view.View;
import android.view.ViewGroup;
/**
* Utility: Assign random light colors to the backgrounds of all the
* widgets in the given hierarchy. Used to debug layouts.
*/
class RandColors {
static Random rng = null;
static public void Colors(View top, int base) {
if( top == null ) return;
if( rng == null ) rng = new Random();
int color = 0xff000000 | base |
(rng.nextInt(128) << 16) |
(rng.nextInt(128) << 8) |
rng.nextInt(128);
top.setBackgroundColor(color);
if( top instanceof ViewGroup ) {
ViewGroup parent = (ViewGroup) top;
int n = parent.getChildCount();
for( int i = 0; i < n; ++i ) {
Colors(parent.getChildAt(i), base);
}
}
}
static public void Colors(View top) {
Colors(top, 0x808080);
}
static public void ColorsDark(View top) {
Colors(top, 0);
}
}