private void addOpacityStopsToGradientIfNeeded ( GradientColor gradientColor , List < Float > array ) { int startIndex = colorPoints * 4 ; if ( array . size ( ) <= startIndex ) { return ; } int opacityStops = ( array . size ( ) - startIndex ) / 2 ; double [ ] positions = new double [ opacityStops ] ; double [ ] opacities = new double [ opacityStops ] ; for ( int i = startIndex , j = 0 ; i < array . size ( ) ; i ++ ) { if ( i % 2 == 0 ) { positions [ j ] = array . get ( i ) ; } else { opacities [ j ] = array . get ( i ) ; j ++ ; } } for ( int i = 0 ; i < gradientColor . getSize ( ) ; i ++ ) { int color = gradientColor . getColors ( ) [ i ] ; color = Color . argb ( getOpacityAtPosition ( gradientColor . getPositions ( ) [ i ] , positions , opacities ) , Color . red ( color ) , Color . green ( color ) , Color . blue ( color ) ) ; gradientColor . getColors ( ) [ i ] = color ; } }
This cheats a little bit . Opacity stops can be at arbitrary intervals independent of color stops . This uses the existing color stops and modifies the opacity at each existing color stop based on what the opacity would be .