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.jecelyin.editor.v2.ui.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        if (mDrawerLayout != null) {
            if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
                mDrawerLayout.closeDrawer(Gravity.LEFT);
                return true;
            }// ww w  .j a v  a2s  . co  m
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
                return true;
            }
        }
        if ((System.currentTimeMillis() - mExitTime) > 2000) {
            UIUtils.toast(getContext(), R.string.press_again_will_exit);
            mExitTime = System.currentTimeMillis();
            return true;
        } else {
            return tabManager == null || tabManager.closeAllTabAndExitApp();
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.cw.litenote.main.MainAct.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //        System.out.println("MainAct / _onKeyDown / keyCode = " + keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS: //88
        if (TabsHost.audioUi_page != null)
            TabsHost.audioUi_page.audioPanel_previous_btn.performClick();
        return true;

    case KeyEvent.KEYCODE_MEDIA_NEXT: //87
        if (TabsHost.audioUi_page != null)
            TabsHost.audioUi_page.audioPanel_next_btn.performClick();

        return true;

    case KeyEvent.KEYCODE_MEDIA_PLAY: //126
        if (TabsHost.audioUi_page != null)
            TabsHost.audioUi_page.audioPanel_play_button.performClick();
        else//from  w w w.  j av  a  2  s .  co m
            playFirstAudio();
        return true;

    case KeyEvent.KEYCODE_MEDIA_PAUSE: //127
        if (TabsHost.audioUi_page != null)
            TabsHost.audioUi_page.audioPanel_play_button.performClick();
        return true;

    case KeyEvent.KEYCODE_BACK:
        onBackPressed();
        return true;

    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
        return true;

    case KeyEvent.KEYCODE_MEDIA_REWIND:
        return true;

    case KeyEvent.KEYCODE_MEDIA_STOP:
        return true;
    }
    return false;
}

From source file:com.fvd.nimbus.PaintActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_DOWN) {
            drawView.zoom(1.25f);//from   w  w  w.  ja  v a 2  s  .  com
        }
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            drawView.zoom(0.75f);
        }
        return true;
    case KeyEvent.KEYCODE_BACK:
        if (action == KeyEvent.ACTION_DOWN) {
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START);
                return true;
            } else if (findViewById(R.id.text_field).getVisibility() != View.GONE) {
                findViewById(R.id.text_field).setVisibility(View.GONE);
                drawView.hideCrop();
                drawView.startEdit();
                setSelectedFoot(0);
                return true;
            } else if (findViewById(R.id.color_menu).getVisibility() != View.GONE) {
                findViewById(R.id.color_menu).setVisibility(View.GONE);
                drawView.hideCrop();
                drawView.startEdit();
                setSelectedFoot(0);
                return true;
            } else if (findViewById(R.id.draw_tools).getVisibility() != View.GONE) {
                findViewById(R.id.draw_tools).setVisibility(View.GONE);
                drawView.hideCrop();
                drawView.startEdit();
                setSelectedFoot(0);
                return false;
            } else if (!drawView.hideCrop()) {
                if (!saved && storePath.length() == 0)
                    showDialog(0);
                else {
                    drawView.recycle();
                    finish();
                    return true;
                }
            } else {
                ((ImageButton) findViewById(R.id.bToolCrop)).setSelected(false);
                drawView.startEdit();
                setSelectedFoot(0);
                return true;
            }

        }
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java

public boolean onKeyDown(int keyCode, KeyEvent e) {
    long curTime = System.currentTimeMillis();
    // ?1/5//www  . j  a  v a  2  s.co m
    if ((curTime - keyTimeMillis) > LSystem.SECOND / 5) {
        keyTimeMillis = curTime;
        if (gameHandler != null) {
            synchronized (gameHandler) {
                if (!isBackLocked) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        LSystem.exit();
                        return true;
                    }
                }
                if (keyCode == KeyEvent.KEYCODE_MENU) {
                    return super.onKeyDown(keyCode, e);
                }
                if (gameHandler.onKeyDown(keyCode, e)) {
                    return true;
                }
                // ??Android???
                try {
                    Thread.sleep(16);
                } catch (Exception ex) {
                }
                return super.onKeyDown(keyCode, e);
            }
        }
    }
    return true;
}

From source file:com.data.pack.ViewVideo.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Log.d("CDA", "onKeyDown Called");
        //  onBackPressed();
    }/*from  w  w w  .ja  v  a  2  s.  com*/

    return false;// super.onKeyDown(keyCode, event);
}

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Log.i(AnkiDroidApp.TAG, "DeckOptions - onBackPressed()");
        closePreferences();/*  w w w .  ja v  a  2  s. c o  m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Timber.i("DeckOptions - onBackPressed()");
        closeWithResult();//from   w  w w  . ja  v  a 2  s  .  c om
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // if prev folders is empty, send the back button to the TabView activity.
        if (mPrevFolderIds.isEmpty()) {
            return false;
        }//from www.  j av a  2  s .co m

        loadFolder(mPrevFolderIds.pop());
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:net.bluecarrot.lite.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            if (webViewFacebook.canGoBack()) {
                webViewFacebook.goBack();
            } else {
                // exit
                finish();/*from  ww  w  .j a  v a  2s .  co  m*/
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.paic.zhifu.wallet.activity.modules.register.PhoneValidationActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        backBtnFunction();/*from ww  w  .  ja  va  2 s  . c om*/
    }
    return super.onKeyDown(keyCode, event);
}