Expose broadcast intents for custom effects
This commit is contained in:
parent
b13ce0b86c
commit
9a52cee239
|
@ -93,5 +93,14 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".CustomEffectReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="net.typeblog.lunatic.EFFECT_START" />
|
||||
<action android:name="net.typeblog.lunatic.EFFECT_SET" />
|
||||
<action android:name="net.typeblog.lunatic.EFFECT_CLEAR" />
|
||||
<action android:name="net.typeblog.lunatic.EFFECT_END" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package net.typeblog.lunatic;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import net.typeblog.lunatic.Manager.LEDManager;
|
||||
import net.typeblog.lunatic.Manager.StatusManager;
|
||||
|
||||
public class CustomEffectReceiver extends BroadcastReceiver {
|
||||
public static final String EFFECT_START = "net.typeblog.lunatic.EFFECT_START";
|
||||
public static final String EFFECT_SET = "net.typeblog.lunatic.EFFECT_SET";
|
||||
public static final String EFFECT_CLEAR = "net.typeblog.lunatic.EFFECT_CLEAR";
|
||||
public static final String EFFECT_END = "net.typeblog.lunatic.EFFECT_END";
|
||||
|
||||
private LEDManager mManager = new LEDManager();
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (EFFECT_START.equals(action)) {
|
||||
StatusManager.setCustomEffectActive(true);
|
||||
} else if (EFFECT_SET.equals(action)) {
|
||||
if (!StatusManager.isCustomEffectActive()) return;
|
||||
int ids = intent.getIntExtra("ids", 0);
|
||||
int color = intent.getIntExtra("color", 0xffffff);
|
||||
int brightness = intent.getIntExtra("brightness", 100);
|
||||
|
||||
mManager.setRawState(ids, color, brightness);
|
||||
} else if (EFFECT_CLEAR.equals(action)) {
|
||||
if (!StatusManager.isCustomEffectActive()) return;
|
||||
mManager.enableAllLEDs(false);
|
||||
} else if (EFFECT_END.equals(action)) {
|
||||
if (!StatusManager.isCustomEffectActive()) return;
|
||||
mManager.enableAllLEDs(false);
|
||||
StatusManager.setCustomEffectActive(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,11 @@ public final class AnimationManager {
|
|||
}
|
||||
|
||||
private static boolean check(Constants.SpotlightMode mode) {
|
||||
if (StatusManager.isCustomEffectActive()) {
|
||||
if (DEBUG) Log.d(TAG, "Custom effects override all animations | name: " + mode.name());
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case FLASHLIGHT:
|
||||
if (!StatusManager.isAllLedsActive())
|
||||
|
|
|
@ -64,4 +64,23 @@ public class LEDManager {
|
|||
mEnabledLeds = enable ? 31 : 0;
|
||||
syncState();
|
||||
}
|
||||
|
||||
public void setRawState(int ids, int color, int brightness) {
|
||||
if (brightness > 100) {
|
||||
brightness = 100;
|
||||
} else if (brightness < 0) {
|
||||
brightness = 0;
|
||||
}
|
||||
|
||||
if (ids >= 32) {
|
||||
ids = 31;
|
||||
} else if (ids < 0) {
|
||||
ids = 0;
|
||||
}
|
||||
|
||||
mEnabledLeds = ids;
|
||||
mColor = color;
|
||||
mBrightness = brightness;
|
||||
syncState();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public final class StatusManager {
|
|||
private static boolean musicLedActive = false;
|
||||
private static boolean notifLedActive = false;
|
||||
private static boolean chargingLedActive = false;
|
||||
private static boolean customEffectActive = false;
|
||||
|
||||
public static boolean isAllLedsActive() {
|
||||
return allLedActive;
|
||||
|
@ -66,4 +67,12 @@ public final class StatusManager {
|
|||
public static void setChargingLedsActive(boolean status) {
|
||||
chargingLedActive = status;
|
||||
}
|
||||
|
||||
public static boolean isCustomEffectActive() {
|
||||
return customEffectActive;
|
||||
}
|
||||
|
||||
public static void setCustomEffectActive(boolean status) {
|
||||
customEffectActive = status;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue