Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44e5f6ca authored by tbalden's avatar tbalden Committed by Gerrit Code Review
Browse files

keyboard: adding functional alt/shift lights

This is useful for devices that has QWERTY keyboard
and leds for the Alt/Shift (Fn/Caps) keys, like
htc doubleshot.

Depends on libhardware patch for the light ids:
http://review.cyanogenmod.org/34902

Change-Id: I66ebc2d881438f5b51db77eaa885421e65a7da0d
parent 651d2191
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -55,4 +55,7 @@ interface IPowerManager
    void cpuBoost(int duration);

    void setKeyboardVisibility(boolean visible);

    void setKeyboardLight(boolean on, int key);

}
+18 −0
Original line number Diff line number Diff line
@@ -868,4 +868,22 @@ public final class PowerManager {
        } catch (RemoteException e) {
        }
    }

    /**
     * sets the keyboard LED state
     *
     * @param on boolean state
     * @param key 1 for caps, 2 for fn
     *
     * {@hide}
     */
    public void setKeyboardLight(boolean on, int key)
    {
        try {
            mService.setKeyboardLight(on, key);
        } catch (RemoteException e) {
        }
    }


}
+31 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ import android.text.Spanned;
import android.view.KeyEvent;
import android.view.View;
import android.view.KeyCharacterMap;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;

/**
 * This base class encapsulates the behavior for tracking the state of
@@ -214,6 +217,14 @@ public abstract class MetaKeyKeyListener {
        adjust(content, CAP);
        adjust(content, ALT);
        adjust(content, SYM);
        try {
            IPowerManager power = IPowerManager.Stub.asInterface(
                ServiceManager.getService("power"));
            if (getMetaState(content, META_SHIFT_ON) <= 0)
                power.setKeyboardLight(false, 1);
            if (getMetaState(content, META_ALT_ON) <= 0)
                power.setKeyboardLight(false, 2);
        } catch (RemoteException doe) {}
    }

    /**
@@ -266,12 +277,32 @@ public abstract class MetaKeyKeyListener {
    public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
            press(content, CAP);
            try {
                IPowerManager power = IPowerManager.Stub.asInterface(
                    ServiceManager.getService("power"));
                int state = content.getSpanFlags(CAP);
                if (state == PRESSED || state == LOCKED) {
                    power.setKeyboardLight(true, 1);
                } else {
                    power.setKeyboardLight(false, 1);
                }
            } catch (RemoteException doe) {}
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT
                || keyCode == KeyEvent.KEYCODE_NUM) {
            press(content, ALT);
            try {
                IPowerManager power = IPowerManager.Stub.asInterface(
                    ServiceManager.getService("power"));
                int state = content.getSpanFlags(ALT);
                if (state == PRESSED || state == LOCKED) {
                    power.setKeyboardLight(true, 2);
                } else {
                    power.setKeyboardLight(false, 2);
                }
            } catch (RemoteException doe) {}
            return true;
        }

+3 −1
Original line number Diff line number Diff line
@@ -39,7 +39,9 @@ public class LightsService {
    public static final int LIGHT_ID_ATTENTION = 5;
    public static final int LIGHT_ID_BLUETOOTH = 6;
    public static final int LIGHT_ID_WIFI = 7;
    public static final int LIGHT_ID_COUNT = 8;
    public static final int LIGHT_ID_CAPS = 8;
    public static final int LIGHT_ID_FUNC = 9;
    public static final int LIGHT_ID_COUNT = 10;

    public static final int LIGHT_FLASH_NONE = 0;
    public static final int LIGHT_FLASH_TIMED = 1;
+25 −0
Original line number Diff line number Diff line
@@ -186,6 +186,8 @@ public final class PowerManagerService extends IPowerManager.Stub
    private LightsService.Light mAttentionLight;
    private LightsService.Light mButtonsLight;
    private LightsService.Light mKeyboardLight;
    private LightsService.Light mCapsLight;
    private LightsService.Light mFnLight;

    private final Object mLock = new Object();

@@ -455,6 +457,8 @@ public final class PowerManagerService extends IPowerManager.Stub
            mAttentionLight = mLightsService.getLight(LightsService.LIGHT_ID_ATTENTION);
            mButtonsLight = mLightsService.getLight(LightsService.LIGHT_ID_BUTTONS);
            mKeyboardLight = mLightsService.getLight(LightsService.LIGHT_ID_KEYBOARD);
            mCapsLight = mLightsService.getLight(LightsService.LIGHT_ID_CAPS);
            mFnLight = mLightsService.getLight(LightsService.LIGHT_ID_FUNC);

            // Register for broadcasts from other components of the system.
            IntentFilter filter = new IntentFilter();
@@ -901,9 +905,30 @@ public final class PowerManagerService extends IPowerManager.Stub
            }
            if (mKeyboardVisible != visible) {
                mKeyboardVisible = visible;
                if (!visible) {
                    mKeyboardLight.turnOff();
                    // If hiding keyboard, turn off leds
                    setKeyboardLight(false, 1);
                    setKeyboardLight(false, 2);
                }
            }
        }
    }

    @Override // Binder call
    public void setKeyboardLight(boolean on, int key) {
        if (key == 1) {
            if (on)
                mCapsLight.setColor(0x00ffffff);
            else
                mCapsLight.turnOff();
        } else if (key == 2) {
            if (on)
                mFnLight.setColor(0x00ffffff);
            else
                mFnLight.turnOff();
        }
    }

    @Override // Binder call
    public void wakeUp(long eventTime) {
Loading