Example usage for android.view KeyEvent KEYCODE_BACK

List of usage examples for android.view KeyEvent KEYCODE_BACK

Introduction

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

Prototype

int KEYCODE_BACK

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

Click Source Link

Document

Key code constant: Back key.

Usage

From source file:com.muzima.view.forms.HTMLFormWebViewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        showAlertDialog();// ww w .j  a v  a 2 s. com
        return false;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.hichinaschool.flashcards.anki.CramDeckOptions.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Log.i(AnkiDroidApp.TAG, "DeckOptions - onBackPressed()");
        finish();/*  ww  w . j  a v  a  2s  .c  om*/
        if (AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:android.support.v17.leanback.app.PlaybackSupportFragment.java

private boolean onInterceptInputEvent(InputEvent event) {
    final boolean controlsHidden = !mControlVisible;
    if (DEBUG)//from   w  w  w.ja va  2s.c  o m
        Log.v(TAG, "onInterceptInputEvent hidden " + controlsHidden + " " + event);
    boolean consumeEvent = false;
    int keyCode = KeyEvent.KEYCODE_UNKNOWN;
    int keyAction = 0;

    if (event instanceof KeyEvent) {
        keyCode = ((KeyEvent) event).getKeyCode();
        keyAction = ((KeyEvent) event).getAction();
        if (mInputEventHandler != null) {
            consumeEvent = mInputEventHandler.onKey(getView(), keyCode, (KeyEvent) event);
        }
    }

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        // Event may be consumed; regardless, if controls are hidden then these keys will
        // bring up the controls.
        if (controlsHidden) {
            consumeEvent = true;
        }
        if (keyAction == KeyEvent.ACTION_DOWN) {
            tickle();
        }
        break;
    case KeyEvent.KEYCODE_BACK:
    case KeyEvent.KEYCODE_ESCAPE:
        if (mInSeek) {
            // when in seek, the SeekUi will handle the BACK.
            return false;
        }
        // If controls are not hidden, back will be consumed to fade
        // them out (even if the key was consumed by the handler).
        if (!controlsHidden) {
            consumeEvent = true;

            if (((KeyEvent) event).getAction() == KeyEvent.ACTION_UP) {
                hideControlsOverlay(true);
            }
        }
        break;
    default:
        if (consumeEvent) {
            if (keyAction == KeyEvent.ACTION_DOWN) {
                tickle();
            }
        }
    }
    return consumeEvent;
}

From source file:net.evecom.android.web.Web0Activity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        // webView.goBack();
        if (dialog != null)
            dialog.dismiss();//from   w w w  . j av  a 2  s.  co m
        // finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.hxqc.mall.thirdshop.views.CustomScrollView.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 a va  2s . com*/
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    mTempRect.setEmpty();

    if (!canScroll()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this)
                currentFocused = null;
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN);
        }
        return false;
    }

    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_UP);
            } else {
                handled = fullScroll(View.FOCUS_UP);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_DOWN);
            } else {
                handled = fullScroll(View.FOCUS_DOWN);
            }
            break;
        case KeyEvent.KEYCODE_SPACE:
            pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
            break;
        default:
            break;
        }
    }

    return handled;
}

From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java

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

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (recording) {
            stopRecording();/*from www  . j  a v  a2 s  .com*/
        }

        finish();

        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.battlelancer.seriesguide.ui.ShowsActivity.java

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    // prevent navigating to top activity as this is the top activity
    return keyCode == KeyEvent.KEYCODE_BACK;
}

From source file:com.googlecode.android_scripting.activity.ScriptManager.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (mInSearchResultMode) {
            mInSearchResultMode = false;
            mAdapter.notifyDataSetInvalidated();
            return true;
        }/*from w  ww  .  j  a  v  a 2 s.  c  o  m*/
        if (!mCurrentDir.equals(mBaseDir)) {// 
            mCurrent = mCurrent.getParentFile();
            mCurrentDir = mCurrent;
            mAdapter.notifyDataSetInvalidated();
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.ichi2.anki2.CardBrowser.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Log.i(AnkiDroidApp.TAG, "CardBrowser - onBackPressed()");
        if (mSearchEditText.getText().length() == 0) {
            closeCardBrowser(Activity.RESULT_OK);
        } else {/*  www  . j a  va  2  s  . c  o m*/
            mSearchEditText.setText("");
            mSearchEditText.setHint(R.string.downloaddeck_search);
            mSelectedTags.clear();
        }
        return true;
    }

    return super.onKeyDown(keyCode, event);
}