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.notepadlite.NoteEditActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from   w w  w  .  jav  a2 s  . c  o  m
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    super.dispatchKeyShortcutEvent(event);
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager()
                .findFragmentByTag("NoteEditFragment");
        fragment.dispatchKeyShortcutEvent(event.getKeyCode());

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

From source file:org.ednovo.goorusearchwidget.HomeScreenActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_screen);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE);
    headerSearch = (RelativeLayout) findViewById(R.id.layoutHeader);
    imgViewGooruSearch = (ImageView) findViewById(R.id.ivGooruLogo);
    imgViewSections = (ImageView) findViewById(R.id.imgViewSections);
    imgViewSettings = (ImageView) findViewById(R.id.imgViewSettings);
    imageViewClose = (ImageView) findViewById(R.id.imageViewClose);
    imageViewSearch = (ImageView) findViewById(R.id.imageViewSearch);
    editTexthome = (EditText) findViewById(R.id.textViewSearch);
    switchResColl = (Switch) findViewById(R.id.switchResColl);

    dialog = new ProgressDialog(this);
    imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
    new Loginform().execute();
    switchResColl.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override//from  w w w .j  a va2s  .co m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                Log.i("Hello", "True");
                searchCriteria = true;
            } else {
                Log.i("Hello", "False");
                searchCriteria = false;
            }
        }
    });

    editTexthome.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    searchKeyword = editTexthome.getText().toString().trim();
                    if (searchKeyword.isEmpty() || searchKeyword.length() == 0) {

                    } else {
                        if (!searchCriteria) {
                            Log.i("Resources", searchKeyword);
                            Intent intentResResults = new Intent(getBaseContext(),
                                    SearchResults_resource.class);

                            Bundle extras = new Bundle();
                            extras.putString("keyWord", searchKeyword);
                            intentResResults.putExtras(extras);
                            startActivity(intentResResults);
                            finish();
                        }
                    }
                    return true;
                default:
                    break;
                }
            }
            return false;
        }
    });

    imageViewClose.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            finish();
        }
    });

    imgViewGooruSearch.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Intent intentResResults = new Intent(getBaseContext(), SearchDialogpopup.class);

            startActivity(intentResResults);

        }
    });

}

From source file:com.ekeitho.sound.MainActivity.java

public boolean dispatchKeyEvent(KeyEvent event) {
    double VOLUME_INCREMENT = 0.05;
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_DOWN) {
            if (mRemoteMediaPlayer != null) {
                double currentVolume = Cast.CastApi.getVolume(mApiClient);
                if (currentVolume < 1.0) {
                    try {
                        Cast.CastApi.setVolume(mApiClient, Math.min(currentVolume + VOLUME_INCREMENT, 1.0));
                    } catch (Exception e) {
                        Log.e(TAG, "unable to set volume", e);
                    }/*from  ww  w . j  av a2s.  c o  m*/
                }
            } else {
                Log.e(TAG, "dispatchKeyEvent - volume up");
            }
        }
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            if (mRemoteMediaPlayer != null) {
                double currentVolume = Cast.CastApi.getVolume(mApiClient);
                if (currentVolume > 0.0) {
                    try {
                        Cast.CastApi.setVolume(mApiClient, Math.max(currentVolume - VOLUME_INCREMENT, 0.0));
                    } catch (Exception e) {
                        Log.e(TAG, "unable to set volume", e);
                    }
                }
            } else {
                Log.e(TAG, "dispatchKeyEvent - volume down");
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:com.mooshim.mooshimeter.main.PreferencesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final PreferencesActivity mThis = this;
    Intent intent = getIntent();//from  w w w. ja va 2  s. c o m
    mMeter = ScanActivity.getDeviceWithAddress(intent.getStringExtra("addr"));
    setContentView(R.layout.activity_meter_preference);
    final EditText name_editor = (EditText) findViewById(R.id.meter_rename_edit);
    rateButtons[0] = (Button) findViewById(R.id.rate_button0);
    rateButtons[1] = (Button) findViewById(R.id.rate_button1);
    rateButtons[2] = (Button) findViewById(R.id.rate_button2);
    rateButtons[3] = (Button) findViewById(R.id.rate_button3);

    if (mMeter.meter_name.name != null) {
        name_editor.setText(mMeter.meter_name.name);
    } else {
        name_editor.setText("Mooshimeter V.1");
    }
    name_editor.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                mMeter.meter_name.name = String.valueOf(name_editor.getText());
                mMeter.meter_name.send();
                Log.d(null, "Name sent");
                Toast.makeText(mThis, "Name Sent", Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });
    rateButtonRefresh();
}

