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:com.se.cronus.AbstractCActivity.java

/**
 * /*ww  w  .  jav a2  s .  co m*/
 */
protected void setUpOnClicks() {
    // extract soon
    item.setOnClickListener(this);
    search.setOnClickListener(this);
    refresh.setOnClickListener(this);
    searchTextV.setClickable(true);
    searchTextV.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() != KeyEvent.ACTION_DOWN)
                return false;
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                // your necessary codes...
                onSearchClick();
                return true;
            }
            if (keyCode == KeyEvent.KEYCODE_SEARCH) {
                // your necessary codes...
                onSearchClick();
                return true;
            }
            return false;
        }
    });
    searchTextV.setOnClickListener(this);
}

From source file:com.mstar.tv.tvplayer.philips.setting.SettingFirstFragment.java

@Override
public void onStart() {
    super.onStart();
    listView = getListView();/*from  ww  w  . jav a  2s  .c o  m*/
    if (getFragmentManager().findFragmentById(R.id.first_fragment) != null) {
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }
    listView.setDivider(null);
    listView.setDividerHeight(5);
    listView.setSelector(android.R.color.transparent);
    listView.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (parent.isFocused())
                settingAdapter.setSelectViewPosition(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    listView.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                settingAdapter.setSelectViewPosition(getSelectedItemPosition());
            } else {
                settingAdapter.setSelectViewPosition(-1);
            }
        }
    });
    listView.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_PHOTO) {
                if (K_TvCommonManager.getInstance().K_getCurrentTvInputSource() == K_Constants.INPUT_SOURCE_VGA
                        && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {

                    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                        if (listView.getSelectedItemPosition() == 2) {
                            listView.setSelection(5);
                            return true;
                        }
                    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                        if (listView.getSelectedItemPosition() == 5) {
                            listView.setSelection(2);
                            return true;
                        } else if (listView.getSelectedItemPosition() == 1) {
                            //listView.setSelection(1);
                            return true;
                        }
                    }
                }
            } else if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_TV) {
                if (!(mTvCommonManager.getCurrentTvInputSource() == TvCommonManager.INPUT_SOURCE_HDMI
                        || mTvCommonManager.getCurrentTvInputSource() == TvCommonManager.INPUT_SOURCE_HDMI2
                        || mTvCommonManager.getCurrentTvInputSource() == TvCommonManager.INPUT_SOURCE_HDMI3)) {//EDID??
                    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        if (listView.getSelectedItemPosition() == 4) {
                            listView.setSelection(6);
                            return true;
                        }
                    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP
                            && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        if (listView.getSelectedItemPosition() == 6) {
                            listView.setSelection(4);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    });
}

From source file:org.tanrabad.team.ChatFragment.java

private void initUiComponents(View rootView) {
    mListView = (ListView) rootView.findViewById(R.id.list);
    turnOffListViewDecoration(mListView);
    mListView.setAdapter(mAdapter);// ww w.  j  a  v a 2  s  .c  o m

    mBtnChannel = (ImageButton) rootView.findViewById(R.id.btn_channel);
    mBtnSend = (Button) rootView.findViewById(R.id.btn_send);
    mBtnUpload = (ImageButton) rootView.findViewById(R.id.btn_upload);
    mProgressBtnUpload = (ProgressBar) rootView.findViewById(R.id.progress_btn_upload);
    mEtxtMessage = (EditText) rootView.findViewById(R.id.etxt_message);

    mBtnSend.setEnabled(false);
    mBtnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            send();
        }
    });

    mBtnChannel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mHandler != null) {
                mHandler.onChannelListClicked();
            }
        }
    });

    mBtnUpload.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_PICK_IMAGE);
        }
    });

    mEtxtMessage.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    send();
                }
                return true; // Do not hide keyboard.
            }
            return false;
        }
    });
    mEtxtMessage.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    mEtxtMessage.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mBtnSend.setEnabled(s.length() > 0);
        }
    });
    mListView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            SoftKeyboard.hide(getActivity());
            return false;
        }
    });
    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_IDLE) {
                if (view.getFirstVisiblePosition() == 0 && view.getChildCount() > 0
                        && view.getChildAt(0).getTop() == 0) {
                    resultHandler = new MessageListQuery.MessageListQueryResult() {
                        @Override
                        public void onResult(List<MessageModel> messageModels) {
                            for (MessageModel model : messageModels) {
                                mAdapter.addMessageModel(model);
                            }

                            mAdapter.notifyDataSetChanged();
                            mListView.setSelection(messageModels.size());
                        }

                        @Override
                        public void onError(Exception e) {
                        }
                    };
                    SendBird.queryMessageList(SendBird.getChannelUrl()).prev(mAdapter.getMinMessageTimestamp(),
                            30, resultHandler);
                }
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
}

