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.bingo.hand.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isKeyboardPopup) {
            return super.onKeyUp(keyCode, event);// 
        }//  w ww  .j a v  a 2s .c  o  m
        long secondTime = System.currentTimeMillis();
        if (secondTime - firstTime > 1000) {// 1000
            Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();
            firstTime = secondTime;// firstTime
            return true;
        } else {
            System.exit(0);// 
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.analysedesgeeks.android.MainActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    //we need to check if we can go back in the twitter fragment. Otherwise, just pass the event down 

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar.getSelectedNavigationIndex() == TWITTER_FRAGMENT_INDEX) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                final WebFragment webFragment = (WebFragment) mTabsAdapter.getItem(TWITTER_FRAGMENT_INDEX);
                if (webFragment.goBack()) {
                    return true;
                }/*from   w  ww .  j av  a2s .  c o m*/
            }

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

From source file:com.aboveware.actionbar.common.ActionBarActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (mActionBarHelper.onBack()) {
            return true;
        }/*from  www.ja v  a  2  s  . c om*/
    }
    return super.onKeyDown(keyCode, event);
}

From source file:at.jclehner.rxdroid.DrugEditActivity2.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        final DrugEditFragment f = (DrugEditFragment) getSupportFragmentManager().findFragmentByTag("content");
        f.onBackPressed();//from w w  w  .j av a2  s  .  c om
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:truesculpt.ui.panels.WebFilePanel.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the BACK key and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
        mWebView.goBack();/*from  w ww .  ja v  a  2 s .  c o  m*/
        return true;
    }
    // If it wasn't the BACK key or there's no web page history, bubble up
    // to the default
    // system behavior (probably exit the activity)
    return super.onKeyDown(keyCode, event);
}

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

public void startExitListening(final Runnable popBackStackRunnable) {
    if (interpolator == null) {
        interpolator = new DecelerateInterpolator();
    }//  w w w  . ja  v  a 2  s .  c om
    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();
                            }
                        }
                    }
                });
                return true;
            }
            return false;
        }
    });
}

From source file:at.alladin.rmbt.android.help.RMBTHelpFragment.java

/**
* 
*//*from   w  w w.  ja  va  2 s.  c om*/
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    final Bundle args = getArguments();

    String url = args.getString(ARG_URL);

    if (url == null || url.length() == 0)
        url = this.getString(R.string.url_help);

    final Activity activity = getActivity();

    final WebView webview = new WebView(activity) {
        @Override
        public boolean onKeyDown(final int keyCode, final KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && canGoBack()) {
                goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    };

    final WebSettings webSettings = webview.getSettings();
    final String userAgent = AppConstants.getUserAgentString(getActivity());
    if (userAgent != null) {
        webSettings.setUserAgentString(userAgent);
    }
    webSettings.setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(final WebView view, final int errorCode, final String description,
                final String failingUrl) {
            Log.w(getTag(), "error code:" + errorCode);
            Log.d(getTag(), "error desc:" + description);
            Log.d(getTag(), "error url:" + failingUrl);
            webview.loadUrl("file:///android_res/raw/error.html");
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });

    if (!url.matches("^https?://.*")) {
        final String protocol = ConfigHelper.isControlSeverSSL(activity) ? "https" : "http";
        url = protocol + "://" + url;
    }

    webview.loadUrl(url);

    return webview;
}

From source file:Main.java

