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:com.plusot.senselib.SenseMain.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    final int action = event.getAction();
    final int keyCode = event.getKeyCode();
    boolean result = false;

    if ((lastAction == action && lastKeyCode == keyCode)) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_CAMERA:
            newInterval();//from   ww  w . j a va  2 s  .  co  m
            break;
        case KeyEvent.KEYCODE_POWER:
            //if (action == KeyEvent.)
            LLog.d(Globals.TAG, CLASSTAG + " Power button pressed");
            break;
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (action == KeyEvent.ACTION_DOWN) {
                dimScreen(true);
            }
            result = true;
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                dimScreen(false);
            }
            result = true;
            break;
        }
    } else {
        AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        switch (keyCode) {
        case KeyEvent.KEYCODE_CAMERA:
            newInterval();
            break;
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (sameActionKeyCode < 2 && lastAction == KeyEvent.ACTION_DOWN && action == KeyEvent.ACTION_UP
                    && lastKeyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mgr.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                        AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
            }
            result = true;
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (sameActionKeyCode < 2 && lastAction == KeyEvent.ACTION_DOWN && action == KeyEvent.ACTION_UP
                    && lastKeyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                mgr.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                        AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
            }
            result = true;
            break;
        }
    }
    if (!result) {
        // LLog.d(Globals.TAG, CLASSTAG +
        // ".distpatchKeyEvent: Calling super with " + delta);
        result = super.dispatchKeyEvent(event);
    }
    if (lastAction == action && lastKeyCode == keyCode) {
        sameActionKeyCode++;
    } else
        sameActionKeyCode = 0;

    lastKeyCode = keyCode;
    lastAction = action;
    return result;

}

From source file:de.mrapp.android.sidebar.Sidebar.java

@Override
public final boolean onKeyPreIme(final int keyCode, final KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && isSidebarShown()
            && hideOnBackButton) {
        hideSidebar();//  w  w w  . j a v  a  2s.c om
        return true;
    }

    return false;
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

@TargetApi(11)
private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }//w  w  w .j a va 2s . c  o m

    if (mDataChanged) {
        layoutChildren();
    }

    if (android.os.Build.VERSION.SDK_INT < 11) {
        return false;
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_UP)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_DOWN)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:

            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            }
            handled = true;
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            break;
        }
    }

    if (handled) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);

    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);

    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);

    default: // shouldn't happen
        return false;
    }
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

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

    if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            if (abs_menu != null) {
                abs_menu.performIdentifierAction(R.id.menu_items, 0);
                return true;
            }//  www .jav a 2s. c o m
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

private boolean handleKeyEvent(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }//  w  w w. j  ava2  s . c  o  m

    if (mDataChanged) {
        layoutChildren();
    }

    boolean handled = false;
    final int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (mIsVertical) {
                handled = handleKeyScroll(event, count, View.FOCUS_UP);
            } else if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleFocusWithinItem(View.FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN: {
            if (mIsVertical) {
                handled = handleKeyScroll(event, count, View.FOCUS_DOWN);
            } else if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleFocusWithinItem(View.FOCUS_DOWN);
            }
            break;
        }

        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (!mIsVertical) {
                handled = handleKeyScroll(event, count, View.FOCUS_LEFT);
            } else if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleFocusWithinItem(View.FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!mIsVertical) {
                handled = handleKeyScroll(event, count, View.FOCUS_RIGHT);
            } else if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleFocusWithinItem(View.FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded()
                        || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                handled = resurrectSelectionIfNeeded()
                        || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT);
            }

            handled = true;
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded()
                        || pageScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded()
                        || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded()
                        || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded()
                        || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded()
                        || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded()
                        || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT);
            }
            break;
        }
    }

    if (handled) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);

    case KeyEvent.ACTION_UP:
        if (!isEnabled()) {
            return true;
        }

        if (isClickable() && isPressed() && mSelectedPosition >= 0 && mAdapter != null
                && mSelectedPosition < mAdapter.getCount()) {

            final View child = getChildAt(mSelectedPosition - mFirstPosition);
            if (child != null) {
                performItemClick(child, mSelectedPosition, mSelectedRowId);
                child.setPressed(false);
            }

            setPressed(false);
            return true;
        }

        return false;

    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);

    default:
        return false;
    }
}

From source file:processing.core.PApplet.java

