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:info.zamojski.soft.towercollector.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (event.getAction() == KeyEvent.ACTION_UP && mainMenu != null) {
            Log.i("onKeyUp(): Hardware menu key pressed");
            mainMenu.performIdentifierAction(R.id.main_menu_more, 0);
            return true;
        }//w  w  w  . j  a  va 2s .  co  m
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    // Do this in dispatch to intercept a few of the system keys.
    LogUtils.v(LOGTAG, "dispatchKeyEvent: %s", keyEvent);

    switch (keyEvent.getKeyCode()) {
    // Volume keys and camera keys dismiss the alarm.
    case KeyEvent.KEYCODE_POWER:
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_FOCUS:
        if (!mAlarmHandled && keyEvent.getAction() == KeyEvent.ACTION_UP) {
            switch (mVolumeBehavior) {
            case SettingsActivity.VOLUME_BEHAVIOR_SNOOZE:
                snooze();//from ww  w.  jav  a2  s .  c o  m
                break;
            case SettingsActivity.VOLUME_BEHAVIOR_DISMISS:
                dismiss();
                break;
            default:
                break;
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(keyEvent);
    }
}

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    int action = keyEvent.getAction();
    int keyCode = keyEvent.getKeyCode();
    final View drawerView = findDrawerView();
    if (drawerView != null && getDrawerLockMode(drawerView) == LOCK_MODE_UNLOCKED) {
        if (isDrawerOpen()) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_SOFT_RIGHT) {
                closeDrawer();//from www. jav a2 s . c  o  m
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_BACK && action == KeyEvent.ACTION_UP
                    && mDrawerControllerListener != null) {
                mDrawerControllerListener.onBack();
                return true;
            } else {
                return drawerView.dispatchKeyEvent(keyEvent);
            }
        }
    }

    return mContentView.dispatchKeyEvent(keyEvent);
}

From source file:com.jxlc.tajiproject.ui.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_UP) {
        finish();/*from  ww w  .  ja  v a 2  s  .  c  o  m*/
        return true;
    }

    if (event.getAction() == KeyEvent.ACTION_MULTIPLE) {
        return mUnityPlayer.injectEvent(event);
    }
    return super.dispatchKeyEvent(event);
}

From source file:org.solovyev.android.calculator.variables.EditVariableFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (v.getId() == R.id.variable_name) {
        if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK
                && keyboardWindow.isShown()) {
            keyboardUser.done();/*  w  ww.ja v  a 2  s.  c o  m*/
            return true;
        }
    }
    return false;
}

From source file:com.androidinspain.deskclock.alarms.AlarmActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    // Do this in dispatch to intercept a few of the system keys.
    LOGGER.v("dispatchKeyEvent: %s", keyEvent);

    final int keyCode = keyEvent.getKeyCode();
    switch (keyCode) {
    // Volume keys and camera keys dismiss the alarm.
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
    case KeyEvent.KEYCODE_HEADSETHOOK:
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_FOCUS:
        if (!mAlarmHandled) {
            switch (mVolumeBehavior) {
            case SNOOZE:
                if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
                    snooze();/*from  w  ww.j ava2  s.  c om*/
                }
                return true;
            case DISMISS:
                if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
                    dismiss();
                }
                return true;
            }
        }
    }
    return super.dispatchKeyEvent(keyEvent);
}

From source file:com.android2.calculator3.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    // Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }//w w w.  j a v  a2  s  . co m

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
     * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the DOWN event isn't received, only the UP. So the workaround is to act on UP... http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java

public void toggleSubMenu() {
    if (popupLayout == null) {
        return;/*from  w ww  .j a v  a 2  s.c  om*/
    }
    if (showMenuRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(showMenuRunnable);
        showMenuRunnable = null;
    }
    if (popupWindow != null && popupWindow.isShowing()) {
        popupWindow.dismiss();
        return;
    }
    if (popupWindow == null) {
        popupWindow = new ActionBarPopupWindow(popupLayout, LayoutHelper.WRAP_CONTENT,
                LayoutHelper.WRAP_CONTENT);
        if (Build.VERSION.SDK_INT >= 19) {
            popupWindow.setAnimationStyle(0);
        } else {
            popupWindow.setAnimationStyle(R.style.PopupAnimation);
        }
        popupWindow.setOutsideTouchable(true);
        popupWindow.setClippingEnabled(true);
        popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
        popupLayout.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST),
                MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST));
        popupWindow.getContentView().setFocusableInTouchMode(true);
        popupWindow.getContentView().setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0
                        && event.getAction() == KeyEvent.ACTION_UP && popupWindow != null
                        && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                    return true;
                }
                return false;
            }
        });
    }
    processedPopupClick = false;
    popupWindow.setFocusable(true);
    if (popupLayout.getMeasuredWidth() == 0) {
        updateOrShowPopup(true, true);
    } else {
        updateOrShowPopup(true, false);
    }
    popupWindow.startAnimation();
}

From source file:com.android.calculator2.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    // Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }/*from ww w .  j  av  a 2s .c o  m*/

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
     * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the
     * DOWN event isn't received, only the UP. So the workaround is to act
     * on UP... http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:org.easyaccess.phonedialer.CallStateService.java

@Override
public void onShake(float force) {
    if (Utils.ringing == 1) {
        // answer call
        Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
        buttonUp.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
        cxt.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
    }//  ww w.j av  a  2  s.  c o  m
}