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:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (DEBUG)/*from   w  w  w. ja  va  2  s  .  c o m*/
        Logger.LogDebug("OpenExplorer.onKeyUp(" + keyCode + "," + event + ")");
    if (event.getAction() != KeyEvent.ACTION_UP)
        return super.onKeyUp(keyCode, event);
    if (MenuUtils.getMenuShortcut(event) != null) {
        if (getCurrentFocus() != null) {
            View cf = getCurrentFocus();
            if (cf instanceof TextView)
                return false;
        }
        MenuItem item = MenuUtils.getMenuShortcut(event);
        if (item != null)
            if (onOptionsItemSelected(item)) {
                showToast(item.getTitle(), Toast.LENGTH_SHORT);
                return true;
            }
    }
    if (keyCode == KeyEvent.KEYCODE_MENU && USE_PRETTY_MENUS) {
        View more = findViewById(R.id.menu_more);
        if (more != null && more.isShown() && more.isClickable() && more.performClick()) {
            Logger.LogDebug("!SHOULD BE HERE!");
            return true;
        } else {
            Logger.LogWarning("Couldn't find \"More Menu\"!");
            MenuBuilder menu = new MenuBuilder(this);
            getSelectedFragment().onCreateOptionsMenu(menu, getMenuInflater());
            getMenuInflater().inflate(R.menu.global, menu);
            onPrepareOptionsMenu(menu);
            showMenu(menu, getCurrentFocus(), true);
        }
    } else if (keyCode == KeyEvent.KEYCODE_BOOKMARK) {
        OpenPath path = getDirContentFragment(false).getPath();
        if (mBookmarks.hasBookmark(path))
            addBookmark(path);
        else
            removeBookmark(path);
    } else if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9) {
        int pos = keyCode - KeyEvent.KEYCODE_1;
        if (mToolbarButtons != null) {
            if (pos < mToolbarButtons.getChildCount() && mToolbarButtons.getChildAt(pos).performClick())
                return true;
            return false;
        }
        if (mOptsMenu != null && pos < mOptsMenu.size())
            return onOptionsItemSelected(mOptsMenu.getItem(pos));
        if (mMainMenu != null && pos < mMainMenu.size())
            return onOptionsItemSelected(mMainMenu.getItem(pos));
    }
    /*
    if (keyCode == KeyEvent.KEYCODE_BACK) {
       if (mBackQuit) {
    return super.onKeyUp(keyCode, event);
       } else {
    Toast.makeText(this, "Press back again to quit", Toast.LENGTH_SHORT).show();
    mBackQuit = true;
    return true;
       }      
    }*/
    return super.onKeyUp(keyCode, event);
}

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

/**
 * Display a delete confirmation dialog to remove a device.<br>
 * The user is invited to enter his password to confirm the deletion.
 *
 * @param aDeviceInfoToDelete device info
 *///  w  w w.  j  a v  a2s. co m
private void displayDeviceDeletionDialog(final DeviceInfo aDeviceInfoToDelete) {
    if ((null != aDeviceInfoToDelete) && (null != aDeviceInfoToDelete.device_id)) {
        if (!TextUtils.isEmpty(mAccountPassword)) {
            deleteDevice(aDeviceInfoToDelete.device_id);
        } else {
            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_settings_delete, null);

            final EditText passwordEditText = layout.findViewById(R.id.delete_password);
            builder.setIcon(android.R.drawable.ic_dialog_alert);
            builder.setTitle(R.string.devices_delete_dialog_title);
            builder.setView(layout);

            builder.setPositiveButton(R.string.devices_delete_submit_button_label,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (null != mSession) {
                                if (TextUtils.isEmpty(passwordEditText.toString())) {
                                    CommonActivityUtils.displayToast(VectorSettingsPreferencesFragment.this
                                            .getActivity().getApplicationContext(), "Password missing..");
                                    return;
                                }
                                mAccountPassword = passwordEditText.getText().toString();
                                deleteDevice(aDeviceInfoToDelete.device_id);
                            }
                        }
                    });

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

            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();
                        hideLoadingView();
                        return true;
                    }
                    return false;
                }
            });

            builder.create().show();
        }
    } else {
        Log.e(LOG_TAG, "## displayDeviceDeletionDialog(): sanity check failure");
    }
}

From source file:com.glview.widget.AbsListView.java

/**
 * Sends a key to the text filter window
 *
 * @param keyCode The keycode for the event
 * @param event The actual key event//from   ww w.ja v  a  2s . 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:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_SPACE:
        // Only send spaces once we are filtered
        okToSend = mFiltered;
        break;
    }

    if (okToSend) {

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

        int action = event.getAction();
        switch (action) {
        case KeyEvent.ACTION_DOWN:
            break;

        case KeyEvent.ACTION_UP:
            break;

        case KeyEvent.ACTION_MULTIPLE:
            break;
        }
    }
    return handled;
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (v == null)
        return false;
    if (DEBUG)/*from   w ww . jav a  2 s  .  c o m*/
        Logger.LogDebug("OpenExplorer.onKey(" + v + "," + keyCode + "," + event + ")");
    if (event.getAction() != KeyEvent.ACTION_UP)
        return false;
    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
        if (MenuUtils.getMenuLookupID(v.getId()) > 0)
            if (showMenu(MenuUtils.getMenuLookupSub(v.getId()), v, false))
                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/*from w  w w .j  av a  2 s.  c  om*/
 *
 * @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;
}