Example usage for android.view KeyEvent KEYCODE_MENU

List of usage examples for android.view KeyEvent KEYCODE_MENU

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_MENU.

Prototype

int KEYCODE_MENU

To view the source code for android.view KeyEvent KEYCODE_MENU.

Click Source Link

Document

Key code constant: Menu key.

Usage

From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java

public boolean onKeyDown(int keyCode, KeyEvent e) {
    long curTime = System.currentTimeMillis();
    // ?1/5/*from   w ww  .java  2s.c  o m*/
    if ((curTime - keyTimeMillis) > LSystem.SECOND / 5) {
        keyTimeMillis = curTime;
        if (gameHandler != null) {
            synchronized (gameHandler) {
                if (!isBackLocked) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        LSystem.exit();
                        return true;
                    }
                }
                if (keyCode == KeyEvent.KEYCODE_MENU) {
                    return super.onKeyDown(keyCode, e);
                }
                if (gameHandler.onKeyDown(keyCode, e)) {
                    return true;
                }
                // ??Android???
                try {
                    Thread.sleep(16);
                } catch (Exception ex) {
                }
                return super.onKeyDown(keyCode, e);
            }
        }
    }
    return true;
}

From source file:org.apache.cordova.AndroidWebView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyDownCodes.contains(keyCode)) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            // only override default behavior is event bound
            LOG.d(TAG, "Down Key Hit");
            this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
            return true;
        }//from  w ww  .  j ava2  s  .co  m
        // If volumeup key
        else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            LOG.d(TAG, "Up Key Hit");
            this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    } else if (keyCode == KeyEvent.KEYCODE_BACK) {
        return !(this.startOfHistory()) || this.bound;
    } else if (keyCode == KeyEvent.KEYCODE_MENU) {
        //How did we get here?  Is there a childView?
        View childView = this.getFocusedChild();
        if (childView != null) {
            //Make sure we close the keyboard if it's present
            InputMethodManager imm = (InputMethodManager) cordova.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(childView.getWindowToken(), 0);
            cordova.getActivity().openOptionsMenu();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java

public boolean onKeyUp(int keyCode, KeyEvent e) {
    if (gameHandler != null) {
        synchronized (gameHandler) {
            if (keyCode == KeyEvent.KEYCODE_MENU) {
                return super.onKeyUp(keyCode, e);
            }//from  w  w w.jav  a  2  s  . c  o  m
            if (gameHandler.onKeyUp(keyCode, e)) {
                return true;
            }
            return super.onKeyUp(keyCode, e);
        }
    }
    return true;
}

From source file:org.apache.cordova.CordovaWebView.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // If back key
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // If back key is bound, then send event to JavaScript
        if (this.bound) {
            this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
            return true;
        } else {//from w w  w  .  j  a v  a 2  s. c o m
            // If not bound
            // Go to previous page in webview if it is possible to go back
            if (this.backHistory()) {
                return true;
            }
            // If not, then invoke default behaviour
            else {
                //this.activityState = ACTIVITY_EXITING;
                return false;
            }
        }
    }
    // Legacy
    else if (keyCode == KeyEvent.KEYCODE_MENU) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
        return super.onKeyUp(keyCode, event);
    }
    // If search key
    else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
        return true;
    } else if (keyUpCodes.contains(keyCode)) {
        //What the hell should this do?
        return super.onKeyUp(keyCode, event);
    }

    //Does webkit change this behaviour?
    return super.onKeyUp(keyCode, event);
}

From source file:com.aegiswallet.actions.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (mDrawerLayout != null) {
            if (mDrawerLayout.isDrawerOpen(Gravity.LEFT))
                mDrawerLayout.closeDrawer(Gravity.LEFT);
            else/*  w w w  . j ava 2s  . co m*/
                mDrawerLayout.openDrawer(Gravity.LEFT);
        }
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:paulscode.android.mupen64plusae.game.GameActivity.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
    final boolean keyDown = event.getAction() == KeyEvent.ACTION_DOWN;

    // Attempt to reconnect any disconnected devices
    mGamePrefs.playerMap.reconnectDevice(AbstractProvider.getHardwareId(event));

    if (keyDown && keyCode == KeyEvent.KEYCODE_MENU) {
        if (mDrawerLayout.isDrawerOpen(GravityCompat.START))
            mDrawerLayout.closeDrawer(GravityCompat.START);
        else// w w w.  j av  a  2  s  .  co  m
            mDrawerLayout.openDrawer(GravityCompat.START);
        return true;
    } else if (keyDown && keyCode == KeyEvent.KEYCODE_BACK) {
        if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
            mDrawerLayout.closeDrawer(GravityCompat.START);
        } else {
            mWaitingOnConfirmation = true;
            CoreInterface.exit();
        }
        return true;
    }

    // Let the PeripheralControllers and Android handle everything else
    else {
        if (!mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
            // If PeripheralControllers exist and handle the event,
            // they return true. Else they return false, signaling
            // Android to handle the event (menu button, vol keys).
            if (mKeyProvider != null)
                return mKeyProvider.onKey(view, keyCode, event);
        }

        return false;
    }
}

From source file:com.supremainc.biostar2.main.HomeActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MENU:
            mLayout.onDrawMenu();/*from www .j a v a 2  s  .co  m*/
            return true;
        case KeyEvent.KEYCODE_BACK:
            if (mFragment != null && mFragment.onBack()) {
                return true;
            }
        default:
            break;
        }
    }
    return super.onKeyDown(keyCode, event);

}

From source file:com.teleca.jamendo.activity.PlayerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        mSlidingDrawer.animateToggle();/*from w w  w .jav a2 s  .co m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.hypodiabetic.happ.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU:
        //menu1.toggle(true);
        mDrawerLayout.closeDrawers();//from w  w w  .  j av  a2 s.c  o m
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:org.apache.cordova.AndroidWebView.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // If back key
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // A custom view is currently displayed  (e.g. playing a video)
        if (mCustomView != null) {
            this.hideCustomView();
        } else {//from  w w  w .  j  a  v  a2 s  . c  o m
            // The webview is currently displayed
            // If back key is bound, then send event to JavaScript
            if (this.bound) {
                this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
                return true;
            } else {
                // If not bound
                // Go to previous page in webview if it is possible to go back
                if (this.backHistory()) {
                    return true;
                }
                // If not, then invoke default behavior
                else {
                    //this.activityState = ACTIVITY_EXITING;
                    //return false;
                    // If they hit back button when app is initializing, app should exit instead of hang until initialization (CB2-458)
                    this.cordova.getActivity().finish();
                }
            }
        }
    }
    // Legacy
    else if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (this.lastMenuEventTime < event.getEventTime()) {
            this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
        }
        this.lastMenuEventTime = event.getEventTime();
        return super.onKeyUp(keyCode, event);
    }
    // If search key
    else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
        return true;
    } else if (keyUpCodes.contains(keyCode)) {
        //What the hell should this do?
        return super.onKeyUp(keyCode, event);
    }

    //Does webkit change this behavior?
    return super.onKeyUp(keyCode, event);
}