Enable pixel dithering for this window (but only in API < 17) - Android Graphics

Android examples for Graphics:Pixel

Description

Enable pixel dithering for this window (but only in API < 17)

Demo Code

/*/* ww  w .j  a va  2  s.  c o m*/
 *  Copyright (C) 2012 Simon Robinson
 * 
 *  This file is part of Com-Me.
 * 
 *  Com-Me is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU Lesser General Public License as 
 *  published by the Free Software Foundation; either version 3 of the 
 *  License, or (at your option) any later version.
 *
 *  Com-Me is distributed in the hope that it will be useful, but WITHOUT 
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General 
 *  Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with Com-Me.
 *  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

import android.graphics.PixelFormat;

import android.os.Build;

import android.view.Window;
import android.view.WindowManager;

public class Main {
    /**
     * Enable pixel dithering for this window (but only in API < 17)
     * 
     * @param window
     */
    @SuppressWarnings("deprecation")
    public static void setPixelDithering(Window window) {
        if (window != null
                && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { // deprecated from API 17+
            // better gradient drawables
            window.setFormat(PixelFormat.RGBA_8888);
            window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);
        }
    }
}

Related Tutorials