Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

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

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

From source file:com.igniva.filemanager.activities.MainActivity.java

void initialiseViews() {
    appBarLayout = (AppBarLayout) findViewById(R.id.lin);

    if (!ImageLoader.getInstance().isInited()) {

        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
    }/*  w ww  . j a v  a  2s  .  c o m*/
    displayImageOptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.amaze_header)
            .showImageForEmptyUri(R.drawable.amaze_header).showImageOnFail(R.drawable.amaze_header)
            .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565)
            .build();

    mScreenLayout = (CoordinatorLayout) findViewById(R.id.main_frame);
    buttonBarFrame = (FrameLayout) findViewById(R.id.buttonbarframe);

    //buttonBarFrame.setBackgroundColor(Color.parseColor(currentTab==1 ? skinTwo : skin));
    drawerHeaderLayout = getLayoutInflater().inflate(R.layout.drawerheader, null);
    drawerHeaderParent = (RelativeLayout) drawerHeaderLayout.findViewById(R.id.drawer_header_parent);
    drawerHeaderView = (View) drawerHeaderLayout.findViewById(R.id.drawer_header);
    mFabBackground = findViewById(R.id.fab_bg);
    drawerHeaderView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Intent intent;
            if (Build.VERSION.SDK_INT < 19) {
                intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
            } else {
                intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

            }
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(intent, image_selector_request_code);
            return false;
        }
    });
    drawerProfilePic = (RoundedImageView) drawerHeaderLayout.findViewById(R.id.profile_pic);
    mGoogleName = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_name);
    mGoogleId = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_email);
    toolbar = (Toolbar) findViewById(R.id.action_bar);
    /* For SearchView, see onCreateOptionsMenu(Menu menu)*/
    TOOLBAR_START_INSET = toolbar.getContentInsetStart();
    setSupportActionBar(toolbar);
    frameLayout = (FrameLayout) findViewById(R.id.content_frame);
    indicator_layout = findViewById(R.id.indicator_layout);
    mDrawerLinear = (ScrimInsetsRelativeLayout) findViewById(R.id.left_drawer);
    if (theme1 == 1)
        mDrawerLinear.setBackgroundColor(Color.parseColor("#303030"));
    else
        mDrawerLinear.setBackgroundColor(Color.WHITE);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    mDrawerList = (ListView) findViewById(R.id.menu_drawer);
    drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
    //drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    if (findViewById(R.id.tab_frame) != null) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerLinear);
        mDrawerLayout.openDrawer(mDrawerLinear);
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        isDrawerLocked = true;
    } else if (findViewById(R.id.tab_frame) == null) {

        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLinear);
        mDrawerLayout.closeDrawer(mDrawerLinear);
        isDrawerLocked = false;
    }
    mDrawerList.addHeaderView(drawerHeaderLayout);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    View v = findViewById(R.id.fab_bg);
    /*if (theme1 != 1)
    v.setBackgroundColor(Color.parseColor("#a6ffffff"));*/
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            floatingActionButton.close(true);
            utils.revealShow(view, false);
            if (isSearchViewEnabled)
                hideSearchView();
        }
    });

    pathbar = (LinearLayout) findViewById(R.id.pathbar);
    buttons = (LinearLayout) findViewById(R.id.buttons);
    scroll = (HorizontalScrollView) findViewById(R.id.scroll);
    scroll1 = (HorizontalScrollView) findViewById(R.id.scroll1);
    scroll.setSmoothScrollingEnabled(true);
    scroll1.setSmoothScrollingEnabled(true);
    ImageView divider = (ImageView) findViewById(R.id.divider1);
    if (theme1 == 0)
        divider.setImageResource(R.color.divider);
    else
        divider.setImageResource(R.color.divider_dark);

    setDrawerHeaderBackground();
    View settingsbutton = findViewById(R.id.settingsbutton);
    if (theme1 == 1) {
        settingsbutton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) settingsbutton.findViewById(R.id.settingicon))
                .setImageResource(R.drawable.ic_settings_white_48dp);
        ((TextView) settingsbutton.findViewById(R.id.settingtext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    settingsbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(MainActivity.this, Preferences.class);
            finish();
            final int enter_anim = android.R.anim.fade_in;
            final int exit_anim = android.R.anim.fade_out;
            Activity s = MainActivity.this;
            s.overridePendingTransition(exit_anim, enter_anim);
            s.finish();
            s.overridePendingTransition(enter_anim, exit_anim);
            s.startActivity(in);
        }

    });
    View appbutton = findViewById(R.id.appbutton);
    if (theme1 == 1) {
        appbutton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) appbutton.findViewById(R.id.appicon)).setImageResource(R.drawable.ic_doc_apk_white);
        ((TextView) appbutton.findViewById(R.id.apptext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    appbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new AppsList());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            select = -2;
            adapter.toggleChecked(false);
        }
    });

    View ftpButton = findViewById(R.id.ftpbutton);
    if (theme1 == 1) {
        ftpButton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) ftpButton.findViewById(R.id.ftpicon)).setImageResource(R.drawable.ic_ftp_dark);
        ((TextView) ftpButton.findViewById(R.id.ftptext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    ftpButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new FTPServerFragment());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            select = -2;
            adapter.toggleChecked(false);
        }
    });
    //getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor((currentTab==1 ? skinTwo : skin))));

    // status bar0
    sdk = Build.VERSION.SDK_INT;

    if (sdk == 20 || sdk == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        //tintManager.setStatusBarTintColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.drawer_layout)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        if (!isDrawerLocked)
            p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {

        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (isDrawerLocked) {
            window.setStatusBarColor((skinStatusBar));
        } else
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (colourednavigation)
            window.setNavigationBarColor(skinStatusBar);
    }

    searchViewLayout = (RelativeLayout) findViewById(R.id.search_view);
    searchViewEditText = (AppCompatEditText) findViewById(R.id.search_edit_text);
    ImageView clear = (ImageView) findViewById(R.id.search_close_btn);
    clear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchViewEditText.setText("");
        }
    });
    findViewById(R.id.img_view_back).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideSearchView();
        }
    });
    searchViewEditText.setOnKeyListener(new TextView.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN)) {
                // Perform action on key press
                mainActivityHelper.search(searchViewEditText.getText().toString());
                hideSearchView();
                return true;
            }
            return false;
        }
    });

    //    searchViewEditText.setTextColor(getResources().getColor(android.R.color.black));
    //     searchViewEditText.setHintTextColor(Color.parseColor(BaseActivity.accentSkin));
}

