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.android.tv.MainActivity.java

private boolean dispatchKeyEventToSession(final KeyEvent event) {
    if (SystemProperties.LOG_KEYEVENT.getValue()) {
        Log.d(TAG, "dispatchKeyEventToSession(" + event + ")");
    }//from  w w  w .  j  a va 2 s.c o m
    if (mPipEnabled && mChannelTuner.isCurrentChannelPassthrough()) {
        // If PIP is enabled, key events will be used by UI.
        return false;
    }
    boolean handled = false;
    if (mTvView != null) {
        handled = mTvView.dispatchKeyEvent(event);
    }
    if (isKeyEventBlocked()) {
        if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B)
                && mNeedShowBackKeyGuide) {
            // KeyEvent.KEYCODE_BUTTON_B is also used like the back button.
            Toast.makeText(this, R.string.msg_back_key_guide, Toast.LENGTH_SHORT).show();
            mNeedShowBackKeyGuide = false;
        }
        return true;
    }
    return handled;
}

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   w w  w  . j  ava  2 s.  c  om*/
    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:com.example.android.lightcontrol.MainActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        openOptionsDialog1();/*www  .  java  2  s .c  o m*/
    }
    return false;
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent msg) {
    try {/*from  ww  w . j a v  a 2  s.  com*/
        //         ViewGroup playlistContainer = (ViewGroup) findViewById(R.id.playlist_listview_container);

        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            if (this.containerLayout == null) {
                this.finish();
                return true;
            }
            if (this.songSearchContainer.getVisibility() == View.VISIBLE) {
                this.hideSongSearch();
                this.showMainUI();
                return true;
            }
            if (this.eventListViewContainer.getVisibility() == View.VISIBLE) {
                this.hideEventUI();
                this.showMainUI();
                return true;
            }
            //               if(this.songListContainer.getVisibility() == View.VISIBLE){
            //                  songCursor.moveToPosition(((SongCursorAdapter) songListView.getAdapter()).songInitialPosition);
            //                  this.hideSongListUI();
            //                  this.showMainUI();
            //                  return true;
            //               }
            //               if(playlistContainer.getVisibility() == View.VISIBLE){
            //                  this.hidePlaylistUI();
            //                  //this.showMainUI(); // done onAnimationEnd
            //                  return true;
            //               }
            if (this.helpView.getVisibility() == View.VISIBLE) {
                this.hideHelpUI();
                this.showMainUI();
                return true;
            }
            //            if(this.webView.getVisibility() == View.VISIBLE){
            //               this.hideWebUI();
            //               this.showMainUI();
            //               return true;
            //            }
            this.finish();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

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  a  va  2  s.  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];
}

From source file:com.glview.widget.AbsListView.java

/**
 * Sends a key to the text filter window
 *
 * @param keyCode The keycode for the event
 * @param event The actual key event/*from  w  ww.  jav  a  2 s  . c  om*/
 *
 * @return True if the text filter handled the event, false otherwise.
 */
boolean sendToTextFilter(int keyCode, int count, KeyEvent event) {
    if (!acceptFilter()) {
        return false;
    }

    boolean handled = false;
    boolean okToSend = true;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_BACK:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_SPACE:
        // Only send spaces once we are filtered
        okToSend = mFiltered;
        break;
    }

    if (okToSend) {

        KeyEvent forwardEvent = event;
        if (forwardEvent.getRepeatCount() > 0) {
            forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0);
        }

        int action = event.getAction();
        switch (action) {
        case KeyEvent.ACTION_DOWN:
            break;

        case KeyEvent.ACTION_UP:
            break;

        case KeyEvent.ACTION_MULTIPLE:
            break;
        }
    }
    return handled;
}

From source file:com.if3games.chessonline.DroidFish.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent e) {
    if (keyCode == KeyEvent.KEYCODE_BACK && mCurScreen == R.id.screen_game) {
        if (!isLeaveRoom && isMatch)
            showDialog(GAME_GMS_EXIT);//from   w  ww  .jav a 2  s  .c o  m
        return true;
    }
    return super.onKeyDown(keyCode, e);
}

From source file:com.appunite.list.AbsHorizontalListView.java

/**
 * Sends a key to the text filter window
 *
 * @param keyCode The keycode for the event
 * @param event The actual key event/*from w  w  w .  j av a 2 s.c om*/
 *
 * @return True if the text filter handled the event, false otherwise.
 */
boolean sendToTextFilter(int keyCode, int count, KeyEvent event) {
    if (!acceptFilter()) {
        return false;
    }

    boolean handled = false;
    boolean okToSend = true;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_BACK:
        if (mFiltered && mPopup != null && mPopup.isShowing()) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                KeyEvent.DispatcherState state = getKeyDispatcherState();
                if (state != null) {
                    state.startTracking(event, this);
                }
                handled = true;
            } else if (event.getAction() == KeyEvent.ACTION_UP && event.isTracking() && !event.isCanceled()) {
                handled = true;
                mTextFilter.setText("");
            }
        }
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_SPACE:
        // Only send spaces once we are filtered
        okToSend = mFiltered;
        break;
    }

    if (okToSend) {
        createTextFilter(true);

        KeyEvent forwardEvent = event;
        if (forwardEvent.getRepeatCount() > 0) {
            forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0);
        }

        int action = event.getAction();
        switch (action) {
        case KeyEvent.ACTION_DOWN:
            handled = mTextFilter.onKeyDown(keyCode, forwardEvent);
            break;

        case KeyEvent.ACTION_UP:
            handled = mTextFilter.onKeyUp(keyCode, forwardEvent);
            break;

        case KeyEvent.ACTION_MULTIPLE:
            handled = mTextFilter.onKeyMultiple(keyCode, count, event);
            break;
        }
    }
    return handled;
}