+ * The gamma space effectively provides us a way to make linear changes to the slider that + * result in linear changes in perception. If we made changes to the slider in the linear space + * then we'd see an approximately logarithmic change in perception (c.f. Fechner's Law). + *
+ * Internally, this implements the Hybrid Log Gamma electro-optical transfer function, which is + * a slight improvement to the typical gamma transfer function for displays whose max + * brightness exceeds the 120 nit reference point, but doesn't set a specific reference + * brightness like the PQ function does. + *
+ * Note that this transfer function is only valid if the display's backlight value is a linear + * control. If it's calibrated to be something non-linear, then a different transfer function + * should be used. + * + * @param val The slider value. + * @param min The minimum acceptable value for the setting. + * @param max The maximum acceptable value for the setting. + * @return The corresponding setting value. + */ + public static final int convertGammaToLinear(int val, int min, int max) { + final float normalizedVal = MathUtils.norm(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, val); + final float ret; + if (normalizedVal <= R) { + ret = MathUtils.sq(normalizedVal / R); + } else { + ret = MathUtils.exp((normalizedVal - C) / A) + B; + } + + // HLG is normalized to the range [0, 12], so we need to re-normalize to the range [0, 1] + // in order to derive the correct setting value. + return Math.round(MathUtils.lerp(min, max, ret / 12)); + } + + /** + * Version of {@link #convertGammaToLinear} that takes and returns float values. + * TODO(flc): refactor Android Auto to use float version + * + * @param val The slider value. + * @param min The minimum acceptable value for the setting. + * @param max The maximum acceptable value for the setting. + * @return The corresponding setting value. + */ + public static final float convertGammaToLinearFloat(int val, float min, float max) { + final float normalizedVal = MathUtils.norm(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, val); + final float ret; + if (normalizedVal <= R) { + ret = MathUtils.sq(normalizedVal / R); + } else { + ret = MathUtils.exp((normalizedVal - C) / A) + B; + } + + // HLG is normalized to the range [0, 12], ensure that value is within that range, + // it shouldn't be out of bounds. + final float normalizedRet = MathUtils.constrain(ret, 0, 12); + + // Re-normalize to the range [0, 1] + // in order to derive the correct setting value. + return MathUtils.lerp(min, max, normalizedRet / 12); + } + + /** + * A function for converting from the linear space that the setting works in to the + * gamma space that the slider works in. + *
+ * The gamma space effectively provides us a way to make linear changes to the slider that + * result in linear changes in perception. If we made changes to the slider in the linear space + * then we'd see an approximately logarithmic change in perception (c.f. Fechner's Law). + *
+ * Internally, this implements the Hybrid Log Gamma opto-electronic transfer function, which is + * a slight improvement to the typical gamma transfer function for displays whose max + * brightness exceeds the 120 nit reference point, but doesn't set a specific reference + * brightness like the PQ function does. + *
+ * Note that this transfer function is only valid if the display's backlight value is a linear
+ * control. If it's calibrated to be something non-linear, then a different transfer function
+ * should be used.
+ *
+ * @param val The brightness setting value.
+ * @param min The minimum acceptable value for the setting.
+ * @param max The maximum acceptable value for the setting.
+ * @return The corresponding slider value
+ */
+ public static final int convertLinearToGamma(int val, int min, int max) {
+ return convertLinearToGammaFloat((float) val, (float) min, (float) max);
+ }
+
+ /**
+ * Version of {@link #convertLinearToGamma} that takes float values.
+ * TODO: brightnessfloat merge with above method(?)
+ *
+ * @param val The brightness setting value.
+ * @param min The minimum acceptable value for the setting.
+ * @param max The maximum acceptable value for the setting.
+ * @return The corresponding slider value
+ */
+ public static final int convertLinearToGammaFloat(float val, float min, float max) {
+ // For some reason, HLG normalizes to the range [0, 12] rather than [0, 1]
+ final float normalizedVal = MathUtils.norm(min, max, val) * 12;
+ final float ret;
+ if (normalizedVal <= 1f) {
+ ret = MathUtils.sqrt(normalizedVal) * R;
+ } else {
+ ret = A * MathUtils.log(normalizedVal - B) + C;
+ }
+
+ return Math.round(MathUtils.lerp(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, ret));
+ }
+}
diff --git a/app/src/main/res/drawable-hdpi/battery1.png b/app/src/main/res/drawable-hdpi/battery1.png
new file mode 100644
index 0000000..678ead2
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/battery1.png differ
diff --git a/app/src/main/res/drawable-hdpi/battery2.png b/app/src/main/res/drawable-hdpi/battery2.png
new file mode 100644
index 0000000..93a1dfd
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/battery2.png differ
diff --git a/app/src/main/res/drawable-hdpi/bluetooth1.png b/app/src/main/res/drawable-hdpi/bluetooth1.png
new file mode 100644
index 0000000..19f12dc
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/bluetooth1.png differ
diff --git a/app/src/main/res/drawable-hdpi/bluetooth2.png b/app/src/main/res/drawable-hdpi/bluetooth2.png
new file mode 100644
index 0000000..db1cd87
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/bluetooth2.png differ
diff --git a/app/src/main/res/drawable-hdpi/brightness1.png b/app/src/main/res/drawable-hdpi/brightness1.png
new file mode 100644
index 0000000..8cf154d
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/brightness1.png differ
diff --git a/app/src/main/res/drawable-hdpi/brightness2.png b/app/src/main/res/drawable-hdpi/brightness2.png
new file mode 100644
index 0000000..ae00154
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/brightness2.png differ
diff --git a/app/src/main/res/drawable-hdpi/control_background.png b/app/src/main/res/drawable-hdpi/control_background.png
new file mode 100644
index 0000000..1d32e71
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/control_background.png differ
diff --git a/app/src/main/res/drawable-hdpi/flashlight1.png b/app/src/main/res/drawable-hdpi/flashlight1.png
new file mode 100644
index 0000000..967f575
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/flashlight1.png differ
diff --git a/app/src/main/res/drawable-hdpi/flashlight2.png b/app/src/main/res/drawable-hdpi/flashlight2.png
new file mode 100644
index 0000000..2deef5f
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/flashlight2.png differ
diff --git a/app/src/main/res/drawable-hdpi/position.png b/app/src/main/res/drawable-hdpi/position.png
new file mode 100644
index 0000000..2d118c5
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/position.png differ
diff --git a/app/src/main/res/drawable-hdpi/sound1.png b/app/src/main/res/drawable-hdpi/sound1.png
new file mode 100644
index 0000000..56091c3
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/sound1.png differ
diff --git a/app/src/main/res/drawable-hdpi/sound2.png b/app/src/main/res/drawable-hdpi/sound2.png
new file mode 100644
index 0000000..6e70b6f
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/sound2.png differ
diff --git a/app/src/main/res/drawable-hdpi/wifi1.png b/app/src/main/res/drawable-hdpi/wifi1.png
new file mode 100644
index 0000000..13babc2
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/wifi1.png differ
diff --git a/app/src/main/res/drawable-hdpi/wifi2.png b/app/src/main/res/drawable-hdpi/wifi2.png
new file mode 100644
index 0000000..2a0cd7b
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/wifi2.png differ
diff --git a/app/src/main/res/drawable/control_background_item.xml b/app/src/main/res/drawable/control_background_item.xml
new file mode 100644
index 0000000..4768312
--- /dev/null
+++ b/app/src/main/res/drawable/control_background_item.xml
@@ -0,0 +1,18 @@
+
+