Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

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

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

From source file:butter.droid.tv.fragments.TVPlaybackOverlayFragment.java

@Override
public boolean handleInputEvent(@NonNull InputEvent event) {
    if (event instanceof KeyEvent) {
        KeyEvent keyEvent = (KeyEvent) event;
        if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_DPAD_CENTER)
            return false;
        if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
            if (mFastForwardAction != null && mSelectedActionId == mFastForwardAction.getId()) {
                if (keyEvent.getRepeatCount() == 0) {
                    mCurrentMode = MODE_FAST_FORWARD;
                    invokeFastForwardAction();
                }//from   w  w w  .j av  a  2s. c om
            } else if (mRewindAction != null && mSelectedActionId == mRewindAction.getId()) {
                if (keyEvent.getRepeatCount() == 0) {
                    mCurrentMode = MODE_REWIND;
                    invokeRewindAction();
                }
            }
        } else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
            mCurrentMode = MODE_NOTHING;
        }
    }
    return false;
}

From source file:com.italankin.dictionary.ui.main.MainActivity.java

private void setupInputLayout() {
    mInputLayout.setOnClickListener(new View.OnClickListener() {
        @Override//w ww  .  j a v a  2s.c om
        public void onClick(View v) {
            mInput.requestFocus();
            mInputManager.showSoftInput(mInput, 0);
        }
    });
    ViewTreeObserver vto = mInputLayout.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT >= 16) {
                ViewTreeObserver vto = mInputLayout.getViewTreeObserver();
                vto.removeOnGlobalLayoutListener(this);
            }
            updateInputLayoutPosition();
        }
    });

    mInput.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                lookupNext(mInput.getText().toString());
                return true;
            }
            return false;
        }
    });
}

From source file:de.azapps.mirakel.new_ui.fragments.TaskFragment.java

private void initTaskNameEdit() {
    taskNameEdit.setText(task.getName());
    // Show Keyboard if stub
    if (task.isStub()) {
        taskNameViewSwitcher.showNext();
        taskNameEdit.selectAll();/*from  w ww.  jav a2s .  c  om*/
        taskNameEdit.requestFocus();
        toggleKeyboard();
    }
    taskNameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus) {
                toggleKeyboard();
            }
        }
    });
    taskNameEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            switch (actionId) {
            case EditorInfo.IME_ACTION_DONE:
            case EditorInfo.IME_ACTION_SEND:
                updateName();
                return true;
            }
            return false;
        }
    });
    taskNameEdit.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(final View v, final int keyCode, final KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                updateName();
                return true;
            }
            return false;
        }
    });
}

From source file:com.android.view.leg.ImageDetailActivityLeg.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
    }/*from  w w  w . j  av  a  2  s.  co m*/
    // TODO Auto-generated method stub
    return super.onKeyDown(keyCode, event);
}

From source file:hku.fyp14017.blencode.ui.fragment.FormulaEditorListFragment.java

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    if (position >= itemsIds.length) {
        SensorTagFragment sensorTagFragment;
        FragmentManager fm = getSherlockActivity().getSupportFragmentManager();
        sensorTagFragment = (SensorTagFragment) fm.findFragmentByTag(SensorTagFragment.SENSOR_TAG_FRAGMENT_TAG);
        if (sensorTagFragment == null) {
            sensorTagFragment = new SensorTagFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("Tag number", position - (itemsIds.length - 1));
            sensorTagFragment.setArguments(bundle);
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(hku.fyp14017.blencode.R.id.script_fragment_container, sensorTagFragment,
                    SensorTagFragment.SENSOR_TAG_FRAGMENT_TAG);
            ft.hide(this);
            ft.commit();//from   w w w .  j  a  v  a 2 s . c  om
        } else {
            /*Bundle bundle = new Bundle();
            bundle.putInt("Tag number", position - (itemsIds.length-1));
            sensorTagFragment.setArguments(bundle);*/
            FragmentTransaction ft = fm.beginTransaction();
            ft.hide(this).show(sensorTagFragment).commit();
        }
    } else {
        FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity()
                .getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
        if (formulaEditor != null) {
            formulaEditor.addResourceToActiveFormula(itemsIds[position]);
            formulaEditor.updateButtonViewOnKeyboard();
            KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
            onKey(null, keyEvent.getKeyCode(), keyEvent);
        }
    }

}

