2011-08-18 53 views
3

我有一個從onKeyDown事件回來的日誌,並且該標誌導致了數字520.如何找出該標誌是什麼?我假設它的520 = 512 + 8 = FLAG_TRACKING + FLAG_FROM_SYSTEMandroid - onKeyDown mFlags變量

我需要確定,我聽說它與十六進制代碼有關。如何轉換並找出?

從日誌:

onKeyUp - keycode:118 | info:KeyEvent {action = ACTION_UP code = 118 repeat = 0 meta = 0 scancode = 766 mFlags = 520}

我需要知道mFlags的名字是什麼。

謝謝。

+0

修改我的答案。只有當..沒有其他的.. – Ronnie

回答

0

你可以這樣做檢查

if (mFlags & FLAG_TRACKING == FLAG_TRACKING) 
    // it contains FLAG_TRACKING 
if (mFlags & FLAG_FROM_SYSTEM == FLAG_FROM_SYSTEM) 
    // its contains FLAG_FROM_SYSTEM flag. 
if ... etc... 
+0

它可以是標誌思想的組合。特別是520是兩個組合。所以它會通過所有這些520方法並且不報告任何內容。 – dropsOfJupiter

+0

或者我可能不瞭解java那麼好。 – dropsOfJupiter

+0

只有當包含該特定標誌時,控件纔會輸入一個「if」塊。所以在每個'如果'你可以將標誌附加到一個字符串並記錄所有的離散標誌值。我認爲這回答你的問題。 :) – Ronnie

1

下面是完整的代碼:

Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | isCanceled: " + event.isCanceled() + " | info: " + event.toString()); 

     if ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == KeyEvent.FLAG_FROM_SYSTEM) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_FROM_SYSTEM"); 

     }else {} 

     if ((event.getFlags() & KeyEvent.FLAG_TRACKING) == KeyEvent.FLAG_TRACKING) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_TRACKING"); 
     }else {} 



     ///FLAG_WOKE_HERE 
     if ((event.getFlags() & KeyEvent.FLAG_WOKE_HERE) == KeyEvent.FLAG_WOKE_HERE) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_WOKE_HERE"); 
     }else {} 


     //FLAG_SOFT_KEYBOARD 
     if ((event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_SOFT_KEYBOARD"); 
     }else {} 

     //FLAG_KEEP_TOUCH_MODE 
     if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) == KeyEvent.FLAG_KEEP_TOUCH_MODE) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_KEEP_TOUCH_MODE"); 
     }else {} 


     //FLAG_EDITOR_ACTION 
     if ((event.getFlags() & KeyEvent.FLAG_EDITOR_ACTION) == KeyEvent.FLAG_EDITOR_ACTION) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_EDITOR_ACTION"); 
     }else {} 


     //FLAG_CANCELED 
     if ((event.getFlags() & KeyEvent.FLAG_CANCELED) == KeyEvent.FLAG_CANCELED) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_CANCELED"); 
     }else {} 


     //FLAG_VIRTUAL_HARD_KEY 
     if ((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == KeyEvent.FLAG_VIRTUAL_HARD_KEY) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_VIRTUAL_HARD_KEY"); 
     }else {} 

     //FLAG_LONG_PRESS 
     if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) == KeyEvent.FLAG_LONG_PRESS) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_LONG_PRESS"); 
     }else {} 

     //FLAG_CANCELED_LONG_PRESS 
     if ((event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == KeyEvent.FLAG_CANCELED_LONG_PRESS) 
     { 

      Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_CANCELED_LONG_PRESS"); 
     }else {}