Android Color Filter getSecondaryColorFromPrimaryColor(int color, double secondaryColorStrength)

Here you can find the source of getSecondaryColorFromPrimaryColor(int color, double secondaryColorStrength)

Description

Take a color as input, multiply each of the rgb components by mSecondaryColorStrength and return the new color that results from this.

License

Open Source License

Parameter

Parameter Description
color the primary color to pick rgb values from.
secondaryColorStrength controls how much of the Primary color is left in the Secondary color.

Return

the secondary color.

Declaration

public static int getSecondaryColorFromPrimaryColor(int color,
        double secondaryColorStrength) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from ww w.  j  a va 2 s .co m
     * Max value for the alpha channel in 32 bit argb. Used for bit
     * manipulations of the colors.
     */
    public static final int ALPHA_MASK = 0xff000000;
    /**
     * Max value for the red channel in 32 bit argb. Used for bit manipulations
     * of the colors.
     */
    public static final int RED_MASK = 0xff0000;
    /**
     * Max value for the green channel in 32 bit argb. Used for bit
     * manipulations of the colors.
     */
    public static final int GREEN_MASK = 0xff00;
    /**
     * Max value for the blue channel in 32 bit argb. Used for bit manipulations
     * of the colors.
     */
    public static final int BLUE_MASK = 0xff;

    /**
     * Take a color as input, multiply each of the rgb components by
     * mSecondaryColorStrength and return the new color that results from this.
     *
     * @param color                  the primary color to pick rgb values from.
     * @param secondaryColorStrength controls how much of the Primary color is
     *                               left in the Secondary color.
     * @return the secondary color.
     */
    public static int getSecondaryColorFromPrimaryColor(int color,
            double secondaryColorStrength) {
        // Retain the alpha channel
        return ((color & ALPHA_MASK)
                + ((int) ((color & RED_MASK) * secondaryColorStrength) & RED_MASK)
                + ((int) ((color & GREEN_MASK) * secondaryColorStrength) & GREEN_MASK) + ((int) ((color & BLUE_MASK) * secondaryColorStrength) & BLUE_MASK));
    }
}

Related

  1. ClippedColorPart(int color)
  2. findCommonElementType(Collection collection)
  3. getContrastFilter(float factor)
  4. getScaleContrastFilter(float factor)
  5. getTranslationColorFilter( int amount)