private java . util . HashMap < Float , Color > recalculate ( final List < Float > fractionList , final List < Color > colorList , final float OFFSET ) { // Recalculate the fractions and colors with the given offset final int MAX_FRACTIONS = fractionList . size ( ) ; final HashMap < Float , Color > fractionColors = new HashMap < Float , Color > ( MAX_FRACTIONS ) ; for ( int i = 0 ; i < MAX_FRACTIONS ; i ++ ) { // Add offset to fraction final float TMP_FRACTION = fractionList . get ( i ) + OFFSET ; // Color related to current fraction final Color TMP_COLOR = colorList . get ( i ) ; // Check each fraction for limits (0...1) if ( TMP_FRACTION <= 0 ) { fractionColors . put ( 1.0f + TMP_FRACTION + 0.0001f , TMP_COLOR ) ; final float NEXT_FRACTION ; final Color NEXT_COLOR ; if ( i < MAX_FRACTIONS - 1 ) { NEXT_FRACTION = fractionList . get ( i + 1 ) + OFFSET ; NEXT_COLOR = colorList . get ( i + 1 ) ; } else { NEXT_FRACTION = 1 - fractionList . get ( 0 ) + OFFSET ; NEXT_COLOR = colorList . get ( 0 ) ; } if ( NEXT_FRACTION > 0 ) { final Color NEW_FRACTION_COLOR = getColorFromFraction ( TMP_COLOR , NEXT_COLOR , ( int ) ( ( NEXT_FRACTION - TMP_FRACTION ) * 10000 ) , ( int ) ( ( - TMP_FRACTION ) * 10000 ) ) ; fractionColors . put ( 0.0f , NEW_FRACTION_COLOR ) ; fractionColors . put ( 1.0f , NEW_FRACTION_COLOR ) ; } } else if ( TMP_FRACTION >= 1 ) { fractionColors . put ( TMP_FRACTION - 1.0f - 0.0001f , TMP_COLOR ) ; final float PREVIOUS_FRACTION ; final Color PREVIOUS_COLOR ; if ( i > 0 ) { PREVIOUS_FRACTION = fractionList . get ( i - 1 ) + OFFSET ; PREVIOUS_COLOR = colorList . get ( i - 1 ) ; } else { PREVIOUS_FRACTION = fractionList . get ( MAX_FRACTIONS - 1 ) + OFFSET ; PREVIOUS_COLOR = colorList . get ( MAX_FRACTIONS - 1 ) ; } if ( PREVIOUS_FRACTION < 1 ) { final Color NEW_FRACTION_COLOR = getColorFromFraction ( TMP_COLOR , PREVIOUS_COLOR , ( int ) ( ( TMP_FRACTION - PREVIOUS_FRACTION ) * 10000 ) , ( int ) ( TMP_FRACTION - 1.0f ) * 10000 ) ; fractionColors . put ( 1.0f , NEW_FRACTION_COLOR ) ; fractionColors . put ( 0.0f , NEW_FRACTION_COLOR ) ; } } else { fractionColors . put ( TMP_FRACTION , TMP_COLOR ) ; } } // Clear the original FRACTION_LIST and COLOR_LIST fractionList . clear ( ) ; colorList . clear ( ) ; return fractionColors ; }
Recalculates the fractions in the FRACTION_LIST and their associated colors in the COLOR_LIST with a given OFFSET . Because the conical gradients always starts with 0 at the top and clockwise direction you could rotate the defined conical gradient from - 180 to 180 degrees which equals values from - 0 . 5 to + 0 . 5