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

來源:互聯網
上載者:User

在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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.