From source file:it.rignanese.leo.slimtwitter.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            if (webViewTwitter.canGoBack()) {
                webViewTwitter.goBack();
            } else {
                // exit
                finish();//w w  w.  j  ava2  s  . co  m
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:fr.plnech.igem.game.AbstractGameActivity.java

@Override
public boolean onKeyDown(final int pKeyCode, @NonNull final KeyEvent pEvent) {
    if (gameScene != null && pauseScene != null && pKeyCode == KeyEvent.KEYCODE_MENU
            && pEvent.getAction() == KeyEvent.ACTION_DOWN) {
        if (gameScene.hasChildScene()) { // The game is paused
            music.play();//  w w  w .j a v a  2 s .  c  om
            pauseScene.back();
            updateNextStatus();
        } else {
            music.pause();
            gameScene.setChildScene(pauseScene, false, true, true);
        }
        return true;
    } else {
        return super.onKeyDown(pKeyCode, pEvent);
    }
}

From source file:com.android.tv.TvApplication.java

/**
 * Handles the global key KEYCODE_TV_INPUT.
 *//*from ww w. j  a v  a 2s.  c  o m*/
public void handleTvInputKey() {
    TvInputManager tvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
    List<TvInputInfo> tvInputs = tvInputManager.getTvInputList();
    int inputCount = 0;
    boolean hasTunerInput = false;
    for (TvInputInfo input : tvInputs) {
        if (input.isPassthroughInput()) {
            if (!input.isHidden(this)) {
                ++inputCount;
            }
        } else if (!hasTunerInput) {
            hasTunerInput = true;
            ++inputCount;
        }
    }
    if (inputCount < 2) {
        return;
    }
    Activity activityToHandle = mMainActivityWrapper.isResumed() ? mMainActivityWrapper.getMainActivity()
            : mSelectInputActivity;
    if (activityToHandle != null) {
        // If startActivity is called, MainActivity.onPause is unnecessarily called. To
        // prevent it, MainActivity.dispatchKeyEvent is directly called.
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TV_INPUT));
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TV_INPUT));
    } else if (mMainActivityWrapper.isStarted()) {
        Bundle extras = new Bundle();
        extras.putString(Utils.EXTRA_KEY_ACTION, Utils.EXTRA_ACTION_SHOW_TV_INPUT);
        startMainActivity(extras);
    } else {
        startActivity(new Intent(this, SelectInputActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }
}

From source file:com.oakesville.mythling.MediaPagerActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {
            if ((getCurrentFocus().getParent() instanceof View
                    && ((View) getCurrentFocus().getParent()).getId() == R.id.button_bar)
                    || getCurrentFocus().getId() == R.id.title_text) {
                findViewById(R.id.pager_position).requestFocus();
                return true;
            }/*from w  w  w.  jav  a 2 s  .co m*/
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
            if (getCurrentFocus().getId() == R.id.pager_position) {
                if (pager.getCurrentItem() < getListables().size() - 1) {
                    pager.setCurrentItem(pager.getCurrentItem() + 1);
                    positionBar.setProgress(pager.getCurrentItem());
                    return true;
                }
            }
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
            if (getCurrentFocus().getId() == R.id.pager_position) {
                if (pager.getCurrentItem() > 0) {
                    pager.setCurrentItem(pager.getCurrentItem() - 1);
                    positionBar.setProgress(pager.getCurrentItem());
                    return true;
                }
            }
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
            pager.setCurrentItem(getListables().size() - 1);
            positionBar.setProgress(getListables().size() - 1);
            return true;
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_REWIND) {
            pager.setCurrentItem(0);
            positionBar.setProgress(0);
            return true;
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
                || event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY) {
            Listable listable = getListables().get(pager.getCurrentItem());
            if (listable instanceof Item) {
                playItem((Item) listable);
                return true;
            }
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:org.opensilk.video.tv.ui.playback.PlaybackControlsFragment.java

@Override
protected boolean onInterceptInputEvent(InputEvent event) {
    boolean hidden = areControlsHidden();
    Timber.d("onInterceptInputEvent(%s) hidden = %s", event, hidden);
    boolean consumeEvent = false;
    boolean handled = false;
    int keyCode = KeyEvent.KEYCODE_UNKNOWN;
    if (event instanceof KeyEvent) {
        keyCode = ((KeyEvent) event).getKeyCode();
    }/*from  w ww  . j ava2s .  c om*/
    switch (keyCode) {
    //            case KeyEvent.KEYCODE_DPAD_CENTER:
    //            case KeyEvent.KEYCODE_DPAD_DOWN:
    //            case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (hidden) {
            if (((KeyEvent) event).getAction() == KeyEvent.ACTION_DOWN) {
                int delta = keyCode == KeyEvent.KEYCODE_DPAD_LEFT ? -10000 : 15000;
                consumeEvent = seekDelta(delta);
            }
            handled = true;
        }
        break;
    }
    return handled ? consumeEvent : super.onInterceptInputEvent(event);
}