JB2上如何实现按power键亮屏的时候,能把触摸板上的home/menu/back虚拟按键的背光点亮?
在android 4.2上的版本,google defautl就已经把触摸板上虚拟按键的背光功能去掉了,如想实现按power键亮屏的时候,能把home/menu/back这些键的背光灯点亮,请参考下面的实现方法:KeyguardViewMediator.java
1,
public KeyguardViewMediator(Context context, LockPatternUtils lockPatternUtils) {
mContext = context;
mPM=(PowerManager) context.getSystemService(Context.POWER_SERVICE);
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
//add code here ===============
mButtonWakelock=mPM.newWakeLock(PowerManager.FULL_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP,"button backlight");
//add code here ===============
2,
private void handleWakeWhenReady(int keyCode, int wakeMSGId) {
if (DBG_WAKE) KeyguardUtils.xlogD(TAG, ">>>handleWakeWhenReady(" + keyCode + ") Before--synchronized (KeyguardViewMediator.this) wakeMSGId = " + wakeMSGId); /// M:
synchronized (KeyguardViewMediator.this) {
if (DBG_WAKE) KeyguardUtils.xlogD(TAG, "handleWakeWhenReady(" + keyCode + ") wakeMSGId = " + wakeMSGId);
// this should result in a call to 'poke wakelock' which will set a timeout
// on releasing the wakelock
if (!mKeyguardViewManager.wakeWhenReadyTq(keyCode)) {
// poke wakelock ourselves if keyguard is no longer active
KeyguardUtils.xlogD(TAG, "mKeyguardViewManager.wakeWhenReadyTq did not poke wake lock, so poke it ourselves");
userActivity();
}
/**
* Now that the keyguard is ready and has poked the wake lock, we can
* release the handoff wakelock
*/
mWakeAndHandOff.release();
//add code here =============
mButtonWakelock.acquire(3000);
//add code here =============
if (DBG_WAKE) KeyguardUtils.xlogD(TAG, "<<<handleWakeWhenReady(" + keyCode + ") wakeMSGId = " + wakeMSGId);
}
}
3,
keyguardviewmediator.java
private void handleKeyguardDone(boolean wakeup) {
KeyguardUtils.xlogD(TAG, "handleKeyguardDone, wakeup=" + wakeup);
//add code here ================
if (mButtonWakelock.isHeld())
mButtonWakelock.release();
//add code here ================
handleHide();
if (wakeup) {
wakeUp();
}
sendUserPresentBroadcast();
}
4,
phonewindowmanager.java
/** {@inheritDoc} */
@Override
public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
int result;
if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
// When the screen is on or if the key is injected pass the key to the application.
result = ACTION_PASS_TO_USER;
} else {
// When the screen is off and the key is not injected, determine whether
// to wake the device but don't pass the key to the application.
result = 0;
if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
if (keyguardActive) {
// If the keyguard is showing, let it wake the device when ready.
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
} else {
// Otherwise, wake the device ourselves.
result |= ACTION_WAKE_UP;
//add code her =================================
mKeyguardMediator.pokeWakelock();
//add code her =================================
}
}
}
5,
KeyguardViewMediator.java
//add by mtk
public void pokeWakelock()
{ mButtonWakelock.acquire(3000);
}
//add by mtk
补充:移动开发 , Android ,