Example usage for android.view KeyEvent ACTION_UP

List of usage examples for android.view KeyEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

To view the source code for android.view KeyEvent ACTION_UP.

Click Source Link

Document

#getAction value: the key has been released.

Usage

From source file:Main.java

/**
 * Checks whether the given event is an ACTION_UP event.
 * @param event Event to be checked./*  w  w w  .j ava2  s . c  o m*/
 * @return Whether the event is an ACTION_UP event.
 */
public static boolean isActionUp(KeyEvent event) {
    return event.getAction() == KeyEvent.ACTION_UP;
}

From source file:com.saulcintero.moveon.services.MediaButtonEventReceiver.java

@Override
public void onReceive(Context mContext, Intent intent) {
    String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

        if (event == null)
            return;

        if (event.getAction() == KeyEvent.ACTION_UP) {
            Intent i = new Intent("android.intent.action.ACTION_SAY_PRACTICE_INFORMATION");
            i.putExtra("type", String.valueOf(NotificationTypes.TIME.getTypes()));
            mContext.sendBroadcast(i);/* w ww.ja  va  2  s  . c om*/
        }
    }
}

From source file:com.koma.music.service.MediaButtonIntentReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    LogUtils.i(TAG, "Received intent: " + intent);
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, MusicServiceConstants.CMDPAUSE, System.currentTimeMillis());
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null || event.getAction() != KeyEvent.ACTION_UP) {
            return;
        }//from w w  w  .j  a v a2  s. co  m

        String command = null;
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HEADSETHOOK:
            command = MusicServiceConstants.CMDHEADSETHOOK;
            break;
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicServiceConstants.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicServiceConstants.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicServiceConstants.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicServiceConstants.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicServiceConstants.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicServiceConstants.CMDPLAY;
            break;
        }
        if (command != null) {
            startService(context, command, event.getEventTime());
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
        }
    }
}

From source file:com.kogitune.activitytransition.fragment.ExitFragmentTransition.java

public void startExitListening(final Runnable popBackStackRunnable) {
    if (interpolator == null) {
        interpolator = new DecelerateInterpolator();
    }//  ww w  . jav a2 s  . co m
    final View toView = moveData.toView;
    toView.setFocusableInTouchMode(true);
    toView.requestFocus();
    toView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (event.getAction() != KeyEvent.ACTION_UP) {
                    return true;
                }
                TransitionAnimation.startExitAnimation(moveData, interpolator, new Runnable() {
                    @Override
                    public void run() {
                        if (popBackStackRunnable != null) {
                            popBackStackRunnable.run();
                            return;
                        }
                        if (fragment == null) {
                            if (!supportFragment.isResumed()) {
                                return;
                            }
                            final FragmentManager fragmentManager = supportFragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        } else {
                            if (!fragment.isResumed()) {
                                return;
                            }
                            final android.app.FragmentManager fragmentManager = fragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        }
                    }
                });
                return true;
            }
            return false;
        }
    });
}

From source file:com.commonsware.android.abf.ActionBarFragment.java

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (event == null || event.getAction() == KeyEvent.ACTION_UP) {
        adapter.add(v.getText().toString());
        v.setText("");

        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);

        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }//from  ww  w . java  2 s .  com

    return (true);
}

From source file:com.achep.acdisplay.services.media.MediaController2.java

/**
 * Emulates hardware buttons' click via broadcast system.
 *
 * @see android.view.KeyEvent/*w w  w.  j  av  a  2 s.com*/
 */
public static void broadcastMediaAction(@NonNull Context context, int action) {
    int keyCode;
    switch (action) {
    case ACTION_PLAY_PAUSE:
        keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
        break;
    case ACTION_STOP:
        keyCode = KeyEvent.KEYCODE_MEDIA_STOP;
        break;
    case ACTION_SKIP_TO_NEXT:
        keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
        break;
    case ACTION_SKIP_TO_PREVIOUS:
        keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        break;
    default:
        throw new IllegalArgumentException();
    }

    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    KeyEvent keyDown = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    KeyEvent keyUp = new KeyEvent(KeyEvent.ACTION_UP, keyCode);

    context.sendOrderedBroadcast(intent.putExtra(Intent.EXTRA_KEY_EVENT, keyDown), null);
    context.sendOrderedBroadcast(intent.putExtra(Intent.EXTRA_KEY_EVENT, keyUp), null);
}

From source file:com.kogitune.activity_transition.fragment.ExitFragmentTransition.java

public void startExitListening(final Runnable popBackStackRunnable) {
    if (interpolator == null) {
        interpolator = new DecelerateInterpolator();
    }//from   w ww.j  ava2  s  . c o m
    final View toView = moveData.toView;
    toView.setFocusableInTouchMode(true);
    toView.requestFocus();
    toView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (event.getAction() != KeyEvent.ACTION_UP) {
                    return true;
                }
                TransitionAnimation.startExitAnimation(moveData, interpolator, new Runnable() {
                    @Override
                    public void run() {
                        if (popBackStackRunnable != null) {
                            popBackStackRunnable.run();
                            return;
                        }
                        if (fragment == null) {
                            if (!supportFragment.isResumed()) {
                                return;
                            }
                            final FragmentManager fragmentManager = supportFragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        } else {
                            if (!fragment.isResumed()) {
                                return;
                            }
                            final android.app.FragmentManager fragmentManager = fragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        }
                    }
                }, listener);
                return true;
            }
            return false;
        }
    });
}

From source file:de.appetites.android.menuItemSearchAction.MenuItemSearchAction.java

/**
 * Listen for back button clicks, in order to close the keyboard and collapse the ActionView
 *//* www. ja  va2  s  . c  o  m*/
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        searchItem.collapseActionView();
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
        searchPerformListener.performSearch(MenuItemSearchAction.this.getText().toString());

        searchItem.collapseActionView();

    }
    return super.dispatchKeyEvent(event);
}

From source file:love.juhe.androidmonkey.MonkeyKeyEvent.java

@Override
public boolean isThrottlable() {
    return (getAction() == KeyEvent.ACTION_UP);
}

From source file:hai.tran.mywallet.fragment.CustomFragment.java

@Override
public void onResume() {
    super.onResume();
    getView().setFocusableInTouchMode(true);
    getView().requestFocus();/*  ww w  . java2  s. co  m*/
    getView().setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                Fragment frag = new DateFragment();
                FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager()
                        .beginTransaction();
                fragmentTransaction.setCustomAnimations(R.transition.sli_re_in, R.transition.sli_re_out);
                fragmentTransaction.replace(R.id.fragment_main, frag).commit();
                return true;
            }
            return false;
        }
    });
}