protected void handleKeyEvent(KeyEvent event) {
    // event.isPrintingKey() returns false for whitespace and others,
    // which is a problem if the space bar or tab key are used.
    key = (char) event.getUnicodeChar();
    // if not mappable to a unicode character, instead mark as coded key
    if (key == 0 || key == 0xFFFF) {
        // System.out.println("  key is coded");
        key = CODED;/*from w w w  . ja  va 2 s. c o m*/
        // } else {
        // System.out.println("  key is unicode");
    }

    keyCode = event.getKeyCode();
    // println(key + " " + keyCode);

    int action = event.getAction();
    if (action == KeyEvent.ACTION_DOWN) {
        keyPressed = true;
        keyPressed();
    } else if (action == KeyEvent.ACTION_UP) {
        keyPressed = false;
        keyReleased();
    }

    // if someone else wants to intercept the key, they should
    // set key to zero (or something besides the "ESC").
    // println(event);
    /*
    if (action == KeyEvent.ACTION_DOWN) {        
       if (keyCode == KeyEvent.KEYCODE_BACK) {
    // println("KEYCODE_BACK, calling exit()");
    Preferences.saveRestart(getActivity(), true);
    exit();
    System.exit(0);
       }
    }
    */
    // When running tethered to the Processing application, respond to
    // Ctrl-W (or Cmd-W) events by closing the sketch. Disable this behavior
    // when running independently, because this sketch may be one component
    // embedded inside an application that has its own close behavior.
    // if (external &&
    // event.getModifiers() == MENU_SHORTCUT &&
    // event.getKeyCode() == 'W') {
    // exit();
    // }
    // }
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

private void sendKeyUp(InputConnection ic, int key) {
    if (ic != null)
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, key));
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            // 290661 commented this out to fix bug (Auto lock screen not popping up when back key is pressed from allapps screen)
            //TruMobiTimerClass.userInteractedStopTimer();
            if (!allAppsOpen) {
                // android.os.Process.killProcess(android.os.Process.myPid());
                mWorkspace.dispatchKeyEvent(event);

                finish();//from w w  w.ja  v  a 2s .c  o  m
            }
            mHandleView.updateIcon();
            return true;
        case KeyEvent.KEYCODE_HOME:
            return true;

        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            if (!event.isCanceled()) {
                mWorkspace.dispatchKeyEvent(event);
                if (allAppsOpen) {
                    closeDrawer();
                } else {
                    closeFolder();
                }
                if (isPreviewing()) {
                    dismissPreviews();
                }
                if (mIsEditMode) {
                    stopDesktopEdit();
                }
                if (mIsWidgetEditMode) {
                    stopWidgetEdit();
                }
            }
            return true;
        case KeyEvent.KEYCODE_HOME:
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.android.launcher3.Launcher.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
                dumpState();/*from   w w  w . j a  va 2  s.  c  om*/
                return true;
            }
            break;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

/**
 * Display a dialog containing the device ID, the device name and the "last seen" information.<>
 * This dialog allow to delete the corresponding device (see {@link #displayDeviceDeletionDialog(DeviceInfo)})
 *
 * @param aDeviceInfo the device information
 */// w  w w .  j  a  v  a  2  s .  c o  m
private void displayDeviceDetailsDialog(DeviceInfo aDeviceInfo) {
    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
            getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View layout = inflater.inflate(R.layout.devices_details_settings, null);

    if (null != aDeviceInfo) {
        //device ID
        TextView textView = layout.findViewById(R.id.device_id);
        textView.setText(aDeviceInfo.device_id);

        // device name
        textView = layout.findViewById(R.id.device_name);
        String displayName = (TextUtils.isEmpty(aDeviceInfo.display_name)) ? LABEL_UNAVAILABLE_DATA
                : aDeviceInfo.display_name;
        textView.setText(displayName);

        // last seen info
        textView = layout.findViewById(R.id.device_last_seen);
        if (!TextUtils.isEmpty(aDeviceInfo.last_seen_ip)) {
            String lastSeenIp = aDeviceInfo.last_seen_ip;
            String lastSeenTime = LABEL_UNAVAILABLE_DATA;

            if (null != getActivity()) {
                SimpleDateFormat dateFormatTime = new SimpleDateFormat(
                        getString(R.string.devices_details_time_format));
                String time = dateFormatTime.format(new Date(aDeviceInfo.last_seen_ts));

                DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
                lastSeenTime = dateFormat.format(new Date(aDeviceInfo.last_seen_ts)) + ", " + time;
            }
            String lastSeenInfo = this.getString(R.string.devices_details_last_seen_format, lastSeenIp,
                    lastSeenTime);
            textView.setText(lastSeenInfo);
        } else {
            // hide last time seen section
            layout.findViewById(R.id.device_last_seen_title).setVisibility(View.GONE);
            textView.setVisibility(View.GONE);
        }

        // title & icon
        builder.setTitle(R.string.devices_details_dialog_title);
        builder.setIcon(android.R.drawable.ic_dialog_info);
        builder.setView(layout);

        final DeviceInfo fDeviceInfo = aDeviceInfo;

        builder.setPositiveButton(R.string.rename, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                displayDeviceRenameDialog(fDeviceInfo);
            }
        });

        // disable the deletion for our own device
        if (!TextUtils.equals(mSession.getCrypto().getMyDevice().deviceId, fDeviceInfo.device_id)) {
            builder.setNegativeButton(R.string.delete, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    displayDeviceDeletionDialog(fDeviceInfo);
                }
            });
        }

        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                    dialog.cancel();
                    return true;
                }
                return false;
            }
        });

        builder.create().show();
    } else {
        Log.e(LOG_TAG, "## displayDeviceDetailsDialog(): sanity check failure");
        if (null != getActivity())
            CommonActivityUtils.displayToast(getActivity().getApplicationContext(),
                    "DeviceDetailsDialog cannot be displayed.\nBad input parameters.");
    }
}