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.xingjitong.LinphoneActivity.java

@SuppressLint("NewApi")
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //Log.v("LinphoneActiviey.class", "yypp exit wecareapp 000");

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        //yyppoption add
        if ((statusFragment != null) && (event.getRepeatCount() < 1)) {
            if (pop.isShowing()) {
                pop.dismiss();// w  w w. j  av a 2 s . c  om
                isPopShowing = false;
                return true;
            }
        }
        //yyppoption end
        if (currentFragment == FragmentsAvailable.DIALER) {
            //yyppexit  add
            /*
            Dialog dialog= new AlertDialog.Builder(this).setTitle("??????")  
                   .setIcon(android.R.drawable.ic_dialog_info)  
                   .setPositiveButton("", new DialogInterface.OnClickListener() {
               @Override  
               public void onClick(DialogInterface dialog, int which) {
               // ???  
                // System.exit(0);
                LinphoneActivity.instance().exit();
                  //?
                   //startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                    //.addCategory(Intent.CATEGORY_HOME));
               }
                   })
                   .setNegativeButton("??", new DialogInterface.OnClickListener() {
               @Override  
               public void onClick(DialogInterface dialog, int which) {
               // ???,??  
                // System.exit(0);
                //LinphoneActivity.instance().exit();
                  //?
                   startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                       .addCategory(Intent.CATEGORY_HOME));        
                    
               }  
                   }).show(); 
                    
            */
            //yyppexit end            
            //yyppexit 222 add
            /*
                AlertDialog.Builder builder = new AlertDialog.Builder(this,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
                builder.setTitle("?")    //
            .setIcon(android.R.drawable.ic_dialog_info)    //icon
            .setCancelable(false)    //??back
            .setMessage("??-????")    //?
            //
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                   //
                   dialog.dismiss();
             // System.exit(0);
             LinphoneActivity.instance().exit();
               //?
                //startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                 //.addCategory(Intent.CATEGORY_HOME));                           
                }
            })
            .setNeutralButton("?", new DialogInterface.OnClickListener() {                        
                @Override
                public void onClick(DialogInterface dialog, int which) {
                   //
                   dialog.dismiss();
                            
                }
            })
            .setNegativeButton("??", new DialogInterface.OnClickListener() {                    
                @Override
                public void onClick(DialogInterface dialog, int which) {
                   //
                   dialog.dismiss();
             // System.exit(0);
             //LinphoneActivity.instance().exit();
               //?
                startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                 .addCategory(Intent.CATEGORY_HOME));                          
                }
            }).show();
                //Dialog
                //AlertDialog dlg = builder.create();
                */

            //yyppexit 222 end            

            //yyppexit 333 add

            if ((System.currentTimeMillis() - exitTime) > 2000) {
                //Log.v("LinphoneActiviey.class", "yypp exit wecareapp 222");
                Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
                //changeCurrentFragment(FragmentsAvailable.DIALER, null);
                return true;
            } else {
                //Log.v("LinphoneActiviey.class", "yypp exit wecareapp 333");
                //finish();
                //System.exit(0);

                //?
                LinphoneActivity.instance().exit();
                //?
                //this.startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                //.addCategory(Intent.CATEGORY_HOME));

                return true;
            }

            //yyppexit 333 end                  

            /*
            if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
                       
               Log.v("LinphoneActiviey.class", "yypp exit wecareapp 444");
               return true;
                       
                       
            }
            */
            //???????
        } else if (!isTablet()) {
            int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
            if (backStackEntryCount <= 1) {
                showStatusBar();
            }

            if (currentFragment == FragmentsAvailable.SETTINGS) {
                showStatusBar();
                reloadConfig();
                updateAnimationsState();
            }
            if (currentFragment == FragmentsAvailable.SETTINGS || currentFragment == FragmentsAvailable.CHATLIST
                    || currentFragment == FragmentsAvailable.HISTORY
                    || currentFragment == FragmentsAvailable.CONTACTS) {
                changeCurrentFragment(FragmentsAvailable.DIALER, null);
                return true;
            } else if (currentFragment == FragmentsAvailable.SET_CHONGZHI
                    || currentFragment == FragmentsAvailable.SET_MES
                    || currentFragment == FragmentsAvailable.SET_QUERY) {
                if (tableindex == 1)
                    changeCurrentFragment(FragmentsAvailable.SETTINGS, null);
                else
                    changeCurrentFragment(FragmentsAvailable.CHATLIST, null);
                //               resetSelection();
                //               settings.setSelected(true);
                return true;
            } else if (currentFragment == FragmentsAvailable.SET_CHONGZHIKA
                    || currentFragment == FragmentsAvailable.SET_ALIPAY) {
                changeCurrentFragment(FragmentsAvailable.SET_CHONGZHI, new Bundle());
                //               resetSelection();
                //               settings.setSelected(true);
                return true;
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_MENU && statusFragment != null) {

        Log.v("yyppdebug", "yyppoption keyevent  menu 000");
        if (event.getRepeatCount() < 1) {
            // statusFragment.openOrCloseStatusBar();
            Log.v("yyppdebug", "yyppoption keyevent  menu 111");
            //yyppoption add
            if (!pop.isShowing()) {
                Log.v("yyppdebug", "yyppoption keyevent  menu 222");
                //pop.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                pop.showAtLocation(findViewById(R.id.menu), Gravity.BOTTOM, 0, 0);
                isPopShowing = true;
            } else {
                Log.v("yyppdebug", "yyppoption keyevent  menu 333");
                pop.dismiss();
                isPopShowing = false;
            }
            return true;

            //yyppoption end

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

From source file:com.jtschohl.androidfirewall.MainActivity.java

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

    if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            if (abs_menu != null) {
                abs_menu.performIdentifierAction(R.id.menu_items, 0);
                return true;
            }//from www.ja  va 2s  . c  o m
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:ua.mkh.settings.full.MainActivity.java

@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
    switch (keycode) {
    case KeyEvent.KEYCODE_MENU:
        if (menui == 1) {
            openDialog();//  ww w .  ja va2s . c om
        }
        return true;
    case KeyEvent.KEYCODE_BACK:
        if (sear == true) {
            b11.setVisibility(View.GONE);
            b21.setVisibility(View.GONE);
            ed11.clearFocus();
            ed1.clearFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(ed1.getWindowToken(), 0);
            ed11.setText("");
            ed1.setText("");
            LinearLayout list_res_top = (LinearLayout) findViewById(R.id.list_res_top);
            list_res_top.setVisibility(View.GONE);
            LinearLayout list_res = (LinearLayout) findViewById(R.id.list_res);
            list_res.setVisibility(View.GONE);
            ll1.setVisibility(View.VISIBLE);
            sear = false;
        } else {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        return true;
    }

    return super.onKeyDown(keycode, e);
}

From source file:com.oakesville.mythling.MediaActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && getAppSettings().isTv()) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
            setFocusOnActionBar();// www  .j  av  a 2  s  .  co  m
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.android.tv.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    /*//from www  .ja  v a 2 s  .  co  m
     * The following keyboard keys map to these remote keys or "debug actions"
     *  - --------
     *  A KEYCODE_MEDIA_AUDIO_TRACK
     *  D debug: show debug options
     *  E updateChannelBannerAndShowIfNeeded
     *  I KEYCODE_TV_INPUT
     *  O debug: show display mode option
     *  P debug: togglePipView
     *  S KEYCODE_CAPTIONS: select subtitle
     *  W debug: toggle screen size
     *  V KEYCODE_MEDIA_RECORD debug: record the current channel for 30 sec
     *  X KEYCODE_BUTTON_X KEYCODE_PROG_BLUE debug: record current channel for a few minutes
     *  Y KEYCODE_BUTTON_Y KEYCODE_PROG_GREEN debug: Play a recording
     */
    if (SystemProperties.LOG_KEYEVENT.getValue()) {
        Log.d(TAG, "onKeyUp(" + keyCode + ", " + event + ")");
    }
    // If we are in the middle of channel change, finish it before showing overlays.
    finishChannelChangeIfNeeded();

    if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
        showSearchActivity();
        return true;
    }
    switch (mOverlayManager.onKeyUp(keyCode, event)) {
    case KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY:
        return super.onKeyUp(keyCode, event);
    case KEY_EVENT_HANDLER_RESULT_HANDLED:
        return true;
    case KEY_EVENT_HANDLER_RESULT_NOT_HANDLED:
        return false;
    case KEY_EVENT_HANDLER_RESULT_PASSTHROUGH:
    default:
        // pass through
    }
    if (mSearchFragment.isVisible()) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            getFragmentManager().popBackStack();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // When the event is from onUnhandledInputEvent, onBackPressed is not automatically
        // called. Therefore, we need to explicitly call onBackPressed().
        onBackPressed();
        return true;
    }

    if (!mChannelTuner.areAllChannelsLoaded()) {
        // Now channel map is under loading.
    } else if (mChannelTuner.getBrowsableChannelCount() == 0) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_CHANNEL_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_CHANNEL_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_NUMPAD_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_E:
        case KeyEvent.KEYCODE_MENU:
            showSettingsFragment();
            return true;
        }
    } else {
        if (KeypadChannelSwitchView.isChannelNumberKey(keyCode)) {
            showKeypadChannelSwitchView(keyCode);
            return true;
        }
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!PermissionUtils.hasModifyParentalControls(this)) {
                // TODO: support this feature for non-system LC app. b/23939816
                return true;
            }
            PinDialogFragment dialog = null;
            if (mTvView.isScreenBlocked()) {
                dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_CHANNEL,
                        new PinDialogFragment.ResultListener() {
                            @Override
                            public void done(boolean success) {
                                if (success) {
                                    unblockScreen(mTvView);
                                    mIsCurrentChannelUnblockedByUser = true;
                                }
                            }
                        });
            } else if (mTvView.getBlockedContentRating() != null) {
                final TvContentRating rating = mTvView.getBlockedContentRating();
                dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_PROGRAM,
                        new PinDialogFragment.ResultListener() {
                            @Override
                            public void done(boolean success) {
                                if (success) {
                                    mLastAllowedRatingForCurrentChannel = rating;
                                    mTvView.unblockContent(rating);
                                }
                            }
                        });
            }
            if (dialog != null) {
                mOverlayManager.showDialogFragment(PinDialogFragment.DIALOG_TAG, dialog, false);
            }
            return true;

        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_NUMPAD_ENTER:
        case KeyEvent.KEYCODE_E:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_MENU:
            if (event.isCanceled()) {
                // Ignore canceled key.
                // Note that if there's a TIS granted RECEIVE_INPUT_EVENT,
                // fallback keys not blacklisted will have FLAG_CANCELED.
                // See dispatchKeyEvent() for detail.
                return true;
            }
            if (keyCode != KeyEvent.KEYCODE_MENU) {
                updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_FORCE_SHOW);
            }
            if (keyCode != KeyEvent.KEYCODE_E) {
                mOverlayManager.showMenu(
                        mTvView.isRecordingPlayback() ? Menu.REASON_RECORDING_PLAYBACK : Menu.REASON_NONE);
            }
            return true;
        case KeyEvent.KEYCODE_CHANNEL_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_CHANNEL_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
            // Channel change is already done in the head of this method.
            return true;
        case KeyEvent.KEYCODE_S:
            if (!SystemProperties.USE_DEBUG_KEYS.getValue()) {
                break;
            }
        case KeyEvent.KEYCODE_CAPTIONS: {
            mOverlayManager.getSideFragmentManager().show(new ClosedCaptionFragment());
            return true;
        }
        case KeyEvent.KEYCODE_A:
            if (!SystemProperties.USE_DEBUG_KEYS.getValue()) {
                break;
            }
        case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
            mOverlayManager.getSideFragmentManager().show(new MultiAudioFragment());
            return true;
        }
        case KeyEvent.KEYCODE_GUIDE: {
            mOverlayManager.showProgramGuide();
            return true;
        }
        case KeyEvent.KEYCODE_INFO: {
            mOverlayManager.showBanner();
            return true;
        }
        }
    }
    if (SystemProperties.USE_DEBUG_KEYS.getValue()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_W: {
            mDebugNonFullSizeScreen = !mDebugNonFullSizeScreen;
            if (mDebugNonFullSizeScreen) {
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams();
                params.width = 960;
                params.height = 540;
                params.gravity = Gravity.START;
                mTvView.setLayoutParams(params);
            } else {
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams();
                params.width = ViewGroup.LayoutParams.MATCH_PARENT;
                params.height = ViewGroup.LayoutParams.MATCH_PARENT;
                params.gravity = Gravity.CENTER;
                mTvView.setLayoutParams(params);
            }
            return true;
        }
        case KeyEvent.KEYCODE_P: {
            togglePipView();
            return true;
        }
        case KeyEvent.KEYCODE_CTRL_LEFT:
        case KeyEvent.KEYCODE_CTRL_RIGHT: {
            mUseKeycodeBlacklist = !mUseKeycodeBlacklist;
            return true;
        }
        case KeyEvent.KEYCODE_O: {
            mOverlayManager.getSideFragmentManager().show(new DisplayModeFragment());
            return true;
        }

        case KeyEvent.KEYCODE_D:
            mOverlayManager.getSideFragmentManager().show(new DebugOptionFragment());
            return true;

        case KeyEvent.KEYCODE_MEDIA_RECORD: // TODO(DVR) handle with debug_keys set
        case KeyEvent.KEYCODE_V: {
            DvrManager dvrManager = TvApplication.getSingletons(this).getDvrManager();
            long startTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(5);
            long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(35);
            dvrManager.addSchedule(getCurrentChannel(), startTime, endTime);
            return true;
        }
        case KeyEvent.KEYCODE_PROG_BLUE:
        case KeyEvent.KEYCODE_BUTTON_X:
        case KeyEvent.KEYCODE_X: {
            if (CommonFeatures.DVR.isEnabled(this)) {
                Channel channel = mTvView.getCurrentChannel();
                long channelId = channel.getId();
                Program p = mProgramDataManager.getCurrentProgram(channelId);
                if (p == null) {
                    long now = System.currentTimeMillis();
                    mDvrManager.addSchedule(channel, now, now + TimeUnit.MINUTES.toMillis(1));
                } else {
                    mDvrManager.addSchedule(p, mDvrManager.getScheduledRecordingsThatConflict(p));
                }
                return true;
            }
        }
        case KeyEvent.KEYCODE_PROG_YELLOW:
        case KeyEvent.KEYCODE_BUTTON_Y:
        case KeyEvent.KEYCODE_Y: {
            if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
                // TODO(DVR) only get finished recordings.
                List<RecordedProgram> recordedPrograms = mDvrDataManager.getRecordedPrograms();
                Log.d(TAG, "Found " + recordedPrograms.size() + "  recordings");
                if (recordedPrograms.isEmpty()) {
                    Toast.makeText(this, "No finished recording to play", Toast.LENGTH_LONG).show();
                } else {
                    RecordedProgram r = recordedPrograms.get(0);
                    Intent intent = new Intent(this, DvrPlayActivity.class);
                    intent.putExtra(ScheduledRecording.RECORDING_ID_EXTRA, r.getId());
                    startActivity(intent);
                }
                return true;
            }
        }
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:org.cafemember.ui.LaunchActivity.java

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU && !UserConfig.isWaitingForPasscodeEnter) {
        if (AndroidUtilities.isTablet()) {
            if (layersActionBarLayout.getVisibility() == View.VISIBLE
                    && !layersActionBarLayout.fragmentsStack.isEmpty()) {
                layersActionBarLayout.onKeyUp(keyCode, event);
            } else if (rightActionBarLayout.getVisibility() == View.VISIBLE
                    && !rightActionBarLayout.fragmentsStack.isEmpty()) {
                rightActionBarLayout.onKeyUp(keyCode, event);
            } else {
                actionBarLayout.onKeyUp(keyCode, event);
            }//from   w w  w. j a v a2s . c  om
        } else {
            if (actionBarLayout.fragmentsStack.size() == 1) {
                if (!drawerLayoutContainer.isDrawerOpened()) {
                    if (getCurrentFocus() != null) {
                        AndroidUtilities.hideKeyboard(getCurrentFocus());
                    }
                    drawerLayoutContainer.openDrawer(false);
                } else {
                    drawerLayoutContainer.closeDrawer(false);
                }
            } else {
                actionBarLayout.onKeyUp(keyCode, event);
            }
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.rfo.basic.Run.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) { // The user hit a key
    // Log.v(LOGTAG, "onKeyDown" + keyCode);

    // Eat the MENU key Down event, will handle the Up event.
    if (keyCode == KeyEvent.KEYCODE_MENU)
        return true;

    // If event is null, we called this directly from runLoop(),
    // so the return value does not matter.
    if (event == null)
        return true;

    // Alternate: if the user program has set mBlockVolKeys, block everything but BACK
    // if (mBlockVolKeys && (keyCode != KeyEvent.KEYCODE_BACK)) return true;

    // If the user program has set mBlockVolKeys, block volume and headset keys.
    if (mBlockVolKeys && ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
            || (keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) || (keyCode == KeyEvent.KEYCODE_MUTE)
            || (keyCode == KeyEvent.KEYCODE_HEADSETHOOK))) {
        return true;
    }//ww w .  ja v a2s . co  m

    // Otherwise pass the KeyEvent up the chain.
    return super.onKeyDown(keyCode, event);
}

