DisplayAdjustmentUtilspublic class DisplayAdjustmentUtils extends Object Utility methods for performing accessibility display adjustments. |
Fields Summary |
---|
private static final String | LOG_TAG | private static final float[] | GRAYSCALE_MATRIXMatrix and offset used for converting color to gray-scale. | private static final float[] | INVERSION_MATRIX_VALUE_ONLYMatrix and offset used for value-only display inversion. | private static final int | DEFAULT_DISPLAY_DALTONIZERDefault inversion mode for display color correction. |
Methods Summary |
---|
public static void | applyAdjustments(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 boolean | hasAdjustments(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 void | setColorTransform(float[] m)Sets the surface flinger's color transformation as a 4x4 matrix. If the
matrix is null, color transformations are disabled.
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 void | setDaltonizerMode(int mode)Sets the surface flinger's Daltonization mode. This adjusts the color
space to correct for or simulate various types of color blindness.
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);
}
|
|