public static String getKeyNameByCode(int code) {
    switch (code) {
    case KeyEvent.KEYCODE_0:
        return "<0>";
    case KeyEvent.KEYCODE_1:
        return "<1>";
    case KeyEvent.KEYCODE_2:
        return "<2>";
    case KeyEvent.KEYCODE_3:
        return "<3>";
    case KeyEvent.KEYCODE_4:
        return "<4>";
    case KeyEvent.KEYCODE_5:
        return "<5>";
    case KeyEvent.KEYCODE_6:
        return "<6>";
    case KeyEvent.KEYCODE_7:
        return "<7>";
    case KeyEvent.KEYCODE_8:
        return "<8>";
    case KeyEvent.KEYCODE_9:
        return "<9>";
    case KeyEvent.KEYCODE_A:
        return "<A>";
    case KeyEvent.KEYCODE_B:
        return "<B>";
    case KeyEvent.KEYCODE_C:
        return "<C>";
    case KeyEvent.KEYCODE_D:
        return "<D>";
    case KeyEvent.KEYCODE_E:
        return "<E>";
    case KeyEvent.KEYCODE_F:
        return "<F>";
    case KeyEvent.KEYCODE_G:
        return "<G>";
    case KeyEvent.KEYCODE_H:
        return "<H>";
    case KeyEvent.KEYCODE_I:
        return "<I>";
    case KeyEvent.KEYCODE_J:
        return "<J>";
    case KeyEvent.KEYCODE_K:
        return "<K>";
    case KeyEvent.KEYCODE_L:
        return "<L>";
    case KeyEvent.KEYCODE_M:
        return "<M>";
    case KeyEvent.KEYCODE_N:
        return "<N>";
    case KeyEvent.KEYCODE_O:
        return "<O>";
    case KeyEvent.KEYCODE_P:
        return "<P>";
    case KeyEvent.KEYCODE_Q:
        return "<Q>";
    case KeyEvent.KEYCODE_R:
        return "<R>";
    case KeyEvent.KEYCODE_S:
        return "<S>";
    case KeyEvent.KEYCODE_T:
        return "<T>";
    case KeyEvent.KEYCODE_U:
        return "<U>";
    case KeyEvent.KEYCODE_V:
        return "<V>";
    case KeyEvent.KEYCODE_W:
        return "<W>";
    case KeyEvent.KEYCODE_X:
        return "<X>";
    case KeyEvent.KEYCODE_Y:
        return "<Y>";
    case KeyEvent.KEYCODE_Z:
        return "<Z>";
    case KeyEvent.KEYCODE_APOSTROPHE:
        return "<'>";
    case KeyEvent.KEYCODE_AT:
        return "<@>";
    case KeyEvent.KEYCODE_BACK:
        return "<Back>";
    case KeyEvent.KEYCODE_BACKSLASH:
        return "<\\>";
    case KeyEvent.KEYCODE_CALL:
        return "<Call>";
    case KeyEvent.KEYCODE_CAMERA:
        return "<Camera>";
    case KeyEvent.KEYCODE_CLEAR:
        return "<Clear>";
    case KeyEvent.KEYCODE_COMMA:
        return "<,>";
    case KeyEvent.KEYCODE_DEL:
        return "<Del>";
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "<PadCenter>";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "<PadDown>";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "<PadLeft>";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "<PadRight>";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "<PadUp>";
    case KeyEvent.KEYCODE_ENDCALL:
        return "<EndCall>";
    case KeyEvent.KEYCODE_ENTER:
        return "<Enter>";
    case KeyEvent.KEYCODE_ENVELOPE:
        return "<Envelope>";
    case KeyEvent.KEYCODE_EQUALS:
        return "<=>";
    case KeyEvent.KEYCODE_EXPLORER:
        return "<Explorer>";
    case KeyEvent.KEYCODE_FOCUS:
        return "<??? 0>";
    case KeyEvent.KEYCODE_GRAVE:
        return "<??? 1>";
    case KeyEvent.KEYCODE_HEADSETHOOK:
        return "<??? 2>";
    case KeyEvent.KEYCODE_HOME:
        return "<Home>";
    case KeyEvent.KEYCODE_LEFT_BRACKET:
        return "<(>";
    case KeyEvent.KEYCODE_MENU:
        return "<Menu>";
    case KeyEvent.KEYCODE_MINUS:
        return "<->";
    case KeyEvent.KEYCODE_NOTIFICATION:
        return "<??? 3>";
    case KeyEvent.KEYCODE_NUM:
        return "<Num>";
    case KeyEvent.KEYCODE_PERIOD:
        return "<??? 4>";
    case KeyEvent.KEYCODE_PLUS:
        return "<+>";
    case KeyEvent.KEYCODE_POUND:
        return "<??? 5>";
    case KeyEvent.KEYCODE_POWER:
        return "<Power>";
    case KeyEvent.KEYCODE_RIGHT_BRACKET:
        return "<)>";
    case KeyEvent.KEYCODE_SEMICOLON:
        return "<;>";
    case KeyEvent.KEYCODE_SLASH:
        return "</>";
    case KeyEvent.KEYCODE_SOFT_LEFT:
        return "<??? 6>";
    case KeyEvent.KEYCODE_SOFT_RIGHT:
        return "<??? 7>";
    case KeyEvent.KEYCODE_SPACE:
        return "<Space>";
    case KeyEvent.KEYCODE_STAR:
        return "<*>";
    case KeyEvent.KEYCODE_SYM:
        return "<Sym>";
    case KeyEvent.KEYCODE_TAB:
        return "<Tab>";
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        return "<VolumeDown>";
    case KeyEvent.KEYCODE_VOLUME_UP:
        return "<VolumeUp>";
    case KeyEvent.KEYCODE_UNKNOWN:
    default://from   ww  w .j a v  a 2 s  .  c  om
        return "<Unknown>";
    }
}

From source file:com.barcamppenang2014.tabfragment.Agenda.java

/**
 * Called to instantiate the view. Creates and returns the WebView.
 */// w ww  .jav  a2s .com
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (mWebView != null) {
        mWebView.destroy();
    }
    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()); // forces it to
    // open in app

    // mUrl = "file:///android_asset/agenda/about.html";
    // mUrl = this.getActivity().getFilesDir()+"/agenda.html";
    // mUrl = "file:///data/about.html";
    //       mWebView.loadUrl("http://barcamppenang.org/agenda.html");
    //       mWebView.loadUrl("http://barcamppenang.org/schedule/");

    mWebView.loadData(readFromFile("leaderboard.php"), "text/html", "utf-8");

    // Log.d("ddw", "outside!!");
    mIsWebViewAvailable = true;
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    //      if (isNetworkAvailable() == true){
    //         settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //      }
    //      else{
    //         settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
    //      }
    return mWebView;
}

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

/**
 * Called to instantiate the view. Creates and returns the WebView.
 *///w  w  w.  j av  a2  s .co  m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (mWebView != null) {
        mWebView.destroy();
    }
    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()); // forces it to
    // open in app

    // mUrl = "file:///android_asset/agenda/about.html";
    // mUrl = this.getActivity().getFilesDir()+"/agenda.html";
    // mUrl = "file:///data/about.html";
    //       mWebView.loadUrl("http://barcamppenang.org/agenda.html");
    //       mWebView.loadUrl("http://barcamppenang.org/schedule/");

    mWebView.loadData(readFromFile("agenda.html"), "text/html", "utf-8");

    // Log.d("ddw", "outside!!");
    mIsWebViewAvailable = true;
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    //      if (isNetworkAvailable() == true){
    //         settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //      }
    //      else{
    //         settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
    //      }
    return mWebView;
}