From source file:com.zhongsou.souyue.ui.HListView.java

@TargetApi(11)
private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }//from  ww w  .j  av  a  2s.  co  m

    if (mDataChanged) {
        layoutChildren();
    }

    if (android.os.Build.VERSION.SDK_INT < 11) {
        return false;
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_UP)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_DOWN)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:

            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            }
            handled = true;
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            break;
        }
    }

    if (handled) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);

    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);

    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);

    default: // shouldn't happen
        return false;
    }
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

/**
 * Select Text in the webview and automatically sends the selected text to the clipboard. From
 * http://cosmez.blogspot.com/2010/04/webview-emulateshiftheld-on-android.html
 *//*from  w w w. jav  a  2 s.c  o m*/
private void selectAndCopyText() {
    try {
        KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
        shiftPressEvent.dispatch(mCard);
        shiftPressEvent.isShiftPressed();
        mIsSelecting = true;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}

From source file:org.petero.droidfish.DroidFish.java

private final Dialog selectMoveDialog() {
    setAutoMode(AutoMode.OFF);//from   ww w  .ja v a 2s  .  com
    View content = View.inflate(this, R.layout.select_move_number, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.goto_move);
    final EditText moveNrView = (EditText) content.findViewById(R.id.selmove_number);
    moveNrView.setText("1");
    final Runnable gotoMove = new Runnable() {
        public void run() {
            try {
                int moveNr = Integer.parseInt(moveNrView.getText().toString());
                ctrl.gotoMove(moveNr);
            } catch (NumberFormatException nfe) {
                Toast.makeText(getApplicationContext(), R.string.invalid_number_format, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            gotoMove.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final AlertDialog dialog = builder.create();

    moveNrView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                gotoMove.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:study.tdcc.act.MainCalendar.java

/**
 * ??/*from w w w  . j av  a  2  s.  co  m*/
 *
 * @param kEvent  
 * @return ?????true
 */
@Override
public boolean dispatchKeyEvent(KeyEvent kEvent) {
    Log.d("DEBUG", "MainCalendar dispatchKeyEvent Start");
    //?????
    if (kEvent.getAction() == KeyEvent.ACTION_DOWN) {
        //?????
        if (kEvent.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            //?yes/no?
            showYesNoDialog(this, R.string.mes1_dialog, R.string.mes2_dialog,
                    new DialogInterface.OnClickListener() {
                        //??
                        public void onClick(DialogInterface dialog, int whith) {
                            if (whith == DialogInterface.BUTTON_POSITIVE) {
                                //
                                endActivity();
                            } else if (whith == DialogInterface.BUTTON_NEGATIVE) {
                                //
                                return;
                            }
                        }
                    });
        }
    }
    Log.d("DEBUG", "MainCalendar dispatchKeyEvent End");
    return super.dispatchKeyEvent(kEvent);
}

From source file:org.mdc.chess.MDChess.java

private void selectPgnSaveNewFileDialog() {
    setAutoMode(AutoMode.OFF);//w  w w .  j a  v a2  s  .co  m
    View content = View.inflate(this, R.layout.create_pgn_file, null);

    final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_filename);
    final TextInputLayout fileNameWrapper = (TextInputLayout) content
            .findViewById(R.id.create_pgn_filename_wrapper);
    fileNameWrapper.setHint(content.getResources().getString(R.string.filename));
    fileNameView.setText("");
    final Runnable savePGN = new Runnable() {
        public void run() {
            String pgnFile = fileNameView.getText().toString();
            if ((pgnFile.length() > 0) && !pgnFile.contains(".")) {
                pgnFile += ".pgn";
            }
            String sep = File.separator;
            String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile;
            savePGNToFile(pathName);
        }
    };

    new MaterialDialog.Builder(this).title(R.string.select_pgn_file_save).customView(content, true)
            .positiveText(android.R.string.ok).negativeText(R.string.cancel)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    savePGN.run();
                }
            }).onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

                }
            }).show();

    fileNameView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                savePGN.run();
                return true;
            }
            return false;
        }
    });
}

