Example usage for android.view KeyEvent getKeyCode

List of usage examples for android.view KeyEvent getKeyCode

Introduction

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

Prototype

public final int getKeyCode() 

Source Link

Document

Retrieve the key code of the key event.

Usage

From source file:net.bytten.comicviewer.ComicViewerActivity.java

protected void resetContent() {
    comicDef = makeComicDef();/*from   w w  w  .  ja  v  a 2s .  c  om*/
    provider = comicDef.getProvider();
    comicInfo = provider.createEmptyComicInfo();

    //Only hide the title bar if we're running an android less than Android 3.0
    if (VersionHacks.getSdkInt() < 11)
        requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);
    webview = (HackedWebView) findViewById(R.id.viewer);
    title = (TextView) findViewById(R.id.title);
    comicIdSel = (EditText) findViewById(R.id.comicIdSel);

    webview.requestFocus();
    zoom = webview.getZoomControls();

    webview.setClickable(true);
    webview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!"".equals(comicInfo.getAlt()))
                showDialog(DIALOG_SHOW_HOVER_TEXT);
        }
    });

    title.setText(comicInfo.getTitle());

    comicIdSel.setText(comicInfo.getId());
    if (comicDef.idsAreNumbers())
        comicIdSel.setInputType(InputType.TYPE_CLASS_NUMBER);
    comicIdSel.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String text = comicIdSel.getText().toString();
            if (!text.equals("") && (actionId == EditorInfo.IME_ACTION_GO
                    || (actionId == EditorInfo.IME_NULL && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                loadComic(createComicUri(text));
                comicIdSel.setText("");
                return true;
            }
            return false;
        }
    });
    comicIdSel.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (hasFocus) {
                comicIdSel.setText("");
                imm.showSoftInput(comicIdSel, InputMethodManager.SHOW_IMPLICIT);
            } else {
                imm.hideSoftInputFromWindow(comicIdSel.getWindowToken(), 0);
            }
        }
    });

    ((Button) findViewById(R.id.firstBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFirst();
        }
    });

    ((Button) findViewById(R.id.prevBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToPrev();
        }
    });

    ((Button) findViewById(R.id.nextBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToNext();
        }
    });

    ((Button) findViewById(R.id.finalBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFinal();
        }
    });

    ((ImageView) findViewById(R.id.randomBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToRandom();
        }
    });

    bookmarkBtn = (ImageView) findViewById(R.id.bookmarkBtn);
    bookmarkBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            toggleBookmark();
        }
    });
    refreshBookmarkBtn();
}

From source file:com.owen.tvrecyclerview.widget.TvRecyclerView.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    boolean result = super.dispatchKeyEvent(event);
    if (!result) {
        switch (event.getAction()) {
        case KeyEvent.ACTION_DOWN:
            result = onKeyDown(event.getKeyCode(), event);
            break;
        case KeyEvent.ACTION_UP:
            result = onKeyUp(event.getKeyCode(), event);
            break;
        }//from   w  w w. ja v a2 s.co  m
    }
    return result;
}

From source file:org.catrobat.catroid.ui.ScriptActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    //Dismiss ActionMode without effecting checked items

    FormulaEditorDataFragment formulaEditorDataFragment = (FormulaEditorDataFragment) getSupportFragmentManager()
            .findFragmentByTag(FormulaEditorDataFragment.USER_DATA_TAG);

    if (formulaEditorDataFragment != null && formulaEditorDataFragment.isVisible()) {
        ListAdapter adapter = formulaEditorDataFragment.getListAdapter();
        ((ScriptActivityAdapterInterface) adapter).clearCheckedItems();
        return super.dispatchKeyEvent(event);
    }/*from  w w w .jav  a2 s .c  o  m*/

    if (currentFragment != null && currentFragment.getActionModeActive()
            && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        ListAdapter adapter = null;
        if (currentFragment instanceof ScriptFragment) {
            adapter = ((ScriptFragment) currentFragment).getAdapter();
        } else {
            adapter = currentFragment.getListAdapter();
        }
        ((ScriptActivityAdapterInterface) adapter).clearCheckedItems();
    }

    return super.dispatchKeyEvent(event);
}

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

@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
    if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK
            && event.getAction() == KeyEvent.ACTION_UP) {
        return delegate != null && delegate.onPreIme() || super.dispatchKeyEventPreIme(event);
    }/*  w  ww .ja  v a  2s .  c o  m*/
    return super.dispatchKeyEventPreIme(event);
}

From source file:com.google.fpl.voltair.VoltAirActivity.java

/**
 * @brief Called to process (and possibly intercept) key events.
 * @param event @c KeyEvent to handle//from  w  w w  .  jav  a  2 s . co  m
 * @returns @c true if @p event was handled
 */
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        // Since QtActivity does not handle volume (throwing the events on the floor) and we
        // cannot call super.super, we must handle managing of the volume here
        // TODO: Figure out how to get the volume Ui slide to show up without permanently
        // breaking immersive mode.
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                    0 /* No flags */);
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                    0 /* No flags */);
            break;
        }
    }

    // QtActivity (i.e. super) will convert all key events to QKeyEvents and *always* return
    // true saying it accepted the event -- even on Gamepad key events it doesn't understand.
    // This is annoying, and unfortunately means that we must always let controllers take a look
    // at the event even if QtActivity understood it and accepted it for use (e.g. in the UI).
    // However, we must be careful with events that are successfully translated (e.g. Keyboard
    // key events) so as to not spawn two separate controllers (one here with the Android
    // KeyEvent, and the other one in "InputArea" with the translated QKeyEvent).
    if (isGamepadEvent(event)) {
        if (onGamepadKeyEvent(event)) {
            return true;
        }
    } else if (isTouchNavigationEvent(event)) {
        if (onTouchNavigationKeyEvent(event)) {
            return true;
        }
    } else if (isKeyboardEvent(event)) {
        if (onKeyboardKeyEvent(event)) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.anjalimacwan.MainActivity.java

@Override
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    super.dispatchKeyShortcutEvent(event);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
            if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) {
                NoteListFragment fragment = (NoteListFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteListFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            } else if (getSupportFragmentManager()
                    .findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment) {
                NoteViewFragment fragment = (NoteViewFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteViewFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            } else if (getSupportFragmentManager()
                    .findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) {
                NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteEditFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            } else if (getSupportFragmentManager()
                    .findFragmentById(R.id.noteViewEdit) instanceof WelcomeFragment) {
                WelcomeFragment fragment = (WelcomeFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteListFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            }/*from w ww.j  a v  a2 s.c o  m*/

            return true;
        }
    }
    return super.dispatchKeyShortcutEvent(event);
}

From source file:com.mobicage.rogerthat.AddFriendsActivity.java

private void configureMailView() {
    T.UI();//from ww  w  . j a  v  a 2 s .c om
    final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.add_via_email_text_field);
    emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>()));
    emailText.setThreshold(1);

    if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) {
        mService.postAtFrontOfBIZZHandler(new SafeRunnable() {

            @SuppressWarnings("unchecked")
            @Override
            protected void safeRun() throws Exception {
                L.d("AddFriendsActivity getEmailAddresses");
                List<String> emailList = ContactListHelper.getEmailAddresses(AddFriendsActivity.this);
                ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter();
                for (int i = 0; i < emailList.size(); i++) {
                    a.add(emailList.get(i));
                }
                a.notifyDataSetChanged();
                L.d("AddFriendsActivity gotEmailAddresses");
            }
        });
    }

    final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            String email = emailText.getText().toString().trim();
            if (RegexPatterns.EMAIL.matcher(email).matches()) {
                if (mFriendsPlugin.inviteFriend(email, null, null, true)) {
                    emailText.setText(null);
                    UIUtils.hideKeyboard(AddFriendsActivity.this, emailText);
                } else {
                    UIUtils.showLongToast(AddFriendsActivity.this, getString(R.string.friend_invite_failed));
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(AddFriendsActivity.this);
                builder.setMessage(R.string.registration_email_not_valid);
                builder.setPositiveButton(R.string.rogerthat, null);
                builder.create().show();
            }
        }
    };
    ((Button) findViewById(R.id.add_via_email_button)).setOnClickListener(onClickListener);

    emailText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                onClickListener.onClick(view);
                return true;
            }
            return false;
        }
    });
}

From source file:com.dwdesign.tweetings.activity.HomeActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPreferences.getBoolean(PREFERENCE_KEY_VOLUME_NAVIGATION, false)) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_VOLUME_UP: {
                Intent broadcast = new Intent();
                broadcast.setAction(BROADCAST_VOLUME_UP);
                sendBroadcast(broadcast);
                //scrollToPrevious();
                return true;
            }//from w ww  .  jav  a  2 s  . c  o  m
            case KeyEvent.KEYCODE_VOLUME_DOWN: {
                Intent broadcast = new Intent();
                broadcast.setAction(BROADCAST_VOLUME_DOWN);
                sendBroadcast(broadcast);
                //scrollToNext();
                return true;
            }
            }
        }
        if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
                || event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.farmerbb.notepad.activity.MainActivity.java

@Override
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    super.dispatchKeyShortcutEvent(event);
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) {
            NoteListFragment fragment = (NoteListFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteListFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        } else if (getSupportFragmentManager()
                .findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment) {
            NoteViewFragment fragment = (NoteViewFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteViewFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        } else if (getSupportFragmentManager()
                .findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) {
            NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteEditFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        } else if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof WelcomeFragment) {
            WelcomeFragment fragment = (WelcomeFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteListFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        }/* ww w .ja v  a2 s .co  m*/

        return true;
    }
    return super.dispatchKeyShortcutEvent(event);
}

From source file:hku.fyp14017.blencode.ui.ScriptActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    //Dismiss ActionMode without effecting checked items

    FormulaEditorVariableListFragment formulaEditorVariableListFragment = (FormulaEditorVariableListFragment) getSupportFragmentManager()
            .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG);

    if (formulaEditorVariableListFragment != null && formulaEditorVariableListFragment.isVisible()) {
        ListAdapter adapter = formulaEditorVariableListFragment.getListAdapter();
        ((ScriptActivityAdapterInterface) adapter).clearCheckedItems();
        return super.dispatchKeyEvent(event);
    }// ww w.ja  v a  2 s  .  co  m

    if (currentFragment != null && currentFragment.getActionModeActive()
            && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        ListAdapter adapter = null;
        if (currentFragment instanceof ScriptFragment) {
            adapter = ((ScriptFragment) currentFragment).getAdapter();
        } else {
            adapter = currentFragment.getListAdapter();
        }
        ((ScriptActivityAdapterInterface) adapter).clearCheckedItems();
    }

    return super.dispatchKeyEvent(event);
}