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.cleverzone.zhizhi.capture.CaptureActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        if (source == IntentSource.NATIVE_APP_INTENT) {
            setResult(RESULT_CANCELED);/*from  ww  w. j a v a  2 s . c o m*/
            finish();
            return true;
        }
        if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
            restartPreviewAfterDelay(0L);
            return true;
        }
        break;
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
        // Handle these events so they don't launch the Camera app
        return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        cameraManager.setTorch(false);
        return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
        cameraManager.setTorch(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:cn.ttyhuo.activity.InfoOwnerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        if (isDoingUpdate) {
            Toast.makeText(this, "?,???", Toast.LENGTH_SHORT).show();
            return true;
        }/*w  ww  . j  a v a 2s .  com*/

        saveParams(false);
        if (!isChanged()) {
            return super.onKeyDown(keyCode, event);
        }
        if (!canUpdate) {
            return super.onKeyDown(keyCode, event);
        }

        DialogUtils.createNormalDialog(mContext, 0, mContext.getText(R.string.app_name).toString(),
                "??", "", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        new MyTask().execute(InfoOwnerActivity.this);
                    }
                }, "?", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        restore();
                    }
                }).show();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.kaku.weac.activities.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        if ((System.currentTimeMillis() - mExitTime) > 2000) {
            ToastUtil.showShortToast(this, getString(R.string.press_again_exit));
            mExitTime = System.currentTimeMillis();
        } else {/*ww  w  .java  2  s  .  co  m*/
            MobclickAgent.onKillProcess(this);
            finish();
            System.exit(0);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.jxlc.tajiproject.ui.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_UP) {
        finish();//from w  w  w.j  av a 2 s.  com
        return true;
    }

    if (event.getAction() == KeyEvent.ACTION_MULTIPLE) {
        return mUnityPlayer.injectEvent(event);
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.example.venkatagovardhan.docorganizer.FolderActivity.java

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    Log.d("Key Long Press", event.toString());
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        finish();//from  w  w  w .j  a v a  2  s  .c om
        return true;
    } else
        return super.onKeyLongPress(keyCode, event);
}

From source file:com.chuhan.privatecalc.fragment.os.FragmentActivity.java

/**
 * Take care of calling onBackPressed() for pre-Eclair platforms.
 *///from www  .  j a v  a  2  s .  c o m
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (android.os.Build.VERSION.SDK_INT < 5 /* ECLAIR */
            && keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Take care of calling this method on earlier versions of
        // the platform where it doesn't exist.
        onBackPressed();
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.lovejoy777sarootool.rootool.fragments.BrowserFragment.java

public boolean onBackPressed(int keycode) {
    if (keycode == KeyEvent.KEYCODE_BACK && mUseBackKey && !mCurrentPath.equals("/")) {
        File file = new File(mCurrentPath);
        navigateTo(file.getParent());/*from   ww  w  .ja va 2s . com*/

        // get position of the previous folder in ListView
        mListView.setSelection(mListAdapter.getPosition(file.getPath()));
        return true;
    } else if (keycode == KeyEvent.KEYCODE_BACK && mUseBackKey && mCurrentPath.equals("/")) {
        Toast.makeText(mActivity, getString(R.string.pressbackagaintoquit), Toast.LENGTH_SHORT).show();

        mUseBackKey = false;
        return false;
    } else if (keycode == KeyEvent.KEYCODE_BACK && !mUseBackKey && mCurrentPath.equals("/")) {
        mActivity.finish();
        return false;
    }

    return true;
}

From source file:aarddict.android.ArticleViewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        goBack();/*from  ww w.j a  v a 2  s  .  c  o m*/
        break;
    case NOOK_KEY_PREV_LEFT:
    case NOOK_KEY_PREV_RIGHT:
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!articleView.pageUp(false)) {
            goBack();
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case NOOK_KEY_NEXT_LEFT:
    case NOOK_KEY_NEXT_RIGHT:
        if (!articleView.pageDown(false)) {
            nextArticle();
        }
        ;
        break;
    default:
        return super.onKeyDown(keyCode, event);
    }
    return true;
}

From source file:com.example.health_connect.MySampleFragment5.java

public boolean onKey(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {

        int screen = fliper.getDisplayedChild();

        if (screen == VIEW_PIC_SCREEN) {
            Sliding.slideFromLeftToRight(LIST_PIC_SCREEN, fliper);
            return true;
        }//  w ww . ja  v a  2s  .  c o m
    }
    return false;

}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

/**
 * http://stackoverflow.com/questions/2257963/android-how-to-show-dialog-to-confirm-user-wishes-to-exit-activity
 *//*from www. j  av  a 2  s. c  o  m*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //Handle the back button
    if (mSettings.isConfirmQuitOrLogout() && keyCode == KeyEvent.KEYCODE_BACK && isTaskRoot()) {
        //Ask the user if they want to quit
        new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()))
                .setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.quit)
                .setMessage(R.string.really_quit)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //Stop the activity
                        finish();
                    }
                }).setNegativeButton(R.string.no, null).show();

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