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.mobilevue.vod.VideoControllerView.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPlayer == null) {
        return true;
    }/*from w ww . j a v  a  2s .  c  o m*/

    int keyCode = event.getKeyCode();
    final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN;
    if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
            || keyCode == KeyEvent.KEYCODE_SPACE) {
        if (uniqueDown) {
            doPauseResume();
            show(sDefaultTimeout);
            if (mPauseButton != null) {
                mPauseButton.requestFocus();
            }
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
        if (uniqueDown && !mPlayer.isPlaying()) {
            mPlayer.start();
            updatePausePlay();
            show(sDefaultTimeout);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
        if (uniqueDown && mPlayer.isPlaying()) {
            mPlayer.pause();
            updatePausePlay();
            show(sDefaultTimeout);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP
            || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
        // don't show the controls for volume adjustment
        return super.dispatchKeyEvent(event);
    } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
        if (uniqueDown) {
            hide();
        }
        return true;
    }

    show(sDefaultTimeout);
    return super.dispatchKeyEvent(event);
}

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

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK: {
        mHasLongPressedBack = true;//www  .jav  a  2s .  c o m

        mTools.navigateUp(mActivity);

        return true;
    }
    default: {
        return super.onKeyLongPress(keyCode, event);
    }
    }
}

From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java

/**
 * {@inheritDoc}//ww  w.  j  a  v  a  2s . c  om
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Override the back button
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (mWebView.canGoBack()) {
            // Check to see if there's history to go back to
            mWebView.goBack();
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.mattfred.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//from   w  w  w  . j a  va2s.  c  o  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(RadialTimePickerDialogFragment.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:com.wikitude.phonegap.WikitudePlugin.java

/**
 * add architectView to current screen/*from w  ww .ja  v a 2 s .com*/
 * @param apiKey developers's api key to use (hides watermarking/intro-animation if it matches your package-name)
 * @param filePath the url (starting with http:// for online use; starting with LOCAL_ASSETS_PATH_ROOT if oyu want to load assets within your app-assets folder)
 * @throws IOException might be thrown from ARchitect-SDK
 */
private void addArchitectView(final String apiKey, String filePath) throws IOException {
    if (this.architectView == null) {

        this.architectView = new ArchitectViewPhoneGap(this.cordova.getActivity(), new OnKeyDownListener() {

            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event) {
                if (WikitudePlugin.this.architectView != null && keyCode == KeyEvent.KEYCODE_BACK) {
                    WikitudePlugin.this.locationProvider.onPause();
                    removeArchitectView();
                    return true;
                }
                return false;
            }
        });

        this.architectView.setFocusableInTouchMode(true);
        this.architectView.requestFocus();

        this.locationListener = new LocationListener() {

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }

            @Override
            public void onProviderEnabled(String provider) {
            }

            @Override
            public void onProviderDisabled(String provider) {
            }

            @Override
            public void onLocationChanged(final Location location) {
                if (location != null) {
                    WikitudePlugin.this.lastKnownLocaton = location;
                    if (WikitudePlugin.this.architectView != null) {
                        if (location.hasAltitude()) {
                            WikitudePlugin.this.architectView.setLocation(location.getLatitude(),
                                    location.getLongitude(), location.getAltitude(), location.getAccuracy());
                        } else {
                            WikitudePlugin.this.architectView.setLocation(location.getLatitude(),
                                    location.getLongitude(), location.getAccuracy());
                        }
                    }
                }
            }
        };

        /* add content view and fake initial life-cycle */
        (this.cordova.getActivity()).addContentView(this.architectView,
                new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        /* fake life-cycle calls, because activity is already up and running */
        this.architectView.onCreate(getArchitectConfig(apiKey));
        this.architectView.onPostCreate();

        /* register self as url listener to fwd these native calls to PhoneGap */
        this.architectView.registerUrlListener(WikitudePlugin.this);

        /* load asset from local directory if prefix is used */
        if (filePath.startsWith(WikitudePlugin.LOCAL_ASSETS_PATH_ROOT)) {
            filePath = filePath.substring(WikitudePlugin.LOCAL_ASSETS_PATH_ROOT.length());
        }
        this.architectView.load(filePath);

        /* also a fake-life-cycle call (the last one before it is really shown in UI */
        this.architectView.onResume();

        this.locationProvider = new LocationProvider(this.cordova.getActivity(), this.locationListener);

        this.locationProvider.onResume();

    }

    // hide keyboard when adding AR view on top of views
    InputMethodManager inputManager = (InputMethodManager) (this.cordova.getActivity())
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow((this.cordova.getActivity()).getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.kjsaw.alcosys.ibacapp.IBAC.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        Session.isKeepRunning = false;//from  ww w  .  ja va 2s. c o m
        CancelAllServices();
        ActivityStackControlUtil.finishProgram(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java

/**
 * {@inheritDoc}//from w w w.  j a v  a  2 s .c  o m
 */
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (checkBackAction()) {
            return true;
        }

        // An exit event has occurred, force the destroy the consoles
        exit();
    }
    return super.onKeyUp(keyCode, event);
}

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

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU: {
        mWebView.loadUrl("javascript:nativeAppAction('menu')");
        return true;
    }//from www . j a  v  a2s.  c  o m
    case KeyEvent.KEYCODE_SEARCH: {
        mWebView.loadUrl("javascript:nativeAppAction('search')");
        return true;
    }
    case KeyEvent.KEYCODE_BACK: {
        if (mHasLongPressedBack)
            return true;

        if (mWebView.canGoBack() && mWebView.getUrl().contains("accounts.spotify.com/")
                || mWebView.canGoBack() && mWebView.getUrl().contains("facebook.com/")) {
            mWebView.goBack();

            return true;
        } else if (mWebView.canGoBack() || mTools.getSharedPreferencesBoolean("CAN_CLOSE_COVER")) {
            mWebView.loadUrl("javascript:nativeAppAction('back')");

            return true;
        }

        mTools.showToast(getString(R.string.webview_back), 1);

        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        mWebView.loadUrl("javascript:nativeAppAction('volume_down')");
        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_UP: {
        mWebView.loadUrl("javascript:nativeAppAction('volume_up')");
        return true;
    }
    default: {
        return super.onKeyUp(keyCode, event);
    }
    }
}

From source file:com.eeshana.icstories.activities.UploadVideoActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent i = new Intent(UploadVideoActivity.this, CaptureVideoActivity.class);
        startActivity(i);//www  .  j  a  v  a2s . c o m
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.ll.myapplication.vitamio.widget.VideoView.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_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
                  || keyCode == KeyEvent.KEYCODE_SPACE) {
              if (mMediaPlayer.isPlaying()) {
                  pause();/*from w  ww .ja v  a 2 s  .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);
  }