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.codeskraps.lolo.home.PrefsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onKeyDown");

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.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.
        Log.d(TAG, "SDK < Eclair");
        onBackPressed();//www.j a v a2s .c  o  m
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.kogitune.activity_transition.fragment.ExitFragmentTransition.java

public void startExitListening(final Runnable popBackStackRunnable) {
    if (interpolator == null) {
        interpolator = new DecelerateInterpolator();
    }//  w w w.j a v a  2  s . c o  m
    final View toView = moveData.toView;
    toView.setFocusableInTouchMode(true);
    toView.requestFocus();
    toView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (event.getAction() != KeyEvent.ACTION_UP) {
                    return true;
                }
                TransitionAnimation.startExitAnimation(moveData, interpolator, new Runnable() {
                    @Override
                    public void run() {
                        if (popBackStackRunnable != null) {
                            popBackStackRunnable.run();
                            return;
                        }
                        if (fragment == null) {
                            if (!supportFragment.isResumed()) {
                                return;
                            }
                            final FragmentManager fragmentManager = supportFragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        } else {
                            if (!fragment.isResumed()) {
                                return;
                            }
                            final android.app.FragmentManager fragmentManager = fragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        }
                    }
                }, listener);
                return true;
            }
            return false;
        }
    });
}

From source file:com.barcamppenang2013.tabfragment.IndoorMapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ((MainActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (mWebView != null) {
        mWebView.destroy();/*from w ww  .  ja va2s  .  c  o m*/
    }
    mWebView = new WebView(getActivity());
    mWebView.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return false;
        }

    });
    mWebView.setWebViewClient(new InnerWebViewClient());
    String imageUrl = "file:///android_asset/qb_indoor_map.png";

    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.loadUrl(imageUrl);

    mIsWebViewAvailable = true;
    //      WebSettings settings = mWebView.getSettings();
    //      settings.setJavaScriptEnabled(true);
    return mWebView;
}

From source file:com.barcamppenang2013.tabfragment.SponsorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ((MainActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (mWebView != null) {
        mWebView.destroy();/*from ww w  . j av a 2s  . com*/
    }
    mWebView = new WebView(getActivity());
    mWebView.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return false;
        }

    });
    //      mWebView.setWebViewClient(new InnerWebViewClient());
    //        String imageUrl =  "file:///android_asset/info_sponsor.png";
    //      String imageUrl = "";
    mWebView.getSettings().setJavaScriptEnabled(true);

    //        mWebView.loadUrl(imageUrl);
    mWebView.loadData(readFromFile("sponsor.html"), "text/html", "utf-8");

    mIsWebViewAvailable = true;
    //      WebSettings settings = mWebView.getSettings();
    //      settings.setJavaScriptEnabled(true);
    return mWebView;
}

From source file:android.support.v17.leanback.app.BrowseFragmentTest.java

public void testTwoBackKeysWithBackStack() throws Throwable {
    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), BrowseFragmentTestActivity.class);
    intent.putExtra(BrowseFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, (long) 1000);
    intent.putExtra(BrowseFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK, true);
    initActivity(intent);// w ww.  j a  va2  s.  c  om

    sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    Thread.sleep(TRANSITION_LENGTH);

    sendKeys(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BACK);
}

From source file:com.chat.activity.BaseActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        exit();/*from   www. ja v  a2  s .co m*/
        return false;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.example.t_gallery.ImageDetail.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent data = getIntent();/* w ww . j  a  v  a  2s . c  o  m*/

        data.putExtra(Config.DISPLAY_ITEM_INDEX, mPager.getCurrentItem());
        setResult(Config.REQUEST_CODE, data);
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.judepereira.android.co.uncyclopedia.UncyclopediaActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the Back button and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        client.setUniqueId(Math.random());
        ArticleHistory back;//from  w ww. j  ava2  s. c om
        try {
            history.pop();
            back = history.peek();
        } catch (EmptyStackException ex) {
            finish();
            return true;
        }
        client.setGoingBack(true);
        wikiView.loadDataWithBaseURL(back.getUrl(), back.getContentHtml(), null, "utf-8", back.getUrl());
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:android.support.v17.leanback.app.BrowseSupportFragmentTest.java

public void testTwoBackKeysWithBackStack() throws Throwable {
    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), BrowseSupportFragmentTestActivity.class);
    intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, (long) 1000);
    intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK, true);
    initActivity(intent);/*from www.j  a va  2 s.  c o m*/

    sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    Thread.sleep(TRANSITION_LENGTH);

    sendKeys(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BACK);
}

From source file:com.android.calculator2.StoreActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        startActivity(new Intent(this, Calculator.class));
        finish();//from ww w  . j  a v  a2 s  .c  o m
        overridePendingTransition(R.anim.activity_open_enter, R.anim.activity_close_exit);
        return true;
    }
    return super.onKeyDown(keyCode, keyEvent);
}