public void drawPalette ( int [ ] colors , int selectedColor ) { if ( colors == null ) { return ; } this . removeAllViews ( ) ; int tableElements = 0 ; int rowElements = 0 ; int rowNumber = 0 ; // Fills the table with swatches based on the array of colors. TableRow row = createTableRow ( ) ; for ( int color : colors ) { tableElements ++ ; View colorSwatch = createColorSwatch ( color , selectedColor ) ; setSwatchDescription ( rowNumber , tableElements , rowElements , color == selectedColor , colorSwatch ) ; addSwatchToRow ( row , colorSwatch , rowNumber ) ; rowElements ++ ; if ( rowElements == mNumColumns ) { addView ( row ) ; row = createTableRow ( ) ; rowElements = 0 ; rowNumber ++ ; } } // Create blank views to fill the row if the last row has not been filled. if ( rowElements > 0 ) { while ( rowElements != mNumColumns ) { addSwatchToRow ( row , createBlankSpace ( ) , rowNumber ) ; rowElements ++ ; } addView ( row ) ; } }
Adds swatches to table in a serpentine format .