Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> JB2上如何實現按power鍵亮屏的時候,能把觸摸板上的home/menu/back虛擬按鍵的背光點亮?

JB2上如何實現按power鍵亮屏的時候,能把觸摸板上的home/menu/back虛擬按鍵的背光點亮?

編輯:關於Android編程

在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
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved