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.apps.anker.facepunchdroid.SettingsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }/*from  ww w .  j av  a2s.  c o m*/

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

From source file:com.crearo.gpslogger.GpsMainActivity.java

/**
 * Handles the hardware back-button press
 *//*  ww w  .j a  v  a2  s  .c om*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && Session.isBoundToService()) {
        stopAndUnbindServiceIfRequired();
    }

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
            toggleDrawer();
            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java

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

    if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {

        showDialog(this);
        return true;

    } else {//w  w w.  j  a v  a  2  s  .c o  m
        return false;
    }
}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode != RESULT_OK)
        return;//from   ww  w  .j  a  va2 s . c o  m

    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(PostSubmitActivity.this, getString(R.string.comment_reply_oncancel));
            progressDialog.dismiss();
        }
    });

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

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

            return true;
        }
    });

    final CacheManager cm = CacheManager.getInstance(this);

    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(PostSubmitActivity.this, getString(R.string.post_submit_done));
                    finish();
                }
            });
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(PostSubmitActivity.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(PostSubmitActivity.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(PostSubmitActivity.this, error);
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                }
            });
        }
    };

    final boolean is_self = !typeSpinner.getSelectedItem().equals("Link");

    final RedditAccount selectedAccount = RedditAccountManager.getInstance(this)
            .getAccount((String) usernameSpinner.getSelectedItem());

    String subreddit = subredditEdit.getText().toString();
    final String title = titleEdit.getText().toString();
    final String text = textEdit.getText().toString();
    final String captchaId = data.getStringExtra("captchaId");
    final String captchaText = data.getStringExtra("captchaText");

    while (subreddit.startsWith("/"))
        subreddit = subreddit.substring(1);
    while (subreddit.startsWith("r/"))
        subreddit = subreddit.substring(2);
    while (subreddit.endsWith("/"))
        subreddit = subreddit.substring(0, subreddit.length() - 1);

    RedditAPI.submit(cm, handler, selectedAccount, is_self, subreddit, title, text, captchaId, captchaText,
            this);

    progressDialog.show();
}

From source file:zxing.util.CaptureActivity.java

License:asdf

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        Intent intent = new Intent();
        if (lastResult != null) {
            intent.putExtra("BarCode", lastResult);
            setResult(RESULT_OK, intent);
            finish();//from  w w  w . j a  va  2s . co  m
            return true;
        } else {
            restartPreviewAfterDelay(0L);
            return true;
        }
        //         if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK)
        //               && lastResult != null) {
        //            restartPreviewAfterDelay(0L);
        //            return true;
        //         }
        //         break;
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
        // Handle these events so they don't launch the Camera app
        return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        cameraManager.setTorch(false);
        return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
        cameraManager.setTorch(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.launcher.silverfish.launcher.LauncherActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // Override the functionality of back and home key
    if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) && event.isTracking()
            && !event.isCanceled()) {
        mViewPager.setCurrentItem(1);//from  ww  w  . j  av a 2s  . co m
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:at.alladin.rmbt.android.map.RMBTMapFilterFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        if (currentOptionList != null && !isRoot) {
            populateList(options.getRootOptions(), true);
            return true;
        }//from   w w w .  j a va  2  s .c o m
    }
    return false;
}

From source file:com.ryan.ryanreader.activities.PostSubmitActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode != RESULT_OK)
        return;//from w ww .  j  a va 2s.  c  o m

    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(PostSubmitActivity.this, getString(R.string.comment_reply_oncancel));
            progressDialog.dismiss();
        }
    });

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

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

            return true;
        }
    });

    final CacheManager cm = CacheManager.getInstance(this);

    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(PostSubmitActivity.this, getString(R.string.post_submit_done));
                    finish();
                }
            });
        }

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

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

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

            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    General.showResultDialog(PostSubmitActivity.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(PostSubmitActivity.this, error);
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                }
            });
        }
    };

    final boolean is_self = !typeSpinner.getSelectedItem().equals("Link");

    final RedditAccount selectedAccount = RedditAccountManager.getInstance(this)
            .getAccount((String) usernameSpinner.getSelectedItem());

    final String subreddit = subredditEdit.getText().toString();
    final String title = titleEdit.getText().toString();
    final String text = textEdit.getText().toString();
    final String captchaId = data.getStringExtra("captchaId");
    final String captchaText = data.getStringExtra("captchaText");

    RedditAPI.submit(cm, handler, selectedAccount, is_self, subreddit, title, text, captchaId, captchaText,
            this);

    progressDialog.show();
}

From source file:com.gao.im.ui.ECLauncherUI.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    LogUtil.d(LogUtil.getLogUtilsTag(ECLauncherUI.class), " onKeyDown");

    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_UP) {
        // dismiss PlusSubMenuHelper
        if (mOverflowHelper != null && mOverflowHelper.isOverflowShowing()) {
            mOverflowHelper.dismiss();//from   www  .  ja  v  a2 s  .c om
            return true;
        }
    }

    // ?menu??
    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_DOWN) {
        doTaskToBackEvent();
    }

    try {

        return super.dispatchKeyEvent(event);
    } catch (Exception e) {
        LogUtil.e(LogUtil.getLogUtilsTag(ECLauncherUI.class),
                "dispatch key event catch exception " + e.getMessage());
    }

    return false;
}

From source file:com.instiwork.RegistrationActivity.java

public void dialogTermsUse() {
    View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog_terms_use, null);
    mBottomSheetDialogTermsUse = new Dialog(RegistrationActivity.this, R.style.MaterialDialogSheet);
    mBottomSheetDialogTermsUse.setContentView(view);
    mBottomSheetDialogTermsUse.setCancelable(false);
    mBottomSheetDialogTermsUse.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBottomSheetDialogTermsUse.getWindow()
                .addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        mBottomSheetDialogTermsUse.getWindow().setStatusBarColor(Color.parseColor("#536942"));
    }//from w  w w .  ja v a 2  s . c o m
    mBottomSheetDialogTermsUse.getWindow().setGravity(Gravity.BOTTOM);
    mBottomSheetDialogTermsUse.show();

    view.findViewById(R.id.back_me_dlog_payment).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mBottomSheetDialogTermsUse.dismiss();
        }
    });

    pBarTermsUse = (ProgressBar) view.findViewById(R.id.pbar_terms_use);
    //        txtTermsUse = (RobotoLight) view.findViewById(R.id.txt_terms_use);

    webViewTermsUse = (WebView) view.findViewById(R.id.webv);
    webViewTermsUse.getSettings().setJavaScriptEnabled(true);
    webViewTermsUse.setVisibility(View.GONE);

    getTermsUse(InstiworkConstants.URL_DOMAIN + "Privacy_control");

    mBottomSheetDialogTermsUse.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
                if ((keyCode == KeyEvent.KEYCODE_BACK)) {
                    mBottomSheetDialogTermsUse.dismiss();
                    return true;
                }
            return false;
        }
    });
}