FileDocCategorySizeDatePackage
DisplayAdjustmentUtils.javaAPI DocAndroid 5.1 API6066Thu Mar 12 22:22:42 GMT 2015com.android.server.accessibility

DisplayAdjustmentUtils

public class DisplayAdjustmentUtils extends Object
Utility methods for performing accessibility display adjustments.

Fields Summary
private static final String
LOG_TAG
private static final float[]
GRAYSCALE_MATRIX
Matrix and offset used for converting color to gray-scale.
private static final float[]
INVERSION_MATRIX_VALUE_ONLY
Matrix and offset used for value-only display inversion.
private static final int
DEFAULT_DISPLAY_DALTONIZER
Default inversion mode for display color correction.
Constructors Summary
Methods Summary
public static voidapplyAdjustments(android.content.Context context, int userId)
Applies the specified user's display color adjustments.

        final ContentResolver cr = context.getContentResolver();
        float[] colorMatrix = null;

        if (Settings.Secure.getIntForUser(cr,
                Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, userId) != 0) {
            colorMatrix = multiply(colorMatrix, INVERSION_MATRIX_VALUE_ONLY);
        }

        if (Settings.Secure.getIntForUser(cr,
                Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) != 0) {
            final int daltonizerMode = Settings.Secure.getIntForUser(cr,
                    Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, DEFAULT_DISPLAY_DALTONIZER,
                    userId);
            // Monochromacy isn't supported by the native Daltonizer.
            if (daltonizerMode == AccessibilityManager.DALTONIZER_SIMULATE_MONOCHROMACY) {
                colorMatrix = multiply(colorMatrix, GRAYSCALE_MATRIX);
                setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED);
            } else {
                setDaltonizerMode(daltonizerMode);
            }
        } else {
            setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED);
        }

        setColorTransform(colorMatrix);
    
public static booleanhasAdjustments(android.content.Context context, int userId)
Returns whether the specified user with has any display color adjustments.


                    
           
        final ContentResolver cr = context.getContentResolver();

        if (Settings.Secure.getIntForUser(cr,
                Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, userId) != 0) {
            return true;
        }

        if (Settings.Secure.getIntForUser(cr,
                Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) != 0) {
            return true;
        }

        return false;
    
private static float[]multiply(float[] matrix, float[] other)

        if (matrix == null) {
            return other;
        }
        float[] result = new float[16];
        Matrix.multiplyMM(result, 0, matrix, 0, other, 0);
        return result;
    
private static voidsetColorTransform(float[] m)
Sets the surface flinger's color transformation as a 4x4 matrix. If the matrix is null, color transformations are disabled.

param
m the float array that holds the transformation matrix, or null to disable transformation

        try {
            final IBinder flinger = ServiceManager.getService("SurfaceFlinger");
            if (flinger != null) {
                final Parcel data = Parcel.obtain();
                data.writeInterfaceToken("android.ui.ISurfaceComposer");
                if (m != null) {
                    data.writeInt(1);
                    for (int i = 0; i < 16; i++) {
                        data.writeFloat(m[i]);
                    }
                } else {
                    data.writeInt(0);
                }
                flinger.transact(1015, data, null, 0);
                data.recycle();
            }
        } catch (RemoteException ex) {
            Slog.e(LOG_TAG, "Failed to set color transform", ex);
        }
    
private static voidsetDaltonizerMode(int mode)
Sets the surface flinger's Daltonization mode. This adjusts the color space to correct for or simulate various types of color blindness.

param
mode new Daltonization mode

        try {
            final IBinder flinger = ServiceManager.getService("SurfaceFlinger");
            if (flinger != null) {
                final Parcel data = Parcel.obtain();
                data.writeInterfaceToken("android.ui.ISurfaceComposer");
                data.writeInt(mode);
                flinger.transact(1014, data, null, 0);
                data.recycle();
            }
        } catch (RemoteException ex) {
            Slog.e(LOG_TAG, "Failed to set Daltonizer mode", ex);
        }