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:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    String message = getResources().getString(R.string.exitOnBackButtonPressed);

    if (keyCode == KeyEvent.KEYCODE_BACK) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(message).setCancelable(false).setPositiveButton(
                getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface iDialog, int id) {

                        stopService(new Intent(context, DeviceMonitorService.class));

                        // Unregistering the broadcast receivers
                        //   unregisterReceiver(bReceiver);
                        unregisterReceiver(mConnReceiver);
                        unregisterReceiver(wifiReceiver);

                        if (connected) {

                            close = true;

                            /*
                             * The progress dialog is not created by
                             * the AsyncTask because the peer just
                             * sends a message to the bootstrap.
                             * This takes very few time and the
                             * dialog would disappear almost
                             * immediately. By showing it before
                             * executing the AsyncTask, it can stay
                             * on the screen until the bootstrap
                             * informs the peer that it is part of
                             * the network. Thus, the dialog is
                             * removed from the function listening
                             * for received messages
                             * onReceivedMessage(String).
                             *//*from  w  ww. ja  va2 s .c om*/
                            dialog = new ProgressDialog(NAM4JAndroidActivity.this);
                            dialog.setMessage(NAM4JAndroidActivity.this.getString(R.string.pwLeaving));
                            dialog.show();

                            new LeaveNetwork(null).execute();

                            connected = false;

                        } else {

                            // finish();

                            // AFTER LEAVING THE NETWORK, THE APP GETS CLOSED

                            /*
                             * Notify the system to finalize and
                             * collect all objects of the app on
                             * exit so that the virtual machine
                             * running the app can be killed by the
                             * system without causing issues.
                             * 
                             * NOTE: If this is set to true then the
                             * virtual machine will not be killed
                             * until all of its threads have closed.
                             */
                            System.runFinalizersOnExit(true);

                            /*
                             * Force the system to close the app
                             * down completely instead of retaining
                             * it in the background. The virtual
                             * machine that runs the app will be
                             * killed. The app will be completely
                             * created as a new app in a new virtual
                             * machine running in a new process if
                             * the user starts the app again.
                             */
                            System.exit(0);
                        }
                    }
                }).setNegativeButton(getResources().getString(R.string.no),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });

        AlertDialog alert = builder.create();
        alert.show();

        return true;
    }

    else if (keyCode == KeyEvent.KEYCODE_MENU) {
        displaySideMenu();
    }

    return super.onKeyDown(keyCode, event);
    // return true;
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU:
        onKeyDownPanel(Window.FEATURE_OPTIONS_PANEL, event);
        // We need to return true here and not let it bubble up to the Window.
        // For empty menus, PhoneWindow's KEYCODE_BACK handling will steals all events,
        // not allowing the Activity to call onBackPressed().
        return true;
    case KeyEvent.KEYCODE_BACK:
        // Certain devices allow opening the options menu via a long press of the back
        // button. We keep a record of whether the last event is from a long press.
        mLongPressBackDown = (event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0;
        break;/*w w w. j  a v  a2  s  . c  o  m*/
    }

    // On API v7-10 we need to manually call onKeyShortcut() as this is not called
    // from the Activity
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        // We do not return true here otherwise dispatchKeyEvent will not reach the Activity
        // (which results in the back button not working)
        onKeyShortcut(keyCode, event);
    }
    return false;
}

From source file:com.todoroo.astrid.activity.TaskListActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        mainMenuPopover.suppressNextKeyEvent();
        mainMenu.performClick();//from   w ww . j  a  va 2s  .co m
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK) {
        TaskEditFragment tef = getTaskEditFragment();
        if (tef != null && tef.onKeyDown(keyCode))
            return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:androidVNC.VncCanvasActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent evt) {
    if (keyCode == KeyEvent.KEYCODE_MENU)
        return super.onKeyDown(keyCode, evt);

    return inputHandler.onKeyDown(keyCode, evt);
}

From source file:androidVNC.VncCanvasActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent evt) {
    if (keyCode == KeyEvent.KEYCODE_MENU)
        return super.onKeyUp(keyCode, evt);

    return inputHandler.onKeyUp(keyCode, evt);
}

From source file:im.vector.activity.HomeActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_SEARCH)) {
        toggleSearchButton();//from  ww w.  j a  v a  2 s  .  co m
        return true;
    }

    if ((keyCode == KeyEvent.KEYCODE_MENU)) {
        HomeActivity.this.startActivity(new Intent(HomeActivity.this, SettingsActivity.class));
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // PersonaLog.e(LOG_TAG, "keyCode" + keyCode);
    //System.out.println("==========OnKeyDown ===========" + keyCode);
    //System.out.println("===========KeyEvent" + event.getAction());
    boolean handled = super.onKeyDown(keyCode, event);

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        return true;
    }/*from  w w  w . jav  a 2  s .co  m*/

    if (112 == keyCode) /* 112 represents F2 key; */
    {
        /* Invoke Application PersonaDrawer screen in case F2 is selected */
        fireHomeBinding(BIND_APPS, 0);
    } else if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
        /*
         * boolean gotKey =
         * TextKeyListener.getInstance().onKeyDown(mWorkspace,
         * mDefaultKeySsb, keyCode, event);
         * 
         * if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() >
         * 0) { // something usable has been typed - start a search // the
         * typed text will be retrieved and cleared by // showSearchDialog()
         * // If there are multiple keystrokes before the search dialog
         * takes focus, // onSearchRequested() will be called for every
         * keystroke, // but it is idempotent, so it's fine. return
         * onSearchRequested(); }
         */

        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        onBackPressed();
    }

    return handled;
}

From source file:com.affectiva.affdexme.MainActivity.java

/**
 * If a user has a phone with a physical menu button, they may expect it to toggle
 * the menu, so we add that functionality.
 *///from   w  w  w .  j av  a2 s .co m
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        setMenuVisible(!isMenuVisible);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            if (getCurrentWebView().canGoBack()) {
                getCurrentWebView().goBack();
            } else {
                finish();//from w  w w. j ava2  s .  c  om
            }
            if (compatCallback.mIsActive) {
                compatCallback.finish();
            }
            return true;
        case KeyEvent.KEYCODE_MENU:
            openOptionsMenu();
            return true;
        }
    }
    return false;
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_UP) {
        return false;
    }/*from   ww  w  .  j  av  a 2  s  .co  m*/
    switch (keyCode) {
    // NOTE:
    // KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_MENU);
    case KeyEvent.KEYCODE_MENU:
    case KeyEvent.KEYCODE_BUTTON_X:
    case KeyEvent.KEYCODE_INFO: {
        if (tb == null) {
            return showTorrentContextMenu();
        }
        break;
    }

    }
    return false;
}