Example usage for android.view KeyEvent isTracking

List of usage examples for android.view KeyEvent isTracking

Introduction

In this page you can find the example usage for android.view KeyEvent isTracking.

Prototype

public final boolean isTracking() 

Source Link

Document

For #ACTION_UP events, indicates that the event is still being tracked from its initial down event as per #FLAG_TRACKING .

Usage

From source file:com.audiokernel.euphonyrmt.library.SimpleLibraryActivity.java

@Override
public boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) {
    boolean result = true;

    if (event.isTracking() && !event.isCanceled() && !mApp.isLocalAudible()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            MPDControl.run(MPDControl.ACTION_VOLUME_STEP_UP);
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            MPDControl.run(MPDControl.ACTION_VOLUME_STEP_DOWN);
            break;
        default:/*from   w  w w  .j a va 2s  .c  o m*/
            result = super.onKeyUp(keyCode, event);
            break;
        }
    } else {
        result = super.onKeyUp(keyCode, event);
    }

    return result;
}

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  w  w w  .  j  a v a 2s  . c  o  m*/
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.AppsViewFragment.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
        if (!event.isTracking()) {
            return true;
        }/*from  ww  w  .j  av  a2  s  .com*/
        if (!event.isLongPress()) {
            AudioManager audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
            audio.adjustVolume(AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
            return true;
        }
    }
    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (!event.isTracking()) {
            return true;
        }
        if (!event.isLongPress()) {
            AudioManager audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
            audio.adjustVolume(AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
            return true;
        }
    }
    return false;
}

From source file:com.holo.fileexplorer.MainActivity.java

/**
 * //from   w w  w  .j  a va  2  s .  c  om
 */
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        // *** DO ACTION HERE ***
        if (mViewPager.getFragment(mPager, mPager.getCurrentItem()).backOneLevel()) {
            return true;
        } else {
            new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage("Quit the application?")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // android.os.Debug.stopMethodTracing();
                            finish();
                        }

                    }).setNegativeButton("No", null).show();
        }
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

@Override
public final boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) {
    boolean result = true;

    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (event.isTracking() && !event.isCanceled() && !mApp.isLocalAudible()) {
            if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                MPDControl.run(MPDControl.ACTION_VOLUME_STEP_UP);
            } else {
                MPDControl.run(MPDControl.ACTION_VOLUME_STEP_DOWN);
            }//from   w  w  w  .  ja v a  2s .c  o  m
        }
        break;
    default:
        result = super.onKeyUp(keyCode, event);
        break;
    }

    return result;
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * Filter pre-IME key events. By forwarding {@link View#onKeyPreIme(int, KeyEvent)}
 * events to this function, views using ListPopupWindow can have it dismiss the popup
 * when the back key is pressed./*from w  ww  .  ja  va 2s .  c o  m*/
 *
 * @param keyCode keyCode param passed to the host view's onKeyPreIme
 * @param event event param passed to the host view's onKeyPreIme
 * @return true if the event was handled, false if it was ignored.
 * @see #setModal(boolean)
 */
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && isShowing()) {
        // special case for the back key, we do not even try to send it
        // to the drop down list but instead, consume it immediately
        final View anchorView = mDropDownAnchorView;
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState();
            if (state != null) {
                state.startTracking(event, this);
            }
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState();
            if (state != null) {
                state.handleUpEvent(event);
            }
            if (event.isTracking() && !event.isCanceled()) {
                dismiss();
                return true;
            }
        }
    }
    return false;
}

From source file:android.app.Activity.java

/**
 * Called when a key was released and not handled by any of the views
 * inside of the activity. So, for example, key presses while the cursor 
 * is inside a TextView will not trigger the event (unless it is a navigation
 * to another object) because TextView handles its own key presses.
 * //from   ww w.  jav  a 2 s . c o  m
 * <p>The default implementation handles KEYCODE_BACK to stop the activity
 * and go back.
 * 
 * @return Return <code>true</code> to prevent this event from being propagated
 * further, or <code>false</code> to indicate that you have not handled 
 * this event and it should continue to be propagated. 
 * @see #onKeyDown
 * @see KeyEvent
 */
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.ECLAIR) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
            onBackPressed();
            return true;
        }
    }
    return false;
}

From source file:com.appunite.list.AbsHorizontalListView.java

/**
 * Sends a key to the text filter window
 *
 * @param keyCode The keycode for the event
 * @param event The actual key event/* ww w. j  av  a2 s  .  c o  m*/
 *
 * @return True if the text filter handled the event, false otherwise.
 */
boolean sendToTextFilter(int keyCode, int count, KeyEvent event) {
    if (!acceptFilter()) {
        return false;
    }

    boolean handled = false;
    boolean okToSend = true;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_BACK:
        if (mFiltered && mPopup != null && mPopup.isShowing()) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                KeyEvent.DispatcherState state = getKeyDispatcherState();
                if (state != null) {
                    state.startTracking(event, this);
                }
                handled = true;
            } else if (event.getAction() == KeyEvent.ACTION_UP && event.isTracking() && !event.isCanceled()) {
                handled = true;
                mTextFilter.setText("");
            }
        }
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_SPACE:
        // Only send spaces once we are filtered
        okToSend = mFiltered;
        break;
    }

    if (okToSend) {
        createTextFilter(true);

        KeyEvent forwardEvent = event;
        if (forwardEvent.getRepeatCount() > 0) {
            forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0);
        }

        int action = event.getAction();
        switch (action) {
        case KeyEvent.ACTION_DOWN:
            handled = mTextFilter.onKeyDown(keyCode, forwardEvent);
            break;

        case KeyEvent.ACTION_UP:
            handled = mTextFilter.onKeyUp(keyCode, forwardEvent);
            break;

        case KeyEvent.ACTION_MULTIPLE:
            handled = mTextFilter.onKeyMultiple(keyCode, count, event);
            break;
        }
    }
    return handled;
}