Code example for SparseArray

Methods: size, valueAt

0
    <T> T pick(T[] a) {
        return a[(int)(Math.random()*a.length)];
    } 
 
    <T> T pick(SparseArray<T> sa) {
        return sa.valueAt((int)(Math.random()*sa.size()));
    } 
 
    float[] hsv = new float[] { 0, 1f, .85f };
    int random_color() { 
//        return 0xFF000000 | (int) (Math.random() * (float) 0xFFFFFF); // totally random 
        final int COLORS = 12;
        hsv[0] = irand(0,COLORS) * (360f/COLORS);
        return Color.HSVToColor(hsv);
    } 
 
    @Override 
    protected synchronized void onSizeChanged (int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (mWidth == w && mHeight == h) return;