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:edu.berkeley.boinc.BOINCActivity.java

public final boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) {
            this.mDrawerLayout.closeDrawer(this.mDrawerList);
        } else {/*from ww  w  . ja  v  a  2s . c  om*/
            this.mDrawerLayout.openDrawer(this.mDrawerList);
        }
        return true;
    }
    return super.onKeyDown(keyCode, keyEvent);
}

From source file:com.ruesga.rview.SearchActivity.java

@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
    switch (keycode) {
    case KeyEvent.KEYCODE_MENU:
        mBinding.searchView.openMenu(true);
        return true;
    }//  w  w w  .ja v a2s . co  m

    return super.onKeyDown(keycode, e);
}

From source file:de.wikilab.android.friendica01.activity.HomeActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        toggleMenuBarVisible();/*from   ww  w.  ja  v a2 s .c o  m*/
        return false;
    } else {
        return super.onKeyUp(keyCode, event);
    }
}

From source file:com.ruesga.rview.BaseActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU:
        if (getContentBinding().drawerLayout != null && getContentBinding().drawerLayout
                .getDrawerLockMode(GravityCompat.START) != DrawerLayout.LOCK_MODE_LOCKED_CLOSED) {
            if (getContentBinding().drawerLayout.isDrawerOpen(GravityCompat.START)) {
                getContentBinding().drawerLayout.closeDrawer(GravityCompat.START);
            } else {
                getContentBinding().drawerLayout.openDrawer(GravityCompat.START);
            }/*  ww w . j av  a 2  s .c  om*/
            return true;
        } else if (getOptionsMenu() != null && getOptionsMenu().getMenu() != null
                && getOptionsMenu().getMenu().size() > 0) {
            if (getContentBinding().drawerLayout.isDrawerOpen(GravityCompat.END)) {
                closeOptionsDrawer();
            } else {
                openOptionsDrawer();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (DEBUG)//from   w  w  w .j a v  a  2 s .  c om
        Log.d(TAG, "[dispatchKeyEvent] event: " + event);

    final int keyCode = event.getKeyCode();

    // Not handled by the view hierarchy, does the action bar want it
    // to cancel out of something special?
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        final int action = event.getAction();
        // Back cancels action modes first.
        if (mActionMode != null) {
            if (action == KeyEvent.ACTION_UP) {
                mActionMode.finish();
            }
            if (DEBUG)
                Log.d(TAG, "[dispatchKeyEvent] returning true");
            return true;
        }

        // Next collapse any expanded action views.
        if (wActionBar != null && wActionBar.hasExpandedActionView()) {
            if (action == KeyEvent.ACTION_UP) {
                wActionBar.collapseActionView();
            }
            if (DEBUG)
                Log.d(TAG, "[dispatchKeyEvent] returning true");
            return true;
        }
    }

    boolean result = false;
    if (keyCode == KeyEvent.KEYCODE_MENU && isReservingOverflow()) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()) {
            mMenuKeyIsLongPress = true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            if (!mMenuKeyIsLongPress) {
                if (mActionMode == null && wActionBar != null) {
                    if (wActionBar.isOverflowMenuShowing()) {
                        wActionBar.hideOverflowMenu();
                    } else {
                        wActionBar.showOverflowMenu();
                    }
                }
                result = true;
            }
            mMenuKeyIsLongPress = false;
        }
    }

    if (DEBUG)
        Log.d(TAG, "[dispatchKeyEvent] returning " + result);
    return result;
}

From source file:paulscode.android.mupen64plusae.persistent.GlobalPrefs.java

/**
 * Instantiates a new user preferences wrapper.
 *
 * @param context//www  . j  av a 2 s.  co  m
 *            The application context.
 */
