|
|
|
|
@@ -56,13 +56,7 @@ public final class AnimationManager {
|
|
|
|
|
|
|
|
|
|
if (StatusManager.isAnimationActive()) {
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
if (name == "volume" && StatusManager.isVolumeLedActive()) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "There is already a volume animation playing, update");
|
|
|
|
|
StatusManager.setVolumeLedUpdate(true);
|
|
|
|
|
while (StatusManager.isVolumeLedUpdate()) {
|
|
|
|
|
if (System.currentTimeMillis() - start >= 2500) return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (wait) {
|
|
|
|
|
if (wait) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "There is already an animation playing, wait | name: " + name);
|
|
|
|
|
while (StatusManager.isAnimationActive()) {
|
|
|
|
|
if (System.currentTimeMillis() - start >= 2500) return false;
|
|
|
|
|
@@ -79,8 +73,7 @@ public final class AnimationManager {
|
|
|
|
|
private static boolean checkInterruption(String name) {
|
|
|
|
|
if (StatusManager.isAllLedActive()
|
|
|
|
|
|| (name != "call" && StatusManager.isCallLedEnabled())
|
|
|
|
|
|| (name == "call" && !StatusManager.isCallLedEnabled())
|
|
|
|
|
|| (name == "volume" && StatusManager.isVolumeLedUpdate())) {
|
|
|
|
|
|| (name == "call" && !StatusManager.isCallLedEnabled())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
@@ -93,12 +86,10 @@ public final class AnimationManager {
|
|
|
|
|
public static void playCsv(String name, boolean wait) {
|
|
|
|
|
submit(() -> {
|
|
|
|
|
if (!check(name, wait))
|
|
|
|
|
return;
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StatusManager.setAnimationActive(true);
|
|
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
|
|
|
|
ResourceUtils.getAnimation(name)))) {
|
|
|
|
|
String line;
|
|
|
|
|
@@ -113,8 +104,7 @@ public final class AnimationManager {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Animation line length mismatch | name: " + name + " | line: " + line);
|
|
|
|
|
throw new InterruptedException();
|
|
|
|
|
}
|
|
|
|
|
long delay = 16666L - (System.currentTimeMillis() - start);
|
|
|
|
|
Thread.sleep(delay/1000);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation | name: " + name + " | exception: " + e);
|
|
|
|
|
@@ -127,170 +117,214 @@ public final class AnimationManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void playCharging(int batteryLevel, boolean wait) {
|
|
|
|
|
submit(() -> {
|
|
|
|
|
if (!check("charging", wait))
|
|
|
|
|
if (!check("charging", wait))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StatusManager.setAnimationActive(true);
|
|
|
|
|
StatusManager.setAnimationActive(true);
|
|
|
|
|
|
|
|
|
|
boolean batteryDot = ResourceUtils.getBoolean("glyph_settings_battery_dot");
|
|
|
|
|
int[] batteryArray = new int[ResourceUtils.getInteger("glyph_settings_battery_levels_num")];
|
|
|
|
|
int amount = (int) (Math.floor((batteryLevel / 100.0) * (batteryArray.length - (batteryDot ? 2 : 1))) + (batteryDot ? 2 : 1));
|
|
|
|
|
boolean batteryDot = ResourceUtils.getBoolean("glyph_settings_battery_dot");
|
|
|
|
|
int[] batteryArray = new int[ResourceUtils.getInteger("glyph_settings_battery_levels_num")];
|
|
|
|
|
int amount = (int) (Math.floor((batteryLevel / 100.0) * (batteryArray.length - (batteryDot ? 2 : 1))) + (batteryDot ? 2 : 1));
|
|
|
|
|
int last = StatusManager.getChargingLedLast();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (int i = 0; i < batteryArray.length; i++) {
|
|
|
|
|
try {
|
|
|
|
|
for (int i = 0; i < batteryArray.length; i++) {
|
|
|
|
|
if ( i <= amount - 1 && batteryLevel > 0) {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
batteryArray[i] = Constants.getBrightness();
|
|
|
|
|
StatusManager.setChargingLedLast(i);
|
|
|
|
|
batteryArray[i] = Constants.MAX_PATTERN_BRIGHTNESS;
|
|
|
|
|
if (batteryDot && i == 0) continue;
|
|
|
|
|
updateLedFrame(batteryArray);
|
|
|
|
|
Thread.sleep(15);
|
|
|
|
|
if (last == 0) {
|
|
|
|
|
updateLedFrame(batteryArray);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int i = batteryArray.length - 1; i > amount - 1; i--) {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
batteryArray[i] = 0;
|
|
|
|
|
updateLedFrame(batteryArray);
|
|
|
|
|
Thread.sleep(5);
|
|
|
|
|
}
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
while (System.currentTimeMillis() - start <= 2000) {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
}
|
|
|
|
|
for (int i = amount - 1; i >= 0; i--) {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
batteryArray[i] = 0;
|
|
|
|
|
updateLedFrame(batteryArray);
|
|
|
|
|
Thread.sleep(11);
|
|
|
|
|
}
|
|
|
|
|
long start2 = System.currentTimeMillis();
|
|
|
|
|
while (System.currentTimeMillis() - start2 <= 730) {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation, interrupted | name: charging");
|
|
|
|
|
if (!StatusManager.isAllLedActive()) {
|
|
|
|
|
updateLedFrame(new int[batteryArray.length]);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
StatusManager.setAnimationActive(false);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: charging");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (last != 0) {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
updateLedFrame(batteryArray);
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation, interrupted | name: charging");
|
|
|
|
|
if (!StatusManager.isAllLedActive())
|
|
|
|
|
updateLedFrame(new int[batteryArray.length]);
|
|
|
|
|
} finally {
|
|
|
|
|
StatusManager.setAnimationActive(false);
|
|
|
|
|
StatusManager.setBatteryLevelLast(batteryLevel);
|
|
|
|
|
StatusManager.setBatteryArrayLast(batteryArray);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: charging");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void playVolume(int volumeLevel, boolean wait) {
|
|
|
|
|
submit(() -> {
|
|
|
|
|
if (!check("volume", wait))
|
|
|
|
|
return;
|
|
|
|
|
public static void dismissCharging() {
|
|
|
|
|
if (StatusManager.getBatteryLevelLast() == 0
|
|
|
|
|
|| StatusManager.getBatteryArrayLast() == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StatusManager.setVolumeLedActive(true);
|
|
|
|
|
StatusManager.setAnimationActive(true);
|
|
|
|
|
if (!check("Dismiss charging", false))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int[] volumeArray = new int[ResourceUtils.getInteger("glyph_settings_volume_levels_num")];
|
|
|
|
|
int amount = (int) (Math.floor((volumeLevel / 100D) * (volumeArray.length - 1)) + 1);
|
|
|
|
|
int last = StatusManager.getVolumeLedLast();
|
|
|
|
|
StatusManager.setAnimationActive(true);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (int i = 0; i < volumeArray.length; i++) {
|
|
|
|
|
if (volumeLevel == 0) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
StatusManager.setVolumeLedLast(0);
|
|
|
|
|
updateLedFrame(new int[volumeArray.length]);
|
|
|
|
|
break;
|
|
|
|
|
} else if ( i <= amount - 1 && volumeLevel > 0) {
|
|
|
|
|
int[] batteryArrayLast = StatusManager.getBatteryArrayLast();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
for (int i = batteryArrayLast.length - 1; i >= 0; i--) {
|
|
|
|
|
if (checkInterruption("charging")) throw new InterruptedException();
|
|
|
|
|
if (batteryArrayLast[i] != 0) {
|
|
|
|
|
StatusManager.setChargingLedLast(i);
|
|
|
|
|
batteryArrayLast[i] = 0;
|
|
|
|
|
updateLedFrame(batteryArrayLast);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation, interrupted | name: Dismiss charging");
|
|
|
|
|
if (!StatusManager.isAllLedActive()) {
|
|
|
|
|
updateLedFrame(new int[batteryArrayLast.length]);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
StatusManager.setAnimationActive(false);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: Dismiss charging");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void playVolume(int volumeLevel, boolean wait, boolean increase, boolean decrease) {
|
|
|
|
|
if (!check("volume", wait))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StatusManager.setAnimationActive(true);
|
|
|
|
|
|
|
|
|
|
int[] volumeArray = new int[ResourceUtils.getInteger("glyph_settings_volume_levels_num")];
|
|
|
|
|
int amount = (int) (Math.floor((volumeLevel / 100D) * (volumeArray.length - 1)) + 1);
|
|
|
|
|
int last = StatusManager.getVolumeLedLast();
|
|
|
|
|
int next = amount - 1;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (volumeLevel == 0) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
StatusManager.setVolumeLedLast(0);
|
|
|
|
|
updateLedFrame(new int[volumeArray.length]);
|
|
|
|
|
} else {
|
|
|
|
|
if (last == 0) {
|
|
|
|
|
for (int i = 0; i <= next; i++) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
StatusManager.setVolumeLedLast(i);
|
|
|
|
|
volumeArray[i] = Constants.getBrightness();
|
|
|
|
|
if (last == 0) {
|
|
|
|
|
updateLedFrame(volumeArray);
|
|
|
|
|
Thread.sleep(15);
|
|
|
|
|
volumeArray[i] = Constants.MAX_PATTERN_BRIGHTNESS;
|
|
|
|
|
updateLedFrame(volumeArray);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
int[] lastArray = StatusManager.getVolumeArrayLast();
|
|
|
|
|
if (increase) {
|
|
|
|
|
for (int i = last; i <= next; i++) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
StatusManager.setVolumeLedLast(i);
|
|
|
|
|
lastArray[i] = Constants.MAX_PATTERN_BRIGHTNESS;
|
|
|
|
|
updateLedFrame(lastArray);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
} else if (decrease) {
|
|
|
|
|
for (int i = last; i >= amount; i--) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
StatusManager.setVolumeLedLast(i);
|
|
|
|
|
lastArray[i] = 0;
|
|
|
|
|
updateLedFrame(lastArray);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volumeArray = lastArray;
|
|
|
|
|
}
|
|
|
|
|
if (last != 0) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
updateLedFrame(volumeArray);
|
|
|
|
|
}
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
while (System.currentTimeMillis() - start <= 1800) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
}
|
|
|
|
|
for (int i = volumeArray.length - 1; i >= 0; i--) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
if (volumeArray[i] != 0) {
|
|
|
|
|
StatusManager.setVolumeLedLast(i);
|
|
|
|
|
volumeArray[i] = 0;
|
|
|
|
|
updateLedFrame(volumeArray);
|
|
|
|
|
Thread.sleep(15);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
long start2 = System.currentTimeMillis();
|
|
|
|
|
while (System.currentTimeMillis() - start2 <= 730) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation, interrupted | name: volume");
|
|
|
|
|
if (!StatusManager.isAllLedActive() && !StatusManager.isVolumeLedUpdate()) {
|
|
|
|
|
updateLedFrame(new int[volumeArray.length]);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
if (!StatusManager.isVolumeLedUpdate()) {
|
|
|
|
|
StatusManager.setVolumeLedLast(0);
|
|
|
|
|
StatusManager.setAnimationActive(false);
|
|
|
|
|
StatusManager.setVolumeLedActive(false);
|
|
|
|
|
}
|
|
|
|
|
StatusManager.setVolumeLedUpdate(false);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: volume");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation, interrupted | name: volume");
|
|
|
|
|
if (!StatusManager.isAllLedActive())
|
|
|
|
|
updateLedFrame(new int[volumeArray.length]);
|
|
|
|
|
} finally {
|
|
|
|
|
StatusManager.setAnimationActive(false);
|
|
|
|
|
StatusManager.setVolumeLevelLast(volumeLevel);
|
|
|
|
|
StatusManager.setVolumeArrayLast(volumeArray);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: volume");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void dismissVolume() {
|
|
|
|
|
if (StatusManager.getVolumeLevelLast() == 0
|
|
|
|
|
|| StatusManager.getVolumeArrayLast() == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!check("Dismiss volume", false))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StatusManager.setAnimationActive(true);
|
|
|
|
|
|
|
|
|
|
int[] volumeArrayLast = StatusManager.getVolumeArrayLast();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
for (int i = volumeArrayLast.length - 1; i >= 0; i--) {
|
|
|
|
|
if (volumeArrayLast[i] != 0) {
|
|
|
|
|
if (checkInterruption("volume")) throw new InterruptedException();
|
|
|
|
|
StatusManager.setVolumeLedLast(i);
|
|
|
|
|
volumeArrayLast[i] = 0;
|
|
|
|
|
updateLedFrame(volumeArrayLast);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation, interrupted | name: Dismiss volume");
|
|
|
|
|
if (!StatusManager.isAllLedActive()) {
|
|
|
|
|
updateLedFrame(new int[volumeArrayLast.length]);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
StatusManager.setAnimationActive(false);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: Dismiss volume");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void playCall(String name) {
|
|
|
|
|
submit(() -> {
|
|
|
|
|
StatusManager.setCallLedEnabled(true);
|
|
|
|
|
StatusManager.setCallLedEnabled(true);
|
|
|
|
|
|
|
|
|
|
if (!check("call: " + name, true))
|
|
|
|
|
return;
|
|
|
|
|
if (!check("call: " + name, true))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StatusManager.setCallLedActive(true);
|
|
|
|
|
StatusManager.setCallLedActive(true);
|
|
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
while (StatusManager.isCallLedEnabled()) {
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
|
|
|
|
ResourceUtils.getCallAnimation(name)))) {
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
if (checkInterruption("call")) throw new InterruptedException();
|
|
|
|
|
line = line.replace(" ", "");
|
|
|
|
|
line = line.endsWith(",") ? line.substring(0, line.length() - 1) : line;
|
|
|
|
|
String[] pattern = line.split(",");
|
|
|
|
|
if (ArrayUtils.contains(Constants.getSupportedAnimationPatternLengths(), pattern.length)) {
|
|
|
|
|
updateLedFrame(pattern);
|
|
|
|
|
} else {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Animation line length mismatch | name: " + name + " | line: " + line);
|
|
|
|
|
throw new InterruptedException();
|
|
|
|
|
}
|
|
|
|
|
long delay = 16666L - (System.currentTimeMillis() - start);
|
|
|
|
|
Thread.sleep(delay/1000);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation | name: " + name + " | exception: " + e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (StatusManager.isAllLedActive()) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "All LED active, pause playing animation | name: " + name);
|
|
|
|
|
while (StatusManager.isAllLedActive()) {}
|
|
|
|
|
while (StatusManager.isCallLedEnabled()) {
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
|
|
|
|
ResourceUtils.getCallAnimation(name)))) {
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
if (checkInterruption("call")) throw new InterruptedException();
|
|
|
|
|
line = line.replace(" ", "");
|
|
|
|
|
line = line.endsWith(",") ? line.substring(0, line.length() - 1) : line;
|
|
|
|
|
String[] pattern = line.split(",");
|
|
|
|
|
if (ArrayUtils.contains(Constants.getSupportedAnimationPatternLengths(), pattern.length)) {
|
|
|
|
|
updateLedFrame(pattern);
|
|
|
|
|
} else {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Animation line length mismatch | name: " + name + " | line: " + line);
|
|
|
|
|
throw new InterruptedException();
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation | name: " + name + " | exception: " + e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (StatusManager.isAllLedActive()) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "All LED active, pause playing animation | name: " + name);
|
|
|
|
|
while (StatusManager.isAllLedActive()) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateLedFrame(new float[5]);
|
|
|
|
|
StatusManager.setCallLedActive(false);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: " + name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void stopCall() {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Disabling Call Animation");
|
|
|
|
|
StatusManager.setCallLedEnabled(false);
|
|
|
|
|
updateLedFrame(new float[5]);
|
|
|
|
|
StatusManager.setCallLedActive(false);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing Call Animation");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void playEssential() {
|
|
|
|
|
@@ -305,24 +339,21 @@ public final class AnimationManager {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (checkInterruption("essential")) throw new InterruptedException();
|
|
|
|
|
int[] steps = {1, 2, 4, 7};
|
|
|
|
|
int[] steps = {12, 24, 36, 48, 60};
|
|
|
|
|
for (int i : steps) {
|
|
|
|
|
if (checkInterruption("essential")) throw new InterruptedException();
|
|
|
|
|
updateLedSingle(led, Constants.getMaxBrightness() / 100 * i);
|
|
|
|
|
Thread.sleep(25);
|
|
|
|
|
updateLedSingle(led, Constants.MAX_PATTERN_BRIGHTNESS / 100 * i);
|
|
|
|
|
Thread.sleep(16, 666000);
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(250);
|
|
|
|
|
} catch (InterruptedException e) {}
|
|
|
|
|
|
|
|
|
|
StatusManager.setAnimationActive(false);
|
|
|
|
|
StatusManager.setEssentialLedActive(true);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: essential");
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
updateLedSingle(led, Constants.getMaxBrightness() / 100 * 7);
|
|
|
|
|
updateLedSingle(led, Constants.MAX_PATTERN_BRIGHTNESS / 100 * 60);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void stopEssential() {
|
|
|
|
|
@@ -335,41 +366,39 @@ public final class AnimationManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void playMusic(String name) {
|
|
|
|
|
submit(() -> {
|
|
|
|
|
float maxBrightness = (float) Constants.getMaxBrightness();
|
|
|
|
|
float[] pattern = new float[5];
|
|
|
|
|
float maxPatternBrightness = (float) Constants.MAX_PATTERN_BRIGHTNESS;
|
|
|
|
|
float[] pattern = new float[5];
|
|
|
|
|
|
|
|
|
|
switch (name) {
|
|
|
|
|
case "low":
|
|
|
|
|
pattern[4] = maxBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "mid_low":
|
|
|
|
|
pattern[3] = maxBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "mid":
|
|
|
|
|
pattern[2] = maxBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "mid_high":
|
|
|
|
|
pattern[0] = maxBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "high":
|
|
|
|
|
pattern[1] = maxBrightness;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Name doesn't match any zone, returning | name: " + name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (name) {
|
|
|
|
|
case "low":
|
|
|
|
|
pattern[4] = maxPatternBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "mid_low":
|
|
|
|
|
pattern[3] = maxPatternBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "mid":
|
|
|
|
|
pattern[2] = maxPatternBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "mid_high":
|
|
|
|
|
pattern[0] = maxPatternBrightness;
|
|
|
|
|
break;
|
|
|
|
|
case "high":
|
|
|
|
|
pattern[1] = maxPatternBrightness;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Name doesn't match any zone, returning | name: " + name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
updateLedFrame(pattern);
|
|
|
|
|
Thread.sleep(90);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation | name: music: " + name + " | exception: " + e);
|
|
|
|
|
} finally {
|
|
|
|
|
updateLedFrame(new float[5]);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: " + name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
updateLedFrame(pattern);
|
|
|
|
|
Thread.sleep(106);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Exception while playing animation | name: music: " + name + " | exception: " + e);
|
|
|
|
|
} finally {
|
|
|
|
|
updateLedFrame(new float[5]);
|
|
|
|
|
if (DEBUG) Log.d(TAG, "Done playing animation | name: " + name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void updateLedFrame(String[] pattern) {
|
|
|
|
|
@@ -378,7 +407,7 @@ public final class AnimationManager {
|
|
|
|
|
.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void updateLedFrame(int[] pattern) {
|
|
|
|
|
private static void updateLedFrame(int[] pattern) {
|
|
|
|
|
float[] floatPattern = new float[pattern.length];
|
|
|
|
|
for (int i = 0; i < pattern.length; i++) {
|
|
|
|
|
floatPattern[i] = (float) pattern[i];
|
|
|
|
|
@@ -388,21 +417,24 @@ public final class AnimationManager {
|
|
|
|
|
|
|
|
|
|
private static void updateLedFrame(float[] pattern) {
|
|
|
|
|
//if (DEBUG) Log.d(TAG, "Updating pattern: " + pattern);
|
|
|
|
|
float maxBrightness = (float) Constants.getMaxBrightness();
|
|
|
|
|
float maxPatternBrightness = (float) Constants.MAX_PATTERN_BRIGHTNESS;
|
|
|
|
|
float currentBrightness = (float) Constants.getBrightness();
|
|
|
|
|
int essentialLed = ResourceUtils.getInteger("glyph_settings_notifs_essential_led");
|
|
|
|
|
|
|
|
|
|
if (StatusManager.isEssentialLedActive()) {
|
|
|
|
|
if (pattern.length == 5) { // Phone (1) pattern
|
|
|
|
|
if (pattern[1] < (maxBrightness / 100 * 7)) {
|
|
|
|
|
pattern[1] = maxBrightness / 100 * 7;
|
|
|
|
|
if (pattern[1] < (maxPatternBrightness / 100 * 60)) {
|
|
|
|
|
pattern[1] = maxPatternBrightness / 100 * 60;
|
|
|
|
|
}
|
|
|
|
|
} else if (pattern.length == 33) { // Phone (2) pattern
|
|
|
|
|
if (pattern[2] < (maxBrightness / 100 * 7)) {
|
|
|
|
|
pattern[2] = maxBrightness / 100 * 7;
|
|
|
|
|
if (pattern[2] < (maxPatternBrightness / 100 * 60)) {
|
|
|
|
|
pattern[2] = maxPatternBrightness / 100 * 60;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pattern.length; i++) {
|
|
|
|
|
pattern[i] = pattern[i] / maxBrightness * Constants.getBrightness();
|
|
|
|
|
pattern[i] = pattern[i] / maxPatternBrightness * currentBrightness;
|
|
|
|
|
}
|
|
|
|
|
FileUtils.writeFrameLed(pattern);
|
|
|
|
|
}
|
|
|
|
|
@@ -417,13 +449,18 @@ public final class AnimationManager {
|
|
|
|
|
|
|
|
|
|
private static void updateLedSingle(int led, float brightness) {
|
|
|
|
|
//if (DEBUG) Log.d(TAG, "Updating led | led: " + led + " | brightness: " + brightness);
|
|
|
|
|
float maxBrightness = (float) Constants.getMaxBrightness();
|
|
|
|
|
float maxPatternBrightness = (float) Constants.MAX_PATTERN_BRIGHTNESS;
|
|
|
|
|
float currentBrightness = (float) Constants.getBrightness();
|
|
|
|
|
int essentialLed = ResourceUtils.getInteger("glyph_settings_notifs_essential_led");
|
|
|
|
|
|
|
|
|
|
if (StatusManager.isEssentialLedActive()
|
|
|
|
|
&& led == essentialLed
|
|
|
|
|
&& brightness < (maxBrightness / 100 * 7)) {
|
|
|
|
|
brightness = maxBrightness / 100 * 7;
|
|
|
|
|
&& brightness < (maxPatternBrightness / 100 * 60)) {
|
|
|
|
|
brightness = maxPatternBrightness / 100 * 60;
|
|
|
|
|
}
|
|
|
|
|
FileUtils.writeSingleLed(led, brightness / maxBrightness * Constants.getBrightness());
|
|
|
|
|
|
|
|
|
|
brightness = brightness / maxPatternBrightness * currentBrightness;
|
|
|
|
|
|
|
|
|
|
FileUtils.writeSingleLed(led, brightness);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|