Add accessibility display adjustments

BUG: 9057596
Change-Id: I5e7cc05159387cb00701e162d015e2f7ca6cbf4c
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 6c6635d..7258e16 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3752,6 +3752,97 @@
                 "accessibility_captioning_font_scale";
 
         /**
+         * Setting that specifies whether the quick setting tile for display
+         * color inversion is enabled.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_INVERSION_QUICK_SETTING_ENABLED =
+                "accessibility_display_inversion_quick_setting_enabled";
+
+        /**
+         * Setting that specifies whether display color inversion is enabled.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_INVERSION_ENABLED =
+                "accessibility_display_inversion_enabled";
+
+        /**
+         * Integer property that specifies the type of color inversion to
+         * perform. Valid values are defined in AccessibilityManager.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_INVERSION =
+                "accessibility_display_inversion";
+
+        /**
+         * Setting that specifies whether the quick setting tile for display
+         * color space adjustment is enabled.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_DALTONIZER_QUICK_SETTING_ENABLED =
+                "accessibility_display_daltonizer_quick_setting_enabled";
+
+        /**
+         * Setting that specifies whether display color space adjustment is
+         * enabled.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED =
+                "accessibility_display_daltonizer_enabled";
+
+        /**
+         * Integer property that specifies the type of color space adjustment to
+         * perform. Valid values are defined in AccessibilityManager.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_DALTONIZER =
+                "accessibility_display_daltonizer";
+
+        /**
+         * Setting that specifies whether the quick setting tile for display
+         * contrast enhancement is enabled.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_CONTRAST_QUICK_SETTING_ENABLED =
+                "accessibility_display_contrast_quick_setting_enabled";
+
+        /**
+         * Setting that specifies whether display contrast enhancement is
+         * enabled.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_CONTRAST_ENABLED =
+                "accessibility_display_contrast_enabled";
+
+        /**
+         * Floating point property that specifies display contrast adjustment.
+         * Valid range is [0, ...] where 0 is gray, 1 is normal, and higher
+         * values indicate enhanced contrast.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_CONTRAST =
+                "accessibility_display_contrast";
+
+        /**
+         * Floating point property that specifies display brightness adjustment.
+         * Valid range is [-1, 1] where -1 is black, 0 is default, and 1 is
+         * white.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_BRIGHTNESS =
+                "accessibility_display_brightness";
+
+        /**
          * The timout for considering a press to be a long press in milliseconds.
          * @hide
          */
diff --git a/core/java/android/util/MatrixUtils.java b/core/java/android/util/MatrixUtils.java
new file mode 100644
index 0000000..c443d6c
--- /dev/null
+++ b/core/java/android/util/MatrixUtils.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.util;
+
+import java.util.Arrays;
+
+/**
+ * A class that contains utility methods related to matrices.
+ *
+ * @hide
+ */
+public class MatrixUtils {
+    private MatrixUtils() {
+        // This class is non-instantiable.
+    }
+
+    /**
+     * Sets a matrix to the identity matrix.
+     *
+     * @param out output matrix of size n*m
+     * @param n number of rows in the output matrix
+     * @param m number of columns in the output matrix
+     */
+    public static void setIdentityM(float[] out, int n, int m) {
+        final int size = n * m;
+        if (out.length != size) {
+            throw new IllegalArgumentException("Invalid dimensions for output matrix");
+        }
+
+        Arrays.fill(out, 0, size, 0);
+        for (int i = Math.min(m,n) - 1; i >= 0; i--) {
+            out[i * (m + 1)] = 1;
+        }
+    }
+
+    /**
+     * Add two matrices. May be used in-place by specifying the same value for
+     * the out matrix and one of the input matrices.
+     *
+     * @param ab output matrix of size n*m
+     * @param a left-hand matrix of size n*m
+     * @param n number of rows in the left-hand matrix
+     * @param m number of columns in the left-hand matrix
+     * @param b right-hand matrix of size n*m
+     */
+    public static void addMM(float[] ab, float[] a, int n, int m, float[] b) {
+        final int size = n * m;
+        if (a.length != size) {
+            throw new IllegalArgumentException("Invalid dimensions for matrix a");
+        } else if (b.length != size) {
+            throw new IllegalArgumentException("Invalid dimensions for matrix b");
+        } else if (ab.length != size) {
+            throw new IllegalArgumentException("Invalid dimensions for matrix ab");
+        }
+
+        for (int i = 0; i < size; i++) {
+            ab[i] = a[i] + b[i];
+        }
+    }
+
+    /**
+     * Multiply two matrices.
+     *
+     * @param ab output matrix of size n*p
+     * @param a left-hand matrix of size n*m
+     * @param n number of rows in the left-hand matrix
+     * @param m number of columns in the left-hand matrix
+     * @param b right-hand matrix of size m*p
+     * @param p number of columns in the right-hand matrix
+     */
+    public static void multiplyMM(float[] ab, float[] a, int n, int m, float[] b, int p) {
+        if (a.length != n * m) {
+            throw new IllegalArgumentException("Invalid dimensions for matrix a");
+        } else if (b.length != m * p) {
+            throw new IllegalArgumentException("Invalid dimensions for matrix b");
+        } else if (ab.length != n * p) {
+            throw new IllegalArgumentException("Invalid dimensions for matrix ab");
+        }
+
+        for (int i = 0; i < n; i++) {
+            for (int j = 0; j < p; j++) {
+                float sum = 0;
+                for (int k = 0; k < m; k++) {
+                    sum += a[i * m + k] * b[k * p + j];
+                }
+                ab[i * p + j] = sum;
+            }
+        }
+    }
+
+    /**
+     * Multiply a matrix by a scalar value. May be used in-place by specifying
+     * the same value for the input and output matrices.
+     *
+     * @param out output matrix
+     * @param in input matrix
+     * @param scalar scalar value
+     */
+    public static void multiplyMS(float[] out, float[] in, float scalar) {
+        final int n = out.length;
+        for (int i = 0; i < n; i++) {
+            out[i] = in[i] * scalar;
+        }
+    }
+}
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index 04ce7e2..020b92c 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -75,6 +75,42 @@
     /** @hide */
     public static final int STATE_FLAG_TOUCH_EXPLORATION_ENABLED = 0x00000002;
 
+    /** @hide */
+    public static final int INVERSION_DISABLED = -1;
+
+    /** @hide */
+    public static final int INVERSION_STANDARD = 0;
+
+    /** @hide */
+    public static final int INVERSION_HUE_ONLY = 1;
+
+    /** @hide */
+    public static final int INVERSION_VALUE_ONLY = 2;
+
+    /** @hide */
+    public static final int DALTONIZER_DISABLED = -1;
+
+    /** @hide */
+    public static final int DALTONIZER_SIMULATE_MONOCHROMACY = 0;
+
+    /** @hide */
+    public static final int DALTONIZER_SIMULATE_PROTANOMALY = 1;
+
+    /** @hide */
+    public static final int DALTONIZER_SIMULATE_DEUTERANOMALY = 2;
+
+    /** @hide */
+    public static final int DALTONIZER_SIMULATE_TRITANOMALY = 3;
+
+    /** @hide */
+    public static final int DALTONIZER_CORRECT_PROTANOMALY = 11;
+
+    /** @hide */
+    public static final int DALTONIZER_CORRECT_DEUTERANOMALY = 12;
+
+    /** @hide */
+    public static final int DALTONIZER_CORRECT_TRITANOMALY = 13;
+
     static final Object sInstanceSync = new Object();
 
     private static AccessibilityManager sInstance;