From source file:com.rfo.basic.Run.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // Log.v(LOGTAG, "onKeyUp" + keyCode);
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        return handleMenuKey(event);
    }/*from   ww w  . ja  va 2  s.  c  o  m*/
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        return super.onKeyUp(keyCode, event);
    }

    char c;
    String theKey = "@";
    int n;
    if (keyCode >= 7 && keyCode <= 16) {
        n = keyCode - 7;
        c = Numbers.charAt(n);
        theKey = Character.toString(c);

    } else if (keyCode >= 29 && keyCode <= 54) {
        n = keyCode - 29;
        c = Chars.charAt(n);
        theKey = Character.toString(c);
    } else if (keyCode == 62) {
        c = ' ';
        theKey = Character.toString(c);
    } else if (keyCode >= 19 && keyCode <= 23) {
        switch (keyCode) {
        case 19:
            theKey = "up";
            break;
        case 20:
            theKey = "down";
            break;
        case 21:
            theKey = "left";
            break;
        case 22:
            theKey = "right";
            break;
        case 23:
            theKey = "go";
            break;
        }
    } else {
        theKey = "key " + keyCode;
    }

    synchronized (this) {
        InChar.add(theKey);
    }
    triggerInterrupt(Interrupt.KEY_BIT);

    return true;
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (DEBUG)//from  www.ja  v  a2 s .c  o  m
        Logger.LogDebug("OpenExplorer.onKeyUp(" + keyCode + "," + event + ")");
    if (event.getAction() != KeyEvent.ACTION_UP)
        return super.onKeyUp(keyCode, event);
    if (MenuUtils.getMenuShortcut(event) != null) {
        if (getCurrentFocus() != null) {
            View cf = getCurrentFocus();
            if (cf instanceof TextView)
                return false;
        }
        MenuItem item = MenuUtils.getMenuShortcut(event);
        if (item != null)
            if (onOptionsItemSelected(item)) {
                showToast(item.getTitle(), Toast.LENGTH_SHORT);
                return true;
            }
    }
    if (keyCode == KeyEvent.KEYCODE_MENU && USE_PRETTY_MENUS) {
        View more = findViewById(R.id.menu_more);
        if (more != null && more.isShown() && more.isClickable() && more.performClick()) {
            Logger.LogDebug("!SHOULD BE HERE!");
            return true;
        } else {
            Logger.LogWarning("Couldn't find \"More Menu\"!");
            MenuBuilder menu = new MenuBuilder(this);
            getSelectedFragment().onCreateOptionsMenu(menu, getMenuInflater());
            getMenuInflater().inflate(R.menu.global, menu);
            onPrepareOptionsMenu(menu);
            showMenu(menu, getCurrentFocus(), true);
        }
    } else if (keyCode == KeyEvent.KEYCODE_BOOKMARK) {
        OpenPath path = getDirContentFragment(false).getPath();
        if (mBookmarks.hasBookmark(path))
            addBookmark(path);
        else
            removeBookmark(path);
    } else if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9) {
        int pos = keyCode - KeyEvent.KEYCODE_1;
        if (mToolbarButtons != null) {
            if (pos < mToolbarButtons.getChildCount() && mToolbarButtons.getChildAt(pos).performClick())
                return true;
            return false;
        }
        if (mOptsMenu != null && pos < mOptsMenu.size())
            return onOptionsItemSelected(mOptsMenu.getItem(pos));
        if (mMainMenu != null && pos < mMainMenu.size())
            return onOptionsItemSelected(mMainMenu.getItem(pos));
    }
    /*
    if (keyCode == KeyEvent.KEYCODE_BACK) {
       if (mBackQuit) {
    return super.onKeyUp(keyCode, event);
       } else {
    Toast.makeText(this, "Press back again to quit", Toast.LENGTH_SHORT).show();
    mBackQuit = true;
    return true;
       }      
    }*/
    return super.onKeyUp(keyCode, event);
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public PeerComponent createBrowserComponent(final Object parent) {
    if (getActivity() == null) {
        return null;
    }/*from   w  w  w.j av a 2s .  c o m*/
    final AndroidImplementation.AndroidBrowserComponent[] bc = new AndroidImplementation.AndroidBrowserComponent[1];
    final Throwable[] error = new Throwable[1];
    final Object lock = new Object();

    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {

            synchronized (lock) {
                try {
                    WebView wv = new WebView(getActivity()) {

                        public boolean onKeyDown(int keyCode, KeyEvent event) {
                            switch (keyCode) {
                            case KeyEvent.KEYCODE_BACK:
                                Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_BACK);
                                return true;
                            case KeyEvent.KEYCODE_MENU:
                                //if the native commands are used don't handle the keycode
                                if (Display.getInstance()
                                        .getCommandBehavior() != Display.COMMAND_BEHAVIOR_NATIVE) {
                                    Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_MENU);
                                    return true;
                                }
                            }
                            return super.onKeyDown(keyCode, event);
                        }

                        public boolean onKeyUp(int keyCode, KeyEvent event) {
                            switch (keyCode) {
                            case KeyEvent.KEYCODE_BACK:
                                Display.getInstance().keyReleased(AndroidImplementation.DROID_IMPL_KEY_BACK);
                                return true;
                            case KeyEvent.KEYCODE_MENU:
                                //if the native commands are used don't handle the keycode
                                if (Display.getInstance()
                                        .getCommandBehavior() != Display.COMMAND_BEHAVIOR_NATIVE) {
                                    Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_MENU);
                                    return true;
                                }
                            }
                            return super.onKeyUp(keyCode, event);
                        }
                    };
                    wv.setOnTouchListener(new View.OnTouchListener() {

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            switch (event.getAction()) {
                            case MotionEvent.ACTION_DOWN:
                            case MotionEvent.ACTION_UP:
                                if (!v.hasFocus()) {
                                    v.requestFocus();
                                }
                                break;
                            }
                            return false;
                        }
                    });
                    wv.getSettings().setDomStorageEnabled(true);
                    wv.requestFocus(View.FOCUS_DOWN);
                    wv.setFocusableInTouchMode(true);
                    bc[0] = new AndroidImplementation.AndroidBrowserComponent(wv, getActivity(), parent);
                    lock.notify();
                } catch (Throwable t) {
                    error[0] = t;
                    lock.notify();
                }
            }
        }
    });
    while (bc[0] == null && error[0] == null) {
        Display.getInstance().invokeAndBlock(new Runnable() {
            public void run() {
                synchronized (lock) {
                    if (bc[0] == null && error[0] == null) {
                        try {
                            lock.wait(20);
                        } catch (InterruptedException ex) {
                            ex.printStackTrace();
                        }
                    }
                }
            }

        });
    }
    if (error[0] != null) {
        throw new RuntimeException(error[0]);
    }
    return bc[0];
}