From source file:net.xpece.android.support.preference.SeekBarPreference.java

/**
 * Listener reacting to the user pressing DPAD left/right keys if {@code
 * adjustable} attribute is set to true; it transfers the key presses to the SeekBar
 * to be handled accordingly.// www.j av a 2s.com
 */
private View.OnKeyListener buildSeekBarKeyListener(final SeekBar seekBar) {
    return new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() != KeyEvent.ACTION_DOWN) {
                return false;
            }

            if (!mAdjustable
                    && (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) {
                // Right or left keys are pressed when in non-adjustable mode; Skip the keys.
                return false;
            }

            // We don't want to propagate the click keys down to the seekbar view since it will
            // create the ripple effect for the thumb.
            if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
                return false;
            }

            if (seekBar == null) {
                Log.e(TAG, "SeekBar view is null and hence cannot be adjusted.");
                return false;
            }
            return seekBar.onKeyDown(keyCode, event);
        }
    };
}

From source file:com.example.nq.journalism_master.innerbrowser.InnerBrowserFragment.java

@Nullable
@Override//from   w ww  . j a v  a2s. c  o  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_inner_browser, container, false);

    initViews(view);
    initWebViewSettings(webView);

    // if not set this, click the back arrow will call nothing
    setHasOptionsMenu(true);

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            changeToolbarAndProgressBar(newProgress);
        }
    });

    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onReceivedError(WebView view1, WebResourceRequest request, WebResourceError error) {

            webView.setVisibility(View.GONE);
            imageView.setVisibility(View.VISIBLE);
            textView.setVisibility(View.VISIBLE);

            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (NetworkState.networkConnected(getContext())) {
                        webView.loadUrl(url);
                        webView.setVisibility(View.VISIBLE);
                        imageView.setVisibility(View.GONE);
                        textView.setVisibility(View.GONE);
                    }
                }
            });

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
        }
    });

    // WebView?html?
    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
                    webView.goBack();
                    return true;
                }
            }
            return false;
        }
    });

    webView.loadUrl(url);

    return view;
}

From source file:com.google.android.marvin.mytalkback.ProcessorVolumeStream.java

@Override
public boolean onKeyEvent(KeyEvent event) {
    boolean handled = false;
    switch (event.getAction()) {
    case KeyEvent.ACTION_DOWN:
        handled = handleKeyDown(event.getKeyCode());
        break;/*from w w w  . j ava  2s  . c om*/
    case KeyEvent.ACTION_UP:
        handled = handleKeyUp(event.getKeyCode());
        break;
    }

    if (handled) {
        // Quickly acquire and release the wake lock so that
        // PowerManager.ON_AFTER_RELEASE takes effect.
        mWakeLock.acquire();
        mWakeLock.release();
    }

    return handled;
}

From source file:org.deviceconnect.android.deviceplugin.hue.activity.fragment.HueFragment04.java

/**
 * Edit serial./*from ww  w  . j a  v  a 2 s .c om*/
 */
private void editSerial() {
    final EditText editText = new EditText(getActivity());
    editText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.frag04_serial_number_title)
            .setMessage(R.string.frag04_serial_number_message).setView(editText)
            .setPositiveButton(R.string.frag04_serial_ok, new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int whichButton) {
                    String serial = editText.getText().toString();
                    searchLightManually(serial);
                }
            }).setNegativeButton(R.string.frag04_serial_cancel, new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int whichButton) {
                }
            }).show();
    final Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    positiveButton.setEnabled(false);

    // Input limit of the serial number
    InputFilter inputFilter = new InputFilter() {
        @Override
        public CharSequence filter(final CharSequence source, final int start, final int end,
                final Spanned dest, final int dstart, final int dend) {
            if (source.toString().matches("[0-9a-fA-F]+")) {
                return source;
            } else {
                return "";
            }
        }
    };
    InputFilter[] filters = new InputFilter[] { inputFilter, new InputFilter.LengthFilter(6) };
    editText.setFilters(filters);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
        }

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            positiveButton.setEnabled(editText.length() == 6);
        }

        @Override
        public void afterTextChanged(final Editable s) {
        }
    });
    editText.setHint(R.string.frag04_serial_number_hint);
}

From source file:com.mstar.tv.tvplayer.philips.option.OptionThirdFragment.java