public GlobalPrefs(Context context, AppData appData) {
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);

    // Locale
    mLocaleCode = mPreferences.getString(KEY_LOCALE_OVERRIDE, DEFAULT_LOCALE_OVERRIDE);
    mLocale = TextUtils.isEmpty(mLocaleCode) ? Locale.getDefault() : createLocale(mLocaleCode);
    final Locale[] availableLocales = Locale.getAvailableLocales();
    String[] values = context.getResources().getStringArray(R.array.localeOverride_values);
    String[] entries = new String[values.length];
    for (int i = values.length - 1; i > 0; i--) {
        final Locale locale = createLocale(values[i]);

        // Get intersection of languages (available on device) and (translated for Mupen)
        if (ArrayUtils.contains(availableLocales, locale)) {
            // Get the name of the language, as written natively
            entries[i] = WordUtils.capitalize(locale.getDisplayName(locale));
        } else {
            // Remove the item from the list
            entries = (String[]) ArrayUtils.remove(entries, i);
            values = (String[]) ArrayUtils.remove(values, i);
        }
    }
    entries[0] = context.getString(R.string.localeOverride_entrySystemDefault);
    mLocaleNames = entries;
    mLocaleCodes = values;

    // Files
    userDataDir = mPreferences.getString("pathGameSaves", "");
    galleryCacheDir = userDataDir + "/GalleryCache";
    coverArtDir = galleryCacheDir + "/CoverArt";
    unzippedRomsDir = galleryCacheDir + "/UnzippedRoms";
    profilesDir = userDataDir + "/Profiles";
    crashLogDir = userDataDir + "/CrashLogs";
    coreUserDataDir = userDataDir + "/CoreConfig/UserData";
    coreUserCacheDir = userDataDir + "/CoreConfig/UserCache";
    hiResTextureDir = coreUserDataDir + "/mupen64plus/hires_texture/"; // MUST match what rice assumes natively
    textureCacheDir = coreUserCacheDir + "/mupen64plus/cache";
    romInfoCache_cfg = galleryCacheDir + "/romInfoCache.cfg";
    controllerProfiles_cfg = profilesDir + "/controller.cfg";
    touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg";
    emulationProfiles_cfg = profilesDir + "/emulation.cfg";
    customCheats_txt = profilesDir + "/customCheats.txt";
    touchscreenCustomSkinsDir = userDataDir + "/CustomSkins";
    legacyAutoSaves = userDataDir + "/AutoSaves";
    legacySlotSaves = userDataDir + "/SlotSaves";

    // Plug-ins
    audioPlugin = new Plugin(mPreferences, appData.libsDir, "audioPlugin");

    // Library prefs
    isRecentShown = mPreferences.getBoolean("showRecentlyPlayed", true);
    isFullNameShown = mPreferences.getBoolean("showFullNames", true);

    // Touchscreen prefs
    isTouchscreenFeedbackEnabled = mPreferences.getBoolean("touchscreenFeedback", false);
    touchscreenScale = (mPreferences.getInt("touchscreenScale", 100)) / 100.0f;
    touchscreenTransparency = (255 * mPreferences.getInt("touchscreenTransparency", 100)) / 100;
    touchscreenAutoHold = getSafeInt(mPreferences, "touchscreenAutoHold", 0);

    // Video prefs
    displayOrientation = getSafeInt(mPreferences, "displayOrientation", 0);
    displayPosition = getSafeInt(mPreferences, "displayPosition", Gravity.CENTER_VERTICAL);
    final int transparencyPercent = mPreferences.getInt("displayActionBarTransparency", 50);
    displayActionBarTransparency = (255 * transparencyPercent) / 100;
    isFpsEnabled = mPreferences.getBoolean("displayFps", false);
    final int selectedHardwareType = getSafeInt(mPreferences, "videoHardwareType", -1);
    isPolygonOffsetHackEnabled = selectedHardwareType > -2;
    videoHardwareType = selectedHardwareType < 0 ? appData.hardwareInfo.hardwareType : selectedHardwareType;
    switch (videoHardwareType) {
    case HardwareInfo.HARDWARE_TYPE_OMAP:
        videoPolygonOffset = 0.2f;
        break;
    case HardwareInfo.HARDWARE_TYPE_OMAP_2:
        videoPolygonOffset = -1.5f;
        break;
    case HardwareInfo.HARDWARE_TYPE_QUALCOMM:
        videoPolygonOffset = -0.2f;
        break;
    case HardwareInfo.HARDWARE_TYPE_IMAP:
        videoPolygonOffset = -0.001f;
        break;
    case HardwareInfo.HARDWARE_TYPE_TEGRA:
        videoPolygonOffset = -2.0f;
        break;
    case HardwareInfo.HARDWARE_TYPE_UNKNOWN:
        videoPolygonOffset = -1.5f;
        break;
    default:
        videoPolygonOffset = SafeMethods.toFloat(mPreferences.getString("videoPolygonOffset", "-1.5"), -1.5f);
        break;
    }
    isImmersiveModeEnabled = mPreferences.getBoolean("displayImmersiveMode", false);

    // Audio prefs
    audioSwapChannels = mPreferences.getBoolean("audioSwapChannels", false);
    audioSDLSecondaryBufferSize = getSafeInt(mPreferences, "audioSDLBufferSize", 2048);
    audioSLESSecondaryBufferSize = getSafeInt(mPreferences, "audioSLESBufferSize2", 256);
    audioSLESSecondaryBufferNbr = getSafeInt(mPreferences, "audioSLESBufferNbr2", 20);
    audioSLESSamplingRate = getSafeInt(mPreferences, "audioSLESSamplingRate", 0);

    if (audioPlugin.enabled)
        isFramelimiterEnabled = !mPreferences.getBoolean("audioSynchronize", true);
    else
        isFramelimiterEnabled = !mPreferences.getString("audioPlugin", "").equals("nospeedlimit");

    // User interface modes
    final String navMode = mPreferences.getString("navigationMode", "auto");
    if (navMode.equals("bigscreen"))
        isBigScreenMode = true;
    else if (navMode.equals("standard"))
        isBigScreenMode = false;
    else
        isBigScreenMode = AppData.IS_OUYA_HARDWARE || appData.isAndroidTv; // TODO: Add other systems as they enter market

    // Peripheral share mode
    isControllerShared = mPreferences.getBoolean("inputShareController", false);

    maxAutoSaves = mPreferences.getInt("gameAutoSaves", 5);

    // Determine the key codes that should not be mapped to controls
    final boolean volKeysMappable = mPreferences.getBoolean("inputVolumeMappable", false);
    final List<Integer> unmappables = new ArrayList<>();
    unmappables.add(KeyEvent.KEYCODE_MENU);

    // Back key is needed to show/hide the action bar in HC+
    unmappables.add(KeyEvent.KEYCODE_BACK);

    if (!volKeysMappable) {
        unmappables.add(KeyEvent.KEYCODE_VOLUME_UP);
        unmappables.add(KeyEvent.KEYCODE_VOLUME_DOWN);
        unmappables.add(KeyEvent.KEYCODE_VOLUME_MUTE);
    }
    unmappableKeyCodes = Collections.unmodifiableList(unmappables);

    // Controller profiles
    controllerProfile1 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE1,
            getControllerProfileDefault(1), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());
    controllerProfile2 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE2,
            getControllerProfileDefault(2), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());
    controllerProfile3 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE3,
            getControllerProfileDefault(3), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());
    controllerProfile4 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE4,
            getControllerProfileDefault(4), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());

    // Player map
    playerMap = new PlayerMap(mPreferences.getString(GamePrefs.PLAYER_MAP, ""));

    // Determine whether controller deconfliction is needed
    int numControllers = 0;
    numControllers += controllerProfile1 != null ? 1 : 0;
    numControllers += controllerProfile2 != null ? 1 : 0;
    numControllers += controllerProfile3 != null ? 1 : 0;
    numControllers += controllerProfile4 != null ? 1 : 0;

    playerMap.setEnabled(numControllers > 1 && !isControllerShared);
}

