Parses a android.graphics.PorterDuff.Mode from a tintMode attribute's enum value. - Android android.graphics

Android examples for android.graphics:PorterDuff

Description

Parses a android.graphics.PorterDuff.Mode from a tintMode attribute's enum value.

Demo Code


//package com.java2s;
import android.annotation.TargetApi;

import android.graphics.PorterDuff;

import android.os.Build;

public class Main {
    final static boolean COMPAT = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;

    /**//from  ww  w  .ja v  a  2s  . c  o  m
     * Parses a {@link android.graphics.PorterDuff.Mode} from a tintMode
     * attribute's enum value.
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static PorterDuff.Mode parseTintMode(int value,
            PorterDuff.Mode defaultMode) {
        switch (value) {
        case 3:
            return PorterDuff.Mode.SRC_OVER;
        case 5:
            return PorterDuff.Mode.SRC_IN;
        case 9:
            return PorterDuff.Mode.SRC_ATOP;
        case 14:
            return PorterDuff.Mode.MULTIPLY;
        case 15:
            return PorterDuff.Mode.SCREEN;
        case 16:
            return COMPAT ? defaultMode : PorterDuff.Mode.ADD;
        default:
            return defaultMode;
        }
    }
}

Related Tutorials