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:org.petero.droidfish.DroidFish.java

private final Dialog selectPgnSaveNewFileDialog() {
    setAutoMode(AutoMode.OFF);//  ww w . j  ava2s .  c o m
    View content = View.inflate(this, R.layout.create_pgn_file, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.select_pgn_file_save);
    final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_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, false);
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            savePGN.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final Dialog dialog = builder.create();
    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();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog selectMoveDialog() {
    View content = View.inflate(this, R.layout.select_move_number, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);/*from   w  w  w  .  j a  va2 s . c  o m*/
    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:com.android.launcher3.Launcher.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
                dumpState();//from  w ww.ja va2  s. co m
                return true;
            }
            break;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    boolean ret = false;
    if (KeyEvent.ACTION_DOWN == event.getAction()) {
        ret = onCustomKeyDown(event.getKeyCode(), event);
    }/*from   w w w  . j ava2s .  c o m*/
    if (!ret) {
        ret = super.dispatchKeyEvent(event);
    }
    return ret;
}

From source file:com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.java

/**
 * Clients can call this method to delegate handling of the volume. Clients should override
 * {@code dispatchEvent} and call this method:
 * <pre>// w w w.  ja v a 2  s  . c  o m
 public boolean dispatchKeyEvent(KeyEvent event) {
 if (mCastManager.onDispatchVolumeKeyEvent(event, VOLUME_DELTA)) {
    return true;
 }
 return super.dispatchKeyEvent(event);
 }
 * </pre>
 * @param event The dispatched event.
 * @param volumeDelta The amount by which volume should be increased or decreased in each step
 * @return <code>true</code> if volume is handled by the library, <code>false</code> otherwise.
 */
public boolean onDispatchVolumeKeyEvent(KeyEvent event, double volumeDelta) {
    if (isConnected()) {
        boolean isKeyDown = event.getAction() == KeyEvent.ACTION_DOWN;
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (changeVolume(volumeDelta, isKeyDown)) {
                return true;
            }
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (changeVolume(-volumeDelta, isKeyDown)) {
                return true;
            }
            break;
        }
    }
    return false;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog selectPgnSaveNewFileDialog() {
    View content = View.inflate(this, R.layout.create_pgn_file, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);//from  w  w  w  .  j a v a2  s  .  c  om
    builder.setTitle(R.string.select_pgn_file_save);
    final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_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, false);
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            savePGN.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final Dialog dialog = builder.create();
    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();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:cn.androidy.materialdesignsample.ryanharterviewpager.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 w  w  . j  a  v a  2s. 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:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_UP);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_DOWN);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:com.guide.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   www .jav a  2 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:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_UP);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_DOWN);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and
                // FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:android.improving.utils.views.cardsview.OrientedViewPager.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./*  w w  w  . j a  va 2 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 (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.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 ww  w.j a v  a2 s  .c  o m
private void selectAndCopyText() {
    try {
        KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
        if (mCurrentSimpleInterface) {
            shiftPressEvent.dispatch(mSimpleCard);
        } else {
            shiftPressEvent.dispatch(mCard);
        }
        shiftPressEvent.isShiftPressed();
        mIsSelecting = true;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}