From source file:org.mariotaku.twidere.activity.support.HomeActivity.java

/**
 * Called when the context is first created.
 *///from w  w w.  j a va2s . co m
@Override
protected void onCreate(final Bundle savedInstanceState) {
    final Window window = getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    super.onCreate(savedInstanceState);
    if (!isDatabaseReady(this)) {
        Toast.makeText(this, R.string.preparing_database_toast, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mTwitterWrapper = getTwitterWrapper();
    final TwidereApplication app = TwidereApplication.getInstance(this);
    mReadStateManager = app.getReadStateManager();
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mMultiSelectHandler = new MultiSelectEventHandler(this);
    mMultiSelectHandler.dispatchOnCreate();
    //        if (!Utils.hasAccount(this)) {
    //            final Intent signInIntent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
    //            signInIntent.setClass(this, SignInActivity.class);
    //            startActivity(signInIntent);
    //            finish();
    //            return;
    //        } else {
    //            notifyAccountsChanged();
    //        }
    final Intent intent = getIntent();
    if (openSettingsWizard()) {
        finish();
        return;
    }
    setContentView(R.layout.activity_home);
    setSupportActionBar(mActionBar);
    sendBroadcast(new Intent(BROADCAST_HOME_ACTIVITY_ONCREATE));
    final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
    int tabDisplayOptionInt = getTabDisplayOptionInt(this);

    mTabColumns = getResources().getInteger(R.integer.default_tab_columns);

    mColorStatusFrameLayout.setOnFitSystemWindowsListener(this);
    mPagerAdapter = new SupportTabsAdapter(this, getSupportFragmentManager(), mTabIndicator, mTabColumns);
    mViewPager.setAdapter(mPagerAdapter);
    //        mViewPager.setOffscreenPageLimit(3);
    mTabIndicator.setViewPager(mViewPager);
    mTabIndicator.setOnPageChangeListener(this);
    mTabIndicator.setColumns(mTabColumns);
    if (tabDisplayOptionInt == 0) {
        tabDisplayOptionInt = TabPagerIndicator.ICON;
    }
    mTabIndicator.setTabDisplayOption(tabDisplayOptionInt);
    mTabIndicator.setTabExpandEnabled((tabDisplayOptionInt & TabPagerIndicator.LABEL) == 0);
    mTabIndicator.setDisplayBadge(mPreferences.getBoolean(KEY_UNREAD_COUNT, true));
    mTabIndicator.updateAppearance();

    mActionsButton.setOnClickListener(this);
    mActionsButton.setOnLongClickListener(this);
    mEmptyTabHint.setOnClickListener(this);

    ThemeUtils.setCompatContentViewOverlay(this, new EmptyDrawable());
    ViewCompat.setElevation(mActionBarContainer, ThemeUtils.getSupportActionBarElevation(this));
    ViewSupport.setOutlineProvider(mActionBarContainer, ViewOutlineProviderCompat.BACKGROUND);
    final View windowOverlay = findViewById(R.id.window_overlay);
    ViewSupport.setBackground(windowOverlay,
            ThemeUtils.getNormalWindowContentOverlay(this, getCurrentThemeResourceId()));

    setupSlidingMenu();
    setupBars();
    showDataProfilingRequest();
    initUnreadCount();
    updateActionsButton();
    updateSlidingMenuTouchMode();
    getDelegate().setKeyListener(new ThemedAppCompatDelegateFactory.KeyListener() {
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            return false;
        }

        @Override
        public boolean onKeyUp(int keyCode, KeyEvent event) {
            // Steal MENU key event
            switch (keyCode) {
            case KeyEvent.KEYCODE_MENU: {
                if (mSlidingMenu != null) {
                    mSlidingMenu.toggle(true);
                    return true;
                }
                break;
            }
            }
            return false;
        }
    });

    if (savedInstanceState == null) {
        if (refreshOnStart) {
            mTwitterWrapper.refreshAll(getActivatedAccountIds());
        }
        if (intent.getBooleanExtra(EXTRA_OPEN_ACCOUNTS_DRAWER, false)) {
            openAccountsDrawer();
        }
    }
    setupHomeTabs();

    final int initialTabPosition = handleIntent(intent, savedInstanceState == null);
    setTabPosition(initialTabPosition);

    startService(new Intent(this, StreamingService.class));
}

From source file:com.breadwallet.presenter.activities.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (BRAnimator.level > 1 || BRAnimator.scanResultFragmentOn || BRAnimator.decoderFragmentOn) {
            this.onBackPressed();
        } else if (BRAnimator.checkTheMultipressingAvailability()) {
            BRAnimator.pressMenuButton(app);
        }/*from www . j ava  2 s.co  m*/
    }
    // let the system handle all other key events
    return super.onKeyDown(keyCode, event);
}

From source file:org.getlantern.firetweet.activity.support.HomeActivity.java

@Override
public boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU: {
        if (mSlidingMenu != null) {
            mSlidingMenu.toggle(true);//from  www .  ja  va 2  s. c  om
            return true;
        }
        break;
    }
    default: {
        if (mHotKeyHandler.handleKey(keyCode, event))
            return true;
    }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:augsburg.se.alltagsguide.overview.OverviewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (drawerLayout.isDrawerOpen(navigationView)) {
            drawerLayout.closeDrawers();
        } else {// ww  w.  j av  a2  s  .c  om
            drawerLayout.openDrawer(navigationView);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}