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.abcvoipsip.ui.SipHome.java

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

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && !Compatibility.isCompatible(5)) {
        onBackPressed();//from w  w  w. j a v a  2s  .c o  m

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

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//from   w  ww.  j  ava  2 s  .  co m
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(RadialTimePickerDialog.this, mTimePicker.getHours(), mTimePicker.getMinutes());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}

From source file:CookieVideoView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();/*w  w  w  . j  av  a 2s . c o  m*/
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.eleybourn.bookcatalogue.BookEdit.java

/**
 * If 'back' is pressed, and the user has made changes, ask them if they
 * really want to lose the changes./*  w  w  w .j  a  va2 s  .com*/
 * 
 * We don't use onBackPressed because it does not work with API level 4.
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isDirty()) {
            StandardDialogs.showConfirmUnsavedEditsDialog(this, null);
        } else {
            doFinish();
        }
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.speed.traquer.app.Feedback_rate_taxi.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        if (actv_comp_taxi.length() != 0 || inputTaxi.length() != 0) {
            final AlertDialog.Builder alertBox = new AlertDialog.Builder(Feedback_rate_taxi.this);
            alertBox.setIcon(R.drawable.info_icon);
            alertBox.setCancelable(false);
            alertBox.setTitle("Do you want to cancel feedback?");
            alertBox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // finish used for destroyed activity
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (Yes)",
                            "Feedback taxi event", null).build());
                    finish();/* ww  w.ja  va  2s  .c  o m*/
                    Intent intent = new Intent(Feedback_rate_taxi.this, Speedometer.class);
                    Feedback_rate_taxi.this.startActivity(intent);
                }
            });

            alertBox.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int arg1) {
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (No)",
                            "Feedback taxi event", null).build());
                    dialog.cancel();
                }
            });

            alertBox.show();
        } else {
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.android.returncandidate.activities.SdmScannerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        //Enable button setting
        imbFilter.setClickable(true);/*from  ww  w  .  j a v  a 2s .c  o  m*/
        //Enable button switch
        aSwitchOCR.setClickable(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.company.millenium.iwannask.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            //                    if (myWebView.canGoBack()) {
            //                        myWebView.goBack();
            //                    } else {
            //                        finish();
            //                    }
            return true;
        }//w  w w  . j  a v a 2 s  .  com

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

From source file:com.entertailion.android.dial.ServerFinder.java

private ProgressDialog buildProgressDialog(String message, DialogInterface.OnClickListener cancelListener) {
    ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(message);// ww w  . j  av  a2  s . c  o m
    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        public boolean onKey(DialogInterface dialogInterface, int which, KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                finish();
                return true;
            }
            return false;
        }
    });
    dialog.setButton(getString(R.string.finder_cancel), cancelListener);
    return dialog;
}

From source file:net.olejon.spotcommander.WebViewActivity.java

@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK: {
        event.startTracking();/*from  ww  w .j a  v a2s .  c  o m*/
        return true;
    }
    case KeyEvent.KEYCODE_MENU: {
        return true;
    }
    case KeyEvent.KEYCODE_SEARCH: {
        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_UP: {
        return true;
    }
    default: {
        return super.onKeyDown(keyCode, event);
    }
    }
}