From source file:io.github.hidroh.materialistic.WebFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    if (mIsHackerNewsUrl) {
        return createLocalView(container, savedInstanceState);
    }/* w  ww  .  j a v  a  2  s. c o  m*/

    final View view = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_web, container, false);
    mScrollView = (NestedScrollView) view.findViewById(R.id.nested_scroll_view);
    final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress);
    mWebView = (WebView) view.findViewById(R.id.web_view);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
                mWebView.setBackgroundColor(Color.WHITE);
                mWebView.setVisibility(mExternalRequired ? View.GONE : View.VISIBLE);
            }
        }
    });
    mWebView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            if (getActivity() == null) {
                return;
            }
            final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            if (intent.resolveActivity(getActivity().getPackageManager()) == null) {
                return;
            }
            mExternalRequired = true;
            mWebView.setVisibility(View.GONE);
            view.findViewById(R.id.empty).setVisibility(View.VISIBLE);
            view.findViewById(R.id.download_button).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(intent);
                }
            });
        }
    });
    mWebView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                    return true;
                }
            }
            return false;
        }
    });
    setWebViewSettings(mWebView.getSettings());
    return view;
}

From source file:com.gecq.musicwave.player.MediaButtonIntentReceiver.java

/**
 * {@inheritDoc}// w  w  w. j a v  a2 s  .c  om
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    if (DEBUG)
        Log.v(TAG, "Received intent: " + intent);
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, PlayerService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = PlayerService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = PlayerService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = PlayerService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = PlayerService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = PlayerService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = PlayerService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (PlayerService.CMDTOGGLEPAUSE.equals(command) || PlayerService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:org.yaawp.hmi.activities.CustomActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.i(TAG, "onKeyDown( KeyCode=" + keyCode + " KeyEvent=" + event.getAction());
    boolean status = false;

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.getKeyCode() == lastKeyCode
                && event.getDownTime() - lastPressedTime < Const.DOUBLE_PRESS_HK_BACK_PERIOD) {
            status = onKeyTwiceDown(event.getKeyCode(), event);
        } else {//from  w w  w.j ava  2 s  .  c o  m
            lastPressedTime = event.getDownTime();
            lastKeyCode = event.getKeyCode();
            status = onKeyOnceDown(keyCode, event);
        }
    } else {
        status = super.onKeyDown(keyCode, event);
    }
    return status;
}

From source file:com.mobicage.rogerthat.plugins.friends.ServiceSearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.service_search);

    mSearchCategoryLabels = (LinearLayout) findViewById(R.id.search_category);
    mSearchCategoryViewFlipper = (SafeViewFlipper) findViewById(R.id.search_result_lists);

    mSearchInfoByCategory = new HashMap<String, ServiceSearchActivity.SearchInfo>();
    mSearchInfoByListView = new HashMap<AbsListView, ServiceSearchActivity.SearchInfo>();

    mGestureScanner = new GestureDetector(new ViewFlipperSlider(mOnSwipeLeft, mOnSwipeRight));

    final Context ctx = this;
    final EditText editText = (EditText) findViewById(R.id.search_text);
    editText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override/*from   w w w  .  j a v  a2s .  c o  m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                if (!TextUtils.isEmptyOrWhitespace(mSearchString)) {
                    UIUtils.hideKeyboard(ServiceSearchActivity.this, v);
                    launchFindServiceCall();
                    return true;
                }
            }
            return false;
        }
    });
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            mSearchString = s.toString();
            clearSearches();
        }
    });

    findViewById(R.id.search_button).setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            if (TextUtils.isEmptyOrWhitespace(mSearchString)) {
                mSearchString = "";
            }
            UIUtils.hideKeyboard(ctx, editText);
            clearSearches();
            launchFindServiceCall();
        }
    });
}

From source file:org.videolan.vlc.gui.dialogs.PickTimeFragment.java

@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN)
        return false;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
        updateViews(keyCode);/*from  w ww.ja v a2  s  .  c o  m*/
        return true;
    }
    return false;
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.playback.PlaybackAndroidService.java

private void onActionMediaButton(@NonNull final Intent intent) {
    final KeyEvent keyEvent = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyEvent.getKeyCode()) {
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            onActionPlayPause();//from  w w w  .  j  a v a  2  s  . co m
            break;

        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            onActionPause();
            break;

        case KeyEvent.KEYCODE_MEDIA_NEXT:
            onActionNext();
            break;

        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            onActionPrev();
            break;

        case KeyEvent.KEYCODE_MEDIA_STOP:
            onActionStop();
            break;

        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            onActionPlayPause();
            break;
        }
    }
}