public void updateView(String data, int dataPositon) {
    vseekbar_title.setText(data);//from   www.  j av  a 2  s.c  om
    switch (dataPositon) {
    case 0:
        currentIndex = K_TvPictureManager.getInstance().K_getPCHPos();
        Log.v(TAG, "=========hpos===currentIndex=" + currentIndex);
        break;
    case 1:
        currentIndex = K_TvPictureManager.getInstance().K_getPCVPos();
        Log.v(TAG, "=========vpos===currentIndex=" + currentIndex);
        break;
    case 2:
        currentIndex = K_TvPictureManager.getInstance().K_getPCClock();
        Log.v(TAG, "=========clock===currentIndex=" + currentIndex);
        break;
    case 3:
        currentIndex = K_TvPictureManager.getInstance().K_getPCPhase();
        Log.v(TAG, "=========phase===currentIndex=" + currentIndex);
        break;

    default:
        break;
    }
    seekBar.setProgress(currentIndex);
    progressVal.setText(String.valueOf(seekBar.getProgress()));
    up_img.setBackgroundResource(R.drawable.slider_arrow_up_highlighted);
    down_img.setBackgroundResource(R.drawable.slider_arrow_down_highlighted);
    final int flag = dataPositon;
    seekBar.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View arg0, int keyCode, KeyEvent keyevent) {
            if (keyevent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_UP:
                    seekBar.incrementProgressBy(1);
                    progressVal.setText(String.valueOf(seekBar.getProgress()));
                    up_img.setBackgroundResource(R.drawable.slider_arrow_up_pressed);
                    down_img.setBackgroundResource(R.drawable.slider_arrow_down_highlighted);
                    updateSeekbarData(flag, seekBar);
                    return true;
                case KeyEvent.KEYCODE_DPAD_DOWN:
                    seekBar.incrementProgressBy(-1);
                    progressVal.setText(String.valueOf(seekBar.getProgress()));
                    up_img.setBackgroundResource(R.drawable.slider_arrow_up_highlighted);
                    down_img.setBackgroundResource(R.drawable.slider_arrow_down_pressed);
                    updateSeekbarData(flag, seekBar);
                    return true;
                case KeyEvent.KEYCODE_DPAD_LEFT:
                    getActivity().onKeyDown(keyCode, keyevent);
                    return true;
                case KeyEvent.KEYCODE_DPAD_RIGHT:

                    return true;
                default:
                    break;
                }

            }
            return false;
        }
    });
}

From source file:org.chromium.content_shell.Shell.java

private void initializeUrlField() {
    mUrlTextView = (EditText) findViewById(R.id.url);
    mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() {
        @Override// ww w  . j a v  a  2s .co m
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId != EditorInfo.IME_ACTION_GO)
                    && (event == null || event.getKeyCode() != KeyEvent.KEYCODE_ENTER
                            || event.getAction() != KeyEvent.ACTION_DOWN)) {
                return false;
            }
            loadUrl(mUrlTextView.getText().toString());
            setKeyboardVisibilityForUrl(false);
            mContentView.requestFocus();
            return true;
        }
    });
    mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            setKeyboardVisibilityForUrl(hasFocus);
            mNextButton.setVisibility(hasFocus ? GONE : VISIBLE);
            mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE);
            if (!hasFocus) {
                mUrlTextView.setText(mContentView.getUrl());
            }
        }
    });
}

From source file:com.battlelancer.seriesguide.ui.FixGetGlueCheckInActivity.java

private void setupViews() {
    mHeaderView = getLayoutInflater().inflate(R.layout.getglue_header, null);
    mSelectedValue = (TextView) mHeaderView.findViewById(R.id.textViewSelectedShowValue);

    mFooterView = getLayoutInflater().inflate(R.layout.getglue_footer, null);
    mSearchBox = (EditText) mFooterView.findViewById(R.id.editTextGetGlueSearch);
    mSearchBox.setOnKeyListener(new OnKeyListener() {
        @Override/* w  w  w  . j av a 2s . c  om*/
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // we only want to react to down events
            if (event.getAction() != KeyEvent.ACTION_DOWN) {
                return false;
            }

            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                onSearch(mSearchBox.getText().toString());
                return true;
            } else {
                return false;
            }
        }
    });
    mFooterView.findViewById(R.id.buttonShowSearch).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            v.setVisibility(View.GONE);
            mSearchBox.setVisibility(View.VISIBLE);
            mSearchBox.requestFocus();
        }
    });

    findViewById(R.id.buttonDiscard).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    final Context context = this;
    mSaveButton = findViewById(R.id.buttonSaveSelection);
    mSaveButton.setEnabled(false);
    mSaveButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // save new GetGlue object id
            CharSequence text = mSelectedValue.getText();
            ShowTools.get(context).storeGetGlueId(Integer.valueOf(mShowId),
                    text != null ? text.toString() : "");
            finish();
        }
    });
}