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.hwx.wheel.steeringwheel.bluetooth.ScaleActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        onBackPressed();/*from w w w .  j  a v a 2  s. c  om*/
        return true;
    }
    return false;
}

From source file:com.camnter.easygank.core.BaseDrawerLayoutActivity.java

/**
 * Take care of calling onBackPressed() for pre-Eclair platforms.
 *
 * @param keyCode keyCode/*from w ww .j a  v  a2  s.  com*/
 * @param event   event
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // 
    if (keyCode == KeyEvent.KEYCODE_BACK && this.mDrawerLayout.isDrawerOpen(this.mNavigationView)) {
        this.mDrawerLayout.closeDrawer(this.mNavigationView);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.zhihuigu.sosoOffice.LoginActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (MyApplication.getInstance().getNotlogin() == 1) {
            finish();//from  w w  w.j  a  v a 2 s. c  o  m
        } else {
            showExitDialog(this);
        }

    }
    return false;
}

From source file:com.google.android.apps.tvremote.PairingActivity.java

private ProgressDialog buildProgressDialog() {
    ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(getString(R.string.pairing_waiting));
    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        public boolean onKey(DialogInterface dialogInterface, int which, KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                cancelPairing();//from   w  w  w .  ja  v  a 2s  . co m
                return true;
            }
            return false;
        }
    });
    dialog.setButton(getString(R.string.pairing_cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int which) {
            cancelPairing();
        }
    });
    return dialog;
}

From source file:com.giltesa.taskcalendar.activity.Main.java

/**
 * Se capturan todas las pulsaciones de las teclas fsicas del dispositivo para poder personalizar los eventos que lanzan.
 *//*from www.  j  a  va 2s .  c  o m*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //Si la tecla pulsada es la de Atrs, y el usuario ha configurado la solicitud de confirmacin. Se pide dicha solicitud:
    if (keyCode == KeyEvent.KEYCODE_BACK && prefs.isConfirmExit()) {
        // Se muestra el mensaje por pantalla:
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setIcon(android.R.drawable.ic_dialog_alert);
        alert.setTitle(getResources().getString(R.string.main_exit_title));
        alert.setMessage(getResources().getString(R.string.main_exit_summary));
        alert.setNegativeButton(android.R.string.cancel, null);
        alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        alert.show();
        // Como se ha tratado el evento de la tecla atrs, se devuelve true.
        return true;
    }
    // Si aqu no se ha tratado el evento se le enva al padre para que lo trate l.
    return super.onKeyDown(keyCode, event);
}

From source file:com.mercandalli.android.apps.files.file.text.FileTextActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        this.finish();
        this.overridePendingTransition(R.anim.right_in, R.anim.right_out);
    }//from   w  w w  . j a v  a2 s. c om
    return super.onKeyDown(keyCode, event);
}

From source file:com.irccloud.android.ActionEditText.java

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (mDrawerLayout != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK
            && event.getAction() == KeyEvent.ACTION_UP) {
        mDrawerLayout.closeDrawers();//w  ww.ja  v  a  2s.co  m
    }
    return super.onKeyPreIme(keyCode, event);
}

From source file:com.codeskraps.sbrowser.home.SBrowserActivity.java

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

        if (webView.canGoBack())
            webView.goBack();/*  w w  w  .  j  a v  a  2s  . c  om*/
        else {
            if (webView != null) {
                webView.clearCache(true);
                webView.clearHistory();
            }

            sBrowserData.setSelected(false);
            sBrowserData.setSaveState(sBrowserData.getetxtHome());

            finish();
            overridePendingTransition(R.anim.fadein, R.anim.fadeout);
        }
        return true;

    } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        doSearch();
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.hctrom.romcontrol.packagehunter.PackageHunterMain.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        onBackPressed();// w  ww.j av a2  s  .  co m
        return true;
    } else {
        return super.onKeyUp(keyCode, event);
    }
}

From source file:com.anxpp.blog.fragment.AboutFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void initView() {
    webView = (WebView) getView().findViewById(R.id.webView);
    //      webView.setVisibility(View.GONE);
    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            Activity activity = getActivity();
            /**/*from w  w  w  .j  a va2 s.  co  m*/
             * ?Fragment???
             * I am not sure why are you getting this error, 
             * i think it should be something like NullPointerException. 
             * Try next: 
             *     Evert time you calling getActivity() on Fragment instance you should be sure,
             *     that fragment is actually have this Activity. 
             *     Because when your webview is loading you are calling this function:
             * */
            if (activity == null)
                return;
            activity.setTitle("Loading..." + progress + "%");
            activity.setProgress(progress * 100);
            if (progress == 100) {
                activity.setTitle(R.string.app_name);
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Toast("shouldOverrideUrlLoading");
            view.loadUrl(url);
            return true;
        }
    });
    //??
    WebSettings webSettings = webView.getSettings();
    //?
    //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //?js
    webSettings.setJavaScriptEnabled(true);
    //? ?
    webSettings.setUseWideViewPort(false); //??
    webSettings.setLoadWithOverviewMode(true); // ??
    webView.loadUrl("http://anxpp.com");
    //
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //trueWebViewfalse??
            view.loadUrl(url);
            return true; //false?
        }
    });
    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { // ?
                    webView.goBack(); //?
                    return true; //?
                }
            }
            return false;
        }
    });
}