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:co.taqat.call.CallIncomingActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (LinphoneManager.isInstanciated()
            && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME)) {
        LinphoneManager.getLc().terminateCall(mCall);
        finish();/* w  w  w .  j  av a  2  s  . c  om*/
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.geometerplus.android.fbreader.network.NetworkCatalogActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        doStopLoading();/* w  w  w .j  ava 2 s  .c  om*/
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.haoxue.zixueplayer.MainActivity.java

/**
 * ?/*from w  w  w  .j  a  v  a2s .c o  m*/
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        new CustomDialog.Builder(MainActivity.this).setTitle(R.string.info).setMessage(R.string.dialog_messenge)
                .setPositiveButton(R.string.confrim, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        exit();

                    }
                }).setNeutralButton(R.string.cancel, null).show();
        return false;
    }
    return false;
}

From source file:com.conduit.plastic.common.BaseActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isExit) {
            if ((System.currentTimeMillis() - mExitTime) > 2000) {
                showShortToast("??");
                mExitTime = System.currentTimeMillis();
            } else {
                finish();/*from ww w  . jav  a  2  s .  c  o m*/
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        Limiter limiter = mPagerAdapter.getCurrentLimiter();

        if (mSlidingView.isShrinkable()) {
            mSlidingView.hideSlide();/*from   www  .  ja  v  a 2  s  .  c  o  m*/
            break;
        }

        if (mBottomBarControls.showSearch(false)) {
            break;
        }

        if (limiter != null) {
            int pos = -1;
            switch (limiter.type) {
            case MediaUtils.TYPE_ALBUM:
                setLimiter(MediaUtils.TYPE_ARTIST, limiter.data.toString());
                pos = mPagerAdapter.getMediaTypePosition(limiter.type);
                break;
            case MediaUtils.TYPE_ARTIST:
            case MediaUtils.TYPE_ALBARTIST:
            case MediaUtils.TYPE_COMPOSER:
            case MediaUtils.TYPE_GENRE:
                mPagerAdapter.clearLimiter(limiter.type);
                pos = mPagerAdapter.getMediaTypePosition(limiter.type);
                break;
            case MediaUtils.TYPE_FILE:
                File parentFile = ((File) limiter.data).getParentFile();
                mPagerAdapter.setLimiter(FileSystemAdapter.buildLimiter(parentFile));
                break;
            }
            if (pos == -1) {
                updateLimiterViews();
            } else {
                mViewPager.setCurrentItem(pos);
            }
        } else {
            finish();
        }
        break;
    case KeyEvent.KEYCODE_MENU:
        // We intercept these to avoid showing the activity-default menu
        mBottomBarControls.openMenu();
        break;
    case KeyEvent.KEYCODE_SEARCH:
        mBottomBarControls.showSearch(true);
        break;
    default:
        return false;
    }

    return true;
}

From source file:com.haibison.android.anhuu.FileChooserActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, String.format("onKeyDown() >> %,d", keyCode));

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        /*//  ww w. ja  va 2 s.com
         * Use this hook instead of onBackPressed(), because onBackPressed()
         * is not available in API 4.
         */
        if (mFragmentFiles.isLoading()) {
            if (BuildConfig.DEBUG)
                Log.d(CLASSNAME, "onKeyDown() >> KEYCODE_BACK >> cancelling previous query...");
            mFragmentFiles.cancelPreviousLoader();
            Dlg.toast(this, R.string.anhuu_f5be488d_msg_cancelled, Dlg.LENGTH_SHORT);
            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.hfs.materialhome.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if ((System.currentTimeMillis() - mExitTime) > 2000) {
            Toast.makeText(this, "??", Toast.LENGTH_SHORT).show();
            mExitTime = System.currentTimeMillis();

        } else {//from w  w w. j a va  2 s.co  m
            finish();
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.github.obsessive.simplifyreader.ui.activity.HomeActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawer(Gravity.LEFT);
        } else {/*from ww w.j av a  2s .com*/
            mDrawerLayout.openDrawer(Gravity.LEFT);
        }
        return true;
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawer(Gravity.LEFT);
        } else {
            if ((System.currentTimeMillis() - DOUBLE_CLICK_TIME) > 2000) {
                showToast(getString(R.string.double_click_exit));
                DOUBLE_CLICK_TIME = System.currentTimeMillis();
            } else {
                getBaseApplication().exitApp();
            }
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.king.base.BaseActivity.java

protected void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,
        final boolean isCancel) {
    dismissDialog();//w  w  w . jav  a  2s .c om
    dialog = new Dialog(context, resId);
    dialog.setContentView(contentView);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && isCancel) {
                dismissDialog();
            }
            return true;

        }
    });
    setDialogWindow(dialog, widthRatio);
    dialog.show();

}

From source file:zjut.soft.finalwork.ui.SlidingActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    System.out.println("right:" + mSlidingMenu.hasClickRight());
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        if (!mSlidingMenu.hasClickLeft() && !mSlidingMenu.hasClickRight()) {
            mSlidingMenu.showLeftView();
        } else if (mSlidingMenu.hasClickRight()) {
            mSlidingMenu.showRightView();
        } else {//from w w  w .j  ava  2 s .c om
            new AlertDialog.Builder(this).setTitle("").setMessage("?")
                    .setPositiveButton("", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            DefaultHttpClient client = ((YCApplication) getApplication()).getClient();
                            client = null;
                            Runtime.getRuntime().gc();
                            SlidingActivity.this.finish();
                            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                        }
                    }).setNegativeButton("", null).create().show();
        }
    }
    return true;
}