From source file:processing.core.PApplet.java

protected void handleKeyEvent(KeyEvent event) {
    // event.isPrintingKey() returns false for whitespace and others,
    // which is a problem if the space bar or tab key are used.
    key = (char) event.getUnicodeChar();
    // if not mappable to a unicode character, instead mark as coded key
    if (key == 0 || key == 0xFFFF) {
        // System.out.println("  key is coded");
        key = CODED;/*from   w  ww. jav a 2 s  .  co m*/
        // } else {
        // System.out.println("  key is unicode");
    }

    keyCode = event.getKeyCode();
    // println(key + " " + keyCode);

    int action = event.getAction();
    if (action == KeyEvent.ACTION_DOWN) {
        keyPressed = true;
        keyPressed();
    } else if (action == KeyEvent.ACTION_UP) {
        keyPressed = false;
        keyReleased();
    }

    // if someone else wants to intercept the key, they should
    // set key to zero (or something besides the "ESC").
    // println(event);
    /*
    if (action == KeyEvent.ACTION_DOWN) {        
       if (keyCode == KeyEvent.KEYCODE_BACK) {
    // println("KEYCODE_BACK, calling exit()");
    Preferences.saveRestart(getActivity(), true);
    exit();
    System.exit(0);
       }
    }
    */
    // When running tethered to the Processing application, respond to
    // Ctrl-W (or Cmd-W) events by closing the sketch. Disable this behavior
    // when running independently, because this sketch may be one component
    // embedded inside an application that has its own close behavior.
    // if (external &&
    // event.getModifiers() == MENU_SHORTCUT &&
    // event.getKeyCode() == 'W') {
    // exit();
    // }
    // }
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

@TargetApi(11)
private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }//from   w w w . ja  v  a2 s .  c o  m

    if (mDataChanged) {
        layoutChildren();
    }

    if (android.os.Build.VERSION.SDK_INT < 11) {
        return false;
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_UP)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_DOWN)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:

            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            }
            handled = true;
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            break;
        }
    }

    if (handled) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);

    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);

    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);

    default: // shouldn't happen
        return false;
    }
}

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();/*from w  w  w  .j  a  va 2  s .c o m*/
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.android.internal.widget.ViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//from w ww  .j  ava2  s. c o m
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (event.hasNoModifiers()) {
                handled = arrowScroll(FOCUS_FORWARD);
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                handled = arrowScroll(FOCUS_BACKWARD);
            }
            break;
        }
    }
    return handled;
}