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:org.droidpres.activity.TransferActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN && mStartTransferFlag)
        return true;
    else/* w  w  w . j  a  v  a2s.  co m*/
        return super.onKeyDown(keyCode, event);
}

From source file:com.gao.im.ui.contact.ContactSelectListActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        finish();/* w  w w. j a v a  2s. c om*/
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.gsma.rcs.ri.sharing.geoloc.InitiateGeolocSharing.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (KeyEvent.KEYCODE_BACK == keyCode) {
        quitSession();/*  w ww .  j a  v  a  2 s  .c om*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.quantumbadger.redreader.activities.CommentReplyActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getTitle().equals(getString(R.string.comment_reply_send))) {

        final ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setTitle(getString(R.string.comment_reply_submitting_title));
        progressDialog.setMessage(getString(R.string.comment_reply_submitting_message));
        progressDialog.setIndeterminate(true);
        progressDialog.setCancelable(true);
        progressDialog.setCanceledOnTouchOutside(false);

        progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(final DialogInterface dialogInterface) {
                General.quickToast(CommentReplyActivity.this, getString(R.string.comment_reply_oncancel));
                progressDialog.dismiss();
            }/* w ww .j  a v a  2  s .co m*/
        });

        progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            public boolean onKey(final DialogInterface dialogInterface, final int keyCode,
                    final KeyEvent keyEvent) {

                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    General.quickToast(CommentReplyActivity.this, getString(R.string.comment_reply_oncancel));
                    progressDialog.dismiss();
                }

                return true;
            }
        });

        final APIResponseHandler.ActionResponseHandler handler = new APIResponseHandler.ActionResponseHandler(
                this) {
            @Override
            protected void onSuccess() {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    public void run() {
                        if (progressDialog.isShowing())
                            progressDialog.dismiss();
                        General.quickToast(CommentReplyActivity.this, getString(R.string.comment_reply_done));
                        finish();
                    }
                });
            }

            @Override
            protected void onCallbackException(Throwable t) {
                BugReportActivity.handleGlobalError(CommentReplyActivity.this, t);
            }

            @Override
            protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                    String readableMessage) {

                final RRError error = General.getGeneralErrorForFailure(context, type, t, status, null);

                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    public void run() {
                        General.showResultDialog(CommentReplyActivity.this, error);
                        if (progressDialog.isShowing())
                            progressDialog.dismiss();
                    }
                });
            }

            @Override
            protected void onFailure(final APIFailureType type) {

                final RRError error = General.getGeneralErrorForFailure(context, type);

                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    public void run() {
                        General.showResultDialog(CommentReplyActivity.this, error);
                        if (progressDialog.isShowing())
                            progressDialog.dismiss();
                    }
                });
            }
        };

        final CacheManager cm = CacheManager.getInstance(this);

        final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
        RedditAccount selectedAccount = null;

        for (RedditAccount account : accounts) {
            if (!account.isAnonymous()
                    && account.username.equalsIgnoreCase((String) usernameSpinner.getSelectedItem())) {
                selectedAccount = account;
                break;
            }
        }

        RedditAPI.comment(cm, handler, selectedAccount, parentIdAndType, textEdit.getText().toString(), this);

        progressDialog.show();

    } else if (item.getTitle().equals(getString(R.string.comment_reply_preview))) {
        MarkdownPreviewDialog.newInstance(textEdit.getText().toString()).show(getSupportFragmentManager());
    }

    return true;
}

From source file:at.tomtasche.reader.ui.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (fullscreen && keyCode == KeyEvent.KEYCODE_BACK) {
        leaveFullscreen();/*from w  ww.j  av  a  2  s .c  o m*/

        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.cjones.taskforcemamba.activity.WebActivity.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) && this.myWebView.canGoBack()) {
        this.myWebView.goBack();
        return true;
    }/*w  w  w .j  a  va2 s .c o m*/
    // 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.jungle.apps.photos.module.homepage.HomepageActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        long time = System.currentTimeMillis();
        if (time - mLastBackKeyUpTime <= 800) {
            exitApp();//  w ww.jav  a2  s .  c o  m
        } else {
            mLastBackKeyUpTime = time;
            JungleToast.makeText(this, R.string.back_press_exit_tips).show();
        }

        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.example.mp_master.BasicAuthLogin.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        this.finish();
        System.exit(0);/*www.  java2  s.  c o m*/
        android.os.Process.killProcess(android.os.Process.myPid());
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.activiti.android.app.fragments.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    getToolbar().setVisibility(View.GONE);

    webView = (WebView) v.findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(R.id.empty);
    emptyTextView = (TextView) v.findViewById(R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final Activity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override//from  w w w  .  j  a v  a  2 s  . c om
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            getActivity().setProgressBarIndeterminateVisibility(true);
            refreshIcon.setVisible(false);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }

            if (getActivity() != null) {
                getActivity().setProgressBarIndeterminateVisibility(false);
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:com.tweetlanes.android.core.view.DirectMessageActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {

        if (mDeleting) {
            showNoBackToast();/*from w  w w .  ja v  a2s  . co m*/
            return false;
        }

        if (event.getRepeatCount() == 0) {
            Intent returnIntent = new Intent();
            returnIntent.putExtra("statusDelete", mHasDoneDelete);
            setResult(RESULT_OK, returnIntent);
            finish();
            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}