JB2上如何实现按power键亮屏的时候,能把触摸板上的home/menu/back虚拟按键的背光点亮?

本文详细介绍了如何在Android 4.2系统中通过修改KeyguardViewMediator类来实现按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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值