Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
551f62cebc |
@@ -56,7 +56,13 @@ public final class AnimationManager {
|
||||
|
||||
if (StatusManager.isAnimationActive()) {
|
||||
long start = System.currentTimeMillis();
|
||||
if (wait) {
|
||||
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 (DEBUG) Log.d(TAG, "There is already an animation playing, wait | name: " + name);
|
||||
while (StatusManager.isAnimationActive()) {
|
||||
if (System.currentTimeMillis() - start >= 2500) return false;
|
||||
@@ -73,7 +79,8 @@ public final class AnimationManager {
|
||||
private static boolean checkInterruption(String name) {
|
||||
if (StatusManager.isAllLedActive()
|
||||
|| (name != "call" && StatusManager.isCallLedEnabled())
|
||||
|| (name == "call" && !StatusManager.isCallLedEnabled())) {
|
||||
|| (name == "call" && !StatusManager.isCallLedEnabled())
|
||||
|| (name == "volume" && StatusManager.isVolumeLedUpdate())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -86,10 +93,12 @@ 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;
|
||||
@@ -104,7 +113,8 @@ public final class AnimationManager {
|
||||
if (DEBUG) Log.d(TAG, "Animation line length mismatch | name: " + name + " | line: " + line);
|
||||
throw new InterruptedException();
|
||||
}
|
||||
Thread.sleep(16, 666000);
|
||||
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);
|
||||
@@ -117,214 +127,170 @@ public final class AnimationManager {
|
||||
}
|
||||
|
||||
public static void playCharging(int batteryLevel, boolean wait) {
|
||||
if (!check("charging", wait))
|
||||
submit(() -> {
|
||||
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));
|
||||
int last = StatusManager.getChargingLedLast();
|
||||
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));
|
||||
|
||||
try {
|
||||
for (int i = 0; i < batteryArray.length; i++) {
|
||||
if ( i <= amount - 1 && batteryLevel > 0) {
|
||||
try {
|
||||
for (int i = 0; i < batteryArray.length; i++) {
|
||||
if (checkInterruption("charging")) throw new InterruptedException();
|
||||
StatusManager.setChargingLedLast(i);
|
||||
batteryArray[i] = Constants.MAX_PATTERN_BRIGHTNESS;
|
||||
batteryArray[i] = Constants.getBrightness();
|
||||
if (batteryDot && i == 0) continue;
|
||||
if (last == 0) {
|
||||
updateLedFrame(batteryArray);
|
||||
Thread.sleep(16, 666000);
|
||||
}
|
||||
updateLedFrame(batteryArray);
|
||||
Thread.sleep(15);
|
||||
}
|
||||
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 dismissCharging() {
|
||||
if (StatusManager.getBatteryLevelLast() == 0
|
||||
|| StatusManager.getBatteryArrayLast() == null)
|
||||
return;
|
||||
public static void playVolume(int volumeLevel, boolean wait) {
|
||||
submit(() -> {
|
||||
if (!check("volume", wait))
|
||||
return;
|
||||
|
||||
if (!check("Dismiss charging", false))
|
||||
return;
|
||||
StatusManager.setVolumeLedActive(true);
|
||||
StatusManager.setAnimationActive(true);
|
||||
|
||||
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[] 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++) {
|
||||
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) {
|
||||
if (checkInterruption("volume")) throw new InterruptedException();
|
||||
StatusManager.setVolumeLedLast(i);
|
||||
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[i] = Constants.getBrightness();
|
||||
if (last == 0) {
|
||||
updateLedFrame(volumeArray);
|
||||
Thread.sleep(15);
|
||||
}
|
||||
}
|
||||
volumeArray = lastArray;
|
||||
}
|
||||
}
|
||||
} 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 (last != 0) {
|
||||
if (checkInterruption("volume")) throw new InterruptedException();
|
||||
StatusManager.setVolumeLedLast(i);
|
||||
volumeArrayLast[i] = 0;
|
||||
updateLedFrame(volumeArrayLast);
|
||||
Thread.sleep(16, 666000);
|
||||
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: 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) {
|
||||
StatusManager.setCallLedEnabled(true);
|
||||
submit(() -> {
|
||||
StatusManager.setCallLedEnabled(true);
|
||||
|
||||
if (!check("call: " + name, true))
|
||||
return;
|
||||
if (!check("call: " + name, true))
|
||||
return;
|
||||
|
||||
StatusManager.setCallLedActive(true);
|
||||
StatusManager.setCallLedActive(true);
|
||||
|
||||
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 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()) {}
|
||||
}
|
||||
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() {
|
||||
@@ -339,21 +305,24 @@ public final class AnimationManager {
|
||||
|
||||
try {
|
||||
if (checkInterruption("essential")) throw new InterruptedException();
|
||||
int[] steps = {12, 24, 36, 48, 60};
|
||||
int[] steps = {1, 2, 4, 7};
|
||||
for (int i : steps) {
|
||||
if (checkInterruption("essential")) throw new InterruptedException();
|
||||
updateLedSingle(led, Constants.MAX_PATTERN_BRIGHTNESS / 100 * i);
|
||||
Thread.sleep(16, 666000);
|
||||
updateLedSingle(led, Constants.getMaxBrightness() / 100 * i);
|
||||
Thread.sleep(25);
|
||||
}
|
||||
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.MAX_PATTERN_BRIGHTNESS / 100 * 60);
|
||||
updateLedSingle(led, Constants.getMaxBrightness() / 100 * 7);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void stopEssential() {
|
||||
@@ -366,39 +335,41 @@ public final class AnimationManager {
|
||||
}
|
||||
|
||||
public static void playMusic(String name) {
|
||||
float maxPatternBrightness = (float) Constants.MAX_PATTERN_BRIGHTNESS;
|
||||
float[] pattern = new float[5];
|
||||
submit(() -> {
|
||||
float maxBrightness = (float) Constants.getMaxBrightness();
|
||||
float[] pattern = new float[5];
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void updateLedFrame(String[] pattern) {
|
||||
@@ -407,7 +378,7 @@ public final class AnimationManager {
|
||||
.toArray());
|
||||
}
|
||||
|
||||
private static void updateLedFrame(int[] pattern) {
|
||||
public static void updateLedFrame(int[] pattern) {
|
||||
float[] floatPattern = new float[pattern.length];
|
||||
for (int i = 0; i < pattern.length; i++) {
|
||||
floatPattern[i] = (float) pattern[i];
|
||||
@@ -417,24 +388,21 @@ public final class AnimationManager {
|
||||
|
||||
private static void updateLedFrame(float[] pattern) {
|
||||
//if (DEBUG) Log.d(TAG, "Updating pattern: " + pattern);
|
||||
float maxPatternBrightness = (float) Constants.MAX_PATTERN_BRIGHTNESS;
|
||||
float currentBrightness = (float) Constants.getBrightness();
|
||||
float maxBrightness = (float) Constants.getMaxBrightness();
|
||||
int essentialLed = ResourceUtils.getInteger("glyph_settings_notifs_essential_led");
|
||||
|
||||
if (StatusManager.isEssentialLedActive()) {
|
||||
if (pattern.length == 5) { // Phone (1) pattern
|
||||
if (pattern[1] < (maxPatternBrightness / 100 * 60)) {
|
||||
pattern[1] = maxPatternBrightness / 100 * 60;
|
||||
if (pattern[1] < (maxBrightness / 100 * 7)) {
|
||||
pattern[1] = maxBrightness / 100 * 7;
|
||||
}
|
||||
} else if (pattern.length == 33) { // Phone (2) pattern
|
||||
if (pattern[2] < (maxPatternBrightness / 100 * 60)) {
|
||||
pattern[2] = maxPatternBrightness / 100 * 60;
|
||||
if (pattern[2] < (maxBrightness / 100 * 7)) {
|
||||
pattern[2] = maxBrightness / 100 * 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < pattern.length; i++) {
|
||||
pattern[i] = pattern[i] / maxPatternBrightness * currentBrightness;
|
||||
pattern[i] = pattern[i] / maxBrightness * Constants.getBrightness();
|
||||
}
|
||||
FileUtils.writeFrameLed(pattern);
|
||||
}
|
||||
@@ -449,18 +417,13 @@ public final class AnimationManager {
|
||||
|
||||
private static void updateLedSingle(int led, float brightness) {
|
||||
//if (DEBUG) Log.d(TAG, "Updating led | led: " + led + " | brightness: " + brightness);
|
||||
float maxPatternBrightness = (float) Constants.MAX_PATTERN_BRIGHTNESS;
|
||||
float currentBrightness = (float) Constants.getBrightness();
|
||||
float maxBrightness = (float) Constants.getMaxBrightness();
|
||||
int essentialLed = ResourceUtils.getInteger("glyph_settings_notifs_essential_led");
|
||||
|
||||
if (StatusManager.isEssentialLedActive()
|
||||
&& led == essentialLed
|
||||
&& brightness < (maxPatternBrightness / 100 * 60)) {
|
||||
brightness = maxPatternBrightness / 100 * 60;
|
||||
&& brightness < (maxBrightness / 100 * 7)) {
|
||||
brightness = maxBrightness / 100 * 7;
|
||||
}
|
||||
|
||||
brightness = brightness / maxPatternBrightness * currentBrightness;
|
||||
|
||||
FileUtils.writeSingleLed(led, brightness);
|
||||
FileUtils.writeSingleLed(led, brightness / maxBrightness * Constants.getBrightness());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ public class NotificationService extends NotificationListenerService
|
||||
@Override
|
||||
public void onCreate() {
|
||||
if (DEBUG) Log.d(TAG, "Creating service");
|
||||
|
||||
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||
@@ -210,4 +209,4 @@ public class NotificationService extends NotificationListenerService
|
||||
super.onChange(selfChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,13 +38,10 @@ import co.aospa.glyph.Preference.GlyphAnimationPreference;
|
||||
import co.aospa.glyph.Utils.ResourceUtils;
|
||||
import co.aospa.glyph.Utils.ServiceUtils;
|
||||
|
||||
public class CallSettingsFragment extends SettingsBasePreferenceFragment implements OnPreferenceChangeListener,
|
||||
OnCheckedChangeListener {
|
||||
public class CallSettingsFragment extends SettingsBasePreferenceFragment implements OnPreferenceChangeListener {
|
||||
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private MainSwitchPreference mSwitchBar;
|
||||
|
||||
private ListPreference mListPreference;
|
||||
|
||||
private GlyphAnimationPreference mGlyphAnimationPreference;
|
||||
@@ -58,9 +55,9 @@ public class CallSettingsFragment extends SettingsBasePreferenceFragment impleme
|
||||
mScreen = this.getPreferenceScreen();
|
||||
getActivity().setTitle(R.string.glyph_settings_call_toggle_title);
|
||||
|
||||
mSwitchBar = (MainSwitchPreference) findPreference(Constants.GLYPH_CALL_SUB_ENABLE);
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.setChecked(SettingsManager.isGlyphCallEnabled());
|
||||
MainSwitchPreference switchBar = findPreference(Constants.GLYPH_CALL_SUB_ENABLE);
|
||||
switchBar.setOnPreferenceChangeListener(this);
|
||||
switchBar.setChecked(SettingsManager.isGlyphCallEnabled());
|
||||
|
||||
mListPreference = (ListPreference) findPreference(Constants.GLYPH_CALL_SUB_ANIMATIONS);
|
||||
mListPreference.setOnPreferenceChangeListener(this);
|
||||
@@ -84,6 +81,14 @@ public class CallSettingsFragment extends SettingsBasePreferenceFragment impleme
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final String preferenceKey = preference.getKey();
|
||||
|
||||
if (preferenceKey.equals(Constants.GLYPH_CALL_SUB_ENABLE)) {
|
||||
boolean isChecked = (Boolean) newValue;
|
||||
SettingsManager.setGlyphCallEnabled(isChecked);
|
||||
ServiceUtils.checkGlyphService();
|
||||
mGlyphAnimationPreference.updateAnimation(isChecked,
|
||||
SettingsManager.getGlyphCallAnimation());
|
||||
}
|
||||
|
||||
if (preferenceKey.equals(Constants.GLYPH_CALL_SUB_ANIMATIONS)) {
|
||||
mGlyphAnimationPreference.updateAnimation(SettingsManager.isGlyphCallEnabled(),
|
||||
newValue.toString());
|
||||
@@ -94,12 +99,4 @@ public class CallSettingsFragment extends SettingsBasePreferenceFragment impleme
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
SettingsManager.setGlyphCallEnabled(isChecked);
|
||||
ServiceUtils.checkGlyphService();
|
||||
mGlyphAnimationPreference.updateAnimation(isChecked,
|
||||
SettingsManager.getGlyphCallAnimation());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,12 +46,10 @@ import co.aospa.glyph.Preference.GlyphAnimationPreference;
|
||||
import co.aospa.glyph.Utils.ResourceUtils;
|
||||
import co.aospa.glyph.Utils.ServiceUtils;
|
||||
|
||||
public class NotifsSettingsFragment extends SettingsBasePreferenceFragment implements OnPreferenceChangeListener,
|
||||
OnCheckedChangeListener {
|
||||
public class NotifsSettingsFragment extends SettingsBasePreferenceFragment implements OnPreferenceChangeListener {
|
||||
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private MainSwitchPreference mSwitchBar;
|
||||
private PreferenceCategory mCategory;
|
||||
|
||||
private List<String> mEssentialApps = new ArrayList<String>();
|
||||
@@ -73,9 +71,9 @@ public class NotifsSettingsFragment extends SettingsBasePreferenceFragment imple
|
||||
mScreen = this.getPreferenceScreen();
|
||||
getActivity().setTitle(R.string.glyph_settings_notifs_toggle_title);
|
||||
|
||||
mSwitchBar = (MainSwitchPreference) findPreference(Constants.GLYPH_NOTIFS_SUB_ENABLE);
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.setChecked(SettingsManager.isGlyphNotifsEnabled());
|
||||
MainSwitchPreference switchBar = findPreference(Constants.GLYPH_NOTIFS_SUB_ENABLE);
|
||||
switchBar.setOnPreferenceChangeListener(this);
|
||||
switchBar.setChecked(SettingsManager.isGlyphNotifsEnabled());
|
||||
|
||||
mCategory = (PreferenceCategory) findPreference(Constants.GLYPH_NOTIFS_SUB_CATEGORY);
|
||||
|
||||
@@ -125,6 +123,14 @@ public class NotifsSettingsFragment extends SettingsBasePreferenceFragment imple
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final String preferenceKey = preference.getKey();
|
||||
|
||||
if (preferenceKey.equals(Constants.GLYPH_NOTIFS_SUB_ENABLE)) {
|
||||
boolean isChecked = (Boolean) newValue;
|
||||
SettingsManager.setGlyphNotifsEnabled(isChecked);
|
||||
ServiceUtils.checkGlyphService();
|
||||
mGlyphAnimationPreference.updateAnimation(isChecked,
|
||||
SettingsManager.getGlyphNotifsAnimation(), 1500);
|
||||
}
|
||||
|
||||
if (preferenceKey.equals(Constants.GLYPH_NOTIFS_SUB_ANIMATIONS)) {
|
||||
mGlyphAnimationPreference.updateAnimation(SettingsManager.isGlyphNotifsEnabled(),
|
||||
newValue.toString(), 1500);
|
||||
@@ -139,12 +145,4 @@ public class NotifsSettingsFragment extends SettingsBasePreferenceFragment imple
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
SettingsManager.setGlyphNotifsEnabled(isChecked);
|
||||
ServiceUtils.checkGlyphService();
|
||||
mGlyphAnimationPreference.updateAnimation(isChecked,
|
||||
SettingsManager.getGlyphNotifsAnimation(), 1500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,9 +24,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
@@ -42,10 +39,7 @@ import co.aospa.glyph.Constants.Constants;
|
||||
import co.aospa.glyph.Manager.SettingsManager;
|
||||
import co.aospa.glyph.Utils.ServiceUtils;
|
||||
|
||||
public class SettingsFragment extends SettingsBasePreferenceFragment implements OnPreferenceChangeListener,
|
||||
OnCheckedChangeListener {
|
||||
|
||||
private MainSwitchPreference mSwitchBar;
|
||||
public class SettingsFragment extends SettingsBasePreferenceFragment implements OnPreferenceChangeListener {
|
||||
|
||||
private SwitchPreferenceCompat mFlipPreference;
|
||||
private SeekBarPreference mBrightnessPreference;
|
||||
@@ -71,9 +65,9 @@ public class SettingsFragment extends SettingsBasePreferenceFragment implements
|
||||
|
||||
boolean glyphEnabled = SettingsManager.isGlyphEnabled();
|
||||
|
||||
mSwitchBar = (MainSwitchPreference) findPreference(Constants.GLYPH_ENABLE);
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.setChecked(glyphEnabled);
|
||||
MainSwitchPreference switchBar = findPreference(Constants.GLYPH_ENABLE);
|
||||
switchBar.setOnPreferenceChangeListener(this);
|
||||
switchBar.setChecked(glyphEnabled);
|
||||
|
||||
mFlipPreference = (SwitchPreferenceCompat) findPreference(Constants.GLYPH_FLIP_ENABLE);
|
||||
mFlipPreference.setEnabled(glyphEnabled);
|
||||
@@ -133,6 +127,22 @@ public class SettingsFragment extends SettingsBasePreferenceFragment implements
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final String preferenceKey = preference.getKey();
|
||||
|
||||
if (preferenceKey.equals(Constants.GLYPH_ENABLE)) {
|
||||
boolean isChecked = (Boolean) newValue;
|
||||
SettingsManager.enableGlyph(isChecked);
|
||||
|
||||
mFlipPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mBrightnessPreference.setEnabled(isChecked);
|
||||
mNotifsPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mNotifsPreference.setSwitchEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mCallPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mCallPreference.setSwitchEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mChargingLevelPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mChargingPowersharePreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mVolumeLevelPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mMusicVisualizerPreference.setEnabled(isChecked);
|
||||
}
|
||||
|
||||
if (preferenceKey.equals(Constants.GLYPH_CALL_ENABLE)) {
|
||||
SettingsManager.setGlyphCallEnabled(!mCallPreference.isChecked());
|
||||
}
|
||||
@@ -159,26 +169,6 @@ public class SettingsFragment extends SettingsBasePreferenceFragment implements
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
SettingsManager.enableGlyph(isChecked);
|
||||
|
||||
mSwitchBar.setChecked(isChecked);
|
||||
|
||||
mFlipPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mBrightnessPreference.setEnabled(isChecked);
|
||||
mNotifsPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mNotifsPreference.setSwitchEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mCallPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mCallPreference.setSwitchEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mChargingLevelPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mChargingPowersharePreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mVolumeLevelPreference.setEnabled(isChecked && !mMusicVisualizerPreference.isChecked());
|
||||
mMusicVisualizerPreference.setEnabled(isChecked);
|
||||
|
||||
mHandler.post(() -> ServiceUtils.checkGlyphService());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mSettingObserver.unregister(mContentResolver);
|
||||
|
||||
Reference in New Issue
Block a user